Simplify various Symbol
use points.
Including removing a bunch of unnecessary `.as_str()` calls, and a bunch of unnecessary sigils.
This commit is contained in:
parent
5bc7084f7e
commit
b9cef6984b
@ -3423,7 +3423,7 @@ pub fn is_range_literal(sess: &Session, expr: &hir::Expr) -> bool {
|
||||
ExprKind::Call(ref func, _) => {
|
||||
if let ExprKind::Path(QPath::TypeRelative(ref ty, ref segment)) = func.kind {
|
||||
if let TyKind::Path(QPath::Resolved(None, ref path)) = ty.kind {
|
||||
let new_call = segment.ident.as_str() == "new";
|
||||
let new_call = segment.ident.name == sym::new;
|
||||
return is_range_path(&path) && is_lit(sess, &expr.span) && new_call;
|
||||
}
|
||||
}
|
||||
|
@ -486,7 +486,7 @@ impl CodegenUnitNameBuilder<'tcx> {
|
||||
if self.tcx.sess.opts.debugging_opts.human_readable_cgu_names {
|
||||
cgu_name
|
||||
} else {
|
||||
let cgu_name = &cgu_name.as_str()[..];
|
||||
let cgu_name = &cgu_name.as_str();
|
||||
Symbol::intern(&CodegenUnit::mangle_name(cgu_name))
|
||||
}
|
||||
}
|
||||
|
@ -1130,7 +1130,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
let restrict_msg = "consider further restricting this bound";
|
||||
let param_name = self_ty.to_string();
|
||||
for param in generics.params.iter().filter(|p| {
|
||||
¶m_name == std::convert::AsRef::<str>::as_ref(&p.name.ident().as_str())
|
||||
p.name.ident().as_str() == param_name
|
||||
}) {
|
||||
if param_name.starts_with("impl ") {
|
||||
// `impl Trait` in argument:
|
||||
|
@ -314,7 +314,7 @@ pub fn from_fn_attrs(
|
||||
codegen_fn_attrs.target_features
|
||||
.iter()
|
||||
.map(|f| {
|
||||
let feature = &*f.as_str();
|
||||
let feature = &f.as_str();
|
||||
format!("+{}", llvm_util::to_llvm_feature(cx.tcx.sess, feature))
|
||||
})
|
||||
)
|
||||
|
@ -34,11 +34,11 @@ pub fn item_namespace(cx: &CodegenCx<'ll, '_>, def_id: DefId) -> &'ll DIScope {
|
||||
});
|
||||
|
||||
let namespace_name = match def_key.disambiguated_data.data {
|
||||
DefPathData::CrateRoot => cx.tcx.crate_name(def_id.krate).as_str(),
|
||||
data => data.as_symbol().as_str()
|
||||
DefPathData::CrateRoot => cx.tcx.crate_name(def_id.krate),
|
||||
data => data.as_symbol()
|
||||
};
|
||||
|
||||
let namespace_name = SmallCStr::new(&namespace_name);
|
||||
let namespace_name = SmallCStr::new(&namespace_name.as_str());
|
||||
|
||||
let scope = unsafe {
|
||||
llvm::LLVMRustDIBuilderCreateNameSpace(
|
||||
|
@ -129,9 +129,9 @@ fn reachable_non_generics_provider(
|
||||
//
|
||||
// In general though we won't link right if these
|
||||
// symbols are stripped, and LTO currently strips them.
|
||||
if &*name == "rust_eh_personality" ||
|
||||
&*name == "rust_eh_register_frames" ||
|
||||
&*name == "rust_eh_unregister_frames" {
|
||||
if name == "rust_eh_personality" ||
|
||||
name == "rust_eh_register_frames" ||
|
||||
name == "rust_eh_unregister_frames" {
|
||||
SymbolExportLevel::C
|
||||
} else {
|
||||
SymbolExportLevel::Rust
|
||||
|
@ -121,9 +121,10 @@ fn get_symbol_hash<'tcx>(
|
||||
substs.hash_stable(&mut hcx, &mut hasher);
|
||||
|
||||
if let Some(instantiating_crate) = instantiating_crate {
|
||||
(&tcx.original_crate_name(instantiating_crate).as_str()[..])
|
||||
tcx.original_crate_name(instantiating_crate).as_str()
|
||||
.hash_stable(&mut hcx, &mut hasher);
|
||||
tcx.crate_disambiguator(instantiating_crate)
|
||||
.hash_stable(&mut hcx, &mut hasher);
|
||||
(&tcx.crate_disambiguator(instantiating_crate)).hash_stable(&mut hcx, &mut hasher);
|
||||
}
|
||||
|
||||
// We want to avoid accidental collision between different types of instances.
|
||||
|
@ -67,7 +67,7 @@ impl AssertModuleSource<'tcx> {
|
||||
} else if attr.check_name(ATTR_PARTITION_CODEGENED) {
|
||||
(CguReuse::No, ComparisonKind::Exact)
|
||||
} else if attr.check_name(ATTR_EXPECTED_CGU_REUSE) {
|
||||
match &self.field(attr, sym::kind).as_str()[..] {
|
||||
match &*self.field(attr, sym::kind).as_str() {
|
||||
"no" => (CguReuse::No, ComparisonKind::Exact),
|
||||
"pre-lto" => (CguReuse::PreLto, ComparisonKind::Exact),
|
||||
"post-lto" => (CguReuse::PostLto, ComparisonKind::Exact),
|
||||
|
@ -303,7 +303,7 @@ impl DirtyCleanVisitor<'tcx> {
|
||||
for item in attr.meta_item_list().unwrap_or_else(Vec::new) {
|
||||
if item.check_name(LABEL) {
|
||||
let value = expect_associated_value(self.tcx, &item);
|
||||
return Some(self.resolve_labels(&item, value.as_str().as_ref()));
|
||||
return Some(self.resolve_labels(&item, &value.as_str()));
|
||||
}
|
||||
}
|
||||
None
|
||||
@ -314,7 +314,7 @@ impl DirtyCleanVisitor<'tcx> {
|
||||
for item in attr.meta_item_list().unwrap_or_else(Vec::new) {
|
||||
if item.check_name(EXCEPT) {
|
||||
let value = expect_associated_value(self.tcx, &item);
|
||||
return self.resolve_labels(&item, value.as_str().as_ref());
|
||||
return self.resolve_labels(&item, &value.as_str());
|
||||
}
|
||||
}
|
||||
// if no `label` or `except` is given, only the node's group are asserted
|
||||
|
@ -1476,14 +1476,12 @@ impl KeywordIdents {
|
||||
let mut lint = cx.struct_span_lint(
|
||||
KEYWORD_IDENTS,
|
||||
ident.span,
|
||||
&format!("`{}` is a keyword in the {} edition",
|
||||
ident.as_str(),
|
||||
next_edition),
|
||||
&format!("`{}` is a keyword in the {} edition", ident, next_edition),
|
||||
);
|
||||
lint.span_suggestion(
|
||||
ident.span,
|
||||
"you can use a raw identifier to stay compatible",
|
||||
format!("r#{}", ident.as_str()),
|
||||
format!("r#{}", ident),
|
||||
Applicability::MachineApplicable,
|
||||
);
|
||||
lint.emit()
|
||||
|
@ -121,7 +121,7 @@ impl<'a> CrateLoader<'a> {
|
||||
// `source` stores paths which are normalized which may be different
|
||||
// from the strings on the command line.
|
||||
let source = &self.cstore.get_crate_data(cnum).source;
|
||||
if let Some(entry) = self.sess.opts.externs.get(&*name.as_str()) {
|
||||
if let Some(entry) = self.sess.opts.externs.get(&name.as_str()) {
|
||||
// Only use `--extern crate_name=path` here, not `--extern crate_name`.
|
||||
let found = entry.locations.iter().filter_map(|l| l.as_ref()).any(|l| {
|
||||
let l = fs::canonicalize(l).ok();
|
||||
|
@ -68,7 +68,7 @@ impl ItemLikeVisitor<'tcx> for Collector<'tcx> {
|
||||
Some(name) => name,
|
||||
None => continue, // skip like historical compilers
|
||||
};
|
||||
lib.kind = match &kind.as_str()[..] {
|
||||
lib.kind = match &*kind.as_str() {
|
||||
"static" => cstore::NativeStatic,
|
||||
"static-nobundle" => cstore::NativeStaticNobundle,
|
||||
"dylib" => cstore::NativeUnknown,
|
||||
|
@ -974,7 +974,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||
let mut err = self.cannot_borrow_across_destructor(borrow_span);
|
||||
|
||||
let what_was_dropped = match self.describe_place(place.as_ref()) {
|
||||
Some(name) => format!("`{}`", name.as_str()),
|
||||
Some(name) => format!("`{}`", name),
|
||||
None => String::from("temporary value"),
|
||||
};
|
||||
|
||||
|
@ -95,7 +95,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||
) -> InterpResult<'tcx, bool> {
|
||||
let substs = instance.substs;
|
||||
|
||||
let intrinsic_name = &self.tcx.item_name(instance.def_id()).as_str()[..];
|
||||
let intrinsic_name = &*self.tcx.item_name(instance.def_id()).as_str();
|
||||
match intrinsic_name {
|
||||
"caller_location" => {
|
||||
let caller = self.tcx.sess.source_map().lookup_char_pos(span.lo());
|
||||
|
@ -642,8 +642,8 @@ pub fn check_unsafety(tcx: TyCtxt<'_>, def_id: DefId) {
|
||||
struct_span_err!(
|
||||
tcx.sess, source_info.span, E0133,
|
||||
"{} is unsafe and requires unsafe function or block", description)
|
||||
.span_label(source_info.span, &description.as_str()[..])
|
||||
.note(&details.as_str()[..])
|
||||
.span_label(source_info.span, &*description.as_str())
|
||||
.note(&details.as_str())
|
||||
.emit();
|
||||
}
|
||||
UnsafetyViolationKind::ExternStatic(lint_hir_id) => {
|
||||
@ -651,8 +651,8 @@ pub fn check_unsafety(tcx: TyCtxt<'_>, def_id: DefId) {
|
||||
lint_hir_id,
|
||||
source_info.span,
|
||||
&format!("{} is unsafe and requires unsafe function or block \
|
||||
(error E0133)", &description.as_str()[..]),
|
||||
&details.as_str()[..]);
|
||||
(error E0133)", description),
|
||||
&details.as_str());
|
||||
}
|
||||
UnsafetyViolationKind::BorrowPacked(lint_hir_id) => {
|
||||
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) {
|
||||
lint_hir_id,
|
||||
source_info.span,
|
||||
&format!("{} is unsafe and requires unsafe function or block \
|
||||
(error E0133)", &description.as_str()[..]),
|
||||
&details.as_str()[..]);
|
||||
(error E0133)", description),
|
||||
&details.as_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -537,7 +537,7 @@ impl Qualif for IsNotPromotable {
|
||||
Abi::RustIntrinsic |
|
||||
Abi::PlatformIntrinsic => {
|
||||
assert!(!cx.tcx.is_const_fn(def_id));
|
||||
match &cx.tcx.item_name(def_id).as_str()[..] {
|
||||
match &*cx.tcx.item_name(def_id).as_str() {
|
||||
| "size_of"
|
||||
| "min_align_of"
|
||||
| "needs_drop"
|
||||
@ -1476,7 +1476,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Checker<'a, 'tcx> {
|
||||
Abi::RustIntrinsic |
|
||||
Abi::PlatformIntrinsic => {
|
||||
assert!(!self.tcx.is_const_fn(def_id));
|
||||
match &self.tcx.item_name(def_id).as_str()[..] {
|
||||
match &*self.tcx.item_name(def_id).as_str() {
|
||||
// special intrinsic that can be called diretly without an intrinsic
|
||||
// feature gate needs a language feature gate
|
||||
"transmute" => {
|
||||
|
@ -402,7 +402,7 @@ fn check_terminator(
|
||||
///
|
||||
/// Adding more intrinsics requires sign-off from @rust-lang/lang.
|
||||
fn is_intrinsic_whitelisted(tcx: TyCtxt<'tcx>, def_id: DefId) -> bool {
|
||||
match &tcx.item_name(def_id).as_str()[..] {
|
||||
match &*tcx.item_name(def_id).as_str() {
|
||||
| "size_of"
|
||||
| "min_align_of"
|
||||
| "needs_drop"
|
||||
|
@ -1876,7 +1876,7 @@ impl<'a, 'b> LateResolutionVisitor<'a, '_> {
|
||||
None
|
||||
}
|
||||
});
|
||||
find_best_match_for_name(names, &*ident.as_str(), None)
|
||||
find_best_match_for_name(names, &ident.as_str(), None)
|
||||
});
|
||||
self.r.record_partial_res(expr.id, PartialRes::new(Res::Err));
|
||||
self.r.report_error(
|
||||
|
@ -308,7 +308,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
}) = parent {
|
||||
if let Ok(src) = cm.span_to_snippet(sp) {
|
||||
for field in fields {
|
||||
if field.ident.as_str() == src.as_str() && field.is_shorthand {
|
||||
if field.ident.as_str() == src && field.is_shorthand {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -409,13 +409,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
let mut sugg_sp = sp;
|
||||
if let hir::ExprKind::MethodCall(segment, _sp, args) = &expr.kind {
|
||||
let clone_trait = self.tcx.lang_items().clone_trait().unwrap();
|
||||
if let ([arg], Some(true), "clone") = (
|
||||
if let ([arg], Some(true), sym::clone) = (
|
||||
&args[..],
|
||||
self.tables.borrow().type_dependent_def_id(expr.hir_id).map(|did| {
|
||||
let ai = self.tcx.associated_item(did);
|
||||
ai.container == ty::TraitContainer(clone_trait)
|
||||
}),
|
||||
&segment.ident.as_str()[..],
|
||||
segment.ident.name,
|
||||
) {
|
||||
// If this expression had a clone call when suggesting borrowing
|
||||
// we want to suggest removing it because it'd now be unecessary.
|
||||
|
@ -835,11 +835,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
sp,
|
||||
&message(format!(
|
||||
"restrict type parameter `{}` with",
|
||||
param.name.ident().as_str(),
|
||||
param.name.ident(),
|
||||
)),
|
||||
candidates.iter().map(|t| format!(
|
||||
"{}{} {}{}",
|
||||
param.name.ident().as_str(),
|
||||
param.name.ident(),
|
||||
if impl_trait { " +" } else { ":" },
|
||||
self.tcx.def_path_str(t.def_id),
|
||||
if has_bounds.is_some() { " + "} else { "" },
|
||||
|
@ -978,7 +978,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
);
|
||||
|
||||
// we don't want to throw `E0027` in case we have thrown `E0026` for them
|
||||
unmentioned_fields.retain(|&x| x.as_str() != suggested_name.as_str());
|
||||
unmentioned_fields.retain(|&x| x.name != suggested_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2404,7 +2404,7 @@ fn compute_sig_of_foreign_fn_decl<'tcx>(
|
||||
abi: abi::Abi,
|
||||
) -> ty::PolyFnSig<'tcx> {
|
||||
let unsafety = if abi == abi::Abi::RustIntrinsic {
|
||||
intrinsic_operation_unsafety(&*tcx.item_name(def_id).as_str())
|
||||
intrinsic_operation_unsafety(&tcx.item_name(def_id).as_str())
|
||||
} else {
|
||||
hir::Unsafety::Unsafe
|
||||
};
|
||||
|
@ -404,7 +404,7 @@ impl<'a> fmt::Display for Html<'a> {
|
||||
if !human_readable.is_empty() {
|
||||
fmt.write_str(human_readable)
|
||||
} else if let Some(v) = value {
|
||||
write!(fmt, "<code>{}=\"{}\"</code>", Escape(n), Escape(&*v.as_str()))
|
||||
write!(fmt, "<code>{}=\"{}\"</code>", Escape(n), Escape(&v.as_str()))
|
||||
} else {
|
||||
write!(fmt, "<code>{}</code>", Escape(n))
|
||||
}
|
||||
|
@ -3704,7 +3704,7 @@ fn qpath_to_string(p: &hir::QPath) -> String {
|
||||
s.push_str("::");
|
||||
}
|
||||
if seg.ident.name != kw::PathRoot {
|
||||
s.push_str(&*seg.ident.as_str());
|
||||
s.push_str(&seg.ident.as_str());
|
||||
}
|
||||
}
|
||||
s
|
||||
|
@ -2964,7 +2964,7 @@ fn render_attribute(attr: &ast::MetaItem) -> Option<String> {
|
||||
if attr.is_word() {
|
||||
Some(path)
|
||||
} else if let Some(v) = attr.value_str() {
|
||||
Some(format!("{} = {:?}", path, v.as_str()))
|
||||
Some(format!("{} = {:?}", path, v))
|
||||
} else if let Some(values) = attr.meta_item_list() {
|
||||
let display: Vec<_> = values.iter().filter_map(|attr| {
|
||||
attr.meta_item().and_then(|mi| render_attribute(mi))
|
||||
|
@ -90,7 +90,7 @@ impl fmt::Debug for Lifetime {
|
||||
|
||||
impl fmt::Display for Lifetime {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "{}", self.ident.name.as_str())
|
||||
write!(f, "{}", self.ident.name)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -730,7 +730,7 @@ pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute],
|
||||
}
|
||||
|
||||
if let Some(allowed) = allow_features.as_ref() {
|
||||
if allowed.iter().find(|&f| f == &name.as_str() as &str).is_none() {
|
||||
if allowed.iter().find(|&f| name.as_str() == *f).is_none() {
|
||||
span_err!(span_handler, mi.span(), E0725,
|
||||
"the feature `{}` is not in the list of allowed features",
|
||||
name);
|
||||
|
@ -134,9 +134,9 @@ impl LitKind {
|
||||
let (kind, symbol, suffix) = match *self {
|
||||
LitKind::Str(symbol, ast::StrStyle::Cooked) => {
|
||||
// Don't re-intern unless the escaped string is different.
|
||||
let s: &str = &symbol.as_str();
|
||||
let s = symbol.as_str();
|
||||
let escaped = s.escape_default().to_string();
|
||||
let symbol = if escaped == *s { symbol } else { Symbol::intern(&escaped) };
|
||||
let symbol = if s == escaped { symbol } else { Symbol::intern(&escaped) };
|
||||
(token::Str, symbol, None)
|
||||
}
|
||||
LitKind::Str(symbol, ast::StrStyle::Raw(n)) => {
|
||||
|
@ -229,7 +229,7 @@ impl<'a> Parser<'a> {
|
||||
// `./<id>.rs` and `./<id>/mod.rs`.
|
||||
let relative_prefix_string;
|
||||
let relative_prefix = if let Some(ident) = relative {
|
||||
relative_prefix_string = format!("{}{}", ident.as_str(), path::MAIN_SEPARATOR);
|
||||
relative_prefix_string = format!("{}{}", ident, path::MAIN_SEPARATOR);
|
||||
&relative_prefix_string
|
||||
} else {
|
||||
""
|
||||
|
@ -21,7 +21,7 @@ pub fn expand_option_env<'cx>(cx: &'cx mut ExtCtxt<'_>,
|
||||
};
|
||||
|
||||
let sp = cx.with_def_site_ctxt(sp);
|
||||
let e = match env::var(&*var.as_str()) {
|
||||
let e = match env::var(&var.as_str()) {
|
||||
Err(..) => {
|
||||
let lt = cx.lifetime(sp, Ident::new(kw::StaticLifetime, sp));
|
||||
cx.expr_path(cx.path_all(sp,
|
||||
|
@ -992,7 +992,7 @@ pub fn expand_preparsed_format_args(
|
||||
vec![]
|
||||
};
|
||||
|
||||
let fmt_str = &*fmt_str.as_str(); // for the suggestions below
|
||||
let fmt_str = &fmt_str.as_str(); // for the suggestions below
|
||||
let mut parser = parse::Parser::new(fmt_str, str_style, skips, append_newline);
|
||||
|
||||
let mut unverified_pieces = Vec::new();
|
||||
|
Loading…
x
Reference in New Issue
Block a user