Skip to content

Commit b9cef69

Browse files
committed
Simplify various Symbol use points.
Including removing a bunch of unnecessary `.as_str()` calls, and a bunch of unnecessary sigils.
1 parent 5bc7084 commit b9cef69

File tree

31 files changed

+49
-50
lines changed

31 files changed

+49
-50
lines changed

src/librustc/hir/lowering.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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/mir/mono.rs

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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_codegen_llvm/attributes.rs

Lines changed: 1 addition & 1 deletion
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

Lines changed: 3 additions & 3 deletions
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/symbol_export.rs

Lines changed: 3 additions & 3 deletions
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_utils/symbol_names/legacy.rs

Lines changed: 3 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ impl AssertModuleSource<'tcx> {
6767
} else if attr.check_name(ATTR_PARTITION_CODEGENED) {
6868
(CguReuse::No, ComparisonKind::Exact)
6969
} else if attr.check_name(ATTR_EXPECTED_CGU_REUSE) {
70-
match &self.field(attr, sym::kind).as_str()[..] {
70+
match &*self.field(attr, sym::kind).as_str() {
7171
"no" => (CguReuse::No, ComparisonKind::Exact),
7272
"pre-lto" => (CguReuse::PreLto, ComparisonKind::Exact),
7373
"post-lto" => (CguReuse::PostLto, ComparisonKind::Exact),

src/librustc_incremental/persist/dirty_clean.rs

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 4 deletions
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()

0 commit comments

Comments
 (0)