Rollup merge of #128140 - veera-sivarajan:remove-ident-to-str-conversions, r=compiler-errors

Remove Unnecessary `.as_str()` Conversions

Because comparing interned values is much more efficient than converting a `rustc_span::symbol::Ident` to `&str`  and then doing the comparison.

docs: https://doc.rust-lang.org/stable/nightly-rustc/rustc_span/symbol/struct.Ident.html#method.as_str
This commit is contained in:
Matthias Krüger 2024-07-24 22:22:18 +02:00 committed by GitHub
commit 104a421a46
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1846,7 +1846,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
/// Determine if the associated item with the given DefId matches /// Determine if the associated item with the given DefId matches
/// the desired name via a doc alias. /// the desired name via a doc alias.
fn matches_by_doc_alias(&self, def_id: DefId) -> bool { fn matches_by_doc_alias(&self, def_id: DefId) -> bool {
let Some(name) = self.method_name else { let Some(method) = self.method_name else {
return false; return false;
}; };
let Some(local_def_id) = def_id.as_local() else { let Some(local_def_id) = def_id.as_local() else {
@ -1863,7 +1863,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
// #[rustc_confusables("foo", "bar"))] // #[rustc_confusables("foo", "bar"))]
for n in confusables { for n in confusables {
if let Some(lit) = n.lit() if let Some(lit) = n.lit()
&& name.as_str() == lit.symbol.as_str() && method.name == lit.symbol
{ {
return true; return true;
} }
@ -1883,14 +1883,14 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
// #[doc(alias("foo", "bar"))] // #[doc(alias("foo", "bar"))]
for n in nested { for n in nested {
if let Some(lit) = n.lit() if let Some(lit) = n.lit()
&& name.as_str() == lit.symbol.as_str() && method.name == lit.symbol
{ {
return true; return true;
} }
} }
} else if let Some(meta) = v.meta_item() } else if let Some(meta) = v.meta_item()
&& let Some(lit) = meta.name_value_literal() && let Some(lit) = meta.name_value_literal()
&& name.as_str() == lit.symbol.as_str() && method.name == lit.symbol
{ {
// #[doc(alias = "foo")] // #[doc(alias = "foo")]
return true; return true;