Skip to content

Commit bf5734f

Browse files
authored
Unrolled build for rust-lang#129061
Rollup merge of rust-lang#129061 - compiler-errors:lang-item, r=Urgau Use `is_lang_item` more Few places that I missed since introducing `TyCtxt::is_lang_item`.
2 parents e9c965d + bac1968 commit bf5734f

File tree

12 files changed

+26
-24
lines changed

12 files changed

+26
-24
lines changed

compiler/rustc_hir_typeck/src/check.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -160,15 +160,11 @@ pub(super) fn check_fn<'a, 'tcx>(
160160
fcx.demand_suptype(span, ret_ty, actual_return_ty);
161161

162162
// Check that a function marked as `#[panic_handler]` has signature `fn(&PanicInfo) -> !`
163-
if let Some(panic_impl_did) = tcx.lang_items().panic_impl()
164-
&& panic_impl_did == fn_def_id.to_def_id()
165-
{
166-
check_panic_info_fn(tcx, panic_impl_did.expect_local(), fn_sig);
163+
if tcx.is_lang_item(fn_def_id.to_def_id(), LangItem::PanicImpl) {
164+
check_panic_info_fn(tcx, fn_def_id, fn_sig);
167165
}
168166

169-
if let Some(lang_start_defid) = tcx.lang_items().start_fn()
170-
&& lang_start_defid == fn_def_id.to_def_id()
171-
{
167+
if tcx.is_lang_item(fn_def_id.to_def_id(), LangItem::Start) {
172168
check_lang_start_fn(tcx, fn_sig, fn_def_id);
173169
}
174170

compiler/rustc_lint/src/for_loops_over_fallibles.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use hir::{Expr, Pat};
2-
use rustc_hir as hir;
2+
use rustc_hir::{self as hir, LangItem};
33
use rustc_infer::infer::TyCtxtInferExt;
44
use rustc_infer::traits::ObligationCause;
55
use rustc_middle::ty;
@@ -126,7 +126,10 @@ fn extract_iterator_next_call<'tcx>(
126126
) -> Option<&'tcx Expr<'tcx>> {
127127
// This won't work for `Iterator::next(iter)`, is this an issue?
128128
if let hir::ExprKind::MethodCall(_, recv, _, _) = expr.kind
129-
&& cx.typeck_results().type_dependent_def_id(expr.hir_id) == cx.tcx.lang_items().next_fn()
129+
&& cx
130+
.typeck_results()
131+
.type_dependent_def_id(expr.hir_id)
132+
.is_some_and(|def_id| cx.tcx.is_lang_item(def_id, LangItem::IteratorNext))
130133
{
131134
Some(recv)
132135
} else {

compiler/rustc_lint/src/traits.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ impl<'tcx> LateLintPass<'tcx> for DropTraitConstraints {
114114
let hir::TyKind::TraitObject(bounds, _lifetime, _syntax) = &ty.kind else { return };
115115
for (bound, modifier) in &bounds[..] {
116116
let def_id = bound.trait_ref.trait_def_id();
117-
if cx.tcx.lang_items().drop_trait() == def_id
117+
if def_id.is_some_and(|def_id| cx.tcx.is_lang_item(def_id, LangItem::Drop))
118118
&& *modifier != hir::TraitBoundModifier::Maybe
119119
{
120120
let Some(def_id) = cx.tcx.get_diagnostic_item(sym::needs_drop) else { return };

compiler/rustc_middle/src/ty/diagnostics.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ use std::ops::ControlFlow;
66

77
use rustc_data_structures::fx::FxHashMap;
88
use rustc_errors::{into_diag_arg_using_display, Applicability, Diag, DiagArgValue, IntoDiagArg};
9-
use rustc_hir as hir;
109
use rustc_hir::def::DefKind;
1110
use rustc_hir::def_id::DefId;
12-
use rustc_hir::{PredicateOrigin, WherePredicate};
11+
use rustc_hir::{self as hir, LangItem, PredicateOrigin, WherePredicate};
1312
use rustc_span::{BytePos, Span};
1413
use rustc_type_ir::TyKind::*;
1514

@@ -290,8 +289,9 @@ pub fn suggest_constraining_type_params<'a>(
290289
let Some(param) = param else { return false };
291290

292291
{
293-
let mut sized_constraints =
294-
constraints.extract_if(|(_, def_id)| *def_id == tcx.lang_items().sized_trait());
292+
let mut sized_constraints = constraints.extract_if(|(_, def_id)| {
293+
def_id.is_some_and(|def_id| tcx.is_lang_item(def_id, LangItem::Sized))
294+
});
295295
if let Some((_, def_id)) = sized_constraints.next() {
296296
applicability = Applicability::MaybeIncorrect;
297297

compiler/rustc_middle/src/ty/instance.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,7 @@ impl<'tcx> Instance<'tcx> {
838838
return None;
839839
};
840840

841-
if tcx.lang_items().get(coroutine_callable_item) == Some(trait_item_id) {
841+
if tcx.is_lang_item(trait_item_id, coroutine_callable_item) {
842842
let ty::Coroutine(_, id_args) = *tcx.type_of(coroutine_def_id).skip_binder().kind()
843843
else {
844844
bug!()

compiler/rustc_middle/src/ty/print/pretty.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1145,7 +1145,9 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
11451145
let term = if let Some(ty) = term.skip_binder().as_type()
11461146
&& let ty::Alias(ty::Projection, proj) = ty.kind()
11471147
&& let Some(assoc) = tcx.opt_associated_item(proj.def_id)
1148-
&& assoc.trait_container(tcx) == tcx.lang_items().coroutine_trait()
1148+
&& assoc
1149+
.trait_container(tcx)
1150+
.is_some_and(|def_id| tcx.is_lang_item(def_id, LangItem::Coroutine))
11491151
&& assoc.name == rustc_span::sym::Return
11501152
{
11511153
if let ty::Coroutine(_, args) = args.type_at(0).kind() {

compiler/rustc_middle/src/ty/sty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1916,7 +1916,7 @@ impl<'tcx> Ty<'tcx> {
19161916

19171917
pub fn is_c_void(self, tcx: TyCtxt<'_>) -> bool {
19181918
match self.kind() {
1919-
ty::Adt(adt, _) => tcx.lang_items().get(LangItem::CVoid) == Some(adt.did()),
1919+
ty::Adt(adt, _) => tcx.is_lang_item(adt.did(), LangItem::CVoid),
19201920
_ => false,
19211921
}
19221922
}

compiler/rustc_monomorphize/src/partitioning.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,9 @@ fn characteristic_def_id_of_mono_item<'tcx>(
648648

649649
if let Some(impl_def_id) = tcx.impl_of_method(def_id) {
650650
if tcx.sess.opts.incremental.is_some()
651-
&& tcx.trait_id_of_impl(impl_def_id) == tcx.lang_items().drop_trait()
651+
&& tcx
652+
.trait_id_of_impl(impl_def_id)
653+
.is_some_and(|def_id| tcx.is_lang_item(def_id, LangItem::Drop))
652654
{
653655
// Put `Drop::drop` into the same cgu as `drop_in_place`
654656
// since `drop_in_place` is the only thing that can

compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
230230
post_message,
231231
);
232232

233-
let (err_msg, safe_transmute_explanation) = if Some(main_trait_ref.def_id())
234-
== self.tcx.lang_items().transmute_trait()
233+
let (err_msg, safe_transmute_explanation) = if self.tcx.is_lang_item(main_trait_ref.def_id(), LangItem::TransmuteTrait)
235234
{
236235
// Recompute the safe transmute reason and use that for the error reporting
237236
match self.get_safe_transmute_error_and_reason(

compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2831,7 +2831,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
28312831
// Do not suggest relaxing if there is an explicit `Sized` obligation.
28322832
&& !bounds.iter()
28332833
.filter_map(|bound| bound.trait_ref())
2834-
.any(|tr| tr.trait_def_id() == tcx.lang_items().sized_trait())
2834+
.any(|tr| tr.trait_def_id().is_some_and(|def_id| tcx.is_lang_item(def_id, LangItem::Sized)))
28352835
{
28362836
let (span, separator) = if let [.., last] = bounds {
28372837
(last.span().shrink_to_hi(), " +")

compiler/rustc_trait_selection/src/traits/query/type_op/prove_predicate.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use rustc_hir::LangItem;
12
use rustc_infer::traits::Obligation;
23
pub use rustc_middle::traits::query::type_op::ProvePredicate;
34
use rustc_middle::traits::query::NoSolution;
@@ -20,8 +21,7 @@ impl<'tcx> super::QueryTypeOp<'tcx> for ProvePredicate<'tcx> {
2021
// such cases.
2122
if let ty::PredicateKind::Clause(ty::ClauseKind::Trait(trait_ref)) =
2223
key.value.predicate.kind().skip_binder()
23-
&& let Some(sized_def_id) = tcx.lang_items().sized_trait()
24-
&& trait_ref.def_id() == sized_def_id
24+
&& tcx.is_lang_item(trait_ref.def_id(), LangItem::Sized)
2525
&& trait_ref.self_ty().is_trivially_sized(tcx)
2626
{
2727
return Some(());

compiler/rustc_ty_utils/src/abi.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ fn fn_abi_new_uncached<'tcx>(
621621
let rust_abi = matches!(sig.abi, RustIntrinsic | Rust | RustCall);
622622

623623
let is_drop_in_place =
624-
fn_def_id.is_some() && fn_def_id == cx.tcx.lang_items().drop_in_place_fn();
624+
fn_def_id.is_some_and(|def_id| cx.tcx.is_lang_item(def_id, LangItem::DropInPlace));
625625

626626
let arg_of = |ty: Ty<'tcx>, arg_idx: Option<usize>| -> Result<_, &'tcx FnAbiError<'tcx>> {
627627
let span = tracing::debug_span!("arg_of");

0 commit comments

Comments
 (0)