Skip to content

Commit 8217b41

Browse files
committed
Auto merge of #126491 - compiler-errors:is_lang_item, r=oli-obk
Add `TyCtxt::is_lang_item`, use it in the compiler ```rust pub fn is_lang_item(self, def_id: DefId, lang_item: LangItem) -> bool; ``` Easier than having to use `Some(def_id) == tcx.lang_items().iterator_trait()` or something. Also makes it easier to turn into `TraitSolverLangItem` in the future. Hope it's not too bad for perf. r? `@lcnr` or `@oli-obk`
2 parents 9239d3e + 93ff86e commit 8217b41

File tree

48 files changed

+213
-206
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+213
-206
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
284284
&& let CallKind::FnCall { fn_trait_id, self_ty } = kind
285285
&& let ty::Param(_) = self_ty.kind()
286286
&& ty == self_ty
287-
&& Some(fn_trait_id) == self.infcx.tcx.lang_items().fn_once_trait()
287+
&& self.infcx.tcx.is_lang_item(fn_trait_id, LangItem::FnOnce)
288288
{
289289
// this is a type parameter `T: FnOnce()`, don't suggest `T: FnOnce() + Clone`.
290290
true
@@ -708,9 +708,9 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
708708
if let ty::ClauseKind::Trait(pred) = pred.kind().skip_binder()
709709
&& pred.self_ty() == ty
710710
{
711-
if Some(pred.def_id()) == tcx.lang_items().fn_trait() {
711+
if tcx.is_lang_item(pred.def_id(), LangItem::Fn) {
712712
return Some(hir::Mutability::Not);
713-
} else if Some(pred.def_id()) == tcx.lang_items().fn_mut_trait() {
713+
} else if tcx.is_lang_item(pred.def_id(), LangItem::FnMut) {
714714
return Some(hir::Mutability::Mut);
715715
}
716716
}
@@ -1832,7 +1832,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
18321832
if let hir::ExprKind::MethodCall(..) = ex.kind
18331833
&& let Some(method_def_id) =
18341834
self.typeck_results.type_dependent_def_id(ex.hir_id)
1835-
&& self.tcx.lang_items().clone_trait() == Some(self.tcx.parent(method_def_id))
1835+
&& self.tcx.is_lang_item(self.tcx.parent(method_def_id), LangItem::Clone)
18361836
{
18371837
self.clones.push(ex);
18381838
}
@@ -3159,8 +3159,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
31593159
let is_format_arguments_item = if let Some(expr_ty) = expr_ty
31603160
&& let ty::Adt(adt, _) = expr_ty.kind()
31613161
{
3162-
self.infcx.tcx.lang_items().get(LangItem::FormatArguments)
3163-
== Some(adt.did())
3162+
self.infcx.tcx.is_lang_item(adt.did(), LangItem::FormatArguments)
31643163
} else {
31653164
false
31663165
};

compiler/rustc_borrowck/src/diagnostics/mod.rs

+8-9
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ use crate::session_diagnostics::{
66
};
77
use rustc_errors::{Applicability, Diag};
88
use rustc_errors::{DiagCtxt, MultiSpan};
9-
use rustc_hir as hir;
109
use rustc_hir::def::{CtorKind, Namespace};
1110
use rustc_hir::CoroutineKind;
11+
use rustc_hir::{self as hir, LangItem};
1212
use rustc_index::IndexSlice;
1313
use rustc_infer::infer::BoundRegionConversionTime;
1414
use rustc_infer::traits::SelectionError;
@@ -116,7 +116,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
116116
{
117117
if let ty::FnDef(id, _) = *const_.ty().kind() {
118118
debug!("add_moved_or_invoked_closure_note: id={:?}", id);
119-
if Some(self.infcx.tcx.parent(id)) == self.infcx.tcx.lang_items().fn_once_trait() {
119+
if self.infcx.tcx.is_lang_item(self.infcx.tcx.parent(id), LangItem::FnOnce) {
120120
let closure = match args.first() {
121121
Some(Spanned {
122122
node: Operand::Copy(place) | Operand::Move(place), ..
@@ -767,13 +767,12 @@ impl<'tcx> BorrowedContentSource<'tcx> {
767767
ty::FnDef(def_id, args) => {
768768
let trait_id = tcx.trait_of_item(def_id)?;
769769

770-
let lang_items = tcx.lang_items();
771-
if Some(trait_id) == lang_items.deref_trait()
772-
|| Some(trait_id) == lang_items.deref_mut_trait()
770+
if tcx.is_lang_item(trait_id, LangItem::Deref)
771+
|| tcx.is_lang_item(trait_id, LangItem::DerefMut)
773772
{
774773
Some(BorrowedContentSource::OverloadedDeref(args.type_at(0)))
775-
} else if Some(trait_id) == lang_items.index_trait()
776-
|| Some(trait_id) == lang_items.index_mut_trait()
774+
} else if tcx.is_lang_item(trait_id, LangItem::Index)
775+
|| tcx.is_lang_item(trait_id, LangItem::IndexMut)
777776
{
778777
Some(BorrowedContentSource::OverloadedIndex(args.type_at(0)))
779778
} else {
@@ -1041,7 +1040,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
10411040
.unwrap_or_else(|| "value".to_owned());
10421041
match kind {
10431042
CallKind::FnCall { fn_trait_id, self_ty }
1044-
if Some(fn_trait_id) == self.infcx.tcx.lang_items().fn_once_trait() =>
1043+
if self.infcx.tcx.is_lang_item(fn_trait_id, LangItem::FnOnce) =>
10451044
{
10461045
err.subdiagnostic(
10471046
self.dcx(),
@@ -1268,7 +1267,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
12681267
let ty = moved_place.ty(self.body, tcx).ty;
12691268

12701269
if let ty::Adt(def, args) = ty.peel_refs().kind()
1271-
&& Some(def.did()) == tcx.lang_items().pin_type()
1270+
&& tcx.is_lang_item(def.did(), LangItem::Pin)
12721271
&& let ty::Ref(_, _, hir::Mutability::Mut) = args.type_at(0).kind()
12731272
&& let self_ty = self.infcx.instantiate_binder_with_fresh_vars(
12741273
fn_call_span,

compiler/rustc_codegen_cranelift/src/inline_asm.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::fmt::Write;
44

55
use cranelift_codegen::isa::CallConv;
66
use rustc_ast::ast::{InlineAsmOptions, InlineAsmTemplatePiece};
7+
use rustc_hir::LangItem;
78
use rustc_span::sym;
89
use rustc_target::asm::*;
910
use target_lexicon::BinaryFormat;
@@ -927,7 +928,7 @@ fn call_inline_asm<'tcx>(
927928
fn asm_clif_type<'tcx>(fx: &FunctionCx<'_, '_, 'tcx>, ty: Ty<'tcx>) -> Option<types::Type> {
928929
match ty.kind() {
929930
// Adapted from https://github.com/rust-lang/rust/blob/f3c66088610c1b80110297c2d9a8b5f9265b013f/compiler/rustc_hir_analysis/src/check/intrinsicck.rs#L136-L151
930-
ty::Adt(adt, args) if Some(adt.did()) == fx.tcx.lang_items().maybe_uninit() => {
931+
ty::Adt(adt, args) if fx.tcx.is_lang_item(adt.did(), LangItem::MaybeUninit) => {
931932
let fields = &adt.non_enum_variant().fields;
932933
let ty = fields[FieldIdx::from_u32(1)].ty(fx.tcx, args);
933934
let ty::Adt(ty, args) = ty.kind() else {

compiler/rustc_const_eval/src/check_consts/check.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
//! The `Visitor` responsible for actually checking a `mir::Body` for invalid operations.
22
33
use rustc_errors::{Diag, ErrorGuaranteed};
4-
use rustc_hir as hir;
54
use rustc_hir::def_id::DefId;
5+
use rustc_hir::{self as hir, LangItem};
66
use rustc_index::bit_set::BitSet;
77
use rustc_infer::infer::TyCtxtInferExt;
88
use rustc_infer::traits::ObligationCause;
@@ -801,7 +801,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
801801
// const-eval.
802802

803803
// const-eval of the `begin_panic` fn assumes the argument is `&str`
804-
if Some(callee) == tcx.lang_items().begin_panic_fn() {
804+
if tcx.is_lang_item(callee, LangItem::BeginPanic) {
805805
match args[0].node.ty(&self.ccx.body.local_decls, tcx).kind() {
806806
ty::Ref(_, ty, _) if ty.is_str() => return,
807807
_ => self.check_op(ops::PanicNonStr),
@@ -819,7 +819,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
819819
}
820820
}
821821

822-
if Some(callee) == tcx.lang_items().exchange_malloc_fn() {
822+
if tcx.is_lang_item(callee, LangItem::ExchangeMalloc) {
823823
self.check_op(ops::HeapAllocation);
824824
return;
825825
}

compiler/rustc_const_eval/src/check_consts/ops.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
218218
} else {
219219
let mut sugg = None;
220220

221-
if Some(trait_id) == ccx.tcx.lang_items().eq_trait() {
221+
if ccx.tcx.is_lang_item(trait_id, LangItem::PartialEq) {
222222
match (args[0].unpack(), args[1].unpack()) {
223223
(GenericArgKind::Type(self_ty), GenericArgKind::Type(rhs_ty))
224224
if self_ty == rhs_ty

compiler/rustc_const_eval/src/const_eval/machine.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ impl<'tcx> CompileTimeInterpCx<'tcx> {
230230
let def_id = instance.def_id();
231231

232232
if self.tcx.has_attr(def_id, sym::rustc_const_panic_str)
233-
|| Some(def_id) == self.tcx.lang_items().begin_panic_fn()
233+
|| self.tcx.is_lang_item(def_id, LangItem::BeginPanic)
234234
{
235235
let args = self.copy_fn_args(args);
236236
// &str or &&str
@@ -245,7 +245,7 @@ impl<'tcx> CompileTimeInterpCx<'tcx> {
245245
let span = self.find_closest_untracked_caller_location();
246246
let (file, line, col) = self.location_triple_for_span(span);
247247
return Err(ConstEvalErrKind::Panic { msg, file, line, col }.into());
248-
} else if Some(def_id) == self.tcx.lang_items().panic_fmt() {
248+
} else if self.tcx.is_lang_item(def_id, LangItem::PanicFmt) {
249249
// For panic_fmt, call const_panic_fmt instead.
250250
let const_def_id = self.tcx.require_lang_item(LangItem::ConstPanicFmt, None);
251251
let new_instance = ty::Instance::expect_resolve(
@@ -256,7 +256,7 @@ impl<'tcx> CompileTimeInterpCx<'tcx> {
256256
);
257257

258258
return Ok(Some(new_instance));
259-
} else if Some(def_id) == self.tcx.lang_items().align_offset_fn() {
259+
} else if self.tcx.is_lang_item(def_id, LangItem::AlignOffset) {
260260
let args = self.copy_fn_args(args);
261261
// For align_offset, we replace the function call if the pointer has no address.
262262
match self.align_offset(instance, &args, dest, ret)? {

compiler/rustc_hir_analysis/src/bounds.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ impl<'tcx> Bounds<'tcx> {
5353
span,
5454
);
5555
// FIXME(-Znext-solver): We can likely remove this hack once the new trait solver lands.
56-
if tcx.lang_items().sized_trait() == Some(trait_ref.def_id()) {
56+
if tcx.is_lang_item(trait_ref.def_id(), LangItem::Sized) {
5757
self.clauses.insert(0, clause);
5858
} else {
5959
self.clauses.push(clause);

compiler/rustc_hir_analysis/src/check/intrinsicck.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use rustc_ast::InlineAsmTemplatePiece;
22
use rustc_data_structures::fx::FxIndexSet;
3-
use rustc_hir as hir;
3+
use rustc_hir::{self as hir, LangItem};
44
use rustc_middle::bug;
55
use rustc_middle::ty::{self, Article, FloatTy, IntTy, Ty, TyCtxt, TypeVisitableExt, UintTy};
66
use rustc_session::lint;
@@ -134,7 +134,7 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
134134
// `!` is allowed for input but not for output (issue #87802)
135135
ty::Never if is_input => return None,
136136
_ if ty.references_error() => return None,
137-
ty::Adt(adt, args) if Some(adt.did()) == self.tcx.lang_items().maybe_uninit() => {
137+
ty::Adt(adt, args) if self.tcx.is_lang_item(adt.did(), LangItem::MaybeUninit) => {
138138
let fields = &adt.non_enum_variant().fields;
139139
let ty = fields[FieldIdx::from_u32(1)].ty(self.tcx, args);
140140
// FIXME: Are we just trying to map to the `T` in `MaybeUninit<T>`?

compiler/rustc_hir_analysis/src/coherence/mod.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use crate::errors;
99
use rustc_errors::{codes::*, struct_span_code_err};
1010
use rustc_hir::def_id::{DefId, LocalDefId};
11+
use rustc_hir::LangItem;
1112
use rustc_middle::query::Providers;
1213
use rustc_middle::ty::{self, TyCtxt, TypeVisitableExt};
1314
use rustc_session::parse::feature_err;
@@ -49,7 +50,7 @@ fn enforce_trait_manually_implementable(
4950
) -> Result<(), ErrorGuaranteed> {
5051
let impl_header_span = tcx.def_span(impl_def_id);
5152

52-
if tcx.lang_items().freeze_trait() == Some(trait_def_id) {
53+
if tcx.is_lang_item(trait_def_id, LangItem::Freeze) {
5354
if !tcx.features().freeze_impls {
5455
feature_err(
5556
&tcx.sess,
@@ -75,7 +76,7 @@ fn enforce_trait_manually_implementable(
7576

7677
// Maintain explicit error code for `Unsize`, since it has a useful
7778
// explanation about using `CoerceUnsized` instead.
78-
if Some(trait_def_id) == tcx.lang_items().unsize_trait() {
79+
if tcx.is_lang_item(trait_def_id, LangItem::Unsize) {
7980
err.code(E0328);
8081
}
8182

compiler/rustc_hir_typeck/src/callee.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ use super::{Expectation, FnCtxt, TupleArgumentsFlag};
55
use crate::errors;
66
use rustc_ast::util::parser::PREC_POSTFIX;
77
use rustc_errors::{Applicability, Diag, ErrorGuaranteed, StashKey};
8-
use rustc_hir as hir;
98
use rustc_hir::def::{self, CtorKind, Namespace, Res};
109
use rustc_hir::def_id::DefId;
10+
use rustc_hir::{self as hir, LangItem};
1111
use rustc_hir_analysis::autoderef::Autoderef;
1212
use rustc_infer::traits::ObligationCauseCode;
1313
use rustc_infer::{
@@ -41,7 +41,7 @@ pub fn check_legal_trait_for_method_call(
4141
trait_id: DefId,
4242
body_id: DefId,
4343
) -> Result<(), ErrorGuaranteed> {
44-
if tcx.lang_items().drop_trait() == Some(trait_id)
44+
if tcx.is_lang_item(trait_id, LangItem::Drop)
4545
&& tcx.lang_items().fallback_surface_drop_fn() != Some(body_id)
4646
{
4747
let sugg = if let Some(receiver) = receiver.filter(|s| !s.is_empty()) {

compiler/rustc_hir_typeck/src/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3150,7 +3150,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
31503150
error.obligation.predicate.kind().skip_binder(),
31513151
) {
31523152
(ty::PredicateKind::Clause(ty::ClauseKind::Trait(predicate)), _)
3153-
if self.tcx.lang_items().index_trait() == Some(predicate.trait_ref.def_id) =>
3153+
if self.tcx.is_lang_item(predicate.trait_ref.def_id, LangItem::Index) =>
31543154
{
31553155
seen_preds.insert(error.obligation.predicate.kind().skip_binder());
31563156
}

compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
489489
);
490490
return true;
491491
} else if let ty::Adt(adt, _) = found_ty_inner.peel_refs().kind()
492-
&& Some(adt.did()) == self.tcx.lang_items().string()
492+
&& self.tcx.is_lang_item(adt.did(), LangItem::String)
493493
&& peeled.is_str()
494494
// `Result::map`, conversely, does not take ref of the error type.
495495
&& error_tys.is_none_or(|(found, expected)| {
@@ -3147,7 +3147,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
31473147
return;
31483148
}
31493149
if let ty::Adt(adt, _) = expected_ty.kind()
3150-
&& self.tcx.lang_items().range_struct() == Some(adt.did())
3150+
&& self.tcx.is_lang_item(adt.did(), LangItem::Range)
31513151
{
31523152
return;
31533153
}

compiler/rustc_hir_typeck/src/method/suggest.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1102,7 +1102,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11021102
unsatisfied_predicates.iter().any(|(pred, _, _)| {
11031103
match pred.kind().skip_binder() {
11041104
ty::PredicateKind::Clause(ty::ClauseKind::Trait(pred)) => {
1105-
Some(pred.def_id()) == self.tcx.lang_items().sized_trait()
1105+
self.tcx.is_lang_item(pred.def_id(), LangItem::Sized)
11061106
&& pred.polarity == ty::PredicatePolarity::Positive
11071107
}
11081108
_ => false,
@@ -1375,10 +1375,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
13751375
ty.is_str()
13761376
|| matches!(
13771377
ty.kind(),
1378-
ty::Adt(adt, _) if Some(adt.did()) == self.tcx.lang_items().string()
1378+
ty::Adt(adt, _) if self.tcx.is_lang_item(adt.did(), LangItem::String)
13791379
)
13801380
}
1381-
ty::Adt(adt, _) => Some(adt.did()) == self.tcx.lang_items().string(),
1381+
ty::Adt(adt, _) => self.tcx.is_lang_item(adt.did(), LangItem::String),
13821382
_ => false,
13831383
};
13841384
if is_string_or_ref_str && item_name.name == sym::iter {
@@ -2723,7 +2723,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
27232723

27242724
if tcx.is_diagnostic_item(sym::LocalKey, inner_id) {
27252725
err.help("use `with` or `try_with` to access thread local storage");
2726-
} else if Some(kind.did()) == tcx.lang_items().maybe_uninit() {
2726+
} else if tcx.is_lang_item(kind.did(), LangItem::MaybeUninit) {
27272727
err.help(format!(
27282728
"if this `{name}` has been initialized, \
27292729
use one of the `assume_init` methods to access the inner value"

compiler/rustc_hir_typeck/src/pat.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_errors::{
77
};
88
use rustc_hir::def::{CtorKind, DefKind, Res};
99
use rustc_hir::pat_util::EnumerateAndAdjustIterator;
10-
use rustc_hir::{self as hir, BindingMode, ByRef, HirId, Mutability, Pat, PatKind};
10+
use rustc_hir::{self as hir, BindingMode, ByRef, HirId, LangItem, Mutability, Pat, PatKind};
1111
use rustc_infer::infer;
1212
use rustc_middle::mir::interpret::ErrorHandled;
1313
use rustc_middle::ty::{self, Ty, TypeVisitableExt};
@@ -491,7 +491,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
491491
let tcx = self.tcx;
492492
let expected = self.resolve_vars_if_possible(expected);
493493
pat_ty = match expected.kind() {
494-
ty::Adt(def, _) if Some(def.did()) == tcx.lang_items().string() => expected,
494+
ty::Adt(def, _) if tcx.is_lang_item(def.did(), LangItem::String) => expected,
495495
ty::Str => Ty::new_static_str(tcx),
496496
_ => pat_ty,
497497
};

compiler/rustc_lint/src/deref_into_dyn_supertrait.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::{
33
LateContext, LateLintPass, LintContext,
44
};
55

6-
use rustc_hir as hir;
6+
use rustc_hir::{self as hir, LangItem};
77
use rustc_middle::ty;
88
use rustc_session::lint::FutureIncompatibilityReason;
99
use rustc_session::{declare_lint, declare_lint_pass};
@@ -66,7 +66,7 @@ impl<'tcx> LateLintPass<'tcx> for DerefIntoDynSupertrait {
6666
// the trait is a `Deref` implementation
6767
&& let Some(trait_) = &impl_.of_trait
6868
&& let Some(did) = trait_.trait_def_id()
69-
&& Some(did) == tcx.lang_items().deref_trait()
69+
&& tcx.is_lang_item(did, LangItem::Deref)
7070
// the self type is `dyn t_principal`
7171
&& let self_ty = tcx.type_of(item.owner_id).instantiate_identity()
7272
&& let ty::Dynamic(data, _, ty::Dyn) = self_ty.kind()

compiler/rustc_lint/src/non_fmt_panic.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::lints::{NonFmtPanicBraces, NonFmtPanicUnused};
22
use crate::{fluent_generated as fluent, LateContext, LateLintPass, LintContext};
33
use rustc_ast as ast;
44
use rustc_errors::Applicability;
5-
use rustc_hir as hir;
5+
use rustc_hir::{self as hir, LangItem};
66
use rustc_infer::infer::TyCtxtInferExt;
77
use rustc_middle::bug;
88
use rustc_middle::lint::in_external_macro;
@@ -53,8 +53,8 @@ impl<'tcx> LateLintPass<'tcx> for NonPanicFmt {
5353
if let &ty::FnDef(def_id, _) = cx.typeck_results().expr_ty(f).kind() {
5454
let f_diagnostic_name = cx.tcx.get_diagnostic_name(def_id);
5555

56-
if Some(def_id) == cx.tcx.lang_items().begin_panic_fn()
57-
|| Some(def_id) == cx.tcx.lang_items().panic_fn()
56+
if cx.tcx.is_lang_item(def_id, LangItem::BeginPanic)
57+
|| cx.tcx.is_lang_item(def_id, LangItem::Panic)
5858
|| f_diagnostic_name == Some(sym::panic_str_2015)
5959
{
6060
if let Some(id) = f.span.ctxt().outer_expn_data().macro_def_id {
@@ -153,7 +153,7 @@ fn check_panic<'tcx>(cx: &LateContext<'tcx>, f: &'tcx hir::Expr<'tcx>, arg: &'tc
153153
ty::Ref(_, r, _) if r.is_str(),
154154
) || matches!(
155155
ty.ty_adt_def(),
156-
Some(ty_def) if Some(ty_def.did()) == cx.tcx.lang_items().string(),
156+
Some(ty_def) if cx.tcx.is_lang_item(ty_def.did(), LangItem::String),
157157
);
158158

159159
let infcx = cx.tcx.infer_ctxt().build();

compiler/rustc_lint/src/traits.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::lints::{DropGlue, DropTraitConstraintsDiag};
22
use crate::LateContext;
33
use crate::LateLintPass;
44
use crate::LintContext;
5-
use rustc_hir as hir;
5+
use rustc_hir::{self as hir, LangItem};
66
use rustc_session::{declare_lint, declare_lint_pass};
77
use rustc_span::symbol::sym;
88

@@ -96,7 +96,7 @@ impl<'tcx> LateLintPass<'tcx> for DropTraitConstraints {
9696
continue;
9797
};
9898
let def_id = trait_predicate.trait_ref.def_id;
99-
if cx.tcx.lang_items().drop_trait() == Some(def_id) {
99+
if cx.tcx.is_lang_item(def_id, LangItem::Drop) {
100100
// Explicitly allow `impl Drop`, a drop-guards-as-unnameable-type pattern.
101101
if trait_predicate.trait_ref.self_ty().is_impl_trait() {
102102
continue;

0 commit comments

Comments
 (0)