diff --git a/clippy_lints/src/attrs.rs b/clippy_lints/src/attrs.rs index 1edb7c950..489945b51 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, @@ -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 51835ee74..43ad0f760 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 ffe6340bd..31cc36985 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 2cdd59c56..3650e4f91 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/duration_subsec.rs b/clippy_lints/src/duration_subsec.rs index 3070d1050..50dd0d84f 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/enum_variants.rs b/clippy_lints/src/enum_variants.rs index fc3a35efa..689ac6184 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 d30dede83..6903073fb 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 2de2bfc04..a70e58c9c 100644 --- a/clippy_lints/src/floating_point_arithmetic.rs +++ b/clippy_lints/src/floating_point_arithmetic.rs @@ -595,7 +595,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]) ); } @@ -692,7 +692,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 968bbc524..0af6b3b7d 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/mod.rs b/clippy_lints/src/loops/mod.rs index e2f9aee06..b03445b8c 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/loops/needless_collect.rs b/clippy_lints/src/loops/needless_collect.rs index 6f3acb45b..ba895f35f 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/match_str_case_mismatch.rs b/clippy_lints/src/match_str_case_mismatch.rs index 3316ebf40..dbf103143 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()); } } } @@ -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), } } @@ -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/matches.rs b/clippy_lints/src/matches.rs index acac08872..22970507f 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; } } @@ -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 7ecafa1f3..4307cbf00 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 3c43671dd..4934240ab 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -80,7 +80,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; @@ -1997,21 +1997,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)) }; } @@ -2028,8 +2028,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); @@ -2184,7 +2184,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/methods/str_splitn.rs b/clippy_lints/src/methods/str_splitn.rs index e5fafdb07..70f20da1d 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/misc.rs b/clippy_lints/src/misc.rs index 2299a0999..401dc2781 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/missing_enforced_import_rename.rs b/clippy_lints/src/missing_enforced_import_rename.rs index 68d49e0f1..566e15ab2 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/multiple_crate_versions.rs b/clippy_lints/src/multiple_crate_versions.rs index e45cc86d4..1f9db39cf 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_lints/src/mut_reference.rs b/clippy_lints/src/mut_reference.rs index 63a1cf7b7..22834cf61 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 a28b08c33..0931fec14 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/non_expressive_names.rs b/clippy_lints/src/non_expressive_names.rs index 5559fac0a..25fbcb3c6 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 a04d589f8..4722c0310 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/open_options.rs b/clippy_lints/src/open_options.rs index 2c77100bd..1b9285c22 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/path_buf_push_overwrite.rs b/clippy_lints/src/path_buf_push_overwrite.rs index 8ebee9bd0..e58ca95fa 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 8e5983b47..b6d04334d 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/serde_api.rs b/clippy_lints/src/serde_api.rs index a38b3c4ab..398e2c200 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/stable_sort_primitive.rs b/clippy_lints/src/stable_sort_primitive.rs index 953d21e07..20e38dc56 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 73600a8a0..ad8e72ad7 100644 --- a/clippy_lints/src/strings.rs +++ b/clippy_lints/src/strings.rs @@ -327,7 +327,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 85257f311..6d9aff474 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_io_amount.rs b/clippy_lints/src/unused_io_amount.rs index 111413e51..004530db0 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/unused_unit.rs b/clippy_lints/src/unused_unit.rs index 48c17fa2a..bfd17a687 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/unwrap.rs b/clippy_lints/src/unwrap.rs index 71771aae4..01a569122 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 4773e3507..0c62161e5 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 0e4b32541..abd8a3623 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) { diff --git a/clippy_lints/src/write.rs b/clippy_lints/src/write.rs index 5bf0cffdb..f9add927b 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 7ae9615d5..25a84d166 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/consts.rs b/clippy_utils/src/consts.rs index 04347672e..dc5ec5f22 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 { diff --git a/clippy_utils/src/eager_or_lazy.rs b/clippy_utils/src/eager_or_lazy.rs index c2645ac73..61e529a60 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 e6d8ba3f0..1a4da1627 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 {