diff options
| author | Nicholas Nethercote <n.nethercote@gmail.com> | 2021-12-15 08:32:21 +1100 |
|---|---|---|
| committer | Nicholas Nethercote <n.nethercote@gmail.com> | 2021-12-15 13:30:26 +1100 |
| commit | 8cddcd39ba2189da859a5164804556190906ee2a (patch) | |
| tree | 80c9ffaa12dad22abec107679298920b1f07509a /compiler | |
| parent | 22f8bde876f2fa9c5c4e95be1bce29cc271f2b51 (diff) | |
| download | rust-8cddcd39ba2189da859a5164804556190906ee2a.tar.gz rust-8cddcd39ba2189da859a5164804556190906ee2a.zip | |
Remove `SymbolStr`.
By changing `as_str()` to take `&self` instead of `self`, we can just return `&str`. We're still lying about lifetimes, but it's a smaller lie than before, where `SymbolStr` contained a (fake) `&'static str`!
Diffstat (limited to 'compiler')
19 files changed, 75 insertions, 130 deletions
diff --git a/compiler/rustc_codegen_cranelift/src/constant.rs b/compiler/rustc_codegen_cranelift/src/constant.rs index 5c4991f1fb6..9a6c45ae98d 100644 --- a/compiler/rustc_codegen_cranelift/src/constant.rs +++ b/compiler/rustc_codegen_cranelift/src/constant.rs @@ -369,7 +369,7 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant TodoItem::Static(def_id) => { //println!("static {:?}", def_id); - let section_name = tcx.codegen_fn_attrs(def_id).link_section.map(|s| s.as_str()); + let section_name = tcx.codegen_fn_attrs(def_id).link_section; let alloc = tcx.eval_static_initializer(def_id).unwrap(); @@ -388,6 +388,7 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant if let Some(section_name) = section_name { let (segment_name, section_name) = if tcx.sess.target.is_like_osx { + let section_name = section_name.as_str(); if let Some(names) = section_name.split_once(',') { names } else { @@ -397,7 +398,7 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant )); } } else { - ("", &*section_name) + ("", section_name.as_str()) }; data_ctx.set_segment_section(segment_name, section_name); } diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs index cc39332d198..7fdde653833 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs @@ -2087,8 +2087,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!(), @@ -2563,7 +2563,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_expand/src/module.rs b/compiler/rustc_expand/src/module.rs index 1c0b2a9b487..43fd94ce8a7 100644 --- a/compiler/rustc_expand/src/module.rs +++ b/compiler/rustc_expand/src/module.rs @@ -170,8 +170,8 @@ fn mod_file_path_from_attr( ) -> Option<PathBuf> { // Extract path string from first `#[path = "path_string"]` attribute. let first_path = attrs.iter().find(|at| at.has_name(sym::path))?; - let path_string = match first_path.value_str() { - Some(s) => s.as_str(), + let path_sym = match first_path.value_str() { + Some(s) => s, None => { // This check is here mainly to catch attempting to use a macro, // such as #[path = concat!(...)]. This isn't currently supported @@ -189,14 +189,16 @@ fn mod_file_path_from_attr( } }; + let path_str = path_sym.as_str(); + // On windows, the base path might have the form // `\\?\foo\bar` in which case it does not tolerate // mixed `/` and `\` separators, so canonicalize // `/` to `\`. #[cfg(windows)] - let path_string = path_string.replace("/", "\\"); + let path_str = path_str.replace("/", "\\"); - Some(dir_path.join(&*path_string)) + Some(dir_path.join(path_str)) } /// Returns a path to a module. diff --git a/compiler/rustc_interface/src/passes.rs b/compiler/rustc_interface/src/passes.rs index da76f221269..e7ae6c7687c 100644 --- a/compiler/rustc_interface/src/passes.rs +++ b/compiler/rustc_interface/src/passes.rs @@ -1049,8 +1049,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_lint/src/non_fmt_panic.rs b/compiler/rustc_lint/src/non_fmt_panic.rs index 30506445ebb..b63167f56b8 100644 --- a/compiler/rustc_lint/src/non_fmt_panic.rs +++ b/compiler/rustc_lint/src/non_fmt_panic.rs @@ -9,7 +9,7 @@ use rustc_middle::ty::subst::InternalSubsts; use rustc_parse_format::{ParseMode, Parser, Piece}; use rustc_session::lint::FutureIncompatibilityReason; use rustc_span::edition::Edition; -use rustc_span::{hygiene, sym, symbol::kw, symbol::SymbolStr, InnerSpan, Span, Symbol}; +use rustc_span::{hygiene, sym, symbol::kw, InnerSpan, Span, Symbol}; use rustc_trait_selection::infer::InferCtxtExt; declare_lint! { @@ -78,7 +78,7 @@ fn check_panic<'tcx>(cx: &LateContext<'tcx>, f: &'tcx hir::Expr<'tcx>, arg: &'tc // The argument is *not* a string literal. - let (span, panic, symbol_str) = panic_call(cx, f); + let (span, panic, symbol) = panic_call(cx, f); if in_external_macro(cx.sess(), span) { // Nothing that can be done about it in the current crate. @@ -103,7 +103,7 @@ fn check_panic<'tcx>(cx: &LateContext<'tcx>, f: &'tcx hir::Expr<'tcx>, arg: &'tc cx.struct_span_lint(NON_FMT_PANICS, arg_span, |lint| { let mut l = lint.build("panic message is not a string literal"); - l.note(&format!("this usage of {}!() is deprecated; it will be a hard error in Rust 2021", symbol_str)); + l.note(&format!("this usage of {}!() is deprecated; it will be a hard error in Rust 2021", symbol)); l.note("for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/panic-macro-consistency.html>"); if !is_arg_inside_call(arg_span, span) { // No clue where this argument is coming from. @@ -112,7 +112,7 @@ fn check_panic<'tcx>(cx: &LateContext<'tcx>, f: &'tcx hir::Expr<'tcx>, arg: &'tc } if arg_macro.map_or(false, |id| cx.tcx.is_diagnostic_item(sym::format_macro, id)) { // A case of `panic!(format!(..))`. - l.note(format!("the {}!() macro supports formatting, so there's no need for the format!() macro here", symbol_str).as_str()); + l.note(format!("the {}!() macro supports formatting, so there's no need for the format!() macro here", symbol).as_str()); if let Some((open, close, _)) = find_delimiters(cx, arg_span) { l.multipart_suggestion( "remove the `format!(..)` macro call", @@ -301,7 +301,7 @@ fn find_delimiters<'tcx>(cx: &LateContext<'tcx>, span: Span) -> Option<(Span, Sp )) } -fn panic_call<'tcx>(cx: &LateContext<'tcx>, f: &'tcx hir::Expr<'tcx>) -> (Span, Symbol, SymbolStr) { +fn panic_call<'tcx>(cx: &LateContext<'tcx>, f: &'tcx hir::Expr<'tcx>) -> (Span, Symbol, Symbol) { let mut expn = f.span.ctxt().outer_expn_data(); let mut panic_macro = kw::Empty; @@ -328,7 +328,7 @@ fn panic_call<'tcx>(cx: &LateContext<'tcx>, f: &'tcx hir::Expr<'tcx>) -> (Span, let macro_symbol = if let hygiene::ExpnKind::Macro(_, symbol) = expn.kind { symbol } else { sym::panic }; - (expn.call_site, panic_macro, macro_symbol.as_str()) + (expn.call_site, panic_macro, macro_symbol) } fn is_arg_inside_call(arg: Span, call: Span) -> bool { diff --git a/compiler/rustc_metadata/src/locator.rs b/compiler/rustc_metadata/src/locator.rs index e2fd8056f1a..99927a08935 100644 --- a/compiler/rustc_metadata/src/locator.rs +++ b/compiler/rustc_metadata/src/locator.rs @@ -976,7 +976,8 @@ impl CrateError { let candidates = libraries .iter() .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(); let mut paths = lib.source.paths(); // This `unwrap()` should be okay because there has to be at least one diff --git a/compiler/rustc_middle/src/middle/mod.rs b/compiler/rustc_middle/src/middle/mod.rs index 80a54071311..fc35cafcc77 100644 --- a/compiler/rustc_middle/src/middle/mod.rs +++ b/compiler/rustc_middle/src/middle/mod.rs @@ -21,7 +21,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 8a5fc5feeb7..acc8b92b97a 100644 --- a/compiler/rustc_middle/src/middle/stability.rs +++ b/compiler/rustc_middle/src/middle/stability.rs @@ -131,8 +131,7 @@ pub fn report_unstable( /// deprecated (i.e., whether X is not greater than the current rustc version). pub fn deprecation_in_effect(depr: &Deprecation) -> bool { let is_since_rustc_version = depr.is_since_rustc_version; - let since = depr.since.map(Symbol::as_str); - let since = since.as_deref(); + let since = depr.since.as_ref().map(Symbol::as_str); fn parse_version(ver: &str) -> Vec<u32> { // We ignore non-integer components of the version (e.g., "nightly"). @@ -197,7 +196,7 @@ fn deprecation_message( let message = if is_in_effect { format!("use of deprecated {} `{}`", kind, path) } else { - let since = since.map(Symbol::as_str); + let since = since.as_ref().map(Symbol::as_str); if since.as_deref() == Some("TBD") { format!("use of {} `{}` that will be deprecated in a future Rust version", kind, path) diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 0bf457ca8a8..0c31adebda0 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -1216,8 +1216,8 @@ impl<'tcx> TyCtxt<'tcx> { } pub fn consider_optimizing<T: Fn() -> 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) } /// Obtain all lang items of this crate and all dependencies (recursively) diff --git a/compiler/rustc_monomorphize/src/partitioning/merging.rs b/compiler/rustc_monomorphize/src/partitioning/merging.rs index 229468b47ff..09cadc907b1 100644 --- a/compiler/rustc_monomorphize/src/partitioning/merging.rs +++ b/compiler/rustc_monomorphize/src/partitioning/merging.rs @@ -3,7 +3,7 @@ use std::cmp; use rustc_data_structures::fx::FxHashMap; use rustc_hir::def_id::LOCAL_CRATE; use rustc_middle::mir::mono::{CodegenUnit, CodegenUnitNameBuilder}; -use rustc_span::symbol::{Symbol, SymbolStr}; +use rustc_span::symbol::Symbol; use super::PartitioningCx; use crate::partitioning::PreInliningPartitioning; @@ -24,11 +24,11 @@ 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<Symbol, Vec<SymbolStr>> = - codegen_units.iter().map(|cgu| (cgu.name(), vec![cgu.name().as_str()])).collect(); + let mut cgu_contents: FxHashMap<Symbol, Vec<Symbol>> = + codegen_units.iter().map(|cgu| (cgu.name(), vec![cgu.name()])).collect(); // Merge the two smallest codegen units until the target size is reached. while codegen_units.len() > cx.target_cgu_count { @@ -69,7 +69,7 @@ pub fn merge_codegen_units<'tcx>( // were actually modified by merging. .filter(|(_, cgu_contents)| cgu_contents.len() > 1) .map(|(current_cgu_name, cgu_contents)| { - let mut cgu_contents: Vec<&str> = cgu_contents.iter().map(|s| &s[..]).collect(); + let mut cgu_contents: Vec<&str> = cgu_contents.iter().map(|s| s.as_str()).collect(); // Sort the names, so things are deterministic and easy to // predict. diff --git a/compiler/rustc_monomorphize/src/partitioning/mod.rs b/compiler/rustc_monomorphize/src/partitioning/mod.rs index 658c9028ca1..cc60e7a1033 100644 --- a/compiler/rustc_monomorphize/src/partitioning/mod.rs +++ b/compiler/rustc_monomorphize/src/partitioning/mod.rs @@ -208,7 +208,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 0f8c0e1b8cf..8a2ef296c76 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -1679,7 +1679,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..]); @@ -1695,7 +1696,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_query_impl/src/profiling_support.rs b/compiler/rustc_query_impl/src/profiling_support.rs index 95edc1e93a5..cd056141508 100644 --- a/compiler/rustc_query_impl/src/profiling_support.rs +++ b/compiler/rustc_query_impl/src/profiling_support.rs @@ -61,8 +61,8 @@ impl<'p, 'c, 'tcx> QueryKeyStringBuilder<'p, 'c, 'tcx> { match def_key.disambiguated_data.data { DefPathData::CrateRoot => { - crate_name = self.tcx.crate_name(def_id.krate).as_str(); - name = &*crate_name; + crate_name = self.tcx.crate_name(def_id.krate); + name = crate_name.as_str(); dis = ""; end_index = 3; } diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs index 6a13627a563..70e0ca0f5c8 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::{self as ast, Path}; @@ -784,7 +783,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).collect::<Vec<Symbol>>(), @@ -1481,12 +1480,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::<Vec<_>>(); - 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 feb4f82ce8d..3b1ca5db2cb 100644 --- a/compiler/rustc_resolve/src/late/diagnostics.rs +++ b/compiler/rustc_resolve/src/late/diagnostics.rs @@ -1353,7 +1353,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> { 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).collect::<Vec<Symbol>>(), diff --git a/compiler/rustc_resolve/src/late/lifetimes.rs b/compiler/rustc_resolve/src/late/lifetimes.rs index c94c56df75b..662cb3aec15 100644 --- a/compiler/rustc_resolve/src/late/lifetimes.rs +++ b/compiler/rustc_resolve/src/late/lifetimes.rs @@ -689,11 +689,11 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> { hir_id: hir::HirId, ) { let name = match fk { - intravisit::FnKind::ItemFn(id, _, _, _) => id.as_str(), - intravisit::FnKind::Method(id, _, _) => id.as_str(), - intravisit::FnKind::Closure => Symbol::intern("closure").as_str(), + intravisit::FnKind::ItemFn(id, _, _, _) => id.name, + intravisit::FnKind::Method(id, _, _) => id.name, + intravisit::FnKind::Closure => sym::closure, }; - let name: &str = &name; + let name: &str = name.as_str(); let span = span!(Level::DEBUG, "visit_fn", name); let _enter = span.enter(); match fk { diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index eb6063d7612..e879e42c2bd 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -1512,9 +1512,12 @@ impl Ident { Ident::new(self.name, self.span.normalize_to_macro_rules()) } - /// Convert the name to a `SymbolStr`. This is a slowish operation because - /// it requires locking the symbol interner. - pub fn as_str(self) -> SymbolStr { + /// Access the underlying string. This is a slowish operation because it + /// requires locking the symbol interner. + /// + /// Note that the lifetime of the return value is a lie. See + /// `Symbol::as_str()` for details. + pub fn as_str(&self) -> &str { self.name.as_str() } } @@ -1650,12 +1653,17 @@ impl Symbol { with_session_globals(|session_globals| session_globals.symbol_interner.intern(string)) } - /// Convert to a `SymbolStr`. This is a slowish operation because it + /// Access the underlying string. This is a slowish operation because it /// requires locking the symbol interner. - pub fn as_str(self) -> SymbolStr { - with_session_globals(|session_globals| { - let symbol_str = session_globals.symbol_interner.get(self); - unsafe { SymbolStr { string: std::mem::transmute::<&str, &str>(symbol_str) } } + /// + /// Note that the lifetime of the return value is a lie. It's not the same + /// as `&self`, but actually tied to the lifetime of the underlying + /// interner. Interners are long-lived, and there are very few of them, and + /// this function is typically used for short-lived things, so in practice + /// it works out ok. + pub fn as_str(&self) -> &str { + with_session_globals(|session_globals| unsafe { + std::mem::transmute::<&str, &str>(session_globals.symbol_interner.get(*self)) }) } @@ -1709,11 +1717,10 @@ impl<CTX> HashStable<CTX> for Symbol { } impl<CTX> ToStableHashKey<CTX> for Symbol { - type KeyType = SymbolStr; - + type KeyType = String; #[inline] - fn to_stable_hash_key(&self, _: &CTX) -> SymbolStr { - self.as_str() + fn to_stable_hash_key(&self, _: &CTX) -> String { + self.as_str().to_string() } } @@ -1905,70 +1912,3 @@ impl Ident { self.name.can_be_raw() && self.is_reserved() } } - -/// An alternative to [`Symbol`], useful when the chars within the symbol need to -/// be accessed. It deliberately has limited functionality and should only be -/// used for temporary values. -/// -/// Because the interner outlives any thread which uses this type, we can -/// safely treat `string` which points to interner data, as an immortal string, -/// as long as this type never crosses between threads. -// -// FIXME: ensure that the interner outlives any thread which uses `SymbolStr`, -// by creating a new thread right after constructing the interner. -#[derive(Clone, Eq, PartialOrd, Ord)] -pub struct SymbolStr { - string: &'static str, -} - -// This impl allows a `SymbolStr` to be directly equated with a `String` or -// `&str`. -impl<T: std::ops::Deref<Target = str>> std::cmp::PartialEq<T> for SymbolStr { - fn eq(&self, other: &T) -> bool { - self.string == other.deref() - } -} - -impl !Send for SymbolStr {} -impl !Sync for SymbolStr {} - -/// This impl means that if `ss` is a `SymbolStr`: -/// - `*ss` is a `str`; -/// - `&*ss` is a `&str` (and `match &*ss { ... }` is a common pattern). -/// - `&ss as &str` is a `&str`, which means that `&ss` can be passed to a -/// function expecting a `&str`. -impl std::ops::Deref for SymbolStr { - type Target = str; - #[inline] - fn deref(&self) -> &str { - self.string - } -} - -impl fmt::Debug for SymbolStr { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - fmt::Debug::fmt(self.string, f) - } -} - -impl fmt::Display for SymbolStr { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - fmt::Display::fmt(self.string, f) - } -} - -impl<CTX> HashStable<CTX> for SymbolStr { - #[inline] - fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) { - self.string.hash_stable(hcx, hasher) - } -} - -impl<CTX> ToStableHashKey<CTX> for SymbolStr { - type KeyType = SymbolStr; - - #[inline] - fn to_stable_hash_key(&self, _: &CTX) -> SymbolStr { - self.clone() - } -} diff --git a/compiler/rustc_symbol_mangling/src/v0.rs b/compiler/rustc_symbol_mangling/src/v0.rs index 0363ddb0e6e..e20840398b5 100644 --- a/compiler/rustc_symbol_mangling/src/v0.rs +++ b/compiler/rustc_symbol_mangling/src/v0.rs @@ -9,6 +9,7 @@ use rustc_middle::ty::layout::IntegerExt; use rustc_middle::ty::print::{Print, Printer}; use rustc_middle::ty::subst::{GenericArg, GenericArgKind, Subst}; use rustc_middle::ty::{self, FloatTy, Instance, IntTy, Ty, TyCtxt, TypeFoldable, UintTy}; +use rustc_span::symbol::kw; use rustc_target::abi::call::FnAbi; use rustc_target::abi::Integer; use rustc_target::spec::abi::Abi; @@ -702,12 +703,11 @@ impl Printer<'tcx> for &mut SymbolMangler<'tcx> { // just to be able to handle disambiguators. let disambiguated_field = self.tcx.def_key(field_def.did).disambiguated_data; - let field_name = - disambiguated_field.data.get_opt_name().map(|s| s.as_str()); + let field_name = disambiguated_field.data.get_opt_name(); self.push_disambiguator( disambiguated_field.disambiguator as u64, ); - self.push_ident(&field_name.as_ref().map_or("", |s| &s[..])); + self.push_ident(field_name.unwrap_or(kw::Empty).as_str()); self = field.print(self)?; } @@ -736,8 +736,8 @@ impl Printer<'tcx> for &mut SymbolMangler<'tcx> { self.push("C"); let stable_crate_id = self.tcx.def_path_hash(cnum.as_def_id()).stable_crate_id(); self.push_disambiguator(stable_crate_id.to_u64()); - let name = self.tcx.crate_name(cnum).as_str(); - self.push_ident(&name); + let name = self.tcx.crate_name(cnum); + self.push_ident(name.as_str()); Ok(self) } @@ -789,13 +789,13 @@ impl Printer<'tcx> for &mut 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.unwrap_or(kw::Empty).as_str(), ) } diff --git a/compiler/rustc_typeck/src/check/method/probe.rs b/compiler/rustc_typeck/src/check/method/probe.rs index dc724396094..0c2adc6400e 100644 --- a/compiler/rustc_typeck/src/check/method/probe.rs +++ b/compiler/rustc_typeck/src/check/method/probe.rs @@ -1038,7 +1038,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 } |
