Skip to content

Commit abce592

Browse files
committed
Use Symbol in LateContext::get_associated_type.
To avoid unnecessary interning.
1 parent 092a284 commit abce592

File tree

8 files changed

+16
-11
lines changed

8 files changed

+16
-11
lines changed

compiler/rustc_lint/src/context.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -855,11 +855,16 @@ impl<'tcx> LateContext<'tcx> {
855855
&self,
856856
self_ty: Ty<'tcx>,
857857
trait_id: DefId,
858-
name: &str,
858+
name: Symbol,
859859
) -> Option<Ty<'tcx>> {
860860
let tcx = self.tcx;
861861
tcx.associated_items(trait_id)
862-
.find_by_ident_and_kind(tcx, Ident::from_str(name), ty::AssocKind::Type, trait_id)
862+
.find_by_ident_and_kind(
863+
tcx,
864+
Ident::with_dummy_span(name),
865+
ty::AssocKind::Type,
866+
trait_id,
867+
)
863868
.and_then(|assoc| {
864869
let proj = Ty::new_projection(tcx, assoc.def_id, [self_ty]);
865870
tcx.try_normalize_erasing_regions(self.typing_env(), proj).ok()

compiler/rustc_lint/src/deref_into_dyn_supertrait.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ impl<'tcx> LateLintPass<'tcx> for DerefIntoDynSupertrait {
6969
&& let ty::Dynamic(data, _, ty::Dyn) = self_ty.kind()
7070
&& let Some(self_principal) = data.principal()
7171
// `<T as Deref>::Target` is `dyn target_principal`
72-
&& let Some(target) = cx.get_associated_type(self_ty, did, "Target")
72+
&& let Some(target) = cx.get_associated_type(self_ty, did, sym::Target)
7373
&& let ty::Dynamic(data, _, ty::Dyn) = target.kind()
7474
&& let Some(target_principal) = data.principal()
7575
// `target_principal` is a supertrait of `t_principal`

src/tools/clippy/clippy_lints/src/format_args.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ impl<'tcx> FormatArgsExpr<'_, 'tcx> {
550550
// a `Target` that is in `self.ty_msrv_map`.
551551
if let Some(deref_trait_id) = self.cx.tcx.lang_items().deref_trait()
552552
&& implements_trait(self.cx, ty, deref_trait_id, &[])
553-
&& let Some(target_ty) = self.cx.get_associated_type(ty, deref_trait_id, "Target")
553+
&& let Some(target_ty) = self.cx.get_associated_type(ty, deref_trait_id, sym::Target)
554554
&& let Some(msrv) = self.ty_msrv_map.get(&target_ty)
555555
&& msrv.is_none_or(|msrv| self.msrv.meets(self.cx, msrv))
556556
{

src/tools/clippy/clippy_lints/src/len_zero.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ fn has_is_empty(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
644644
&& cx.tcx.get_diagnostic_item(sym::Deref).is_some_and(|deref_id| {
645645
implements_trait(cx, ty, deref_id, &[])
646646
&& cx
647-
.get_associated_type(ty, deref_id, "Target")
647+
.get_associated_type(ty, deref_id, sym::Target)
648648
.is_some_and(|deref_ty| ty_has_is_empty(cx, deref_ty, depth + 1))
649649
}))
650650
},

src/tools/clippy/clippy_lints/src/methods/iter_overeager_cloned.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pub(super) fn check<'tcx>(
4848
&& let Some(method_id) = typeck.type_dependent_def_id(cloned_call.hir_id)
4949
&& cx.tcx.trait_of_item(method_id) == Some(iter_id)
5050
&& let cloned_recv_ty = typeck.expr_ty_adjusted(cloned_recv)
51-
&& let Some(iter_assoc_ty) = cx.get_associated_type(cloned_recv_ty, iter_id, "Item")
51+
&& let Some(iter_assoc_ty) = cx.get_associated_type(cloned_recv_ty, iter_id, sym::Item)
5252
&& matches!(*iter_assoc_ty.kind(), ty::Ref(_, ty, _) if !is_copy(cx, ty))
5353
{
5454
if needs_into_iter

src/tools/clippy/clippy_lints/src/methods/unnecessary_iter_cloned.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ pub fn check_for_loop_iter(
9999
&& let Some(into_iterator_trait_id) = cx.tcx.get_diagnostic_item(sym::IntoIterator)
100100
&& let collection_ty = cx.typeck_results().expr_ty(collection)
101101
&& implements_trait(cx, collection_ty, into_iterator_trait_id, &[])
102-
&& let Some(into_iter_item_ty) = cx.get_associated_type(collection_ty, into_iterator_trait_id, "Item")
102+
&& let Some(into_iter_item_ty) = cx.get_associated_type(collection_ty, into_iterator_trait_id, sym::Item)
103103
&& iter_item_ty == into_iter_item_ty
104104
&& let Some(collection_snippet) = collection.span.get_source_text(cx)
105105
{

src/tools/clippy/clippy_lints/src/methods/unnecessary_to_owned.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ fn check_addr_of_expr(
153153
}
154154
if let Some(deref_trait_id) = cx.tcx.get_diagnostic_item(sym::Deref)
155155
&& implements_trait(cx, receiver_ty, deref_trait_id, &[])
156-
&& cx.get_associated_type(receiver_ty, deref_trait_id, "Target") == Some(target_ty)
156+
&& cx.get_associated_type(receiver_ty, deref_trait_id, sym::Target) == Some(target_ty)
157157
// Make sure that it's actually calling the right `.to_string()`, (#10033)
158158
// *or* this is a `Cow::into_owned()` call (which would be the wrong into_owned receiver (str != Cow)
159159
// but that's ok for Cow::into_owned specifically)
@@ -322,7 +322,7 @@ fn check_split_call_arg(cx: &LateContext<'_>, expr: &Expr<'_>, method_name: Symb
322322
// add `.as_ref()` to the suggestion.
323323
let as_ref = if is_type_lang_item(cx, cx.typeck_results().expr_ty(expr), LangItem::String)
324324
&& let Some(deref_trait_id) = cx.tcx.get_diagnostic_item(sym::Deref)
325-
&& cx.get_associated_type(cx.typeck_results().expr_ty(receiver), deref_trait_id, "Target")
325+
&& cx.get_associated_type(cx.typeck_results().expr_ty(receiver), deref_trait_id, sym::Target)
326326
!= Some(cx.tcx.types.str_)
327327
{
328328
".as_ref()"
@@ -648,7 +648,7 @@ fn is_to_string_on_string_like<'a>(
648648
&& let GenericArgKind::Type(ty) = generic_arg.unpack()
649649
&& let Some(deref_trait_id) = cx.tcx.get_diagnostic_item(sym::Deref)
650650
&& let Some(as_ref_trait_id) = cx.tcx.get_diagnostic_item(sym::AsRef)
651-
&& (cx.get_associated_type(ty, deref_trait_id, "Target") == Some(cx.tcx.types.str_)
651+
&& (cx.get_associated_type(ty, deref_trait_id, sym::Target) == Some(cx.tcx.types.str_)
652652
|| implements_trait(cx, ty, as_ref_trait_id, &[cx.tcx.types.str_.into()]))
653653
{
654654
true

src/tools/clippy/clippy_utils/src/ty/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ pub fn contains_ty_adt_constructor_opaque<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'
156156
pub fn get_iterator_item_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option<Ty<'tcx>> {
157157
cx.tcx
158158
.get_diagnostic_item(sym::Iterator)
159-
.and_then(|iter_did| cx.get_associated_type(ty, iter_did, "Item"))
159+
.and_then(|iter_did| cx.get_associated_type(ty, iter_did, sym::Item))
160160
}
161161

162162
/// Get the diagnostic name of a type, e.g. `sym::HashMap`. To check if a type

0 commit comments

Comments
 (0)