X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=clippy_lints%2Fsrc%2Ftypes.rs;h=28d337d3cd67c1d46e36fb535dc9b8a2441d86a1;hb=2c282252a93effa847517a4ced1b24036372dd46;hp=cf637ceb70686d13ebebd4adf37c49ff3b9472e8;hpb=9ba60b8333bb3ea7c9017a788516677bb1e1ff5c;p=rust.git diff --git a/clippy_lints/src/types.rs b/clippy_lints/src/types.rs index cf637ceb706..28d337d3cd6 100644 --- a/clippy_lints/src/types.rs +++ b/clippy_lints/src/types.rs @@ -1,4 +1,4 @@ -#![allow(default_hash_types)] +#![allow(rustc::default_hash_types)] use std::borrow::Cow; use std::cmp::Ordering; @@ -18,15 +18,14 @@ use syntax::ast::{FloatTy, IntTy, UintTy}; use syntax::errors::DiagnosticBuilder; use syntax::source_map::Span; -use syntax::symbol::Symbol; +use syntax::symbol::sym; use crate::consts::{constant, Constant}; use crate::utils::paths; -use crate::utils::sym; use crate::utils::{ - clip, comparisons, differing_macro_contexts, higher, in_constant, in_macro_or_desugar, int_bits, last_path_segment, - match_def_path, match_path, multispan_sugg, same_tys, sext, snippet, snippet_opt, snippet_with_applicability, - span_help_and_lint, span_lint, span_lint_and_sugg, span_lint_and_then, unsext, + clip, comparisons, differing_macro_contexts, higher, in_constant, int_bits, last_path_segment, match_def_path, + match_path, multispan_sugg, same_tys, sext, snippet, snippet_opt, snippet_with_applicability, + snippet_with_macro_callsite, span_help_and_lint, span_lint, span_lint_and_sugg, span_lint_and_then, unsext, }; declare_clippy_lint! { @@ -134,7 +133,8 @@ /// /// **Example:** /// ```rust - /// let x = LinkedList::new(); + /// # use std::collections::LinkedList; + /// let x: LinkedList = LinkedList::new(); /// ``` pub LINKEDLIST, pedantic, @@ -169,7 +169,7 @@ impl<'a, 'tcx> LateLintPass<'a, '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_by_hir_id(cx.tcx.hir().get_parent_item(id)) { + if let Some(hir::Node::Item(item)) = cx.tcx.hir().find(cx.tcx.hir().get_parent_item(id)) { if let ItemKind::Impl(_, _, _, _, Some(..), _, _) = item.node { return; } @@ -208,7 +208,7 @@ fn check_fn_decl(cx: &LateContext<'_, '_>, decl: &FnDecl) { } /// Checks if `qpath` has last segment with type parameter matching `path` -fn match_type_parameter(cx: &LateContext<'_, '_>, qpath: &QPath, path: &[Symbol]) -> bool { +fn match_type_parameter(cx: &LateContext<'_, '_>, qpath: &QPath, path: &[&str]) -> bool { let last = last_path_segment(qpath); if_chain! { if let Some(ref params) = last.args; @@ -234,7 +234,7 @@ fn match_type_parameter(cx: &LateContext<'_, '_>, qpath: &QPath, path: &[Symbol] /// local bindings should only be checked for the `BORROWED_BOX` lint. #[allow(clippy::too_many_lines)] fn check_ty(cx: &LateContext<'_, '_>, hir_ty: &hir::Ty, is_local: bool) { - if in_macro_or_desugar(hir_ty.span) { + if hir_ty.span.from_expansion() { return; } match hir_ty.node { @@ -243,7 +243,7 @@ fn check_ty(cx: &LateContext<'_, '_>, hir_ty: &hir::Ty, is_local: bool) { let res = cx.tables.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 match_type_parameter(cx, qpath, &*paths::VEC) { + if match_type_parameter(cx, qpath, &paths::VEC) { span_help_and_lint( cx, BOX_VEC, @@ -253,7 +253,7 @@ fn check_ty(cx: &LateContext<'_, '_>, hir_ty: &hir::Ty, is_local: bool) { ); return; // don't recurse into the type } - } else if match_def_path(cx, def_id, &*paths::VEC) { + } else if match_def_path(cx, def_id, &paths::VEC) { if_chain! { // Get the _ part of Vec<_> if let Some(ref last) = last_path_segment(qpath).args; @@ -288,8 +288,8 @@ fn check_ty(cx: &LateContext<'_, '_>, hir_ty: &hir::Ty, is_local: bool) { } } } - } else if match_def_path(cx, def_id, &*paths::OPTION) { - if match_type_parameter(cx, qpath, &*paths::OPTION) { + } else if match_def_path(cx, def_id, &paths::OPTION) { + if match_type_parameter(cx, qpath, &paths::OPTION) { span_lint( cx, OPTION_OPTION, @@ -299,7 +299,7 @@ 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) { + } else if match_def_path(cx, def_id, &paths::LINKED_LIST) { span_help_and_lint( cx, LINKEDLIST, @@ -428,7 +428,7 @@ fn is_any_trait(t: &hir::Ty) -> bool { if traits.len() >= 1; // 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); + if match_path(&traits[0].trait_ref.path, &paths::ANY_TRAIT); then { return true; } @@ -462,21 +462,23 @@ 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.node { if is_unit(cx.tables.pat_ty(&local.pat)) { - if in_external_macro(cx.sess(), stmt.span) || in_macro_or_desugar(local.pat.span) { + if in_external_macro(cx.sess(), stmt.span) || local.pat.span.from_expansion() { return; } if higher::is_from_for_desugar(local) { return; } - span_lint( - cx, - LET_UNIT_VALUE, - stmt.span, - &format!( - "this let-binding has unit value. Consider omitting `let {} =`", - snippet(cx, local.pat.span, "..") - ), - ); + span_lint_and_then(cx, LET_UNIT_VALUE, stmt.span, "this let-binding has unit value", |db| { + if let Some(expr) = &local.init { + let snip = snippet_with_macro_callsite(cx, expr.span, "()"); + db.span_suggestion( + stmt.span, + "omit the `let` binding", + format!("{};", snip), + Applicability::MachineApplicable, // snippet + ); + } + }); } } } @@ -524,7 +526,7 @@ fn check_stmt(&mut self, cx: &LateContext<'a, 'tcx>, stmt: &'tcx Stmt) { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnitCmp { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { - if in_macro_or_desugar(expr.span) { + if expr.span.from_expansion() { return; } if let ExprKind::Binary(ref cmp, ref left, _) = expr.node { @@ -558,7 +560,7 @@ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { /// **Known problems:** None. /// /// **Example:** - /// ```rust + /// ```rust,ignore /// foo({ /// let a = bar(); /// baz(a); @@ -573,7 +575,7 @@ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnitArg { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { - if in_macro_or_desugar(expr.span) { + if expr.span.from_expansion() { return; } @@ -586,7 +588,7 @@ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { } if_chain! { let map = &cx.tcx.hir(); - let opt_parent_node = map.find_by_hir_id(map.get_parent_node_by_hir_id(expr.hir_id)); + 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 { @@ -622,9 +624,9 @@ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { } fn is_questionmark_desugar_marked_call(expr: &Expr) -> bool { - use syntax_pos::hygiene::CompilerDesugaringKind; + use syntax_pos::hygiene::DesugaringKind; if let ExprKind::Call(ref callee, _) = expr.node { - callee.span.is_compiler_desugaring(CompilerDesugaringKind::QuestionMark) + callee.span.is_desugaring(DesugaringKind::QuestionMark) } else { false } @@ -661,8 +663,8 @@ fn is_unit_literal(expr: &Expr) -> bool { /// /// **Example:** /// ```rust - /// let x = u64::MAX; - /// x as f64 + /// let x = std::u64::MAX; + /// x as f64; /// ``` pub CAST_PRECISION_LOSS, pedantic, @@ -683,7 +685,7 @@ fn is_unit_literal(expr: &Expr) -> bool { /// **Example:** /// ```rust /// let y: i8 = -1; - /// y as u128 // will return 18446744073709551615 + /// y as u128; // will return 18446744073709551615 /// ``` pub CAST_SIGN_LOSS, pedantic, @@ -691,7 +693,7 @@ fn is_unit_literal(expr: &Expr) -> bool { } declare_clippy_lint! { - /// **What it does:** Checks for on casts between numerical types that may + /// **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. /// @@ -728,7 +730,7 @@ fn is_unit_literal(expr: &Expr) -> bool { /// /// **Example:** /// ```rust - /// u32::MAX as i32 // will yield a value of `-1` + /// std::u32::MAX as i32; // will yield a value of `-1` /// ``` pub CAST_POSSIBLE_WRAP, pedantic, @@ -736,7 +738,7 @@ fn is_unit_literal(expr: &Expr) -> bool { } declare_clippy_lint! { - /// **What it does:** Checks for on casts between numerical types that may + /// **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 @@ -776,7 +778,7 @@ fn is_unit_literal(expr: &Expr) -> bool { /// /// **Example:** /// ```rust - /// let _ = 2i32 as i32 + /// let _ = 2i32 as i32; /// ``` pub UNNECESSARY_CAST, complexity, @@ -790,7 +792,8 @@ fn is_unit_literal(expr: &Expr) -> bool { /// **Why is this bad?** Dereferencing the resulting pointer may be undefined /// behavior. /// - /// **Known problems:** None. + /// **Known problems:** Using `std::ptr::read_unaligned` and `std::ptr::write_unaligned` or similar + /// on the resulting pointer is fine. /// /// **Example:** /// ```rust @@ -861,7 +864,7 @@ fn is_unit_literal(expr: &Expr) -> bool { /// 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 { +fn int_ty_to_nbits(typ: Ty<'_>, tcx: TyCtxt<'_>) -> u64 { match typ.sty { ty::Int(i) => match i { IntTy::Isize => tcx.data_layout.pointer_size.bits(), @@ -1093,7 +1096,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; } } @@ -1112,7 +1115,7 @@ 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) { - if in_macro_or_desugar(expr.span) { + if expr.span.from_expansion() { return; } if let ExprKind::Cast(ref ex, _) = expr.node { @@ -1121,7 +1124,7 @@ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { if let ExprKind::Lit(ref lit) = ex.node { use syntax::ast::{LitIntType, LitKind}; if let LitKind::Int(n, _) = lit.node { - if cast_to.is_fp() { + if cast_to.is_floating_point() { 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 { @@ -1211,17 +1214,25 @@ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { if_chain! { if let ty::RawPtr(from_ptr_ty) = &cast_from.sty; if let ty::RawPtr(to_ptr_ty) = &cast_to.sty; - if let Some(from_align) = cx.layout_of(from_ptr_ty.ty).ok().map(|a| a.align.abi); - if let Some(to_align) = cx.layout_of(to_ptr_ty.ty).ok().map(|a| a.align.abi); - if from_align < to_align; + 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 (`{}`)", cast_from, cast_to) + &format!( + "casting from `{}` to a more-strictly-aligned pointer (`{}`) ({} < {} bytes)", + cast_from, + cast_to, + from_layout.align.abi.bytes(), + to_layout.align.abi.bytes(), + ), ); } } @@ -1243,7 +1254,7 @@ fn lint_fn_to_numeric_cast( } match cast_from.sty { ty::FnDef(..) | ty::FnPtr(_) => { - let mut applicability = Applicability::MachineApplicable; + 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); @@ -1287,6 +1298,7 @@ fn lint_fn_to_numeric_cast( /// /// **Example:** /// ```rust + /// # use std::rc::Rc; /// struct Foo { /// inner: Rc>>>, /// } @@ -1345,7 +1357,7 @@ fn check_trait_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx TraitItem fn check_impl_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx ImplItem) { match item.node { - ImplItemKind::Const(ref ty, _) | ImplItemKind::Type(ref ty) => self.check_type(cx, ty), + ImplItemKind::Const(ref ty, _) | ImplItemKind::TyAlias(ref ty) => self.check_type(cx, ty), // methods are covered by check_fn _ => (), } @@ -1369,7 +1381,7 @@ fn check_fndecl(&self, cx: &LateContext<'a, 'tcx>, decl: &'tcx FnDecl) { } fn check_type(&self, cx: &LateContext<'_, '_>, ty: &hir::Ty) { - if in_macro_or_desugar(ty.span) { + if ty.span.from_expansion() { return; } let score = { @@ -1450,13 +1462,13 @@ fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { /// **Known problems:** None. /// /// **Example:** - /// ```rust + /// ```rust,ignore /// 'x' as u8 /// ``` /// /// A better version, using the byte literal: /// - /// ```rust + /// ```rust,ignore /// b'x' /// ``` pub CHAR_LIT_AS_U8, @@ -1473,7 +1485,7 @@ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { if let ExprKind::Cast(ref e, _) = expr.node { if let ExprKind::Lit(ref l) = e.node { if let LitKind::Char(_) = l.node { - if ty::Uint(UintTy::U8) == cx.tables.expr_ty(expr).sty && !in_macro_or_desugar(expr.span) { + if ty::Uint(UintTy::U8) == cx.tables.expr_ty(expr).sty && !expr.span.from_expansion() { let msg = "casting character literal to u8. `char`s \ are 4 bytes wide in rust, so casting to u8 \ truncates them"; @@ -1496,7 +1508,7 @@ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { /// checked. /// /// **Why is this bad?** An expression like `min <= x` may misleadingly imply - /// that is is possible for `x` to be less than the minimum. Expressions like + /// 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 @@ -1634,7 +1646,7 @@ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { if let ExprKind::Binary(ref cmp, ref lhs, ref rhs) = expr.node { if let Some((culprit, result)) = detect_absurd_comparison(cx, cmp.node, lhs, rhs) { - if !in_macro_or_desugar(expr.span) { + 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"; @@ -1680,7 +1692,8 @@ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { /// /// **Example:** /// ```rust - /// let x : u8 = ...; (x as u32) > 300 + /// let x: u8 = 1; + /// (x as u32) > 300; /// ``` pub INVALID_UPCAST_COMPARISONS, pedantic, @@ -1717,10 +1730,10 @@ fn eq(&self, other: &Self) -> bool { impl PartialOrd for FullInt { fn partial_cmp(&self, other: &Self) -> Option { Some(match (self, other) { - (&FullInt::S(s), &FullInt::S(o)) => s.cmp(&o), - (&FullInt::U(s), &FullInt::U(o)) => s.cmp(&o), - (&FullInt::S(s), &FullInt::U(o)) => Self::cmp_s_u(s, o), - (&FullInt::U(s), &FullInt::S(o)) => Self::cmp_s_u(o, s).reverse(), + (&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(), }) } } @@ -1915,12 +1928,21 @@ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { /// **Example:** /// ```rust /// # use std::collections::HashMap; - /// # use std::hash::Hash; + /// # 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, style, "missing generalization over different hashers" @@ -2030,8 +2052,11 @@ fn suggestion<'a, 'tcx>( 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.arguments[0].pat.span)) + 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)) @@ -2089,14 +2114,14 @@ fn new<'a>(cx: &LateContext<'a, 'tcx>, hir_ty: &hir::Ty) -> Option { let ty = hir_ty_to_ty(cx.tcx, hir_ty); - if match_path(path, &*paths::HASHMAP) && params_len == 2 { + if match_path(path, &paths::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 match_path(path, &*paths::HASHSET) && params_len == 1 { + } else if match_path(path, &paths::HASHSET) && params_len == 1 { Some(ImplicitHasherType::HashSet( hir_ty.span, ty, @@ -2137,18 +2162,18 @@ fn span(&self) -> Span { } } -struct ImplicitHasherTypeVisitor<'a, 'tcx: 'a> { +struct ImplicitHasherTypeVisitor<'a, 'tcx> { cx: &'a LateContext<'a, 'tcx>, found: Vec>, } -impl<'a, 'tcx: 'a> ImplicitHasherTypeVisitor<'a, 'tcx> { +impl<'a, 'tcx> ImplicitHasherTypeVisitor<'a, 'tcx> { fn new(cx: &'a LateContext<'a, 'tcx>) -> Self { Self { cx, found: vec![] } } } -impl<'a, 'tcx: 'a> Visitor<'tcx> for ImplicitHasherTypeVisitor<'a, 'tcx> { +impl<'a, 'tcx> Visitor<'tcx> for ImplicitHasherTypeVisitor<'a, 'tcx> { fn visit_ty(&mut self, t: &'tcx hir::Ty) { if let Some(target) = ImplicitHasherType::new(self.cx, t) { self.found.push(target); @@ -2163,14 +2188,14 @@ fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { } /// Looks for default-hasher-dependent constructors like `HashMap::new`. -struct ImplicitHasherConstructorVisitor<'a, 'b, 'tcx: 'a + 'b> { +struct ImplicitHasherConstructorVisitor<'a, 'b, 'tcx> { cx: &'a LateContext<'a, 'tcx>, body: &'a TypeckTables<'tcx>, target: &'b ImplicitHasherType<'tcx>, suggestions: BTreeMap, } -impl<'a, 'b, 'tcx: 'a + 'b> ImplicitHasherConstructorVisitor<'a, 'b, 'tcx> { +impl<'a, 'b, 'tcx> ImplicitHasherConstructorVisitor<'a, 'b, 'tcx> { fn new(cx: &'a LateContext<'a, 'tcx>, target: &'b ImplicitHasherType<'tcx>) -> Self { Self { cx, @@ -2181,7 +2206,7 @@ fn new(cx: &'a LateContext<'a, 'tcx>, target: &'b ImplicitHasherType<'tcx>) -> S } } -impl<'a, 'b, 'tcx: 'a + 'b> Visitor<'tcx> for ImplicitHasherConstructorVisitor<'a, 'b, 'tcx> { +impl<'a, 'b, 'tcx> Visitor<'tcx> for ImplicitHasherConstructorVisitor<'a, 'b, 'tcx> { fn visit_body(&mut self, body: &'tcx Body) { let prev_body = self.body; self.body = self.cx.tcx.body_tables(body.id()); @@ -2199,11 +2224,11 @@ fn visit_expr(&mut self, e: &'tcx Expr) { return; } - if match_path(ty_path, &*paths::HASHMAP) { - if method.ident.name == *sym::new { + 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 { + } else if method.ident.name == sym!(with_capacity) { self.suggestions.insert( e.span, format!( @@ -2212,11 +2237,11 @@ fn visit_expr(&mut self, e: &'tcx Expr) { ), ); } - } else if match_path(ty_path, &*paths::HASHSET) { - if method.ident.name == *sym::new { + } 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 { + } else if method.ident.name == sym!(with_capacity) { self.suggestions.insert( e.span, format!(