Skip to content

Commit a4ba181

Browse files
committed
Remove some Symbol:as_str() calls.
1 parent f03c7f8 commit a4ba181

File tree

5 files changed

+13
-10
lines changed

5 files changed

+13
-10
lines changed

src/librustc_middle/ty/print/pretty.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1440,12 +1440,12 @@ impl<F: fmt::Write> Printer<'tcx> for FmtPrinter<'_, 'tcx, F> {
14401440

14411441
// FIXME(eddyb) `name` should never be empty, but it
14421442
// currently is for `extern { ... }` "foreign modules".
1443-
let name = disambiguated_data.data.as_symbol().as_str();
1444-
if !name.is_empty() {
1443+
let name = disambiguated_data.data.as_symbol();
1444+
if name != kw::Invalid {
14451445
if !self.empty_path {
14461446
write!(self, "::")?;
14471447
}
1448-
if Ident::from_str(&name).is_raw_guess() {
1448+
if Ident::with_dummy_span(name).is_raw_guess() {
14491449
write!(self, "r#")?;
14501450
}
14511451
write!(self, "{}", name)?;

src/librustc_middle/ty/query/profiling_support.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,12 @@ impl<'p, 'c, 'tcx> QueryKeyStringBuilder<'p, 'c, 'tcx> {
6060

6161
match def_key.disambiguated_data.data {
6262
DefPathData::CrateRoot => {
63-
name = self.tcx.original_crate_name(def_id.krate).as_str();
63+
name = self.tcx.original_crate_name(def_id.krate);
6464
dis = "";
6565
end_index = 3;
6666
}
6767
other => {
68-
name = other.as_symbol().as_str();
68+
name = other.as_symbol();
6969
if def_key.disambiguated_data.disambiguator == 0 {
7070
dis = "";
7171
end_index = 3;
@@ -79,10 +79,11 @@ impl<'p, 'c, 'tcx> QueryKeyStringBuilder<'p, 'c, 'tcx> {
7979
}
8080
}
8181

82+
let name = &*name.as_str();
8283
let components = [
8384
StringComponent::Ref(parent_string_id),
8485
StringComponent::Value("::"),
85-
StringComponent::Value(&name[..]),
86+
StringComponent::Value(name),
8687
StringComponent::Value(dis),
8788
];
8889

src/librustc_span/symbol.rs

+2
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ symbols! {
252252
allowed,
253253
always,
254254
and,
255+
and_then,
255256
any,
256257
arbitrary_enum_discriminant,
257258
arbitrary_self_types,
@@ -649,6 +650,7 @@ symbols! {
649650
main,
650651
managed_boxes,
651652
manually_drop,
653+
map,
652654
marker,
653655
marker_trait_attr,
654656
masked,

src/librustc_trait_selection/traits/error_reporting/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use rustc_middle::ty::{
2626
TypeFoldable, WithConstness,
2727
};
2828
use rustc_session::DiagnosticMessageId;
29-
use rustc_span::symbol::sym;
29+
use rustc_span::symbol::{kw, sym};
3030
use rustc_span::{ExpnKind, MultiSpan, Span, DUMMY_SP};
3131
use std::fmt;
3232

@@ -1524,7 +1524,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
15241524
(self.tcx.sess.source_map().span_to_snippet(span), &obligation.cause.code)
15251525
{
15261526
let generics = self.tcx.generics_of(*def_id);
1527-
if generics.params.iter().any(|p| p.name.as_str() != "Self")
1527+
if generics.params.iter().any(|p| p.name != kw::SelfUpper)
15281528
&& !snippet.ends_with('>')
15291529
{
15301530
// FIXME: To avoid spurious suggestions in functions where type arguments

src/librustc_typeck/check/demand.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -322,12 +322,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
322322

323323
let self_ty = self.tables.borrow().node_type(method_expr[0].hir_id);
324324
let self_ty = format!("{:?}", self_ty);
325-
let name = method_path.ident.as_str();
325+
let name = method_path.ident.name;
326326
let is_as_ref_able = (self_ty.starts_with("&std::option::Option")
327327
|| self_ty.starts_with("&std::result::Result")
328328
|| self_ty.starts_with("std::option::Option")
329329
|| self_ty.starts_with("std::result::Result"))
330-
&& (name == "map" || name == "and_then");
330+
&& (name == sym::map || name == sym::and_then);
331331
match (is_as_ref_able, self.sess().source_map().span_to_snippet(*method_span)) {
332332
(true, Ok(src)) => {
333333
let suggestion = format!("as_ref().{}", src);

0 commit comments

Comments
 (0)