diff --git a/compiler/rustc_ast_passes/src/feature_gate.rs b/compiler/rustc_ast_passes/src/feature_gate.rs index 0ee8ef55e61bf..1317408a0e554 100644 --- a/compiler/rustc_ast_passes/src/feature_gate.rs +++ b/compiler/rustc_ast_passes/src/feature_gate.rs @@ -47,7 +47,7 @@ impl<'a> PostExpansionVisitor<'a> { fn check_abi(&self, abi: ast::StrLit) { let ast::StrLit { symbol_unescaped, span, .. } = abi; - match &*symbol_unescaped.as_str() { + match symbol_unescaped.as_str() { // Stable "Rust" | "C" | "cdecl" | "stdcall" | "fastcall" | "aapcs" | "win64" | "sysv64" | "system" => {} diff --git a/compiler/rustc_attr/src/builtin.rs b/compiler/rustc_attr/src/builtin.rs index b8929fe088913..9eaabe4b035b8 100644 --- a/compiler/rustc_attr/src/builtin.rs +++ b/compiler/rustc_attr/src/builtin.rs @@ -283,7 +283,7 @@ where // These unwraps are safe because `get` ensures the meta item // is a name/value pair string literal. - issue_num = match &*issue.unwrap().as_str() { + issue_num = match issue.unwrap().as_str() { "none" => None, issue => { let emit_diag = |msg: &str| { diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs index 868eb74cf09cd..1de10c2a56217 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs @@ -2014,8 +2014,8 @@ fn prepare_enum_metadata( let item_name; let discriminant_name = match enum_type.kind() { ty::Adt(..) => { - item_name = tcx.item_name(enum_def_id).as_str(); - &*item_name + item_name = tcx.item_name(enum_def_id); + item_name.as_str() } ty::Generator(..) => enum_name.as_str(), _ => bug!(), @@ -2483,7 +2483,8 @@ pub fn create_global_var_metadata(cx: &CodegenCx<'ll, '_>, def_id: DefId, global let is_local_to_unit = is_node_local_to_unit(cx, def_id); let variable_type = Instance::mono(cx.tcx, def_id).ty(cx.tcx, ty::ParamEnv::reveal_all()); let type_metadata = type_metadata(cx, variable_type, span); - let var_name = tcx.item_name(def_id).as_str(); + let var_name = tcx.item_name(def_id); + let var_name = var_name.as_str(); let linkage_name = mangled_name_of_instance(cx, Instance::mono(tcx, def_id)).name; // When empty, linkage_name field is omitted, // which is what we want for no_mangle statics diff --git a/compiler/rustc_hir/src/definitions.rs b/compiler/rustc_hir/src/definitions.rs index 45befc7b11586..c24b53493717a 100644 --- a/compiler/rustc_hir/src/definitions.rs +++ b/compiler/rustc_hir/src/definitions.rs @@ -214,10 +214,10 @@ impl DefPath { where F: FnOnce(CrateNum) -> Symbol, { - let crate_name_str = crate_imported_name(self.krate).as_str(); - let mut s = String::with_capacity(crate_name_str.len() + self.data.len() * 16); + let crate_name = crate_imported_name(self.krate); + let mut s = String::with_capacity(crate_name.as_str().len() + self.data.len() * 16); - write!(s, "::{}", crate_name_str).unwrap(); + write!(s, "::{}", crate_name).unwrap(); for component in &self.data { if component.disambiguator == 0 { diff --git a/compiler/rustc_interface/src/passes.rs b/compiler/rustc_interface/src/passes.rs index 66d3765d34739..26fb373274dd9 100644 --- a/compiler/rustc_interface/src/passes.rs +++ b/compiler/rustc_interface/src/passes.rs @@ -948,8 +948,8 @@ fn encode_and_write_metadata( let need_metadata_file = tcx.sess.opts.output_types.contains_key(&OutputType::Metadata); if need_metadata_file { - let crate_name = &tcx.crate_name(LOCAL_CRATE).as_str(); - let out_filename = filename_for_metadata(tcx.sess, crate_name, outputs); + let crate_name = &tcx.crate_name(LOCAL_CRATE); + let out_filename = filename_for_metadata(tcx.sess, crate_name.as_str(), outputs); // To avoid races with another rustc process scanning the output directory, // we need to write the file somewhere else and atomically move it to its // final destination, with an `fs::rename` call. In order for the rename to diff --git a/compiler/rustc_metadata/src/locator.rs b/compiler/rustc_metadata/src/locator.rs index 0869ec2836753..2cc9ee42b877a 100644 --- a/compiler/rustc_metadata/src/locator.rs +++ b/compiler/rustc_metadata/src/locator.rs @@ -932,7 +932,8 @@ impl CrateError { let candidates = libraries .iter() .filter_map(|(_, lib)| { - let crate_name = &lib.metadata.get_root().name().as_str(); + let crate_name = lib.metadata.get_root().name(); + let crate_name = crate_name.as_str(); match (&lib.source.dylib, &lib.source.rlib) { (Some((pd, _)), Some((pr, _))) => Some(format!( "\ncrate `{}`: {}\n{:>padding$}", diff --git a/compiler/rustc_metadata/src/native_libs.rs b/compiler/rustc_metadata/src/native_libs.rs index 3976475cb063e..7e169df4ef7a4 100644 --- a/compiler/rustc_metadata/src/native_libs.rs +++ b/compiler/rustc_metadata/src/native_libs.rs @@ -65,7 +65,7 @@ impl ItemLikeVisitor<'tcx> for Collector<'tcx> { Some(name) => name, None => continue, // skip like historical compilers }; - lib.kind = match &*kind.as_str() { + lib.kind = match kind.as_str() { "static" => NativeLibKind::StaticBundle, "static-nobundle" => NativeLibKind::StaticNoBundle, "dylib" => NativeLibKind::Dylib, diff --git a/compiler/rustc_middle/src/hir/map/collector.rs b/compiler/rustc_middle/src/hir/map/collector.rs index dce06a5f7eeec..0a110b95e9bd1 100644 --- a/compiler/rustc_middle/src/hir/map/collector.rs +++ b/compiler/rustc_middle/src/hir/map/collector.rs @@ -86,7 +86,9 @@ fn upstream_crates(cstore: &dyn CrateStore) -> Vec<(Symbol, Fingerprint, Svh)> { (name, disambiguator, hash) }) .collect(); - upstream_crates.sort_unstable_by_key(|&(name, dis, _)| (name.as_str(), dis)); + upstream_crates.sort_unstable_by(|&(name1, dis1, _), &(name2, dis2, _)| { + (name1.as_str(), dis1).partial_cmp(&(name2.as_str(), dis2)).unwrap() + }); upstream_crates } diff --git a/compiler/rustc_middle/src/middle/mod.rs b/compiler/rustc_middle/src/middle/mod.rs index 9bc9ca6707afe..8c502d34ffe6d 100644 --- a/compiler/rustc_middle/src/middle/mod.rs +++ b/compiler/rustc_middle/src/middle/mod.rs @@ -22,7 +22,7 @@ pub mod lib_features { .map(|(f, s)| (*f, Some(*s))) .chain(self.unstable.iter().map(|f| (*f, None))) .collect(); - all_features.sort_unstable_by_key(|f| f.0.as_str()); + all_features.sort_unstable_by(|a, b| a.0.as_str().partial_cmp(b.0.as_str()).unwrap()); all_features } } diff --git a/compiler/rustc_middle/src/middle/stability.rs b/compiler/rustc_middle/src/middle/stability.rs index 27658d50d4582..39720fa758a5f 100644 --- a/compiler/rustc_middle/src/middle/stability.rs +++ b/compiler/rustc_middle/src/middle/stability.rs @@ -184,7 +184,8 @@ pub fn deprecation_suggestion( pub fn deprecation_message(depr: &Deprecation, kind: &str, path: &str) -> (String, &'static Lint) { let (message, lint) = if deprecation_in_effect( depr.is_since_rustc_version, - depr.since.map(Symbol::as_str).as_deref(), + // njn: surely can use as_str() somehow here + depr.since.map(Symbol::as_str2).as_deref(), ) { (format!("use of deprecated {} `{}`", kind, path), DEPRECATED) } else { diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index 96e2a0ba618a3..be9f7fde8eb6f 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -2222,7 +2222,7 @@ impl<'tcx> Debug for Rvalue<'tcx> { if let Some(upvars) = tcx.upvars_mentioned(def_id) { for (&var_id, place) in upvars.keys().zip(places) { let var_name = tcx.hir().name(var_id); - struct_fmt.field(&var_name.as_str(), place); + struct_fmt.field(var_name.as_str(), place); } } @@ -2241,7 +2241,7 @@ impl<'tcx> Debug for Rvalue<'tcx> { if let Some(upvars) = tcx.upvars_mentioned(def_id) { for (&var_id, place) in upvars.keys().zip(places) { let var_name = tcx.hir().name(var_id); - struct_fmt.field(&var_name.as_str(), place); + struct_fmt.field(var_name.as_str(), place); } } diff --git a/compiler/rustc_middle/src/mir/mono.rs b/compiler/rustc_middle/src/mir/mono.rs index 79e2c5aac2385..e7d7b1b90e6b2 100644 --- a/compiler/rustc_middle/src/mir/mono.rs +++ b/compiler/rustc_middle/src/mir/mono.rs @@ -436,7 +436,7 @@ impl CodegenUnitNameBuilder<'tcx> { if self.tcx.sess.opts.debugging_opts.human_readable_cgu_names { cgu_name } else { - Symbol::intern(&CodegenUnit::mangle_name(&cgu_name.as_str())) + Symbol::intern(&CodegenUnit::mangle_name(cgu_name.as_str())) } } diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index aa34dedc4b286..e070c91a7fa89 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -1183,8 +1183,8 @@ impl<'tcx> TyCtxt<'tcx> { } pub fn consider_optimizing String>(&self, msg: T) -> bool { - let cname = self.crate_name(LOCAL_CRATE).as_str(); - self.sess.consider_optimizing(&cname, msg) + let cname = self.crate_name(LOCAL_CRATE); + self.sess.consider_optimizing(cname.as_str(), msg) } pub fn lib_features(self) -> &'tcx middle::lib_features::LibFeatures { diff --git a/compiler/rustc_middle/src/ty/query/profiling_support.rs b/compiler/rustc_middle/src/ty/query/profiling_support.rs index 9b1837356e305..994d3b097e4c5 100644 --- a/compiler/rustc_middle/src/ty/query/profiling_support.rs +++ b/compiler/rustc_middle/src/ty/query/profiling_support.rs @@ -80,7 +80,7 @@ impl<'p, 'c, 'tcx> QueryKeyStringBuilder<'p, 'c, 'tcx> { } } - let name = &*name.as_str(); + let name = name.as_str(); let components = [ StringComponent::Ref(parent_string_id), StringComponent::Value("::"), diff --git a/compiler/rustc_mir/src/borrow_check/diagnostics/conflict_errors.rs b/compiler/rustc_mir/src/borrow_check/diagnostics/conflict_errors.rs index 676065007b7ef..e1472699e5c0c 100644 --- a/compiler/rustc_mir/src/borrow_check/diagnostics/conflict_errors.rs +++ b/compiler/rustc_mir/src/borrow_check/diagnostics/conflict_errors.rs @@ -340,7 +340,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { tcx, generics, &mut err, - ¶m.name.as_str(), + param.name.as_str(), "Copy", None, ); diff --git a/compiler/rustc_mir/src/borrow_check/diagnostics/mod.rs b/compiler/rustc_mir/src/borrow_check/diagnostics/mod.rs index 88ff0271228e0..f8455891b4d6a 100644 --- a/compiler/rustc_mir/src/borrow_check/diagnostics/mod.rs +++ b/compiler/rustc_mir/src/borrow_check/diagnostics/mod.rs @@ -316,7 +316,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { let decl = &self.body.local_decls[local]; match self.local_names[local] { Some(name) if !decl.from_compiler_desugaring() => { - buf.push_str(&name.as_str()); + buf.push_str(name.as_str()); Ok(()) } _ => Err(()), diff --git a/compiler/rustc_mir/src/monomorphize/partitioning/merging.rs b/compiler/rustc_mir/src/monomorphize/partitioning/merging.rs index 1787e6df1b9c7..8939bc99b26b0 100644 --- a/compiler/rustc_mir/src/monomorphize/partitioning/merging.rs +++ b/compiler/rustc_mir/src/monomorphize/partitioning/merging.rs @@ -4,7 +4,7 @@ use rustc_data_structures::fx::FxHashMap; use rustc_hir::def_id::LOCAL_CRATE; use rustc_middle::mir::mono::{CodegenUnit, CodegenUnitNameBuilder}; use rustc_middle::ty::TyCtxt; -use rustc_span::symbol::{Symbol, SymbolStr}; +use rustc_span::symbol::Symbol; use crate::monomorphize::partitioning::PreInliningPartitioning; @@ -25,11 +25,13 @@ pub fn merge_codegen_units<'tcx>( // smallest into each other) we're sure to start off with a deterministic // order (sorted by name). This'll mean that if two cgus have the same size // the stable sort below will keep everything nice and deterministic. - codegen_units.sort_by_cached_key(|cgu| cgu.name().as_str()); + codegen_units.sort_by(|a, b| a.name().as_str().partial_cmp(b.name().as_str()).unwrap()); // This map keeps track of what got merged into what. - let mut cgu_contents: FxHashMap> = - codegen_units.iter().map(|cgu| (cgu.name(), vec![cgu.name().as_str()])).collect(); + let mut cgu_contents: FxHashMap> = codegen_units + .iter() + .map(|cgu| (cgu.name(), vec![cgu.name().as_str().to_owned()])) + .collect(); // Merge the two smallest codegen units until the target size is reached. while codegen_units.len() > target_cgu_count { diff --git a/compiler/rustc_mir/src/monomorphize/partitioning/mod.rs b/compiler/rustc_mir/src/monomorphize/partitioning/mod.rs index e96af77bbb8e0..cb6bcd45db935 100644 --- a/compiler/rustc_mir/src/monomorphize/partitioning/mod.rs +++ b/compiler/rustc_mir/src/monomorphize/partitioning/mod.rs @@ -203,7 +203,7 @@ pub fn partition<'tcx>( internalization_candidates: _, } = post_inlining; - result.sort_by_cached_key(|cgu| cgu.name().as_str()); + result.sort_by(|a, b| a.name().as_str().partial_cmp(b.name().as_str()).unwrap()); result } diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index 69d13b5cf53a2..8868012d873a2 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -1398,7 +1398,8 @@ impl<'a> Parser<'a> { ); } LitError::InvalidIntSuffix => { - let suf = suffix.expect("suffix error with no suffix").as_str(); + let suf = suffix.expect("suffix error with no suffix"); + let suf = suf.as_str(); if looks_like_width_suffix(&['i', 'u'], &suf) { // If it looks like a width, try to be helpful. let msg = format!("invalid width `{}` for integer literal", &suf[1..]); @@ -1414,7 +1415,8 @@ impl<'a> Parser<'a> { } } LitError::InvalidFloatSuffix => { - let suf = suffix.expect("suffix error with no suffix").as_str(); + let suf = suffix.expect("suffix error with no suffix"); + let suf = suf.as_str(); if looks_like_width_suffix(&['f'], &suf) { // If it looks like a width, try to be helpful. let msg = format!("invalid width `{}` for float literal", &suf[1..]); diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs index 48e1068b8daad..f7a5aa861150e 100644 --- a/compiler/rustc_resolve/src/diagnostics.rs +++ b/compiler/rustc_resolve/src/diagnostics.rs @@ -1,4 +1,3 @@ -use std::cmp::Reverse; use std::ptr; use rustc_ast::util::lev_distance::find_best_match_for_name; @@ -711,7 +710,7 @@ impl<'a> Resolver<'a> { }); // Make sure error reporting is deterministic. - suggestions.sort_by_cached_key(|suggestion| suggestion.candidate.as_str()); + suggestions.sort_by(|a, b| a.candidate.as_str().partial_cmp(b.candidate.as_str()).unwrap()); match find_best_match_for_name( suggestions.iter().map(|suggestion| &suggestion.candidate), @@ -1306,12 +1305,12 @@ impl<'a, 'b> ImportResolver<'a, 'b> { return None; } - // Sort extern crate names in reverse order to get + // Sort extern crate names in *reverse* order to get // 1) some consistent ordering for emitted diagnostics, and // 2) `std` suggestions before `core` suggestions. let mut extern_crate_names = self.r.extern_prelude.iter().map(|(ident, _)| ident.name).collect::>(); - extern_crate_names.sort_by_key(|name| Reverse(name.as_str())); + extern_crate_names.sort_by(|a, b| b.as_str().partial_cmp(a.as_str()).unwrap()); for name in extern_crate_names.into_iter() { // Replace first ident with a crate name and check if that is valid. diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs index 8cb6b6553ffe0..c255a5ab095f1 100644 --- a/compiler/rustc_resolve/src/late/diagnostics.rs +++ b/compiler/rustc_resolve/src/late/diagnostics.rs @@ -946,7 +946,7 @@ impl<'a> LateResolutionVisitor<'a, '_, '_> { let name = path[path.len() - 1].ident.name; // Make sure error reporting is deterministic. - names.sort_by_cached_key(|suggestion| suggestion.candidate.as_str()); + names.sort_by(|a, b| a.candidate.as_str().partial_cmp(b.candidate.as_str()).unwrap()); match find_best_match_for_name( names.iter().map(|suggestion| &suggestion.candidate), diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 5092b945f72c4..5824ad695a02e 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -1256,7 +1256,15 @@ impl Ident { /// Convert the name to a `SymbolStr`. This is a slowish operation because /// it requires locking the symbol interner. - pub fn as_str(self) -> SymbolStr { + // njn: want to remove this + pub fn as_str2(self) -> SymbolStr { + self.name.as_str2() + } + + /// Access the underlying string. This is a slowish operation because it + /// requires locking the symbol interner. + // njn: comment about the lifetime of the return value being a lie? + pub fn as_str(&self) -> &str { self.name.as_str() } } @@ -1402,12 +1410,20 @@ impl Symbol { /// Convert to a `SymbolStr`. This is a slowish operation because it /// requires locking the symbol interner. - pub fn as_str(self) -> SymbolStr { + // njn: want to remove this + pub fn as_str2(self) -> SymbolStr { with_interner(|interner| unsafe { SymbolStr { string: std::mem::transmute::<&str, &str>(interner.get(self)) } }) } + /// Access the underlying string. This is a slowish operation because it + /// requires locking the symbol interner. + // njn: comment about the lifetime of the return value being a lie? + pub fn as_str(&self) -> &str { + with_interner(|interner| unsafe { std::mem::transmute::<&str, &str>(interner.get(*self)) }) + } + pub fn as_u32(self) -> u32 { self.0.as_u32() } @@ -1458,7 +1474,8 @@ impl ToStableHashKey for Symbol { #[inline] fn to_stable_hash_key(&self, _: &CTX) -> SymbolStr { - self.as_str() + // njn: hmm + self.as_str2() } } @@ -1635,6 +1652,8 @@ fn with_interner T>(f: F) -> T { // // FIXME: ensure that the interner outlives any thread which uses `SymbolStr`, // by creating a new thread right after constructing the interner. +// +// njn: want to remove this #[derive(Clone, Eq, PartialOrd, Ord)] pub struct SymbolStr { string: &'static str, diff --git a/compiler/rustc_symbol_mangling/src/v0.rs b/compiler/rustc_symbol_mangling/src/v0.rs index 619edf06aa6e6..e44513df7e796 100644 --- a/compiler/rustc_symbol_mangling/src/v0.rs +++ b/compiler/rustc_symbol_mangling/src/v0.rs @@ -536,8 +536,8 @@ impl Printer<'tcx> for SymbolMangler<'tcx> { self.push("C"); let fingerprint = self.tcx.crate_disambiguator(cnum).to_fingerprint(); self.push_disambiguator(fingerprint.to_smaller_hash()); - let name = self.tcx.original_crate_name(cnum).as_str(); - self.push_ident(&name); + let name = self.tcx.original_crate_name(cnum); + self.push_ident(name.as_str()); Ok(self) } fn path_qualified( @@ -596,13 +596,13 @@ impl Printer<'tcx> for SymbolMangler<'tcx> { } }; - let name = disambiguated_data.data.get_opt_name().map(|s| s.as_str()); + let name = disambiguated_data.data.get_opt_name(); self.path_append_ns( print_prefix, ns, disambiguated_data.disambiguator as u64, - name.as_ref().map_or("", |s| &s[..]), + name.as_ref().map_or("", |name| name.as_str()), ) } fn path_generic_args( diff --git a/compiler/rustc_typeck/src/check/method/probe.rs b/compiler/rustc_typeck/src/check/method/probe.rs index 7645ea4ff8cd7..df3989d75d002 100644 --- a/compiler/rustc_typeck/src/check/method/probe.rs +++ b/compiler/rustc_typeck/src/check/method/probe.rs @@ -1008,7 +1008,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { .collect(); // Sort them by the name so we have a stable result. - names.sort_by_cached_key(|n| n.as_str()); + names.sort_by(|a, b| a.as_str().partial_cmp(b.as_str()).unwrap()); names } diff --git a/src/librustdoc/clean/cfg.rs b/src/librustdoc/clean/cfg.rs index c039b181178a4..c65a645f3a7d0 100644 --- a/src/librustdoc/clean/cfg.rs +++ b/src/librustdoc/clean/cfg.rs @@ -443,7 +443,7 @@ impl<'a> fmt::Display for Display<'a> { (sym::unix, None) => "Unix", (sym::windows, None) => "Windows", (sym::debug_assertions, None) => "debug-assertions enabled", - (sym::target_os, Some(os)) => match &*os.as_str() { + (sym::target_os, Some(os)) => match os.as_str() { "android" => "Android", "dragonfly" => "DragonFly BSD", "emscripten" => "Emscripten", @@ -463,7 +463,7 @@ impl<'a> fmt::Display for Display<'a> { "windows" => "Windows", _ => "", }, - (sym::target_arch, Some(arch)) => match &*arch.as_str() { + (sym::target_arch, Some(arch)) => match arch.as_str() { "aarch64" => "AArch64", "arm" => "ARM", "asmjs" => "JavaScript", @@ -479,7 +479,7 @@ impl<'a> fmt::Display for Display<'a> { "x86_64" => "x86-64", _ => "", }, - (sym::target_vendor, Some(vendor)) => match &*vendor.as_str() { + (sym::target_vendor, Some(vendor)) => match vendor.as_str() { "apple" => "Apple", "pc" => "PC", "rumprun" => "Rumprun", @@ -487,7 +487,7 @@ impl<'a> fmt::Display for Display<'a> { "fortanix" => "Fortanix", _ => "", }, - (sym::target_env, Some(env)) => match &*env.as_str() { + (sym::target_env, Some(env)) => match env.as_str() { "gnu" => "GNU", "msvc" => "MSVC", "musl" => "musl", diff --git a/src/test/ui-fulldeps/auxiliary/lint-group-plugin-test.rs b/src/test/ui-fulldeps/auxiliary/lint-group-plugin-test.rs index 02216b33dc3ad..c4766da1eef67 100644 --- a/src/test/ui-fulldeps/auxiliary/lint-group-plugin-test.rs +++ b/src/test/ui-fulldeps/auxiliary/lint-group-plugin-test.rs @@ -22,7 +22,7 @@ declare_lint_pass!(Pass => [TEST_LINT, PLEASE_LINT]); impl<'tcx> LateLintPass<'tcx> for Pass { fn check_item(&mut self, cx: &LateContext, it: &rustc_hir::Item) { - match &*it.ident.as_str() { + match it.ident.as_str() { "lintme" => cx.lint(TEST_LINT, |lint| { lint.build("item is named 'lintme'").set_span(it.span).emit() }), diff --git a/src/tools/clippy/clippy_lints/src/attrs.rs b/src/tools/clippy/clippy_lints/src/attrs.rs index cfcc1b3c5f356..f7ffdc283550d 100644 --- a/src/tools/clippy/clippy_lints/src/attrs.rs +++ b/src/tools/clippy/clippy_lints/src/attrs.rs @@ -16,7 +16,7 @@ use rustc_middle::lint::in_external_macro; use rustc_middle::ty; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::Span; -use rustc_span::symbol::{Symbol, SymbolStr}; +use rustc_span::symbol::Symbol; use semver::Version; static UNIX_SYSTEMS: &[&str] = &[ @@ -316,7 +316,7 @@ impl<'tcx> LateLintPass<'tcx> for Attributes { } if let Some(lint_list) = &attr.meta_item_list() { if let Some(ident) = attr.ident() { - match &*ident.as_str() { + match ident.as_str() { "allow" | "warn" | "deny" | "forbid" => { // permit `unused_imports`, `deprecated` and `unreachable_pub` for `use` items // and `unused_imports` for `extern crate` items with `macro_use` @@ -388,7 +388,7 @@ impl<'tcx> LateLintPass<'tcx> for Attributes { } fn check_clippy_lint_names(cx: &LateContext<'_>, ident: &str, items: &[NestedMetaItem]) { - fn extract_name(lint: &NestedMetaItem) -> Option { + fn extract_name(lint: &NestedMetaItem) -> Option { if_chain! { if let Some(meta_item) = lint.meta_item(); if meta_item.path.segments.len() > 1; @@ -396,7 +396,7 @@ fn check_clippy_lint_names(cx: &LateContext<'_>, ident: &str, items: &[NestedMet if tool_name.as_str() == "clippy"; let lint_name = meta_item.path.segments.last().unwrap().ident.name; then { - return Some(lint_name.as_str()); + return Some(lint_name); } } None @@ -405,8 +405,9 @@ fn check_clippy_lint_names(cx: &LateContext<'_>, ident: &str, items: &[NestedMet let lint_store = cx.lints(); for lint in items { if let Some(lint_name) = extract_name(lint) { + let lint_name = lint_name.as_str(); if let CheckLintNameResult::Tool(Err((None, _))) = - lint_store.check_lint_name(&lint_name, Some(sym!(clippy))) + lint_store.check_lint_name(lint_name, Some(sym!(clippy))) { span_lint_and_then( cx, diff --git a/src/tools/clippy/clippy_lints/src/consts.rs b/src/tools/clippy/clippy_lints/src/consts.rs index 3ee022e4e68a0..b82333d541a87 100644 --- a/src/tools/clippy/clippy_lints/src/consts.rs +++ b/src/tools/clippy/clippy_lints/src/consts.rs @@ -249,8 +249,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/src/tools/clippy/clippy_lints/src/floating_point_arithmetic.rs b/src/tools/clippy/clippy_lints/src/floating_point_arithmetic.rs index 18fea8b34bfd4..064836271c614 100644 --- a/src/tools/clippy/clippy_lints/src/floating_point_arithmetic.rs +++ b/src/tools/clippy/clippy_lints/src/floating_point_arithmetic.rs @@ -701,7 +701,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/src/tools/clippy/clippy_lints/src/methods/manual_saturating_arithmetic.rs b/src/tools/clippy/clippy_lints/src/methods/manual_saturating_arithmetic.rs index 40a6257586164..ab97b2dc6c71f 100644 --- a/src/tools/clippy/clippy_lints/src/methods/manual_saturating_arithmetic.rs +++ b/src/tools/clippy/clippy_lints/src/methods/manual_saturating_arithmetic.rs @@ -93,7 +93,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/src/tools/clippy/clippy_lints/src/methods/mod.rs b/src/tools/clippy/clippy_lints/src/methods/mod.rs index a7a3d67515678..0d420bfee17c4 100644 --- a/src/tools/clippy/clippy_lints/src/methods/mod.rs +++ b/src/tools/clippy/clippy_lints/src/methods/mod.rs @@ -22,7 +22,7 @@ use rustc_middle::lint::in_external_macro; use rustc_middle::ty::{self, TraitRef, Ty, TyS}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::Span; -use rustc_span::symbol::{sym, SymbolStr}; +use rustc_span::symbol::sym; use crate::consts::{constant, Constant}; use crate::utils::usage::mutated_variables; @@ -1442,8 +1442,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods { } let (method_names, arg_lists, method_spans) = method_calls(expr, 2); - let method_names: Vec = method_names.iter().map(|s| s.as_str()).collect(); - let method_names: Vec<&str> = method_names.iter().map(|s| &**s).collect(); + let method_names: Vec<&str> = method_names.iter().map(|s| s.as_str()).collect(); match method_names.as_slice() { ["unwrap", "get"] => lint_get_unwrap(cx, expr, arg_lists[1], false), diff --git a/src/tools/clippy/clippy_lints/src/misc.rs b/src/tools/clippy/clippy_lints/src/misc.rs index d4a50dd9013f0..0962249c640f7 100644 --- a/src/tools/clippy/clippy_lints/src/misc.rs +++ b/src/tools/clippy/clippy_lints/src/misc.rs @@ -434,15 +434,16 @@ impl<'tcx> LateLintPass<'tcx> for MiscLints { } let binding = match expr.kind { ExprKind::Path(ref qpath) if !matches!(qpath, hir::QPath::LangItem(..)) => { - let binding = last_path_segment(qpath).ident.as_str(); - if binding.starts_with('_') && - !binding.starts_with("__") && - binding != "_result" && // FIXME: #944 + let binding = last_path_segment(qpath).ident; + let binding_str = binding.as_str(); + if binding_str.starts_with('_') && + !binding_str.starts_with("__") && + binding_str != "_result" && // FIXME: #944 is_used(cx, expr) && // don't lint if the declaration is in a macro non_macro_local(cx, cx.qpath_res(qpath, expr.hir_id)) { - Some(binding) + Some(binding.name) } else { None } @@ -450,7 +451,7 @@ impl<'tcx> LateLintPass<'tcx> for MiscLints { ExprKind::Field(_, ident) => { let name = ident.as_str(); if name.starts_with('_') && !name.starts_with("__") { - Some(name) + Some(ident.name) } else { None } diff --git a/src/tools/clippy/clippy_lints/src/multiple_crate_versions.rs b/src/tools/clippy/clippy_lints/src/multiple_crate_versions.rs index c1773cef7a8b7..e5b79bfe9491d 100644 --- a/src/tools/clippy/clippy_lints/src/multiple_crate_versions.rs +++ b/src/tools/clippy/clippy_lints/src/multiple_crate_versions.rs @@ -43,7 +43,8 @@ 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 local_name = local_name.as_str(); let mut packages = metadata.packages; packages.sort_by(|a, b| a.name.cmp(&b.name)); diff --git a/src/tools/clippy/clippy_lints/src/open_options.rs b/src/tools/clippy/clippy_lints/src/open_options.rs index e99d0317ba2e8..695aca49b3c43 100644 --- a/src/tools/clippy/clippy_lints/src/open_options.rs +++ b/src/tools/clippy/clippy_lints/src/open_options.rs @@ -83,7 +83,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/src/tools/clippy/clippy_lints/src/serde_api.rs b/src/tools/clippy/clippy_lints/src/serde_api.rs index 339a7cf3bf5d2..b818c89b36a48 100644 --- a/src/tools/clippy/clippy_lints/src/serde_api.rs +++ b/src/tools/clippy/clippy_lints/src/serde_api.rs @@ -34,7 +34,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/src/tools/clippy/clippy_lints/src/types.rs b/src/tools/clippy/clippy_lints/src/types.rs index c82deaa43b266..e588cc6681134 100644 --- a/src/tools/clippy/clippy_lints/src/types.rs +++ b/src/tools/clippy/clippy_lints/src/types.rs @@ -693,7 +693,7 @@ impl<'tcx> LateLintPass<'tcx> for UnitCmp { if let ExprKind::Binary(ref cmp, ref left, _) = expr.kind { let op = cmp.node; if op.is_comparison() && is_unit(cx.typeck_results().expr_ty(left)) { - 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/src/tools/clippy/clippy_lints/src/unused_io_amount.rs b/src/tools/clippy/clippy_lints/src/unused_io_amount.rs index 43166d26787a7..6bc00f0439247 100644 --- a/src/tools/clippy/clippy_lints/src/unused_io_amount.rs +++ b/src/tools/clippy/clippy_lints/src/unused_io_amount.rs @@ -53,7 +53,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedIoAmount { } }, - hir::ExprKind::MethodCall(ref path, _, ref args, _) => match &*path.ident.as_str() { + hir::ExprKind::MethodCall(ref path, _, ref args, _) => match path.ident.as_str() { "expect" | "unwrap" | "unwrap_or" | "unwrap_or_else" => { check_method_call(cx, &args[0], expr); }, diff --git a/src/tools/clippy/clippy_lints/src/utils/internal_lints.rs b/src/tools/clippy/clippy_lints/src/utils/internal_lints.rs index 8fa5d22210a36..a20263f5e3c4e 100644 --- a/src/tools/clippy/clippy_lints/src/utils/internal_lints.rs +++ b/src/tools/clippy/clippy_lints/src/utils/internal_lints.rs @@ -16,7 +16,7 @@ use rustc_lint::{EarlyContext, EarlyLintPass, LateContext, LateLintPass}; use rustc_middle::hir::map::Map; use rustc_session::{declare_lint_pass, declare_tool_lint, impl_lint_pass}; use rustc_span::source_map::{Span, Spanned}; -use rustc_span::symbol::{Symbol, SymbolStr}; +use rustc_span::symbol::Symbol; use std::borrow::{Borrow, Cow}; @@ -219,11 +219,11 @@ impl EarlyLintPass for ClippyLintsInternal { if let ItemKind::Mod(ref utils_mod) = utils.kind { if let Some(paths) = utils_mod.items.iter().find(|item| item.ident.name.as_str() == "paths") { if let ItemKind::Mod(ref paths_mod) = paths.kind { - let mut last_name: Option = None; + let mut last_name: Option = None; for item in &*paths_mod.items { - let name = item.ident.as_str(); + let name = item.ident; if let Some(ref last_name) = last_name { - if **last_name > *name { + if last_name.as_str() > name.as_str() { span_lint( cx, CLIPPY_LINTS_INTERNAL, @@ -233,7 +233,7 @@ impl EarlyLintPass for ClippyLintsInternal { ); } } - last_name = Some(name); + last_name = Some(name.name); } } } @@ -430,8 +430,7 @@ impl<'tcx> LateLintPass<'tcx> for OuterExpnDataPass { } let (method_names, arg_lists, spans) = method_calls(expr, 2); - let method_names: Vec = method_names.iter().map(|s| s.as_str()).collect(); - let method_names: Vec<&str> = method_names.iter().map(|s| &**s).collect(); + let method_names: Vec<&str> = method_names.iter().map(|s| s.as_str()).collect(); if_chain! { if let ["expn_data", "outer_expn"] = method_names.as_slice(); let args = arg_lists[1]; @@ -494,7 +493,7 @@ impl<'tcx> LateLintPass<'tcx> for CollapsibleCalls { let and_then_snippets = get_and_then_snippets(cx, and_then_args); let mut sle = SpanlessEq::new(cx).deny_side_effects(); then { - match &*ps.ident.as_str() { + match ps.ident.as_str() { "span_suggestion" if sle.eq_expr(&and_then_args[2], &span_call_args[1]) => { suggest_suggestion(cx, expr, &and_then_snippets, &span_suggestion_snippets(cx, span_call_args)); },