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

Diff for: src/librustc/hir/lowering.rs

+1-1
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
}

Diff for: 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
}

Diff for: 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:

Diff for: 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
)

Diff for: 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(

Diff for: 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

Diff for: 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.

Diff for: src/librustc_incremental/assert_module_sources.rs

+1-1
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),

Diff for: 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

Diff for: 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()

Diff for: 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();

Diff for: 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,

Diff for: 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

Diff for: 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());

Diff for: 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
}

Diff for: 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"
@@ -1476,7 +1476,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Checker<'a, 'tcx> {
14761476
Abi::RustIntrinsic |
14771477
Abi::PlatformIntrinsic => {
14781478
assert!(!self.tcx.is_const_fn(def_id));
1479-
match &self.tcx.item_name(def_id).as_str()[..] {
1479+
match &*self.tcx.item_name(def_id).as_str() {
14801480
// special intrinsic that can be called diretly without an intrinsic
14811481
// feature gate needs a language feature gate
14821482
"transmute" => {

Diff for: 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"

Diff for: src/librustc_resolve/late.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1876,7 +1876,7 @@ impl<'a, 'b> LateResolutionVisitor<'a, '_> {
18761876
None
18771877
}
18781878
});
1879-
find_best_match_for_name(names, &*ident.as_str(), None)
1879+
find_best_match_for_name(names, &ident.as_str(), None)
18801880
});
18811881
self.r.record_partial_res(expr.id, PartialRes::new(Res::Err));
18821882
self.r.report_error(

Diff for: src/librustc_typeck/check/demand.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
308308
}) = parent {
309309
if let Ok(src) = cm.span_to_snippet(sp) {
310310
for field in fields {
311-
if field.ident.as_str() == src.as_str() && field.is_shorthand {
311+
if field.ident.as_str() == src && field.is_shorthand {
312312
return true;
313313
}
314314
}
@@ -409,13 +409,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
409409
let mut sugg_sp = sp;
410410
if let hir::ExprKind::MethodCall(segment, _sp, args) = &expr.kind {
411411
let clone_trait = self.tcx.lang_items().clone_trait().unwrap();
412-
if let ([arg], Some(true), "clone") = (
412+
if let ([arg], Some(true), sym::clone) = (
413413
&args[..],
414414
self.tables.borrow().type_dependent_def_id(expr.hir_id).map(|did| {
415415
let ai = self.tcx.associated_item(did);
416416
ai.container == ty::TraitContainer(clone_trait)
417417
}),
418-
&segment.ident.as_str()[..],
418+
segment.ident.name,
419419
) {
420420
// If this expression had a clone call when suggesting borrowing
421421
// we want to suggest removing it because it'd now be unecessary.

Diff for: src/librustc_typeck/check/method/suggest.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -835,11 +835,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
835835
sp,
836836
&message(format!(
837837
"restrict type parameter `{}` with",
838-
param.name.ident().as_str(),
838+
param.name.ident(),
839839
)),
840840
candidates.iter().map(|t| format!(
841841
"{}{} {}{}",
842-
param.name.ident().as_str(),
842+
param.name.ident(),
843843
if impl_trait { " +" } else { ":" },
844844
self.tcx.def_path_str(t.def_id),
845845
if has_bounds.is_some() { " + "} else { "" },

Diff for: src/librustc_typeck/check/pat.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -978,7 +978,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
978978
);
979979

980980
// we don't want to throw `E0027` in case we have thrown `E0026` for them
981-
unmentioned_fields.retain(|&x| x.as_str() != suggested_name.as_str());
981+
unmentioned_fields.retain(|&x| x.name != suggested_name);
982982
}
983983
}
984984
}

Diff for: src/librustc_typeck/collect.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2404,7 +2404,7 @@ fn compute_sig_of_foreign_fn_decl<'tcx>(
24042404
abi: abi::Abi,
24052405
) -> ty::PolyFnSig<'tcx> {
24062406
let unsafety = if abi == abi::Abi::RustIntrinsic {
2407-
intrinsic_operation_unsafety(&*tcx.item_name(def_id).as_str())
2407+
intrinsic_operation_unsafety(&tcx.item_name(def_id).as_str())
24082408
} else {
24092409
hir::Unsafety::Unsafe
24102410
};

Diff for: src/librustdoc/clean/cfg.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ impl<'a> fmt::Display for Html<'a> {
404404
if !human_readable.is_empty() {
405405
fmt.write_str(human_readable)
406406
} else if let Some(v) = value {
407-
write!(fmt, "<code>{}=\"{}\"</code>", Escape(n), Escape(&*v.as_str()))
407+
write!(fmt, "<code>{}=\"{}\"</code>", Escape(n), Escape(&v.as_str()))
408408
} else {
409409
write!(fmt, "<code>{}</code>", Escape(n))
410410
}

Diff for: src/librustdoc/clean/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3704,7 +3704,7 @@ fn qpath_to_string(p: &hir::QPath) -> String {
37043704
s.push_str("::");
37053705
}
37063706
if seg.ident.name != kw::PathRoot {
3707-
s.push_str(&*seg.ident.as_str());
3707+
s.push_str(&seg.ident.as_str());
37083708
}
37093709
}
37103710
s

Diff for: src/librustdoc/html/render.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2964,7 +2964,7 @@ fn render_attribute(attr: &ast::MetaItem) -> Option<String> {
29642964
if attr.is_word() {
29652965
Some(path)
29662966
} else if let Some(v) = attr.value_str() {
2967-
Some(format!("{} = {:?}", path, v.as_str()))
2967+
Some(format!("{} = {:?}", path, v))
29682968
} else if let Some(values) = attr.meta_item_list() {
29692969
let display: Vec<_> = values.iter().filter_map(|attr| {
29702970
attr.meta_item().and_then(|mi| render_attribute(mi))

Diff for: src/libsyntax/ast.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ impl fmt::Debug for Lifetime {
9090

9191
impl fmt::Display for Lifetime {
9292
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
93-
write!(f, "{}", self.ident.name.as_str())
93+
write!(f, "{}", self.ident.name)
9494
}
9595
}
9696

Diff for: src/libsyntax/feature_gate/check.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,7 @@ pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute],
730730
}
731731

732732
if let Some(allowed) = allow_features.as_ref() {
733-
if allowed.iter().find(|&f| f == &name.as_str() as &str).is_none() {
733+
if allowed.iter().find(|&f| name.as_str() == *f).is_none() {
734734
span_err!(span_handler, mi.span(), E0725,
735735
"the feature `{}` is not in the list of allowed features",
736736
name);

Diff for: src/libsyntax/parse/literal.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,9 @@ impl LitKind {
134134
let (kind, symbol, suffix) = match *self {
135135
LitKind::Str(symbol, ast::StrStyle::Cooked) => {
136136
// Don't re-intern unless the escaped string is different.
137-
let s: &str = &symbol.as_str();
137+
let s = symbol.as_str();
138138
let escaped = s.escape_default().to_string();
139-
let symbol = if escaped == *s { symbol } else { Symbol::intern(&escaped) };
139+
let symbol = if s == escaped { symbol } else { Symbol::intern(&escaped) };
140140
(token::Str, symbol, None)
141141
}
142142
LitKind::Str(symbol, ast::StrStyle::Raw(n)) => {

Diff for: src/libsyntax/parse/parser/module.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ impl<'a> Parser<'a> {
229229
// `./<id>.rs` and `./<id>/mod.rs`.
230230
let relative_prefix_string;
231231
let relative_prefix = if let Some(ident) = relative {
232-
relative_prefix_string = format!("{}{}", ident.as_str(), path::MAIN_SEPARATOR);
232+
relative_prefix_string = format!("{}{}", ident, path::MAIN_SEPARATOR);
233233
&relative_prefix_string
234234
} else {
235235
""

Diff for: src/libsyntax_ext/env.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub fn expand_option_env<'cx>(cx: &'cx mut ExtCtxt<'_>,
2121
};
2222

2323
let sp = cx.with_def_site_ctxt(sp);
24-
let e = match env::var(&*var.as_str()) {
24+
let e = match env::var(&var.as_str()) {
2525
Err(..) => {
2626
let lt = cx.lifetime(sp, Ident::new(kw::StaticLifetime, sp));
2727
cx.expr_path(cx.path_all(sp,

Diff for: src/libsyntax_ext/format.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -992,7 +992,7 @@ pub fn expand_preparsed_format_args(
992992
vec![]
993993
};
994994

995-
let fmt_str = &*fmt_str.as_str(); // for the suggestions below
995+
let fmt_str = &fmt_str.as_str(); // for the suggestions below
996996
let mut parser = parse::Parser::new(fmt_str, str_style, skips, append_newline);
997997

998998
let mut unverified_pieces = Vec::new();

0 commit comments

Comments
 (0)