Skip to content

Commit

Permalink
Remove some Symbol:as_str() calls.
Browse files Browse the repository at this point in the history
  • Loading branch information
nnethercote committed Jul 16, 2020
1 parent f03c7f8 commit a4ba181
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/librustc_middle/ty/print/pretty.rs
Expand Up @@ -1440,12 +1440,12 @@ impl<F: fmt::Write> Printer<'tcx> for FmtPrinter<'_, 'tcx, F> {

// FIXME(eddyb) `name` should never be empty, but it
// currently is for `extern { ... }` "foreign modules".
let name = disambiguated_data.data.as_symbol().as_str();
if !name.is_empty() {
let name = disambiguated_data.data.as_symbol();
if name != kw::Invalid {
if !self.empty_path {
write!(self, "::")?;
}
if Ident::from_str(&name).is_raw_guess() {
if Ident::with_dummy_span(name).is_raw_guess() {
write!(self, "r#")?;
}
write!(self, "{}", name)?;
Expand Down
7 changes: 4 additions & 3 deletions src/librustc_middle/ty/query/profiling_support.rs
Expand Up @@ -60,12 +60,12 @@ impl<'p, 'c, 'tcx> QueryKeyStringBuilder<'p, 'c, 'tcx> {

match def_key.disambiguated_data.data {
DefPathData::CrateRoot => {
name = self.tcx.original_crate_name(def_id.krate).as_str();
name = self.tcx.original_crate_name(def_id.krate);
dis = "";
end_index = 3;
}
other => {
name = other.as_symbol().as_str();
name = other.as_symbol();
if def_key.disambiguated_data.disambiguator == 0 {
dis = "";
end_index = 3;
Expand All @@ -79,10 +79,11 @@ impl<'p, 'c, 'tcx> QueryKeyStringBuilder<'p, 'c, 'tcx> {
}
}

let name = &*name.as_str();
let components = [
StringComponent::Ref(parent_string_id),
StringComponent::Value("::"),
StringComponent::Value(&name[..]),
StringComponent::Value(name),
StringComponent::Value(dis),
];

Expand Down
2 changes: 2 additions & 0 deletions src/librustc_span/symbol.rs
Expand Up @@ -252,6 +252,7 @@ symbols! {
allowed,
always,
and,
and_then,
any,
arbitrary_enum_discriminant,
arbitrary_self_types,
Expand Down Expand Up @@ -649,6 +650,7 @@ symbols! {
main,
managed_boxes,
manually_drop,
map,
marker,
marker_trait_attr,
masked,
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_trait_selection/traits/error_reporting/mod.rs
Expand Up @@ -26,7 +26,7 @@ use rustc_middle::ty::{
TypeFoldable, WithConstness,
};
use rustc_session::DiagnosticMessageId;
use rustc_span::symbol::sym;
use rustc_span::symbol::{kw, sym};
use rustc_span::{ExpnKind, MultiSpan, Span, DUMMY_SP};
use std::fmt;

Expand Down Expand Up @@ -1524,7 +1524,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
(self.tcx.sess.source_map().span_to_snippet(span), &obligation.cause.code)
{
let generics = self.tcx.generics_of(*def_id);
if generics.params.iter().any(|p| p.name.as_str() != "Self")
if generics.params.iter().any(|p| p.name != kw::SelfUpper)
&& !snippet.ends_with('>')
{
// FIXME: To avoid spurious suggestions in functions where type arguments
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_typeck/check/demand.rs
Expand Up @@ -322,12 +322,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

let self_ty = self.tables.borrow().node_type(method_expr[0].hir_id);
let self_ty = format!("{:?}", self_ty);
let name = method_path.ident.as_str();
let name = method_path.ident.name;
let is_as_ref_able = (self_ty.starts_with("&std::option::Option")
|| self_ty.starts_with("&std::result::Result")
|| self_ty.starts_with("std::option::Option")
|| self_ty.starts_with("std::result::Result"))
&& (name == "map" || name == "and_then");
&& (name == sym::map || name == sym::and_then);
match (is_as_ref_able, self.sess().source_map().span_to_snippet(*method_span)) {
(true, Ok(src)) => {
let suggestion = format!("as_ref().{}", src);
Expand Down

0 comments on commit a4ba181

Please sign in to comment.