diff --git a/CHANGELOG.md b/CHANGELOG.md index 2287b2f9d433..b63111cab722 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -936,6 +936,7 @@ All notable changes to this project will be documented in this file. [`for_loop_over_result`]: https://rust-lang.github.io/rust-clippy/master/index.html#for_loop_over_result [`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 +[`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_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 diff --git a/README.md b/README.md index a779d0dd1f8a..c25c83d87520 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ A collection of lints to catch common mistakes and improve your [Rust](https://github.com/rust-lang/rust) code. -[There are 303 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html) +[There are 304 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html) We have a bunch of lint categories to allow you to choose how much Clippy is supposed to ~~annoy~~ help you: diff --git a/clippy_lints/src/consts.rs b/clippy_lints/src/consts.rs index 8f18102101d3..ef415f453305 100644 --- a/clippy_lints/src/consts.rs +++ b/clippy_lints/src/consts.rs @@ -14,7 +14,7 @@ use std::cmp::PartialOrd; use std::convert::TryInto; use std::hash::{Hash, Hasher}; use syntax::ast::{FloatTy, LitKind}; -use syntax_pos::symbol::{LocalInternedString, Symbol}; +use syntax_pos::symbol::Symbol; /// A `LitKind`-like enum to fold constant `Expr`s into. #[derive(Debug, Clone)] @@ -250,14 +250,18 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> { if let ExprKind::Path(qpath) = &callee.node; let res = self.tables.qpath_res(qpath, callee.hir_id); if let Some(def_id) = res.opt_def_id(); - let get_def_path = self.lcx.get_def_path(def_id); + let get_def_path = self.lcx.get_def_path(def_id, ); let def_path = get_def_path .iter() - .map(LocalInternedString::get) + .copied() + .map(Symbol::as_str) .collect::>(); - if let &["core", "num", impl_ty, "max_value"] = &def_path[..]; + if def_path[0] == "core"; + if def_path[1] == "num"; + if def_path[3] == "max_value"; + if def_path.len() == 4; then { - let value = match impl_ty { + let value = match &*def_path[2] { "" => i8::max_value() as u128, "" => i16::max_value() as u128, "" => i32::max_value() as u128, @@ -326,7 +330,7 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> { let res = self.tables.qpath_res(qpath, id); match res { - Res::Def(DefKind::Const, def_id) | Res::Def(DefKind::AssociatedConst, def_id) => { + Res::Def(DefKind::Const, def_id) | Res::Def(DefKind::AssocConst, def_id) => { let substs = self.tables.node_substs(id); let substs = if self.substs.is_empty() { substs diff --git a/clippy_lints/src/copies.rs b/clippy_lints/src/copies.rs index d85cf97a6bdd..c1e06be7d6bc 100644 --- a/clippy_lints/src/copies.rs +++ b/clippy_lints/src/copies.rs @@ -152,7 +152,7 @@ fn lint_same_cond(cx: &LateContext<'_, '_>, conds: &[&Expr]) { let eq: &dyn Fn(&&Expr, &&Expr) -> bool = &|&lhs, &rhs| -> bool { SpanlessEq::new(cx).ignore_fn().eq_expr(lhs, rhs) }; - if let Some((i, j)) = search_same(conds, hash, eq) { + for (i, j) in search_same(conds, hash, eq) { span_note_and_lint( cx, IFS_SAME_COND, @@ -185,7 +185,7 @@ fn lint_match_arms(cx: &LateContext<'_, '_>, expr: &Expr) { }; let indexed_arms: Vec<(usize, &Arm)> = arms.iter().enumerate().collect(); - if let Some((&(_, i), &(_, j))) = search_same(&indexed_arms, hash, eq) { + for (&(_, i), &(_, j)) in search_same(&indexed_arms, hash, eq) { span_lint_and_then( cx, MATCH_SAME_ARMS, @@ -217,7 +217,10 @@ fn lint_match_arms(cx: &LateContext<'_, '_>, expr: &Expr) { ), ); } else { - db.span_note(i.body.span, &format!("consider refactoring into `{} | {}`", lhs, rhs)); + db.span_help( + i.pats[0].span, + &format!("consider refactoring into `{} | {}`", lhs, rhs), + ); } } }, @@ -323,21 +326,33 @@ where None } -fn search_same(exprs: &[T], hash: Hash, eq: Eq) -> Option<(&T, &T)> +fn search_common_cases<'a, T, Eq>(exprs: &'a [T], eq: &Eq) -> Option<(&'a T, &'a T)> where - Hash: Fn(&T) -> u64, Eq: Fn(&T, &T) -> bool, { - // common cases if exprs.len() < 2 { - return None; + None } else if exprs.len() == 2 { - return if eq(&exprs[0], &exprs[1]) { + if eq(&exprs[0], &exprs[1]) { Some((&exprs[0], &exprs[1])) } else { None - }; + } + } else { + None } +} + +fn search_same(exprs: &[T], hash: Hash, eq: Eq) -> Vec<(&T, &T)> +where + Hash: Fn(&T) -> u64, + Eq: Fn(&T, &T) -> bool, +{ + if let Some(expr) = search_common_cases(&exprs, &eq) { + return vec![expr]; + } + + let mut match_expr_list: Vec<(&T, &T)> = Vec::new(); let mut map: FxHashMap<_, Vec<&_>> = FxHashMap::with_capacity_and_hasher(exprs.len(), BuildHasherDefault::default()); @@ -347,7 +362,7 @@ where Entry::Occupied(mut o) => { for o in o.get() { if eq(o, expr) { - return Some((o, expr)); + match_expr_list.push((o, expr)); } } o.get_mut().push(expr); @@ -358,5 +373,5 @@ where } } - None + match_expr_list } diff --git a/clippy_lints/src/get_last_with_len.rs b/clippy_lints/src/get_last_with_len.rs new file mode 100644 index 000000000000..d6b739e77909 --- /dev/null +++ b/clippy_lints/src/get_last_with_len.rs @@ -0,0 +1,105 @@ +//! lint on using `x.get(x.len() - 1)` instead of `x.last()` + +use crate::utils::{match_type, paths, snippet_with_applicability, span_lint_and_sugg, SpanlessEq}; +use if_chain::if_chain; +use rustc::hir::{BinOpKind, Expr, ExprKind}; +use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; +use rustc::{declare_lint_pass, declare_tool_lint}; +use rustc_errors::Applicability; +use syntax::ast::LitKind; +use syntax::source_map::Spanned; +use syntax::symbol::Symbol; + +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<'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.node; + + // Method name is "get" + if path.ident.name == Symbol::intern("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.tables.expr_ty(struct_calling_on); + if match_type(cx, struct_ty, &paths::VEC); + + // 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.node; + + // LHS of subtraction is "x.len()" + if let ExprKind::MethodCall(arg_lhs_path, _, lhs_args) = &lhs.node; + if arg_lhs_path.ident.name == Symbol::intern("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.node; + if let LitKind::Int(rhs_value, ..) = rhs_lit.node; + if rhs_value == 1; + + 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/len_zero.rs b/clippy_lints/src/len_zero.rs index 624e5eabff05..3dc0765c6373 100644 --- a/clippy_lints/src/len_zero.rs +++ b/clippy_lints/src/len_zero.rs @@ -120,7 +120,7 @@ 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 { item.ident.name.as_str() == name - && if let AssociatedItemKind::Method { has_self } = item.kind { + && if let AssocItemKind::Method { has_self } = item.kind { has_self && { let did = cx.tcx.hir().local_def_id_from_hir_id(item.id.hir_id); cx.tcx.fn_sig(did).inputs().skip_binder().len() == 1 @@ -148,7 +148,7 @@ fn check_trait_items(cx: &LateContext<'_, '_>, visited_trait: &Item, trait_items .iter() .flat_map(|&i| cx.tcx.associated_items(i)) .any(|i| { - i.kind == ty::AssociatedKind::Method + i.kind == ty::AssocKind::Method && i.method_has_self_argument && i.ident.name == sym!(is_empty) && cx.tcx.fn_sig(i.def_id).inputs().skip_binder().len() == 1 @@ -171,7 +171,7 @@ fn check_trait_items(cx: &LateContext<'_, '_>, visited_trait: &Item, trait_items 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 AssociatedItemKind::Method { has_self } = item.kind { + && if let AssocItemKind::Method { has_self } = item.kind { has_self && { let did = cx.tcx.hir().local_def_id_from_hir_id(item.id.hir_id); cx.tcx.fn_sig(did).inputs().skip_binder().len() == 1 @@ -258,9 +258,9 @@ fn check_len( /// Checks if this type has an `is_empty` method. fn has_is_empty(cx: &LateContext<'_, '_>, expr: &Expr) -> bool { - /// Gets an `AssociatedItem` and return true if it matches `is_empty(self)`. - fn is_is_empty(cx: &LateContext<'_, '_>, item: &ty::AssociatedItem) -> bool { - if let ty::AssociatedKind::Method = item.kind { + /// 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::Method = item.kind { if item.ident.name.as_str() == "is_empty" { let sig = cx.tcx.fn_sig(item.def_id); let ty = sig.skip_binder(); diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index f74593662634..53143800f763 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -186,6 +186,7 @@ pub mod fallible_impl_from; pub mod format; pub mod formatting; pub mod functions; +pub mod get_last_with_len; pub mod identity_conversion; pub mod identity_op; pub mod if_not_else; @@ -492,6 +493,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) { reg.register_late_lint_pass(box types::CharLitAsU8); reg.register_late_lint_pass(box vec::UselessVec); reg.register_late_lint_pass(box drop_bounds::DropBounds); + reg.register_late_lint_pass(box get_last_with_len::GetLastWithLen); reg.register_late_lint_pass(box drop_forget_ref::DropForgetRef); reg.register_late_lint_pass(box empty_enum::EmptyEnum); reg.register_late_lint_pass(box types::AbsurdExtremeComparisons); @@ -710,6 +712,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) { formatting::SUSPICIOUS_ELSE_FORMATTING, functions::NOT_UNSAFE_PTR_ARG_DEREF, functions::TOO_MANY_ARGUMENTS, + get_last_with_len::GET_LAST_WITH_LEN, identity_conversion::IDENTITY_CONVERSION, identity_op::IDENTITY_OP, indexing_slicing::OUT_OF_BOUNDS_INDEXING, @@ -981,6 +984,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) { explicit_write::EXPLICIT_WRITE, format::USELESS_FORMAT, functions::TOO_MANY_ARGUMENTS, + get_last_with_len::GET_LAST_WITH_LEN, identity_conversion::IDENTITY_CONVERSION, identity_op::IDENTITY_OP, int_plus_one::INT_PLUS_ONE, diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index de7d5a46453a..4e57b46207d5 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -2157,7 +2157,7 @@ fn lint_binary_expr_with_method_call(cx: &LateContext<'_, '_>, info: &mut Binary lint_with_both_lhs_and_rhs!(lint_chars_last_cmp_with_unwrap, cx, info); } -/// Wrapper fn for `CHARS_NEXT_CMP` and `CHARS_NEXT_CMP` lints. +/// Wrapper fn for `CHARS_NEXT_CMP` and `CHARS_LAST_CMP` lints. fn lint_chars_cmp( cx: &LateContext<'_, '_>, info: &BinaryExprInfo<'_>, diff --git a/clippy_lints/src/new_without_default.rs b/clippy_lints/src/new_without_default.rs index e325f0e70fde..747548328264 100644 --- a/clippy_lints/src/new_without_default.rs +++ b/clippy_lints/src/new_without_default.rs @@ -95,7 +95,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NewWithoutDefault { fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx hir::Item) { if let hir::ItemKind::Impl(_, _, _, _, None, _, ref items) = item.node { for assoc_item in items { - if let hir::AssociatedItemKind::Method { has_self: false } = assoc_item.kind { + if let hir::AssocItemKind::Method { 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; diff --git a/clippy_lints/src/non_copy_const.rs b/clippy_lints/src/non_copy_const.rs index 2d56b4ee8b4e..2652e5e75d33 100644 --- a/clippy_lints/src/non_copy_const.rs +++ b/clippy_lints/src/non_copy_const.rs @@ -195,7 +195,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonCopyConst { // Make sure it is a const item. match cx.tables.qpath_res(qpath, expr.hir_id) { - Res::Def(DefKind::Const, _) | Res::Def(DefKind::AssociatedConst, _) => {}, + Res::Def(DefKind::Const, _) | Res::Def(DefKind::AssocConst, _) => {}, _ => return, }; diff --git a/clippy_lints/src/returns.rs b/clippy_lints/src/returns.rs index d53a64c98f25..8976d73fc9a2 100644 --- a/clippy_lints/src/returns.rs +++ b/clippy_lints/src/returns.rs @@ -7,7 +7,7 @@ use syntax::source_map::Span; use syntax::visit::FnKind; use syntax_pos::BytePos; -use crate::utils::{in_macro_or_desugar, match_path_ast, snippet_opt, span_lint_and_then, span_note_and_lint}; +use crate::utils::{in_macro_or_desugar, match_path_ast, snippet_opt, span_lint_and_then}; declare_clippy_lint! { /// **What it does:** Checks for return statements at the end of a block. @@ -164,13 +164,28 @@ impl Return { if match_path_ast(path, &[&*ident.name.as_str()]); if !in_external_macro(cx.sess(), initexpr.span); then { - span_note_and_lint(cx, - LET_AND_RETURN, - retexpr.span, - "returning the result of a let binding from a block. \ - Consider returning the expression directly.", - initexpr.span, - "this expression can be directly returned"); + 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(snippet) = snippet_opt(cx, initexpr.span) { + 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"); + } + }, + ); } } } diff --git a/clippy_lints/src/trivially_copy_pass_by_ref.rs b/clippy_lints/src/trivially_copy_pass_by_ref.rs index 9866540220d2..319f6311e88e 100644 --- a/clippy_lints/src/trivially_copy_pass_by_ref.rs +++ b/clippy_lints/src/trivially_copy_pass_by_ref.rs @@ -65,7 +65,7 @@ impl<'a, 'tcx> TriviallyCopyPassByRef { // portability problems between 32 and 64-bit targets let bit_width = cmp::min(bit_width, 32); let byte_width = bit_width / 8; - // Use a limit of 2 times the register bit width + // Use a limit of 2 times the register byte width byte_width * 2 }); Self { limit } @@ -118,7 +118,7 @@ impl<'a, 'tcx> TriviallyCopyPassByRef { cx, TRIVIALLY_COPY_PASS_BY_REF, input.span, - "this argument is passed by reference, but would be more efficient if passed by value", + &format!("this argument ({} byte) is passed by reference, but would be more efficient if passed by value (limit: {} byte)", size, self.limit), "consider passing by value instead", value_type, Applicability::Unspecified, @@ -130,7 +130,7 @@ impl<'a, 'tcx> TriviallyCopyPassByRef { fn check_trait_items(&mut self, cx: &LateContext<'_, '_>, trait_items: &[TraitItemRef]) { for item in trait_items { - if let AssociatedItemKind::Method { .. } = item.kind { + if let AssocItemKind::Method { .. } = item.kind { self.check_trait_method(cx, item); } } diff --git a/clippy_lints/src/types.rs b/clippy_lints/src/types.rs index 7bce42369dc8..7b41bea4ff4b 100644 --- a/clippy_lints/src/types.rs +++ b/clippy_lints/src/types.rs @@ -18,6 +18,7 @@ use rustc_typeck::hir_ty_to_ty; use syntax::ast::{FloatTy, IntTy, UintTy}; use syntax::errors::DiagnosticBuilder; use syntax::source_map::Span; +use syntax::symbol::sym; use crate::consts::{constant, Constant}; use crate::utils::paths; @@ -1091,7 +1092,7 @@ fn is_c_void(cx: &LateContext<'_, '_>, ty: Ty<'_>) -> bool { if names.is_empty() { return false; } - if names[0] == "libc" || names[0] == "core" && *names.last().unwrap() == "c_void" { + if names[0] == sym!(libc) || names[0] == sym::core && *names.last().unwrap() == sym!(c_void) { return true; } } diff --git a/clippy_lints/src/unicode.rs b/clippy_lints/src/unicode.rs index d96596bbb525..15c74eff73b1 100644 --- a/clippy_lints/src/unicode.rs +++ b/clippy_lints/src/unicode.rs @@ -1,7 +1,8 @@ -use crate::utils::{is_allowed, snippet, span_help_and_lint}; +use crate::utils::{is_allowed, snippet, span_lint_and_sugg}; use rustc::hir::*; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use rustc::{declare_lint_pass, declare_tool_lint}; +use rustc_errors::Applicability; use syntax::ast::LitKind; use syntax::source_map::Span; use unicode_normalization::UnicodeNormalization; @@ -34,7 +35,11 @@ declare_clippy_lint! { /// /// **Example:** /// ```rust - /// let x = "Hä?" + /// let x = String::from("€"); + /// ``` + /// Could be written as: + /// ```rust + /// let x = String::from("\u{20ac}"); /// ``` pub NON_ASCII_LITERAL, pedantic, @@ -87,43 +92,40 @@ fn escape>(s: T) -> String { fn check_str(cx: &LateContext<'_, '_>, span: Span, id: HirId) { let string = snippet(cx, span, ""); if string.contains('\u{200B}') { - span_help_and_lint( + span_lint_and_sugg( cx, ZERO_WIDTH_SPACE, span, "zero-width space detected", - &format!( - "Consider replacing the string with:\n\"{}\"", - string.replace("\u{200B}", "\\u{200B}") - ), + "consider replacing the string with", + string.replace("\u{200B}", "\\u{200B}"), + Applicability::MachineApplicable, ); } if string.chars().any(|c| c as u32 > 0x7F) { - span_help_and_lint( + span_lint_and_sugg( cx, NON_ASCII_LITERAL, span, "literal non-ASCII character detected", - &format!( - "Consider replacing the string with:\n\"{}\"", - if is_allowed(cx, UNICODE_NOT_NFC, id) { - escape(string.chars()) - } else { - escape(string.nfc()) - } - ), + "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_help_and_lint( + span_lint_and_sugg( cx, UNICODE_NOT_NFC, span, "non-nfc unicode sequence detected", - &format!( - "Consider replacing the string with:\n\"{}\"", - string.nfc().collect::() - ), + "consider replacing the string with", + string.nfc().collect::(), + Applicability::MachineApplicable, ); } } diff --git a/clippy_lints/src/use_self.rs b/clippy_lints/src/use_self.rs index c6ada386f2aa..c18922a394c7 100644 --- a/clippy_lints/src/use_self.rs +++ b/clippy_lints/src/use_self.rs @@ -119,7 +119,7 @@ fn check_trait_method_impl_decl<'a, 'tcx: 'a>( .tcx .associated_items(impl_trait_ref.def_id) .find(|assoc_item| { - assoc_item.kind == ty::AssociatedKind::Method + assoc_item.kind == ty::AssocKind::Method && cx .tcx .hygienic_eq(impl_item.ident, assoc_item.ident, impl_trait_ref.def_id) diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index 179e006ed058..a812b1709bbc 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -1123,5 +1123,7 @@ mod test { } pub fn match_def_path<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, did: DefId, syms: &[&str]) -> bool { + // HACK: find a way to use symbols from clippy or just go fully to diagnostic items + let syms: Vec<_> = syms.iter().map(|sym| Symbol::intern(sym)).collect(); cx.match_def_path(did, &syms) } diff --git a/tests/ui-toml/toml_trivially_copy/test.rs b/tests/ui-toml/toml_trivially_copy/test.rs index f24fe51d30f0..6dcbae040750 100644 --- a/tests/ui-toml/toml_trivially_copy/test.rs +++ b/tests/ui-toml/toml_trivially_copy/test.rs @@ -1,3 +1,6 @@ +// normalize-stderr-test "\(\d+ byte\)" -> "(N byte)" +// normalize-stderr-test "\(limit: \d+ byte\)" -> "(limit: N byte)" + #![allow(clippy::many_single_char_names)] #[derive(Copy, Clone)] diff --git a/tests/ui-toml/toml_trivially_copy/test.stderr b/tests/ui-toml/toml_trivially_copy/test.stderr index 746b9ffa4af1..d2b55eff16db 100644 --- a/tests/ui-toml/toml_trivially_copy/test.stderr +++ b/tests/ui-toml/toml_trivially_copy/test.stderr @@ -1,13 +1,13 @@ -error: this argument is passed by reference, but would be more efficient if passed by value - --> $DIR/test.rs:11:11 +error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte) + --> $DIR/test.rs:14:11 | 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` -error: this argument is passed by reference, but would be more efficient if passed by value - --> $DIR/test.rs:11:20 +error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte) + --> $DIR/test.rs:14:20 | LL | fn bad(x: &u16, y: &Foo) {} | ^^^^ help: consider passing by value instead: `Foo` diff --git a/tests/ui/author/matches.stderr b/tests/ui/author/matches.stderr index fa7e5cce43c2..74d070dc4b28 100644 --- a/tests/ui/author/matches.stderr +++ b/tests/ui/author/matches.stderr @@ -1,15 +1,17 @@ -error: returning the result of a let binding from a block. Consider returning the expression directly. +error: returning the result of a let binding from a block --> $DIR/matches.rs:9:13 | +LL | let x = 3; + | ---------- unnecessary let binding LL | x | ^ | = note: `-D clippy::let-and-return` implied by `-D warnings` -note: this expression can be directly returned - --> $DIR/matches.rs:8:21 +help: return the expression directly + | +LL | +LL | 3 | -LL | let x = 3; - | ^ error: aborting due to previous error diff --git a/tests/ui/get_last_with_len.fixed b/tests/ui/get_last_with_len.fixed new file mode 100644 index 000000000000..c8b363f9c38e --- /dev/null +++ b/tests/ui/get_last_with_len.fixed @@ -0,0 +1,31 @@ +// 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 new file mode 100644 index 000000000000..bf9cb2d7e0cc --- /dev/null +++ b/tests/ui/get_last_with_len.rs @@ -0,0 +1,31 @@ +// 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 new file mode 100644 index 000000000000..55baf87384a2 --- /dev/null +++ b/tests/ui/get_last_with_len.stderr @@ -0,0 +1,10 @@ +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/if_same_then_else.rs b/tests/ui/if_same_then_else.rs index 0ec933e87847..d1213e5e5fda 100644 --- a/tests/ui/if_same_then_else.rs +++ b/tests/ui/if_same_then_else.rs @@ -232,6 +232,20 @@ fn if_same_then_else() -> Result<&'static str, ()> { 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 = ""; diff --git a/tests/ui/if_same_then_else.stderr b/tests/ui/if_same_then_else.stderr index b170db31b853..fa42afff0be0 100644 --- a/tests/ui/if_same_then_else.stderr +++ b/tests/ui/if_same_then_else.stderr @@ -210,5 +210,38 @@ LL | | try!(Ok("foo")); LL | | } else { | |_____^ -error: aborting due to 10 previous errors +error: this `if` has identical blocks + --> $DIR/if_same_then_else.rs:244:12 + | +LL | } else { + | ____________^ +LL | | let foo = ""; +LL | | return Ok(&foo[0..]); +LL | | } + | |_____^ + | +note: same as this + --> $DIR/if_same_then_else.rs:241:20 + | +LL | } else if true { + | ____________________^ +LL | | let foo = ""; +LL | | return Ok(&foo[0..]); +LL | | } else { + | |_____^ + +error: this `if` has the same condition as a previous if + --> $DIR/if_same_then_else.rs:241:15 + | +LL | } else if true { + | ^^^^ + | + = note: #[deny(clippy::ifs_same_cond)] on by default +note: same as this + --> $DIR/if_same_then_else.rs:235:8 + | +LL | if true { + | ^^^^ + +error: aborting due to 12 previous errors diff --git a/tests/ui/let_return.stderr b/tests/ui/let_return.stderr index 69c4720c9b3f..319f45c0a8a0 100644 --- a/tests/ui/let_return.stderr +++ b/tests/ui/let_return.stderr @@ -1,27 +1,30 @@ -error: returning the result of a let binding from a block. Consider returning the expression directly. +error: returning the result of a let binding from a block --> $DIR/let_return.rs:7:5 | +LL | let x = 5; + | ---------- unnecessary let binding LL | x | ^ | = note: `-D clippy::let-and-return` implied by `-D warnings` -note: this expression can be directly returned - --> $DIR/let_return.rs:6:13 +help: return the expression directly + | +LL | +LL | 5 | -LL | let x = 5; - | ^ -error: returning the result of a let binding from a block. Consider returning the expression directly. +error: returning the result of a let binding from a block --> $DIR/let_return.rs:13:9 | +LL | let x = 5; + | ---------- unnecessary let binding LL | x | ^ +help: return the expression directly | -note: this expression can be directly returned - --> $DIR/let_return.rs:12:17 +LL | +LL | 5 | -LL | let x = 5; - | ^ error: aborting due to 2 previous errors diff --git a/tests/ui/match_same_arms.rs b/tests/ui/match_same_arms.rs index 8a7588f2e7f7..880518b010a7 100644 --- a/tests/ui/match_same_arms.rs +++ b/tests/ui/match_same_arms.rs @@ -108,6 +108,22 @@ fn match_same_arms() { (None, Some(a)) => bar(a), // bindings have different types _ => (), } + + 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, + }; } fn main() {} diff --git a/tests/ui/match_same_arms.stderr b/tests/ui/match_same_arms.stderr index 9389e48a3e4b..42c6f910dc30 100644 --- a/tests/ui/match_same_arms.stderr +++ b/tests/ui/match_same_arms.stderr @@ -65,11 +65,11 @@ note: same as this | LL | 42 => foo(), | ^^^^^ -note: consider refactoring into `42 | 51` - --> $DIR/match_same_arms.rs:56:15 +help: consider refactoring into `42 | 51` + --> $DIR/match_same_arms.rs:56:9 | LL | 42 => foo(), - | ^^^^^ + | ^^ error: this `match` has identical arm bodies --> $DIR/match_same_arms.rs:63:17 @@ -82,11 +82,11 @@ note: same as this | LL | Some(_) => 24, | ^^ -note: consider refactoring into `Some(_) | None` - --> $DIR/match_same_arms.rs:62:20 +help: consider refactoring into `Some(_) | None` + --> $DIR/match_same_arms.rs:62:9 | LL | Some(_) => 24, - | ^^ + | ^^^^^^^ error: this `match` has identical arm bodies --> $DIR/match_same_arms.rs:85:28 @@ -99,11 +99,11 @@ note: same as this | LL | (Some(a), None) => bar(a), | ^^^^^^ -note: consider refactoring into `(Some(a), None) | (None, Some(a))` - --> $DIR/match_same_arms.rs:84:28 +help: consider refactoring into `(Some(a), None) | (None, Some(a))` + --> $DIR/match_same_arms.rs:84:9 | LL | (Some(a), None) => bar(a), - | ^^^^^^ + | ^^^^^^^^^^^^^^^ error: this `match` has identical arm bodies --> $DIR/match_same_arms.rs:91:26 @@ -116,11 +116,11 @@ note: same as this | LL | (Some(a), ..) => bar(a), | ^^^^^^ -note: consider refactoring into `(Some(a), ..) | (.., Some(a))` - --> $DIR/match_same_arms.rs:90:26 +help: consider refactoring into `(Some(a), ..) | (.., Some(a))` + --> $DIR/match_same_arms.rs:90:9 | LL | (Some(a), ..) => bar(a), - | ^^^^^^ + | ^^^^^^^^^^^^^ error: this `match` has identical arm bodies --> $DIR/match_same_arms.rs:97:20 @@ -133,11 +133,96 @@ note: same as this | LL | (1, .., 3) => 42, | ^^ -note: consider refactoring into `(1, .., 3) | (.., 3)` - --> $DIR/match_same_arms.rs:96:23 +help: consider refactoring into `(1, .., 3) | (.., 3)` + --> $DIR/match_same_arms.rs:96:9 | LL | (1, .., 3) => 42, - | ^^ + | ^^^^^^^^^^ + +error: this `match` has identical arm bodies + --> $DIR/match_same_arms.rs:114:15 + | +LL | 51 => 1, //~ ERROR match arms have same body + | ^ + | +note: same as this + --> $DIR/match_same_arms.rs:113:15 + | +LL | 42 => 1, + | ^ +help: consider refactoring into `42 | 51` + --> $DIR/match_same_arms.rs:113:9 + | +LL | 42 => 1, + | ^^ + +error: this `match` has identical arm bodies + --> $DIR/match_same_arms.rs:116:15 + | +LL | 52 => 2, //~ ERROR match arms have same body + | ^ + | +note: same as this + --> $DIR/match_same_arms.rs:115:15 + | +LL | 41 => 2, + | ^ +help: consider refactoring into `41 | 52` + --> $DIR/match_same_arms.rs:115:9 + | +LL | 41 => 2, + | ^^ + +error: this `match` has identical arm bodies + --> $DIR/match_same_arms.rs:122:14 + | +LL | 2 => 2, //~ ERROR 2nd matched arms have same body + | ^ + | +note: same as this + --> $DIR/match_same_arms.rs:121:14 + | +LL | 1 => 2, + | ^ +help: consider refactoring into `1 | 2` + --> $DIR/match_same_arms.rs:121:9 + | +LL | 1 => 2, + | ^ + +error: this `match` has identical arm bodies + --> $DIR/match_same_arms.rs:123:14 + | +LL | 3 => 2, //~ ERROR 3rd matched arms have same body + | ^ + | +note: same as this + --> $DIR/match_same_arms.rs:121:14 + | +LL | 1 => 2, + | ^ +help: consider refactoring into `1 | 3` + --> $DIR/match_same_arms.rs:121:9 + | +LL | 1 => 2, + | ^ + +error: this `match` has identical arm bodies + --> $DIR/match_same_arms.rs:123:14 + | +LL | 3 => 2, //~ ERROR 3rd matched arms have same body + | ^ + | +note: same as this + --> $DIR/match_same_arms.rs:122:14 + | +LL | 2 => 2, //~ ERROR 2nd matched arms have same body + | ^ +help: consider refactoring into `2 | 3` + --> $DIR/match_same_arms.rs:122:9 + | +LL | 2 => 2, //~ ERROR 2nd matched arms have same body + | ^ -error: aborting due to 7 previous errors +error: aborting due to 12 previous errors diff --git a/tests/ui/matches.stderr b/tests/ui/matches.stderr index 27438258d232..232ae28009b6 100644 --- a/tests/ui/matches.stderr +++ b/tests/ui/matches.stderr @@ -89,11 +89,11 @@ note: same as this | LL | Ok(3) => println!("ok"), | ^^^^^^^^^^^^^^ -note: consider refactoring into `Ok(3) | Ok(_)` - --> $DIR/matches.rs:53:18 +help: consider refactoring into `Ok(3) | Ok(_)` + --> $DIR/matches.rs:53:9 | LL | Ok(3) => println!("ok"), - | ^^^^^^^^^^^^^^ + | ^^^^^ = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) error: Err(_) will match all errors, maybe not a good idea @@ -115,11 +115,11 @@ note: same as this | LL | Ok(3) => println!("ok"), | ^^^^^^^^^^^^^^ -note: consider refactoring into `Ok(3) | Ok(_)` - --> $DIR/matches.rs:59:18 +help: consider refactoring into `Ok(3) | Ok(_)` + --> $DIR/matches.rs:59:9 | LL | Ok(3) => println!("ok"), - | ^^^^^^^^^^^^^^ + | ^^^^^ = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) error: Err(_) will match all errors, maybe not a good idea @@ -141,11 +141,11 @@ note: same as this | LL | Ok(3) => println!("ok"), | ^^^^^^^^^^^^^^ -note: consider refactoring into `Ok(3) | Ok(_)` - --> $DIR/matches.rs:65:18 +help: consider refactoring into `Ok(3) | Ok(_)` + --> $DIR/matches.rs:65:9 | LL | Ok(3) => println!("ok"), - | ^^^^^^^^^^^^^^ + | ^^^^^ = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) error: this `match` has identical arm bodies @@ -159,11 +159,11 @@ note: same as this | LL | Ok(3) => println!("ok"), | ^^^^^^^^^^^^^^ -note: consider refactoring into `Ok(3) | Ok(_)` - --> $DIR/matches.rs:74:18 +help: consider refactoring into `Ok(3) | Ok(_)` + --> $DIR/matches.rs:74:9 | LL | Ok(3) => println!("ok"), - | ^^^^^^^^^^^^^^ + | ^^^^^ = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) error: this `match` has identical arm bodies @@ -177,11 +177,11 @@ note: same as this | LL | Ok(3) => println!("ok"), | ^^^^^^^^^^^^^^ -note: consider refactoring into `Ok(3) | Ok(_)` - --> $DIR/matches.rs:81:18 +help: consider refactoring into `Ok(3) | Ok(_)` + --> $DIR/matches.rs:81:9 | LL | Ok(3) => println!("ok"), - | ^^^^^^^^^^^^^^ + | ^^^^^ = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) error: this `match` has identical arm bodies @@ -195,11 +195,11 @@ note: same as this | LL | Ok(3) => println!("ok"), | ^^^^^^^^^^^^^^ -note: consider refactoring into `Ok(3) | Ok(_)` - --> $DIR/matches.rs:87:18 +help: consider refactoring into `Ok(3) | Ok(_)` + --> $DIR/matches.rs:87:9 | LL | Ok(3) => println!("ok"), - | ^^^^^^^^^^^^^^ + | ^^^^^ = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) error: this `match` has identical arm bodies @@ -213,11 +213,11 @@ note: same as this | LL | Ok(3) => println!("ok"), | ^^^^^^^^^^^^^^ -note: consider refactoring into `Ok(3) | Ok(_)` - --> $DIR/matches.rs:93:18 +help: consider refactoring into `Ok(3) | Ok(_)` + --> $DIR/matches.rs:93:9 | LL | Ok(3) => println!("ok"), - | ^^^^^^^^^^^^^^ + | ^^^^^ = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) error: this `match` has identical arm bodies @@ -231,11 +231,11 @@ note: same as this | LL | (Ok(x), Some(_)) => println!("ok {}", x), | ^^^^^^^^^^^^^^^^^^^^ -note: consider refactoring into `(Ok(x), Some(_)) | (Ok(_), Some(x))` - --> $DIR/matches.rs:116:29 +help: consider refactoring into `(Ok(x), Some(_)) | (Ok(_), Some(x))` + --> $DIR/matches.rs:116:9 | LL | (Ok(x), Some(_)) => println!("ok {}", x), - | ^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^ = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) error: this `match` has identical arm bodies @@ -249,11 +249,11 @@ note: same as this | LL | Ok(3) => println!("ok"), | ^^^^^^^^^^^^^^ -note: consider refactoring into `Ok(3) | Ok(_)` - --> $DIR/matches.rs:131:18 +help: consider refactoring into `Ok(3) | Ok(_)` + --> $DIR/matches.rs:131:9 | LL | Ok(3) => println!("ok"), - | ^^^^^^^^^^^^^^ + | ^^^^^ = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) error: you don't need to add `&` to all patterns diff --git a/tests/ui/trivially_copy_pass_by_ref.rs b/tests/ui/trivially_copy_pass_by_ref.rs index c12d98565015..f3af8bf014b9 100644 --- a/tests/ui/trivially_copy_pass_by_ref.rs +++ b/tests/ui/trivially_copy_pass_by_ref.rs @@ -1,3 +1,6 @@ +// normalize-stderr-test "\(\d+ byte\)" -> "(N byte)" +// normalize-stderr-test "\(limit: \d+ byte\)" -> "(limit: N byte)" + #![allow( clippy::many_single_char_names, clippy::blacklisted_name, diff --git a/tests/ui/trivially_copy_pass_by_ref.stderr b/tests/ui/trivially_copy_pass_by_ref.stderr index 754069b421cc..1addc3d7195d 100644 --- a/tests/ui/trivially_copy_pass_by_ref.stderr +++ b/tests/ui/trivially_copy_pass_by_ref.stderr @@ -1,91 +1,91 @@ -error: this argument is passed by reference, but would be more efficient if passed by value - --> $DIR/trivially_copy_pass_by_ref.rs:47:11 +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:50:11 | LL | fn bad(x: &u32, y: &Foo, z: &Baz) {} | ^^^^ help: consider passing by value instead: `u32` | = note: `-D clippy::trivially-copy-pass-by-ref` implied by `-D warnings` -error: this argument is passed by reference, but would be more efficient if passed by value - --> $DIR/trivially_copy_pass_by_ref.rs:47:20 +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:50:20 | LL | fn bad(x: &u32, y: &Foo, z: &Baz) {} | ^^^^ help: consider passing by value instead: `Foo` -error: this argument is passed by reference, but would be more efficient if passed by value - --> $DIR/trivially_copy_pass_by_ref.rs:47:29 +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:50:29 | LL | fn bad(x: &u32, y: &Foo, z: &Baz) {} | ^^^^ help: consider passing by value instead: `Baz` -error: this argument is passed by reference, but would be more efficient if passed by value - --> $DIR/trivially_copy_pass_by_ref.rs:54:12 +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:57:12 | LL | fn bad(&self, x: &u32, y: &Foo, z: &Baz) {} | ^^^^^ help: consider passing by value instead: `self` -error: this argument is passed by reference, but would be more efficient if passed by value - --> $DIR/trivially_copy_pass_by_ref.rs:54:22 +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:57:22 | LL | fn bad(&self, x: &u32, y: &Foo, z: &Baz) {} | ^^^^ help: consider passing by value instead: `u32` -error: this argument is passed by reference, but would be more efficient if passed by value - --> $DIR/trivially_copy_pass_by_ref.rs:54:31 +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:57:31 | LL | fn bad(&self, x: &u32, y: &Foo, z: &Baz) {} | ^^^^ help: consider passing by value instead: `Foo` -error: this argument is passed by reference, but would be more efficient if passed by value - --> $DIR/trivially_copy_pass_by_ref.rs:54:40 +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:57:40 | LL | fn bad(&self, x: &u32, y: &Foo, z: &Baz) {} | ^^^^ help: consider passing by value instead: `Baz` -error: this argument is passed by reference, but would be more efficient if passed by value - --> $DIR/trivially_copy_pass_by_ref.rs:56:16 +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:59:16 | LL | fn bad2(x: &u32, y: &Foo, z: &Baz) {} | ^^^^ help: consider passing by value instead: `u32` -error: this argument is passed by reference, but would be more efficient if passed by value - --> $DIR/trivially_copy_pass_by_ref.rs:56:25 +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:59:25 | LL | fn bad2(x: &u32, y: &Foo, z: &Baz) {} | ^^^^ help: consider passing by value instead: `Foo` -error: this argument is passed by reference, but would be more efficient if passed by value - --> $DIR/trivially_copy_pass_by_ref.rs:56:34 +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:59:34 | LL | fn bad2(x: &u32, y: &Foo, z: &Baz) {} | ^^^^ help: consider passing by value instead: `Baz` -error: this argument is passed by reference, but would be more efficient if passed by value - --> $DIR/trivially_copy_pass_by_ref.rs:68:16 +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:71:16 | LL | fn bad2(x: &u32, y: &Foo, z: &Baz) {} | ^^^^ help: consider passing by value instead: `u32` -error: this argument is passed by reference, but would be more efficient if passed by value - --> $DIR/trivially_copy_pass_by_ref.rs:68:25 +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:71:25 | LL | fn bad2(x: &u32, y: &Foo, z: &Baz) {} | ^^^^ help: consider passing by value instead: `Foo` -error: this argument is passed by reference, but would be more efficient if passed by value - --> $DIR/trivially_copy_pass_by_ref.rs:68:34 +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:71:34 | LL | fn bad2(x: &u32, y: &Foo, z: &Baz) {} | ^^^^ help: consider passing by value instead: `Baz` -error: this argument is passed by reference, but would be more efficient if passed by value - --> $DIR/trivially_copy_pass_by_ref.rs:72:34 +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:75:34 | LL | fn trait_method(&self, _foo: &Foo); | ^^^^ help: consider passing by value instead: `Foo` -error: this argument is passed by reference, but would be more efficient if passed by value - --> $DIR/trivially_copy_pass_by_ref.rs:76:37 +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:79:37 | LL | fn trait_method2(&self, _color: &Color); | ^^^^^^ help: consider passing by value instead: `Color` diff --git a/tests/ui/unicode.stderr b/tests/ui/unicode.stderr index c60dcdaec1d3..641680431a2c 100644 --- a/tests/ui/unicode.stderr +++ b/tests/ui/unicode.stderr @@ -5,8 +5,6 @@ LL | print!("Here >​< is a ZWS, and ​another"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::zero-width-space` implied by `-D warnings` - = help: Consider replacing the string with: - ""Here >/u{200B}< is a ZWS, and /u{200B}another"" error: non-nfc unicode sequence detected --> $DIR/unicode.rs:9:12 @@ -15,8 +13,6 @@ LL | print!("̀àh?"); | ^^^^^ | = note: `-D clippy::unicode-not-nfc` implied by `-D warnings` - = help: Consider replacing the string with: - ""̀àh?"" error: literal non-ASCII character detected --> $DIR/unicode.rs:15:12 @@ -25,8 +21,6 @@ LL | print!("Üben!"); | ^^^^^^^ | = note: `-D clippy::non-ascii-literal` implied by `-D warnings` - = help: Consider replacing the string with: - ""/u{dc}ben!"" error: aborting due to 3 previous errors