From 1b154a31cd09c2e251590b82de26927bdc34009a Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 22 Oct 2019 06:20:51 +1100 Subject: [PATCH 1/7] Rename `LocalInternedString` as `SymbolStr`. It makes the relationship with `Symbol` clearer. The `Str` suffix matches the existing `Symbol::as_str()` method nicely, and is also consistent with it being a wrapper of `&str`. --- src/librustc/ich/impls_syntax.rs | 14 ++++++------- src/libsyntax_pos/symbol.rs | 36 ++++++++++++++++---------------- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/librustc/ich/impls_syntax.rs b/src/librustc/ich/impls_syntax.rs index 4fd4e25f64110..304735fb1c7ed 100644 --- a/src/librustc/ich/impls_syntax.rs +++ b/src/librustc/ich/impls_syntax.rs @@ -9,7 +9,7 @@ use std::mem; use syntax::ast; use syntax::feature_gate; use syntax::parse::token; -use syntax::symbol::LocalInternedString; +use syntax::symbol::SymbolStr; use syntax::tokenstream; use syntax_pos::SourceFile; @@ -18,7 +18,7 @@ use crate::hir::def_id::{DefId, CrateNum, CRATE_DEF_INDEX}; use smallvec::SmallVec; use rustc_data_structures::stable_hasher::{HashStable, ToStableHashKey, StableHasher}; -impl<'a> HashStable> for LocalInternedString { +impl<'a> HashStable> for SymbolStr { #[inline] fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { let str = self as &str; @@ -26,13 +26,13 @@ impl<'a> HashStable> for LocalInternedString { } } -impl<'a> ToStableHashKey> for LocalInternedString { - type KeyType = LocalInternedString; +impl<'a> ToStableHashKey> for SymbolStr { + type KeyType = SymbolStr; #[inline] fn to_stable_hash_key(&self, _: &StableHashingContext<'a>) - -> LocalInternedString { + -> SymbolStr { self.clone() } } @@ -45,12 +45,12 @@ impl<'a> HashStable> for ast::Name { } impl<'a> ToStableHashKey> for ast::Name { - type KeyType = LocalInternedString; + type KeyType = SymbolStr; #[inline] fn to_stable_hash_key(&self, _: &StableHashingContext<'a>) - -> LocalInternedString { + -> SymbolStr { self.as_str() } } diff --git a/src/libsyntax_pos/symbol.rs b/src/libsyntax_pos/symbol.rs index 57131ffe18cb3..8e1eb7366d9c0 100644 --- a/src/libsyntax_pos/symbol.rs +++ b/src/libsyntax_pos/symbol.rs @@ -806,9 +806,9 @@ impl Ident { Ident::new(self.name, self.span.modern_and_legacy()) } - /// Convert the name to a `LocalInternedString`. This is a slowish - /// operation because it requires locking the symbol interner. - pub fn as_str(self) -> LocalInternedString { + /// Convert the name to a `SymbolStr`. This is a slowish operation because + /// it requires locking the symbol interner. + pub fn as_str(self) -> SymbolStr { self.name.as_str() } } @@ -896,11 +896,11 @@ impl Symbol { }) } - /// Convert to a `LocalInternedString`. This is a slowish operation because - /// it requires locking the symbol interner. - pub fn as_str(self) -> LocalInternedString { + /// Convert to a `SymbolStr`. This is a slowish operation because it + /// requires locking the symbol interner. + pub fn as_str(self) -> SymbolStr { with_interner(|interner| unsafe { - LocalInternedString { + SymbolStr { string: std::mem::transmute::<&str, &str>(interner.get(self)) } }) @@ -973,6 +973,7 @@ impl Interner { self.names.insert(string, name); name } + // Get the symbol as a string. `Symbol::as_str()` should be used in // preference to this function. pub fn get(&self, symbol: Symbol) -> &str { @@ -1092,15 +1093,14 @@ fn with_interner T>(f: F) -> T { /// 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 -// `LocalInternedString`, by creating a new thread right after constructing the -// interner. +// 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 LocalInternedString { +pub struct SymbolStr { string: &'static str, } -impl std::convert::AsRef for LocalInternedString +impl std::convert::AsRef for SymbolStr where str: std::convert::AsRef { @@ -1110,28 +1110,28 @@ where } } -impl> std::cmp::PartialEq for LocalInternedString { +impl> std::cmp::PartialEq for SymbolStr { fn eq(&self, other: &T) -> bool { self.string == other.deref() } } -impl !Send for LocalInternedString {} -impl !Sync for LocalInternedString {} +impl !Send for SymbolStr {} +impl !Sync for SymbolStr {} -impl std::ops::Deref for LocalInternedString { +impl std::ops::Deref for SymbolStr { type Target = str; #[inline] fn deref(&self) -> &str { self.string } } -impl fmt::Debug for LocalInternedString { +impl fmt::Debug for SymbolStr { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Debug::fmt(self.string, f) } } -impl fmt::Display for LocalInternedString { +impl fmt::Display for SymbolStr { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Display::fmt(self.string, f) } From 2f7d7c2ca44a1487157394e1562e793dbb3db81f Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 22 Oct 2019 06:22:59 +1100 Subject: [PATCH 2/7] Remove an erroneous comment. --- src/libsyntax_pos/symbol.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libsyntax_pos/symbol.rs b/src/libsyntax_pos/symbol.rs index 8e1eb7366d9c0..0d11a4c426aa8 100644 --- a/src/libsyntax_pos/symbol.rs +++ b/src/libsyntax_pos/symbol.rs @@ -1079,7 +1079,6 @@ impl Ident { } } -// If an interner exists, return it. Otherwise, prepare a fresh one. #[inline] fn with_interner T>(f: F) -> T { GLOBALS.with(|globals| f(&mut *globals.symbol_interner.lock())) From e6d541a60abd7941fb19996c0327a1229d4bcbbe Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 22 Oct 2019 11:09:42 +1100 Subject: [PATCH 3/7] Add some explanatory comments. --- src/libsyntax_pos/symbol.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/libsyntax_pos/symbol.rs b/src/libsyntax_pos/symbol.rs index 0d11a4c426aa8..4ff558a22e12d 100644 --- a/src/libsyntax_pos/symbol.rs +++ b/src/libsyntax_pos/symbol.rs @@ -1109,6 +1109,8 @@ where } } +// This impl allows a `SymbolStr` to be directly equated with a `String` or +// `&str`. impl> std::cmp::PartialEq for SymbolStr { fn eq(&self, other: &T) -> bool { self.string == other.deref() @@ -1118,6 +1120,11 @@ impl> std::cmp::PartialEq for SymbolStr { 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`; +/// - `&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] From 9cf59b517867562ebf7413ca2cda762c6b7d6fc0 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 22 Oct 2019 08:22:23 +1100 Subject: [PATCH 4/7] Remove some unnecessary renamings of constants. --- src/librustc_incremental/assert_module_sources.rs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/librustc_incremental/assert_module_sources.rs b/src/librustc_incremental/assert_module_sources.rs index ca035d0cdcb19..6150017f957b2 100644 --- a/src/librustc_incremental/assert_module_sources.rs +++ b/src/librustc_incremental/assert_module_sources.rs @@ -31,10 +31,6 @@ use syntax::symbol::{Symbol, sym}; use rustc::ich::{ATTR_PARTITION_REUSED, ATTR_PARTITION_CODEGENED, ATTR_EXPECTED_CGU_REUSE}; -const MODULE: Symbol = sym::module; -const CFG: Symbol = sym::cfg; -const KIND: Symbol = sym::kind; - pub fn assert_module_sources(tcx: TyCtxt<'_>) { tcx.dep_graph.with_ignore(|| { if tcx.sess.opts.incremental.is_none() { @@ -71,7 +67,7 @@ impl AssertModuleSource<'tcx> { } else if attr.check_name(ATTR_PARTITION_CODEGENED) { (CguReuse::No, ComparisonKind::Exact) } else if attr.check_name(ATTR_EXPECTED_CGU_REUSE) { - match &self.field(attr, KIND).as_str()[..] { + match &self.field(attr, sym::kind).as_str()[..] { "no" => (CguReuse::No, ComparisonKind::Exact), "pre-lto" => (CguReuse::PreLto, ComparisonKind::Exact), "post-lto" => (CguReuse::PostLto, ComparisonKind::Exact), @@ -98,7 +94,7 @@ impl AssertModuleSource<'tcx> { return; } - let user_path = self.field(attr, MODULE).as_str().to_string(); + let user_path = self.field(attr, sym::module).as_str().to_string(); let crate_name = self.tcx.crate_name(LOCAL_CRATE).as_str().to_string(); if !user_path.starts_with(&crate_name) { @@ -125,7 +121,7 @@ impl AssertModuleSource<'tcx> { cgu_path_components, cgu_special_suffix); - debug!("mapping '{}' to cgu name '{}'", self.field(attr, MODULE), cgu_name); + debug!("mapping '{}' to cgu name '{}'", self.field(attr, sym::module), cgu_name); if !self.available_cgus.contains(&cgu_name) { self.tcx.sess.span_err(attr.span, @@ -169,7 +165,7 @@ impl AssertModuleSource<'tcx> { /// cfg flag called `foo`. fn check_config(&self, attr: &ast::Attribute) -> bool { let config = &self.tcx.sess.parse_sess.config; - let value = self.field(attr, CFG); + let value = self.field(attr, sym::cfg); debug!("check_config(config={:?}, value={:?})", config, value); if config.iter().any(|&(name, _)| name == value) { debug!("check_config: matched"); From 5bc7084f7e1be9da93bb014e05f19a80ff6fa188 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 22 Oct 2019 08:31:37 +1100 Subject: [PATCH 5/7] Convert `x.as_str().to_string()` to `x.to_string()` where possible. --- src/librustc/dep_graph/dep_node.rs | 2 +- src/librustc/hir/lowering.rs | 2 +- src/librustc/hir/print.rs | 4 ++-- src/librustc/traits/on_unimplemented.rs | 2 +- src/librustc/ty/query/on_disk_cache.rs | 2 +- src/librustc_codegen_ssa/base.rs | 6 ++---- src/librustc_incremental/assert_module_sources.rs | 6 +++--- src/librustdoc/clean/mod.rs | 2 +- src/libsyntax/print/pprust.rs | 6 +++--- src/libsyntax_expand/mbe/macro_rules.rs | 2 +- 10 files changed, 16 insertions(+), 18 deletions(-) diff --git a/src/librustc/dep_graph/dep_node.rs b/src/librustc/dep_graph/dep_node.rs index dea8d70aaf4e6..cea790375fc3d 100644 --- a/src/librustc/dep_graph/dep_node.rs +++ b/src/librustc/dep_graph/dep_node.rs @@ -525,7 +525,7 @@ impl<'tcx> DepNodeParams<'tcx> for CrateNum { } fn to_debug_str(&self, tcx: TyCtxt<'tcx>) -> String { - tcx.crate_name(*self).as_str().to_string() + tcx.crate_name(*self).to_string() } } diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 12ab44515c38d..9ff52727187a5 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -3382,7 +3382,7 @@ pub fn is_range_literal(sess: &Session, expr: &hir::Expr) -> bool { // either in std or core, i.e. has either a `::std::ops::Range` or // `::core::ops::Range` prefix. fn is_range_path(path: &Path) -> bool { - let segs: Vec<_> = path.segments.iter().map(|seg| seg.ident.as_str().to_string()).collect(); + let segs: Vec<_> = path.segments.iter().map(|seg| seg.ident.to_string()).collect(); let segs: Vec<_> = segs.iter().map(|seg| &**seg).collect(); // "{{root}}" is the equivalent of `::` prefix in `Path`. diff --git a/src/librustc/hir/print.rs b/src/librustc/hir/print.rs index 64b355f6ec9d1..328d475be0606 100644 --- a/src/librustc/hir/print.rs +++ b/src/librustc/hir/print.rs @@ -564,7 +564,7 @@ impl<'a> State<'a> { } hir::ItemKind::GlobalAsm(ref ga) => { self.head(visibility_qualified(&item.vis, "global asm")); - self.s.word(ga.asm.as_str().to_string()); + self.s.word(ga.asm.to_string()); self.end() } hir::ItemKind::TyAlias(ref ty, ref generics) => { @@ -1855,7 +1855,7 @@ impl<'a> State<'a> { self.commasep(Inconsistent, &decl.inputs, |s, ty| { s.ibox(INDENT_UNIT); if let Some(arg_name) = arg_names.get(i) { - s.s.word(arg_name.as_str().to_string()); + s.s.word(arg_name.to_string()); s.s.word(":"); s.s.space(); } else if let Some(body_id) = body_id { diff --git a/src/librustc/traits/on_unimplemented.rs b/src/librustc/traits/on_unimplemented.rs index b39c00a56e349..b64e44b6a5afb 100644 --- a/src/librustc/traits/on_unimplemented.rs +++ b/src/librustc/traits/on_unimplemented.rs @@ -180,7 +180,7 @@ impl<'tcx> OnUnimplementedDirective { c.ident().map_or(false, |ident| { options.contains(&( ident.name, - c.value_str().map(|s| s.as_str().to_string()) + c.value_str().map(|s| s.to_string()) )) }) }) { diff --git a/src/librustc/ty/query/on_disk_cache.rs b/src/librustc/ty/query/on_disk_cache.rs index 21a7cf00b283f..039949d915a92 100644 --- a/src/librustc/ty/query/on_disk_cache.rs +++ b/src/librustc/ty/query/on_disk_cache.rs @@ -264,7 +264,7 @@ impl<'sess> OnDiskCache<'sess> { let sorted_cnums = sorted_cnums_including_local_crate(tcx); let prev_cnums: Vec<_> = sorted_cnums.iter() .map(|&cnum| { - let crate_name = tcx.original_crate_name(cnum).as_str().to_string(); + let crate_name = tcx.original_crate_name(cnum).to_string(); let crate_disambiguator = tcx.crate_disambiguator(cnum); (cnum.as_u32(), crate_name, crate_disambiguator) }) diff --git a/src/librustc_codegen_ssa/base.rs b/src/librustc_codegen_ssa/base.rs index ee4ec7fb41eac..c3f2a5161ae1c 100644 --- a/src/librustc_codegen_ssa/base.rs +++ b/src/librustc_codegen_ssa/base.rs @@ -552,8 +552,7 @@ pub fn codegen_crate( } else if let Some(kind) = *tcx.sess.allocator_kind.get() { let llmod_id = cgu_name_builder.build_cgu_name(LOCAL_CRATE, &["crate"], - Some("allocator")).as_str() - .to_string(); + Some("allocator")).to_string(); let mut modules = backend.new_metadata(tcx, &llmod_id); time(tcx.sess, "write allocator module", || { backend.codegen_allocator(tcx, &mut modules, kind) @@ -576,8 +575,7 @@ pub fn codegen_crate( // Codegen the encoded metadata. let metadata_cgu_name = cgu_name_builder.build_cgu_name(LOCAL_CRATE, &["crate"], - Some("metadata")).as_str() - .to_string(); + Some("metadata")).to_string(); let mut metadata_llvm_module = backend.new_metadata(tcx, &metadata_cgu_name); time(tcx.sess, "write compressed metadata", || { backend.write_compressed_metadata(tcx, &ongoing_codegen.metadata, diff --git a/src/librustc_incremental/assert_module_sources.rs b/src/librustc_incremental/assert_module_sources.rs index 6150017f957b2..f740d1a9bfaf2 100644 --- a/src/librustc_incremental/assert_module_sources.rs +++ b/src/librustc_incremental/assert_module_sources.rs @@ -94,8 +94,8 @@ impl AssertModuleSource<'tcx> { return; } - let user_path = self.field(attr, sym::module).as_str().to_string(); - let crate_name = self.tcx.crate_name(LOCAL_CRATE).as_str().to_string(); + let user_path = self.field(attr, sym::module).to_string(); + let crate_name = self.tcx.crate_name(LOCAL_CRATE).to_string(); if !user_path.starts_with(&crate_name) { let msg = format!("Found malformed codegen unit name `{}`. \ @@ -131,7 +131,7 @@ impl AssertModuleSource<'tcx> { cgu_name, self.available_cgus .iter() - .map(|cgu| cgu.as_str().to_string()) + .map(|cgu| cgu.to_string()) .collect::>() .join(", "))); } diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index bdc0206223036..cc1d1503c43d4 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1167,7 +1167,7 @@ fn external_path(cx: &DocContext<'_>, name: Symbol, trait_did: Option, ha global: false, res: Res::Err, segments: vec![PathSegment { - name: name.as_str().to_string(), + name: name.to_string(), args: external_generic_args(cx, trait_did, has_self, bindings, substs) }], } diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 136fc355f89d4..74ab5c790193d 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -623,7 +623,7 @@ pub trait PrintState<'a>: std::ops::Deref + std::ops::Dere } self.maybe_print_comment(attr.span.lo()); if attr.is_sugared_doc { - self.word(attr.value_str().unwrap().as_str().to_string()); + self.word(attr.value_str().unwrap().to_string()); self.hardbreak() } else { match attr.style { @@ -1234,7 +1234,7 @@ impl<'a> State<'a> { } ast::ItemKind::GlobalAsm(ref ga) => { self.head(visibility_qualified(&item.vis, "global_asm!")); - self.s.word(ga.asm.as_str().to_string()); + self.s.word(ga.asm.to_string()); self.end(); } ast::ItemKind::TyAlias(ref ty, ref generics) => { @@ -2335,7 +2335,7 @@ impl<'a> State<'a> { } crate fn print_name(&mut self, name: ast::Name) { - self.s.word(name.as_str().to_string()); + self.s.word(name.to_string()); self.ann.post(self, AnnNode::Name(&name)) } diff --git a/src/libsyntax_expand/mbe/macro_rules.rs b/src/libsyntax_expand/mbe/macro_rules.rs index 9a4130b2d8d02..2a8c455d7f029 100644 --- a/src/libsyntax_expand/mbe/macro_rules.rs +++ b/src/libsyntax_expand/mbe/macro_rules.rs @@ -225,7 +225,7 @@ fn generic_extension<'cx>( }; let mut p = Parser::new(cx.parse_sess(), tts, Some(directory), true, false, None); p.root_module_name = - cx.current_expansion.module.mod_path.last().map(|id| id.as_str().to_string()); + cx.current_expansion.module.mod_path.last().map(|id| id.to_string()); p.last_type_ascription = cx.current_expansion.prior_type_ascription; p.process_potential_macro_variable(); From b9cef6984b606705f42adf9587f4f1c3babf4d4d Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 22 Oct 2019 11:04:25 +1100 Subject: [PATCH 6/7] Simplify various `Symbol` use points. Including removing a bunch of unnecessary `.as_str()` calls, and a bunch of unnecessary sigils. --- src/librustc/hir/lowering.rs | 2 +- src/librustc/mir/mono.rs | 2 +- src/librustc/traits/error_reporting.rs | 2 +- src/librustc_codegen_llvm/attributes.rs | 2 +- src/librustc_codegen_llvm/debuginfo/namespace.rs | 6 +++--- src/librustc_codegen_ssa/back/symbol_export.rs | 6 +++--- src/librustc_codegen_utils/symbol_names/legacy.rs | 5 +++-- src/librustc_incremental/assert_module_sources.rs | 2 +- src/librustc_incremental/persist/dirty_clean.rs | 4 ++-- src/librustc_lint/builtin.rs | 6 ++---- src/librustc_metadata/creader.rs | 2 +- src/librustc_metadata/native_libs.rs | 2 +- src/librustc_mir/borrow_check/conflict_errors.rs | 2 +- src/librustc_mir/interpret/intrinsics.rs | 2 +- src/librustc_mir/transform/check_unsafety.rs | 12 ++++++------ src/librustc_mir/transform/qualify_consts.rs | 4 ++-- src/librustc_mir/transform/qualify_min_const_fn.rs | 2 +- src/librustc_resolve/late.rs | 2 +- src/librustc_typeck/check/demand.rs | 6 +++--- src/librustc_typeck/check/method/suggest.rs | 4 ++-- src/librustc_typeck/check/pat.rs | 2 +- src/librustc_typeck/collect.rs | 2 +- src/librustdoc/clean/cfg.rs | 2 +- src/librustdoc/clean/mod.rs | 2 +- src/librustdoc/html/render.rs | 2 +- src/libsyntax/ast.rs | 2 +- src/libsyntax/feature_gate/check.rs | 2 +- src/libsyntax/parse/literal.rs | 4 ++-- src/libsyntax/parse/parser/module.rs | 2 +- src/libsyntax_ext/env.rs | 2 +- src/libsyntax_ext/format.rs | 2 +- 31 files changed, 49 insertions(+), 50 deletions(-) diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 9ff52727187a5..3cc5c00130055 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -3423,7 +3423,7 @@ pub fn is_range_literal(sess: &Session, expr: &hir::Expr) -> bool { ExprKind::Call(ref func, _) => { if let ExprKind::Path(QPath::TypeRelative(ref ty, ref segment)) = func.kind { if let TyKind::Path(QPath::Resolved(None, ref path)) = ty.kind { - let new_call = segment.ident.as_str() == "new"; + let new_call = segment.ident.name == sym::new; return is_range_path(&path) && is_lit(sess, &expr.span) && new_call; } } diff --git a/src/librustc/mir/mono.rs b/src/librustc/mir/mono.rs index 58f99667cb3a4..a54635c3d51a3 100644 --- a/src/librustc/mir/mono.rs +++ b/src/librustc/mir/mono.rs @@ -486,7 +486,7 @@ impl CodegenUnitNameBuilder<'tcx> { if self.tcx.sess.opts.debugging_opts.human_readable_cgu_names { cgu_name } else { - let cgu_name = &cgu_name.as_str()[..]; + let cgu_name = &cgu_name.as_str(); Symbol::intern(&CodegenUnit::mangle_name(cgu_name)) } } diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs index 1f7bce1c644c5..184bbe0842b92 100644 --- a/src/librustc/traits/error_reporting.rs +++ b/src/librustc/traits/error_reporting.rs @@ -1130,7 +1130,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { let restrict_msg = "consider further restricting this bound"; let param_name = self_ty.to_string(); for param in generics.params.iter().filter(|p| { - ¶m_name == std::convert::AsRef::::as_ref(&p.name.ident().as_str()) + p.name.ident().as_str() == param_name }) { if param_name.starts_with("impl ") { // `impl Trait` in argument: diff --git a/src/librustc_codegen_llvm/attributes.rs b/src/librustc_codegen_llvm/attributes.rs index 6a36a4a50cbf3..6f4e7d0f0caf5 100644 --- a/src/librustc_codegen_llvm/attributes.rs +++ b/src/librustc_codegen_llvm/attributes.rs @@ -314,7 +314,7 @@ pub fn from_fn_attrs( codegen_fn_attrs.target_features .iter() .map(|f| { - let feature = &*f.as_str(); + let feature = &f.as_str(); format!("+{}", llvm_util::to_llvm_feature(cx.tcx.sess, feature)) }) ) diff --git a/src/librustc_codegen_llvm/debuginfo/namespace.rs b/src/librustc_codegen_llvm/debuginfo/namespace.rs index 628d1372b5702..482bcf2aa5835 100644 --- a/src/librustc_codegen_llvm/debuginfo/namespace.rs +++ b/src/librustc_codegen_llvm/debuginfo/namespace.rs @@ -34,11 +34,11 @@ pub fn item_namespace(cx: &CodegenCx<'ll, '_>, def_id: DefId) -> &'ll DIScope { }); let namespace_name = match def_key.disambiguated_data.data { - DefPathData::CrateRoot => cx.tcx.crate_name(def_id.krate).as_str(), - data => data.as_symbol().as_str() + DefPathData::CrateRoot => cx.tcx.crate_name(def_id.krate), + data => data.as_symbol() }; - let namespace_name = SmallCStr::new(&namespace_name); + let namespace_name = SmallCStr::new(&namespace_name.as_str()); let scope = unsafe { llvm::LLVMRustDIBuilderCreateNameSpace( diff --git a/src/librustc_codegen_ssa/back/symbol_export.rs b/src/librustc_codegen_ssa/back/symbol_export.rs index 85a90459f5ee4..35b62603b076a 100644 --- a/src/librustc_codegen_ssa/back/symbol_export.rs +++ b/src/librustc_codegen_ssa/back/symbol_export.rs @@ -129,9 +129,9 @@ fn reachable_non_generics_provider( // // In general though we won't link right if these // symbols are stripped, and LTO currently strips them. - if &*name == "rust_eh_personality" || - &*name == "rust_eh_register_frames" || - &*name == "rust_eh_unregister_frames" { + if name == "rust_eh_personality" || + name == "rust_eh_register_frames" || + name == "rust_eh_unregister_frames" { SymbolExportLevel::C } else { SymbolExportLevel::Rust diff --git a/src/librustc_codegen_utils/symbol_names/legacy.rs b/src/librustc_codegen_utils/symbol_names/legacy.rs index 601a33a66bb32..66e1b6d949ef7 100644 --- a/src/librustc_codegen_utils/symbol_names/legacy.rs +++ b/src/librustc_codegen_utils/symbol_names/legacy.rs @@ -121,9 +121,10 @@ fn get_symbol_hash<'tcx>( substs.hash_stable(&mut hcx, &mut hasher); if let Some(instantiating_crate) = instantiating_crate { - (&tcx.original_crate_name(instantiating_crate).as_str()[..]) + tcx.original_crate_name(instantiating_crate).as_str() + .hash_stable(&mut hcx, &mut hasher); + tcx.crate_disambiguator(instantiating_crate) .hash_stable(&mut hcx, &mut hasher); - (&tcx.crate_disambiguator(instantiating_crate)).hash_stable(&mut hcx, &mut hasher); } // We want to avoid accidental collision between different types of instances. diff --git a/src/librustc_incremental/assert_module_sources.rs b/src/librustc_incremental/assert_module_sources.rs index f740d1a9bfaf2..483b515f2ba4d 100644 --- a/src/librustc_incremental/assert_module_sources.rs +++ b/src/librustc_incremental/assert_module_sources.rs @@ -67,7 +67,7 @@ impl AssertModuleSource<'tcx> { } else if attr.check_name(ATTR_PARTITION_CODEGENED) { (CguReuse::No, ComparisonKind::Exact) } else if attr.check_name(ATTR_EXPECTED_CGU_REUSE) { - match &self.field(attr, sym::kind).as_str()[..] { + match &*self.field(attr, sym::kind).as_str() { "no" => (CguReuse::No, ComparisonKind::Exact), "pre-lto" => (CguReuse::PreLto, ComparisonKind::Exact), "post-lto" => (CguReuse::PostLto, ComparisonKind::Exact), diff --git a/src/librustc_incremental/persist/dirty_clean.rs b/src/librustc_incremental/persist/dirty_clean.rs index abe0ffb0e02c5..ea156a94ea17b 100644 --- a/src/librustc_incremental/persist/dirty_clean.rs +++ b/src/librustc_incremental/persist/dirty_clean.rs @@ -303,7 +303,7 @@ impl DirtyCleanVisitor<'tcx> { for item in attr.meta_item_list().unwrap_or_else(Vec::new) { if item.check_name(LABEL) { let value = expect_associated_value(self.tcx, &item); - return Some(self.resolve_labels(&item, value.as_str().as_ref())); + return Some(self.resolve_labels(&item, &value.as_str())); } } None @@ -314,7 +314,7 @@ impl DirtyCleanVisitor<'tcx> { for item in attr.meta_item_list().unwrap_or_else(Vec::new) { if item.check_name(EXCEPT) { let value = expect_associated_value(self.tcx, &item); - return self.resolve_labels(&item, value.as_str().as_ref()); + return self.resolve_labels(&item, &value.as_str()); } } // if no `label` or `except` is given, only the node's group are asserted diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index e3c3966c2f5e0..30d68fd0bfcb1 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -1476,14 +1476,12 @@ impl KeywordIdents { let mut lint = cx.struct_span_lint( KEYWORD_IDENTS, ident.span, - &format!("`{}` is a keyword in the {} edition", - ident.as_str(), - next_edition), + &format!("`{}` is a keyword in the {} edition", ident, next_edition), ); lint.span_suggestion( ident.span, "you can use a raw identifier to stay compatible", - format!("r#{}", ident.as_str()), + format!("r#{}", ident), Applicability::MachineApplicable, ); lint.emit() diff --git a/src/librustc_metadata/creader.rs b/src/librustc_metadata/creader.rs index 07c49d91797d4..483b1a40e44d6 100644 --- a/src/librustc_metadata/creader.rs +++ b/src/librustc_metadata/creader.rs @@ -121,7 +121,7 @@ impl<'a> CrateLoader<'a> { // `source` stores paths which are normalized which may be different // from the strings on the command line. let source = &self.cstore.get_crate_data(cnum).source; - if let Some(entry) = self.sess.opts.externs.get(&*name.as_str()) { + if let Some(entry) = self.sess.opts.externs.get(&name.as_str()) { // Only use `--extern crate_name=path` here, not `--extern crate_name`. let found = entry.locations.iter().filter_map(|l| l.as_ref()).any(|l| { let l = fs::canonicalize(l).ok(); diff --git a/src/librustc_metadata/native_libs.rs b/src/librustc_metadata/native_libs.rs index a58db6a903bb9..c9de66a5c8726 100644 --- a/src/librustc_metadata/native_libs.rs +++ b/src/librustc_metadata/native_libs.rs @@ -68,7 +68,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" => cstore::NativeStatic, "static-nobundle" => cstore::NativeStaticNobundle, "dylib" => cstore::NativeUnknown, diff --git a/src/librustc_mir/borrow_check/conflict_errors.rs b/src/librustc_mir/borrow_check/conflict_errors.rs index 36db68a3372eb..0913d743328a7 100644 --- a/src/librustc_mir/borrow_check/conflict_errors.rs +++ b/src/librustc_mir/borrow_check/conflict_errors.rs @@ -974,7 +974,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { let mut err = self.cannot_borrow_across_destructor(borrow_span); let what_was_dropped = match self.describe_place(place.as_ref()) { - Some(name) => format!("`{}`", name.as_str()), + Some(name) => format!("`{}`", name), None => String::from("temporary value"), }; diff --git a/src/librustc_mir/interpret/intrinsics.rs b/src/librustc_mir/interpret/intrinsics.rs index 519f4f0322228..f8aec4a369d05 100644 --- a/src/librustc_mir/interpret/intrinsics.rs +++ b/src/librustc_mir/interpret/intrinsics.rs @@ -95,7 +95,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { ) -> InterpResult<'tcx, bool> { let substs = instance.substs; - let intrinsic_name = &self.tcx.item_name(instance.def_id()).as_str()[..]; + let intrinsic_name = &*self.tcx.item_name(instance.def_id()).as_str(); match intrinsic_name { "caller_location" => { let caller = self.tcx.sess.source_map().lookup_char_pos(span.lo()); diff --git a/src/librustc_mir/transform/check_unsafety.rs b/src/librustc_mir/transform/check_unsafety.rs index d9b983ab790c2..7d5507168587b 100644 --- a/src/librustc_mir/transform/check_unsafety.rs +++ b/src/librustc_mir/transform/check_unsafety.rs @@ -642,8 +642,8 @@ pub fn check_unsafety(tcx: TyCtxt<'_>, def_id: DefId) { struct_span_err!( tcx.sess, source_info.span, E0133, "{} is unsafe and requires unsafe function or block", description) - .span_label(source_info.span, &description.as_str()[..]) - .note(&details.as_str()[..]) + .span_label(source_info.span, &*description.as_str()) + .note(&details.as_str()) .emit(); } UnsafetyViolationKind::ExternStatic(lint_hir_id) => { @@ -651,8 +651,8 @@ pub fn check_unsafety(tcx: TyCtxt<'_>, def_id: DefId) { lint_hir_id, source_info.span, &format!("{} is unsafe and requires unsafe function or block \ - (error E0133)", &description.as_str()[..]), - &details.as_str()[..]); + (error E0133)", description), + &details.as_str()); } UnsafetyViolationKind::BorrowPacked(lint_hir_id) => { if let Some(impl_def_id) = builtin_derive_def_id(tcx, def_id) { @@ -662,8 +662,8 @@ pub fn check_unsafety(tcx: TyCtxt<'_>, def_id: DefId) { lint_hir_id, source_info.span, &format!("{} is unsafe and requires unsafe function or block \ - (error E0133)", &description.as_str()[..]), - &details.as_str()[..]); + (error E0133)", description), + &details.as_str()); } } } diff --git a/src/librustc_mir/transform/qualify_consts.rs b/src/librustc_mir/transform/qualify_consts.rs index f488b457334e5..518f23e23fe91 100644 --- a/src/librustc_mir/transform/qualify_consts.rs +++ b/src/librustc_mir/transform/qualify_consts.rs @@ -537,7 +537,7 @@ impl Qualif for IsNotPromotable { Abi::RustIntrinsic | Abi::PlatformIntrinsic => { assert!(!cx.tcx.is_const_fn(def_id)); - match &cx.tcx.item_name(def_id).as_str()[..] { + match &*cx.tcx.item_name(def_id).as_str() { | "size_of" | "min_align_of" | "needs_drop" @@ -1476,7 +1476,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Checker<'a, 'tcx> { Abi::RustIntrinsic | Abi::PlatformIntrinsic => { assert!(!self.tcx.is_const_fn(def_id)); - match &self.tcx.item_name(def_id).as_str()[..] { + match &*self.tcx.item_name(def_id).as_str() { // special intrinsic that can be called diretly without an intrinsic // feature gate needs a language feature gate "transmute" => { diff --git a/src/librustc_mir/transform/qualify_min_const_fn.rs b/src/librustc_mir/transform/qualify_min_const_fn.rs index c4e44091bc90d..da1fba2518ac7 100644 --- a/src/librustc_mir/transform/qualify_min_const_fn.rs +++ b/src/librustc_mir/transform/qualify_min_const_fn.rs @@ -402,7 +402,7 @@ fn check_terminator( /// /// Adding more intrinsics requires sign-off from @rust-lang/lang. fn is_intrinsic_whitelisted(tcx: TyCtxt<'tcx>, def_id: DefId) -> bool { - match &tcx.item_name(def_id).as_str()[..] { + match &*tcx.item_name(def_id).as_str() { | "size_of" | "min_align_of" | "needs_drop" diff --git a/src/librustc_resolve/late.rs b/src/librustc_resolve/late.rs index 02f4345ac10ed..038de870174b7 100644 --- a/src/librustc_resolve/late.rs +++ b/src/librustc_resolve/late.rs @@ -1876,7 +1876,7 @@ impl<'a, 'b> LateResolutionVisitor<'a, '_> { None } }); - find_best_match_for_name(names, &*ident.as_str(), None) + find_best_match_for_name(names, &ident.as_str(), None) }); self.r.record_partial_res(expr.id, PartialRes::new(Res::Err)); self.r.report_error( diff --git a/src/librustc_typeck/check/demand.rs b/src/librustc_typeck/check/demand.rs index b4e07e4a0dfb4..2961d80e77639 100644 --- a/src/librustc_typeck/check/demand.rs +++ b/src/librustc_typeck/check/demand.rs @@ -308,7 +308,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { }) = parent { if let Ok(src) = cm.span_to_snippet(sp) { for field in fields { - if field.ident.as_str() == src.as_str() && field.is_shorthand { + if field.ident.as_str() == src && field.is_shorthand { return true; } } @@ -409,13 +409,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let mut sugg_sp = sp; if let hir::ExprKind::MethodCall(segment, _sp, args) = &expr.kind { let clone_trait = self.tcx.lang_items().clone_trait().unwrap(); - if let ([arg], Some(true), "clone") = ( + if let ([arg], Some(true), sym::clone) = ( &args[..], self.tables.borrow().type_dependent_def_id(expr.hir_id).map(|did| { let ai = self.tcx.associated_item(did); ai.container == ty::TraitContainer(clone_trait) }), - &segment.ident.as_str()[..], + segment.ident.name, ) { // If this expression had a clone call when suggesting borrowing // we want to suggest removing it because it'd now be unecessary. diff --git a/src/librustc_typeck/check/method/suggest.rs b/src/librustc_typeck/check/method/suggest.rs index d90ed2a790bb6..b7b7861ebef3e 100644 --- a/src/librustc_typeck/check/method/suggest.rs +++ b/src/librustc_typeck/check/method/suggest.rs @@ -835,11 +835,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { sp, &message(format!( "restrict type parameter `{}` with", - param.name.ident().as_str(), + param.name.ident(), )), candidates.iter().map(|t| format!( "{}{} {}{}", - param.name.ident().as_str(), + param.name.ident(), if impl_trait { " +" } else { ":" }, self.tcx.def_path_str(t.def_id), if has_bounds.is_some() { " + "} else { "" }, diff --git a/src/librustc_typeck/check/pat.rs b/src/librustc_typeck/check/pat.rs index 950ae7c1d62e2..f3f4abf01ebdd 100644 --- a/src/librustc_typeck/check/pat.rs +++ b/src/librustc_typeck/check/pat.rs @@ -978,7 +978,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ); // we don't want to throw `E0027` in case we have thrown `E0026` for them - unmentioned_fields.retain(|&x| x.as_str() != suggested_name.as_str()); + unmentioned_fields.retain(|&x| x.name != suggested_name); } } } diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 001d98aece2a0..b6c0b0d09fdf3 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -2404,7 +2404,7 @@ fn compute_sig_of_foreign_fn_decl<'tcx>( abi: abi::Abi, ) -> ty::PolyFnSig<'tcx> { let unsafety = if abi == abi::Abi::RustIntrinsic { - intrinsic_operation_unsafety(&*tcx.item_name(def_id).as_str()) + intrinsic_operation_unsafety(&tcx.item_name(def_id).as_str()) } else { hir::Unsafety::Unsafe }; diff --git a/src/librustdoc/clean/cfg.rs b/src/librustdoc/clean/cfg.rs index 11f45c5f6d01c..09f4873967ed5 100644 --- a/src/librustdoc/clean/cfg.rs +++ b/src/librustdoc/clean/cfg.rs @@ -404,7 +404,7 @@ impl<'a> fmt::Display for Html<'a> { if !human_readable.is_empty() { fmt.write_str(human_readable) } else if let Some(v) = value { - write!(fmt, "{}=\"{}\"", Escape(n), Escape(&*v.as_str())) + write!(fmt, "{}=\"{}\"", Escape(n), Escape(&v.as_str())) } else { write!(fmt, "{}", Escape(n)) } diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index cc1d1503c43d4..e7f7615525292 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -3704,7 +3704,7 @@ fn qpath_to_string(p: &hir::QPath) -> String { s.push_str("::"); } if seg.ident.name != kw::PathRoot { - s.push_str(&*seg.ident.as_str()); + s.push_str(&seg.ident.as_str()); } } s diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index c4ee84d33f39b..29f0b99d8ee69 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -2964,7 +2964,7 @@ fn render_attribute(attr: &ast::MetaItem) -> Option { if attr.is_word() { Some(path) } else if let Some(v) = attr.value_str() { - Some(format!("{} = {:?}", path, v.as_str())) + Some(format!("{} = {:?}", path, v)) } else if let Some(values) = attr.meta_item_list() { let display: Vec<_> = values.iter().filter_map(|attr| { attr.meta_item().and_then(|mi| render_attribute(mi)) diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 8b96704884851..8af38507b48d1 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -90,7 +90,7 @@ impl fmt::Debug for Lifetime { impl fmt::Display for Lifetime { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "{}", self.ident.name.as_str()) + write!(f, "{}", self.ident.name) } } diff --git a/src/libsyntax/feature_gate/check.rs b/src/libsyntax/feature_gate/check.rs index 97b99b9392f3f..4389dae2770ad 100644 --- a/src/libsyntax/feature_gate/check.rs +++ b/src/libsyntax/feature_gate/check.rs @@ -730,7 +730,7 @@ pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute], } if let Some(allowed) = allow_features.as_ref() { - if allowed.iter().find(|&f| f == &name.as_str() as &str).is_none() { + if allowed.iter().find(|&f| name.as_str() == *f).is_none() { span_err!(span_handler, mi.span(), E0725, "the feature `{}` is not in the list of allowed features", name); diff --git a/src/libsyntax/parse/literal.rs b/src/libsyntax/parse/literal.rs index 7952e293a532d..c42f4aa25cc96 100644 --- a/src/libsyntax/parse/literal.rs +++ b/src/libsyntax/parse/literal.rs @@ -134,9 +134,9 @@ impl LitKind { let (kind, symbol, suffix) = match *self { LitKind::Str(symbol, ast::StrStyle::Cooked) => { // Don't re-intern unless the escaped string is different. - let s: &str = &symbol.as_str(); + let s = symbol.as_str(); let escaped = s.escape_default().to_string(); - let symbol = if escaped == *s { symbol } else { Symbol::intern(&escaped) }; + let symbol = if s == escaped { symbol } else { Symbol::intern(&escaped) }; (token::Str, symbol, None) } LitKind::Str(symbol, ast::StrStyle::Raw(n)) => { diff --git a/src/libsyntax/parse/parser/module.rs b/src/libsyntax/parse/parser/module.rs index a0e4d2bbb7ac6..e80b1a7f60785 100644 --- a/src/libsyntax/parse/parser/module.rs +++ b/src/libsyntax/parse/parser/module.rs @@ -229,7 +229,7 @@ impl<'a> Parser<'a> { // `./.rs` and `.//mod.rs`. let relative_prefix_string; let relative_prefix = if let Some(ident) = relative { - relative_prefix_string = format!("{}{}", ident.as_str(), path::MAIN_SEPARATOR); + relative_prefix_string = format!("{}{}", ident, path::MAIN_SEPARATOR); &relative_prefix_string } else { "" diff --git a/src/libsyntax_ext/env.rs b/src/libsyntax_ext/env.rs index 58fe56bd2353a..6fb48bf81735b 100644 --- a/src/libsyntax_ext/env.rs +++ b/src/libsyntax_ext/env.rs @@ -21,7 +21,7 @@ pub fn expand_option_env<'cx>(cx: &'cx mut ExtCtxt<'_>, }; let sp = cx.with_def_site_ctxt(sp); - let e = match env::var(&*var.as_str()) { + let e = match env::var(&var.as_str()) { Err(..) => { let lt = cx.lifetime(sp, Ident::new(kw::StaticLifetime, sp)); cx.expr_path(cx.path_all(sp, diff --git a/src/libsyntax_ext/format.rs b/src/libsyntax_ext/format.rs index 37310f46f7eed..57b948858aa12 100644 --- a/src/libsyntax_ext/format.rs +++ b/src/libsyntax_ext/format.rs @@ -992,7 +992,7 @@ pub fn expand_preparsed_format_args( vec![] }; - let fmt_str = &*fmt_str.as_str(); // for the suggestions below + let fmt_str = &fmt_str.as_str(); // for the suggestions below let mut parser = parse::Parser::new(fmt_str, str_style, skips, append_newline); let mut unverified_pieces = Vec::new(); From d0db29003975d8c4b3a552ff8c3a68435173cdc7 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 22 Oct 2019 11:21:37 +1100 Subject: [PATCH 7/7] Remove the `AsRef` impl for `SymbolStr`. Because it's highly magical, which goes against the goal of keeping `SymbolStr` simple. Plus it's only used in a handful of places that only require minor changes. --- src/librustc_codegen_ssa/back/command.rs | 2 +- src/libsyntax/parse/parser/module.rs | 8 ++++---- src/libsyntax_pos/symbol.rs | 10 ---------- 3 files changed, 5 insertions(+), 15 deletions(-) diff --git a/src/librustc_codegen_ssa/back/command.rs b/src/librustc_codegen_ssa/back/command.rs index 2d84d67e3c85b..b8501f0e12a70 100644 --- a/src/librustc_codegen_ssa/back/command.rs +++ b/src/librustc_codegen_ssa/back/command.rs @@ -53,7 +53,7 @@ impl Command { } pub fn sym_arg(&mut self, arg: Symbol) -> &mut Command { - self.arg(&arg.as_str()); + self.arg(&*arg.as_str()); self } diff --git a/src/libsyntax/parse/parser/module.rs b/src/libsyntax/parse/parser/module.rs index e80b1a7f60785..242a17659a06b 100644 --- a/src/libsyntax/parse/parser/module.rs +++ b/src/libsyntax/parse/parser/module.rs @@ -210,7 +210,7 @@ impl<'a> Parser<'a> { // `/` to `\`. #[cfg(windows)] let s = s.replace("/", "\\"); - Some(dir_path.join(s)) + Some(dir_path.join(&*s)) } else { None } @@ -314,7 +314,7 @@ impl<'a> Parser<'a> { fn push_directory(&mut self, id: Ident, attrs: &[Attribute]) { if let Some(path) = attr::first_attr_value_str_by_name(attrs, sym::path) { - self.directory.path.to_mut().push(&path.as_str()); + self.directory.path.to_mut().push(&*path.as_str()); self.directory.ownership = DirectoryOwnership::Owned { relative: None }; } else { // We have to push on the current module name in the case of relative @@ -325,10 +325,10 @@ impl<'a> Parser<'a> { // directory path to `/x/y/z`, not `/x/z` with a relative offset of `y`. if let DirectoryOwnership::Owned { relative } = &mut self.directory.ownership { if let Some(ident) = relative.take() { // remove the relative offset - self.directory.path.to_mut().push(ident.as_str()); + self.directory.path.to_mut().push(&*ident.as_str()); } } - self.directory.path.to_mut().push(&id.as_str()); + self.directory.path.to_mut().push(&*id.as_str()); } } } diff --git a/src/libsyntax_pos/symbol.rs b/src/libsyntax_pos/symbol.rs index 4ff558a22e12d..3f7b3e5b3d82a 100644 --- a/src/libsyntax_pos/symbol.rs +++ b/src/libsyntax_pos/symbol.rs @@ -1099,16 +1099,6 @@ pub struct SymbolStr { string: &'static str, } -impl std::convert::AsRef for SymbolStr -where - str: std::convert::AsRef -{ - #[inline] - fn as_ref(&self) -> &U { - self.string.as_ref() - } -} - // This impl allows a `SymbolStr` to be directly equated with a `String` or // `&str`. impl> std::cmp::PartialEq for SymbolStr {