Skip to content

Commit a0b4b4d

Browse files
authored
Rollup merge of rust-lang#65776 - nnethercote:rename-LocalInternedString-and-more, r=estebank
Rename `LocalInternedString` and more This PR renames `LocalInternedString` as `SymbolStr`, removes an unnecessary `impl` from it, improves comments, and cleans up some `SymbolStr` uses. r? @estebank
2 parents e4931ea + d0db290 commit a0b4b4d

File tree

41 files changed

+103
-114
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+103
-114
lines changed

src/librustc/dep_graph/dep_node.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ impl<'tcx> DepNodeParams<'tcx> for CrateNum {
525525
}
526526

527527
fn to_debug_str(&self, tcx: TyCtxt<'tcx>) -> String {
528-
tcx.crate_name(*self).as_str().to_string()
528+
tcx.crate_name(*self).to_string()
529529
}
530530
}
531531

src/librustc/hir/lowering.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3382,7 +3382,7 @@ pub fn is_range_literal(sess: &Session, expr: &hir::Expr) -> bool {
33823382
// either in std or core, i.e. has either a `::std::ops::Range` or
33833383
// `::core::ops::Range` prefix.
33843384
fn is_range_path(path: &Path) -> bool {
3385-
let segs: Vec<_> = path.segments.iter().map(|seg| seg.ident.as_str().to_string()).collect();
3385+
let segs: Vec<_> = path.segments.iter().map(|seg| seg.ident.to_string()).collect();
33863386
let segs: Vec<_> = segs.iter().map(|seg| &**seg).collect();
33873387

33883388
// "{{root}}" is the equivalent of `::` prefix in `Path`.
@@ -3423,7 +3423,7 @@ pub fn is_range_literal(sess: &Session, expr: &hir::Expr) -> bool {
34233423
ExprKind::Call(ref func, _) => {
34243424
if let ExprKind::Path(QPath::TypeRelative(ref ty, ref segment)) = func.kind {
34253425
if let TyKind::Path(QPath::Resolved(None, ref path)) = ty.kind {
3426-
let new_call = segment.ident.as_str() == "new";
3426+
let new_call = segment.ident.name == sym::new;
34273427
return is_range_path(&path) && is_lit(sess, &expr.span) && new_call;
34283428
}
34293429
}

src/librustc/hir/print.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ impl<'a> State<'a> {
564564
}
565565
hir::ItemKind::GlobalAsm(ref ga) => {
566566
self.head(visibility_qualified(&item.vis, "global asm"));
567-
self.s.word(ga.asm.as_str().to_string());
567+
self.s.word(ga.asm.to_string());
568568
self.end()
569569
}
570570
hir::ItemKind::TyAlias(ref ty, ref generics) => {
@@ -1855,7 +1855,7 @@ impl<'a> State<'a> {
18551855
self.commasep(Inconsistent, &decl.inputs, |s, ty| {
18561856
s.ibox(INDENT_UNIT);
18571857
if let Some(arg_name) = arg_names.get(i) {
1858-
s.s.word(arg_name.as_str().to_string());
1858+
s.s.word(arg_name.to_string());
18591859
s.s.word(":");
18601860
s.s.space();
18611861
} else if let Some(body_id) = body_id {

src/librustc/ich/impls_syntax.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::mem;
99
use syntax::ast;
1010
use syntax::feature_gate;
1111
use syntax::parse::token;
12-
use syntax::symbol::LocalInternedString;
12+
use syntax::symbol::SymbolStr;
1313
use syntax::tokenstream;
1414
use syntax_pos::SourceFile;
1515

@@ -18,21 +18,21 @@ use crate::hir::def_id::{DefId, CrateNum, CRATE_DEF_INDEX};
1818
use smallvec::SmallVec;
1919
use rustc_data_structures::stable_hasher::{HashStable, ToStableHashKey, StableHasher};
2020

21-
impl<'a> HashStable<StableHashingContext<'a>> for LocalInternedString {
21+
impl<'a> HashStable<StableHashingContext<'a>> for SymbolStr {
2222
#[inline]
2323
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
2424
let str = self as &str;
2525
str.hash_stable(hcx, hasher)
2626
}
2727
}
2828

29-
impl<'a> ToStableHashKey<StableHashingContext<'a>> for LocalInternedString {
30-
type KeyType = LocalInternedString;
29+
impl<'a> ToStableHashKey<StableHashingContext<'a>> for SymbolStr {
30+
type KeyType = SymbolStr;
3131

3232
#[inline]
3333
fn to_stable_hash_key(&self,
3434
_: &StableHashingContext<'a>)
35-
-> LocalInternedString {
35+
-> SymbolStr {
3636
self.clone()
3737
}
3838
}
@@ -45,12 +45,12 @@ impl<'a> HashStable<StableHashingContext<'a>> for ast::Name {
4545
}
4646

4747
impl<'a> ToStableHashKey<StableHashingContext<'a>> for ast::Name {
48-
type KeyType = LocalInternedString;
48+
type KeyType = SymbolStr;
4949

5050
#[inline]
5151
fn to_stable_hash_key(&self,
5252
_: &StableHashingContext<'a>)
53-
-> LocalInternedString {
53+
-> SymbolStr {
5454
self.as_str()
5555
}
5656
}

src/librustc/mir/mono.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ impl CodegenUnitNameBuilder<'tcx> {
486486
if self.tcx.sess.opts.debugging_opts.human_readable_cgu_names {
487487
cgu_name
488488
} else {
489-
let cgu_name = &cgu_name.as_str()[..];
489+
let cgu_name = &cgu_name.as_str();
490490
Symbol::intern(&CodegenUnit::mangle_name(cgu_name))
491491
}
492492
}

src/librustc/traits/error_reporting.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1130,7 +1130,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
11301130
let restrict_msg = "consider further restricting this bound";
11311131
let param_name = self_ty.to_string();
11321132
for param in generics.params.iter().filter(|p| {
1133-
&param_name == std::convert::AsRef::<str>::as_ref(&p.name.ident().as_str())
1133+
p.name.ident().as_str() == param_name
11341134
}) {
11351135
if param_name.starts_with("impl ") {
11361136
// `impl Trait` in argument:

src/librustc/traits/on_unimplemented.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ impl<'tcx> OnUnimplementedDirective {
180180
c.ident().map_or(false, |ident| {
181181
options.contains(&(
182182
ident.name,
183-
c.value_str().map(|s| s.as_str().to_string())
183+
c.value_str().map(|s| s.to_string())
184184
))
185185
})
186186
}) {

src/librustc/ty/query/on_disk_cache.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ impl<'sess> OnDiskCache<'sess> {
264264
let sorted_cnums = sorted_cnums_including_local_crate(tcx);
265265
let prev_cnums: Vec<_> = sorted_cnums.iter()
266266
.map(|&cnum| {
267-
let crate_name = tcx.original_crate_name(cnum).as_str().to_string();
267+
let crate_name = tcx.original_crate_name(cnum).to_string();
268268
let crate_disambiguator = tcx.crate_disambiguator(cnum);
269269
(cnum.as_u32(), crate_name, crate_disambiguator)
270270
})

src/librustc_codegen_llvm/attributes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ pub fn from_fn_attrs(
314314
codegen_fn_attrs.target_features
315315
.iter()
316316
.map(|f| {
317-
let feature = &*f.as_str();
317+
let feature = &f.as_str();
318318
format!("+{}", llvm_util::to_llvm_feature(cx.tcx.sess, feature))
319319
})
320320
)

src/librustc_codegen_llvm/debuginfo/namespace.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ pub fn item_namespace(cx: &CodegenCx<'ll, '_>, def_id: DefId) -> &'ll DIScope {
3434
});
3535

3636
let namespace_name = match def_key.disambiguated_data.data {
37-
DefPathData::CrateRoot => cx.tcx.crate_name(def_id.krate).as_str(),
38-
data => data.as_symbol().as_str()
37+
DefPathData::CrateRoot => cx.tcx.crate_name(def_id.krate),
38+
data => data.as_symbol()
3939
};
4040

41-
let namespace_name = SmallCStr::new(&namespace_name);
41+
let namespace_name = SmallCStr::new(&namespace_name.as_str());
4242

4343
let scope = unsafe {
4444
llvm::LLVMRustDIBuilderCreateNameSpace(

src/librustc_codegen_ssa/back/command.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ impl Command {
5353
}
5454

5555
pub fn sym_arg(&mut self, arg: Symbol) -> &mut Command {
56-
self.arg(&arg.as_str());
56+
self.arg(&*arg.as_str());
5757
self
5858
}
5959

src/librustc_codegen_ssa/back/symbol_export.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,9 @@ fn reachable_non_generics_provider(
129129
//
130130
// In general though we won't link right if these
131131
// symbols are stripped, and LTO currently strips them.
132-
if &*name == "rust_eh_personality" ||
133-
&*name == "rust_eh_register_frames" ||
134-
&*name == "rust_eh_unregister_frames" {
132+
if name == "rust_eh_personality" ||
133+
name == "rust_eh_register_frames" ||
134+
name == "rust_eh_unregister_frames" {
135135
SymbolExportLevel::C
136136
} else {
137137
SymbolExportLevel::Rust

src/librustc_codegen_ssa/base.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -552,8 +552,7 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
552552
} else if let Some(kind) = *tcx.sess.allocator_kind.get() {
553553
let llmod_id = cgu_name_builder.build_cgu_name(LOCAL_CRATE,
554554
&["crate"],
555-
Some("allocator")).as_str()
556-
.to_string();
555+
Some("allocator")).to_string();
557556
let mut modules = backend.new_metadata(tcx, &llmod_id);
558557
time(tcx.sess, "write allocator module", || {
559558
backend.codegen_allocator(tcx, &mut modules, kind)
@@ -576,8 +575,7 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
576575
// Codegen the encoded metadata.
577576
let metadata_cgu_name = cgu_name_builder.build_cgu_name(LOCAL_CRATE,
578577
&["crate"],
579-
Some("metadata")).as_str()
580-
.to_string();
578+
Some("metadata")).to_string();
581579
let mut metadata_llvm_module = backend.new_metadata(tcx, &metadata_cgu_name);
582580
time(tcx.sess, "write compressed metadata", || {
583581
backend.write_compressed_metadata(tcx, &ongoing_codegen.metadata,

src/librustc_codegen_utils/symbol_names/legacy.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,10 @@ fn get_symbol_hash<'tcx>(
121121
substs.hash_stable(&mut hcx, &mut hasher);
122122

123123
if let Some(instantiating_crate) = instantiating_crate {
124-
(&tcx.original_crate_name(instantiating_crate).as_str()[..])
124+
tcx.original_crate_name(instantiating_crate).as_str()
125+
.hash_stable(&mut hcx, &mut hasher);
126+
tcx.crate_disambiguator(instantiating_crate)
125127
.hash_stable(&mut hcx, &mut hasher);
126-
(&tcx.crate_disambiguator(instantiating_crate)).hash_stable(&mut hcx, &mut hasher);
127128
}
128129

129130
// We want to avoid accidental collision between different types of instances.

src/librustc_incremental/assert_module_sources.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@ use syntax::symbol::{Symbol, sym};
3131
use rustc::ich::{ATTR_PARTITION_REUSED, ATTR_PARTITION_CODEGENED,
3232
ATTR_EXPECTED_CGU_REUSE};
3333

34-
const MODULE: Symbol = sym::module;
35-
const CFG: Symbol = sym::cfg;
36-
const KIND: Symbol = sym::kind;
37-
3834
pub fn assert_module_sources(tcx: TyCtxt<'_>) {
3935
tcx.dep_graph.with_ignore(|| {
4036
if tcx.sess.opts.incremental.is_none() {
@@ -71,7 +67,7 @@ impl AssertModuleSource<'tcx> {
7167
} else if attr.check_name(ATTR_PARTITION_CODEGENED) {
7268
(CguReuse::No, ComparisonKind::Exact)
7369
} else if attr.check_name(ATTR_EXPECTED_CGU_REUSE) {
74-
match &self.field(attr, KIND).as_str()[..] {
70+
match &*self.field(attr, sym::kind).as_str() {
7571
"no" => (CguReuse::No, ComparisonKind::Exact),
7672
"pre-lto" => (CguReuse::PreLto, ComparisonKind::Exact),
7773
"post-lto" => (CguReuse::PostLto, ComparisonKind::Exact),
@@ -98,8 +94,8 @@ impl AssertModuleSource<'tcx> {
9894
return;
9995
}
10096

101-
let user_path = self.field(attr, MODULE).as_str().to_string();
102-
let crate_name = self.tcx.crate_name(LOCAL_CRATE).as_str().to_string();
97+
let user_path = self.field(attr, sym::module).to_string();
98+
let crate_name = self.tcx.crate_name(LOCAL_CRATE).to_string();
10399

104100
if !user_path.starts_with(&crate_name) {
105101
let msg = format!("Found malformed codegen unit name `{}`. \
@@ -125,7 +121,7 @@ impl AssertModuleSource<'tcx> {
125121
cgu_path_components,
126122
cgu_special_suffix);
127123

128-
debug!("mapping '{}' to cgu name '{}'", self.field(attr, MODULE), cgu_name);
124+
debug!("mapping '{}' to cgu name '{}'", self.field(attr, sym::module), cgu_name);
129125

130126
if !self.available_cgus.contains(&cgu_name) {
131127
self.tcx.sess.span_err(attr.span,
@@ -135,7 +131,7 @@ impl AssertModuleSource<'tcx> {
135131
cgu_name,
136132
self.available_cgus
137133
.iter()
138-
.map(|cgu| cgu.as_str().to_string())
134+
.map(|cgu| cgu.to_string())
139135
.collect::<Vec<_>>()
140136
.join(", ")));
141137
}
@@ -169,7 +165,7 @@ impl AssertModuleSource<'tcx> {
169165
/// cfg flag called `foo`.
170166
fn check_config(&self, attr: &ast::Attribute) -> bool {
171167
let config = &self.tcx.sess.parse_sess.config;
172-
let value = self.field(attr, CFG);
168+
let value = self.field(attr, sym::cfg);
173169
debug!("check_config(config={:?}, value={:?})", config, value);
174170
if config.iter().any(|&(name, _)| name == value) {
175171
debug!("check_config: matched");

src/librustc_incremental/persist/dirty_clean.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ impl DirtyCleanVisitor<'tcx> {
303303
for item in attr.meta_item_list().unwrap_or_else(Vec::new) {
304304
if item.check_name(LABEL) {
305305
let value = expect_associated_value(self.tcx, &item);
306-
return Some(self.resolve_labels(&item, value.as_str().as_ref()));
306+
return Some(self.resolve_labels(&item, &value.as_str()));
307307
}
308308
}
309309
None
@@ -314,7 +314,7 @@ impl DirtyCleanVisitor<'tcx> {
314314
for item in attr.meta_item_list().unwrap_or_else(Vec::new) {
315315
if item.check_name(EXCEPT) {
316316
let value = expect_associated_value(self.tcx, &item);
317-
return self.resolve_labels(&item, value.as_str().as_ref());
317+
return self.resolve_labels(&item, &value.as_str());
318318
}
319319
}
320320
// if no `label` or `except` is given, only the node's group are asserted

src/librustc_lint/builtin.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1476,14 +1476,12 @@ impl KeywordIdents {
14761476
let mut lint = cx.struct_span_lint(
14771477
KEYWORD_IDENTS,
14781478
ident.span,
1479-
&format!("`{}` is a keyword in the {} edition",
1480-
ident.as_str(),
1481-
next_edition),
1479+
&format!("`{}` is a keyword in the {} edition", ident, next_edition),
14821480
);
14831481
lint.span_suggestion(
14841482
ident.span,
14851483
"you can use a raw identifier to stay compatible",
1486-
format!("r#{}", ident.as_str()),
1484+
format!("r#{}", ident),
14871485
Applicability::MachineApplicable,
14881486
);
14891487
lint.emit()

src/librustc_metadata/creader.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ impl<'a> CrateLoader<'a> {
121121
// `source` stores paths which are normalized which may be different
122122
// from the strings on the command line.
123123
let source = &self.cstore.get_crate_data(cnum).source;
124-
if let Some(entry) = self.sess.opts.externs.get(&*name.as_str()) {
124+
if let Some(entry) = self.sess.opts.externs.get(&name.as_str()) {
125125
// Only use `--extern crate_name=path` here, not `--extern crate_name`.
126126
let found = entry.locations.iter().filter_map(|l| l.as_ref()).any(|l| {
127127
let l = fs::canonicalize(l).ok();

src/librustc_metadata/native_libs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ impl ItemLikeVisitor<'tcx> for Collector<'tcx> {
6868
Some(name) => name,
6969
None => continue, // skip like historical compilers
7070
};
71-
lib.kind = match &kind.as_str()[..] {
71+
lib.kind = match &*kind.as_str() {
7272
"static" => cstore::NativeStatic,
7373
"static-nobundle" => cstore::NativeStaticNobundle,
7474
"dylib" => cstore::NativeUnknown,

src/librustc_mir/borrow_check/conflict_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -974,7 +974,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
974974
let mut err = self.cannot_borrow_across_destructor(borrow_span);
975975

976976
let what_was_dropped = match self.describe_place(place.as_ref()) {
977-
Some(name) => format!("`{}`", name.as_str()),
977+
Some(name) => format!("`{}`", name),
978978
None => String::from("temporary value"),
979979
};
980980

src/librustc_mir/interpret/intrinsics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
9595
) -> InterpResult<'tcx, bool> {
9696
let substs = instance.substs;
9797

98-
let intrinsic_name = &self.tcx.item_name(instance.def_id()).as_str()[..];
98+
let intrinsic_name = &*self.tcx.item_name(instance.def_id()).as_str();
9999
match intrinsic_name {
100100
"caller_location" => {
101101
let caller = self.tcx.sess.source_map().lookup_char_pos(span.lo());

src/librustc_mir/transform/check_unsafety.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -642,17 +642,17 @@ pub fn check_unsafety(tcx: TyCtxt<'_>, def_id: DefId) {
642642
struct_span_err!(
643643
tcx.sess, source_info.span, E0133,
644644
"{} is unsafe and requires unsafe function or block", description)
645-
.span_label(source_info.span, &description.as_str()[..])
646-
.note(&details.as_str()[..])
645+
.span_label(source_info.span, &*description.as_str())
646+
.note(&details.as_str())
647647
.emit();
648648
}
649649
UnsafetyViolationKind::ExternStatic(lint_hir_id) => {
650650
tcx.lint_node_note(SAFE_EXTERN_STATICS,
651651
lint_hir_id,
652652
source_info.span,
653653
&format!("{} is unsafe and requires unsafe function or block \
654-
(error E0133)", &description.as_str()[..]),
655-
&details.as_str()[..]);
654+
(error E0133)", description),
655+
&details.as_str());
656656
}
657657
UnsafetyViolationKind::BorrowPacked(lint_hir_id) => {
658658
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) {
662662
lint_hir_id,
663663
source_info.span,
664664
&format!("{} is unsafe and requires unsafe function or block \
665-
(error E0133)", &description.as_str()[..]),
666-
&details.as_str()[..]);
665+
(error E0133)", description),
666+
&details.as_str());
667667
}
668668
}
669669
}

src/librustc_mir/transform/qualify_consts.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ impl Qualif for IsNotPromotable {
537537
Abi::RustIntrinsic |
538538
Abi::PlatformIntrinsic => {
539539
assert!(!cx.tcx.is_const_fn(def_id));
540-
match &cx.tcx.item_name(def_id).as_str()[..] {
540+
match &*cx.tcx.item_name(def_id).as_str() {
541541
| "size_of"
542542
| "min_align_of"
543543
| "needs_drop"
@@ -1477,7 +1477,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Checker<'a, 'tcx> {
14771477
Abi::RustIntrinsic |
14781478
Abi::PlatformIntrinsic => {
14791479
assert!(!self.tcx.is_const_fn(def_id));
1480-
match &self.tcx.item_name(def_id).as_str()[..] {
1480+
match &*self.tcx.item_name(def_id).as_str() {
14811481
// special intrinsic that can be called diretly without an intrinsic
14821482
// feature gate needs a language feature gate
14831483
"transmute" => {

src/librustc_mir/transform/qualify_min_const_fn.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ fn check_terminator(
402402
///
403403
/// Adding more intrinsics requires sign-off from @rust-lang/lang.
404404
fn is_intrinsic_whitelisted(tcx: TyCtxt<'tcx>, def_id: DefId) -> bool {
405-
match &tcx.item_name(def_id).as_str()[..] {
405+
match &*tcx.item_name(def_id).as_str() {
406406
| "size_of"
407407
| "min_align_of"
408408
| "needs_drop"

0 commit comments

Comments
 (0)