Skip to content

Commit

Permalink
Unrolled build for rust-lang#129061
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
rust-timer authored Aug 14, 2024
2 parents e9c965d + bac1968 commit bf5734f
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 24 deletions.
10 changes: 3 additions & 7 deletions compiler/rustc_hir_typeck/src/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,15 +160,11 @@ pub(super) fn check_fn<'a, 'tcx>(
fcx.demand_suptype(span, ret_ty, actual_return_ty);

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

if let Some(lang_start_defid) = tcx.lang_items().start_fn()
&& lang_start_defid == fn_def_id.to_def_id()
{
if tcx.is_lang_item(fn_def_id.to_def_id(), LangItem::Start) {
check_lang_start_fn(tcx, fn_sig, fn_def_id);
}

Expand Down
7 changes: 5 additions & 2 deletions compiler/rustc_lint/src/for_loops_over_fallibles.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use hir::{Expr, Pat};
use rustc_hir as hir;
use rustc_hir::{self as hir, LangItem};
use rustc_infer::infer::TyCtxtInferExt;
use rustc_infer::traits::ObligationCause;
use rustc_middle::ty;
Expand Down Expand Up @@ -126,7 +126,10 @@ fn extract_iterator_next_call<'tcx>(
) -> Option<&'tcx Expr<'tcx>> {
// This won't work for `Iterator::next(iter)`, is this an issue?
if let hir::ExprKind::MethodCall(_, recv, _, _) = expr.kind
&& cx.typeck_results().type_dependent_def_id(expr.hir_id) == cx.tcx.lang_items().next_fn()
&& cx
.typeck_results()
.type_dependent_def_id(expr.hir_id)
.is_some_and(|def_id| cx.tcx.is_lang_item(def_id, LangItem::IteratorNext))
{
Some(recv)
} else {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ impl<'tcx> LateLintPass<'tcx> for DropTraitConstraints {
let hir::TyKind::TraitObject(bounds, _lifetime, _syntax) = &ty.kind else { return };
for (bound, modifier) in &bounds[..] {
let def_id = bound.trait_ref.trait_def_id();
if cx.tcx.lang_items().drop_trait() == def_id
if def_id.is_some_and(|def_id| cx.tcx.is_lang_item(def_id, LangItem::Drop))
&& *modifier != hir::TraitBoundModifier::Maybe
{
let Some(def_id) = cx.tcx.get_diagnostic_item(sym::needs_drop) else { return };
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_middle/src/ty/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ use std::ops::ControlFlow;

use rustc_data_structures::fx::FxHashMap;
use rustc_errors::{into_diag_arg_using_display, Applicability, Diag, DiagArgValue, IntoDiagArg};
use rustc_hir as hir;
use rustc_hir::def::DefKind;
use rustc_hir::def_id::DefId;
use rustc_hir::{PredicateOrigin, WherePredicate};
use rustc_hir::{self as hir, LangItem, PredicateOrigin, WherePredicate};
use rustc_span::{BytePos, Span};
use rustc_type_ir::TyKind::*;

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

{
let mut sized_constraints =
constraints.extract_if(|(_, def_id)| *def_id == tcx.lang_items().sized_trait());
let mut sized_constraints = constraints.extract_if(|(_, def_id)| {
def_id.is_some_and(|def_id| tcx.is_lang_item(def_id, LangItem::Sized))
});
if let Some((_, def_id)) = sized_constraints.next() {
applicability = Applicability::MaybeIncorrect;

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ impl<'tcx> Instance<'tcx> {
return None;
};

if tcx.lang_items().get(coroutine_callable_item) == Some(trait_item_id) {
if tcx.is_lang_item(trait_item_id, coroutine_callable_item) {
let ty::Coroutine(_, id_args) = *tcx.type_of(coroutine_def_id).skip_binder().kind()
else {
bug!()
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_middle/src/ty/print/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1145,7 +1145,9 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
let term = if let Some(ty) = term.skip_binder().as_type()
&& let ty::Alias(ty::Projection, proj) = ty.kind()
&& let Some(assoc) = tcx.opt_associated_item(proj.def_id)
&& assoc.trait_container(tcx) == tcx.lang_items().coroutine_trait()
&& assoc
.trait_container(tcx)
.is_some_and(|def_id| tcx.is_lang_item(def_id, LangItem::Coroutine))
&& assoc.name == rustc_span::sym::Return
{
if let ty::Coroutine(_, args) = args.type_at(0).kind() {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1916,7 +1916,7 @@ impl<'tcx> Ty<'tcx> {

pub fn is_c_void(self, tcx: TyCtxt<'_>) -> bool {
match self.kind() {
ty::Adt(adt, _) => tcx.lang_items().get(LangItem::CVoid) == Some(adt.did()),
ty::Adt(adt, _) => tcx.is_lang_item(adt.did(), LangItem::CVoid),
_ => false,
}
}
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_monomorphize/src/partitioning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,9 @@ fn characteristic_def_id_of_mono_item<'tcx>(

if let Some(impl_def_id) = tcx.impl_of_method(def_id) {
if tcx.sess.opts.incremental.is_some()
&& tcx.trait_id_of_impl(impl_def_id) == tcx.lang_items().drop_trait()
&& tcx
.trait_id_of_impl(impl_def_id)
.is_some_and(|def_id| tcx.is_lang_item(def_id, LangItem::Drop))
{
// Put `Drop::drop` into the same cgu as `drop_in_place`
// since `drop_in_place` is the only thing that can
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
post_message,
);

let (err_msg, safe_transmute_explanation) = if Some(main_trait_ref.def_id())
== self.tcx.lang_items().transmute_trait()
let (err_msg, safe_transmute_explanation) = if self.tcx.is_lang_item(main_trait_ref.def_id(), LangItem::TransmuteTrait)
{
// Recompute the safe transmute reason and use that for the error reporting
match self.get_safe_transmute_error_and_reason(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2831,7 +2831,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
// Do not suggest relaxing if there is an explicit `Sized` obligation.
&& !bounds.iter()
.filter_map(|bound| bound.trait_ref())
.any(|tr| tr.trait_def_id() == tcx.lang_items().sized_trait())
.any(|tr| tr.trait_def_id().is_some_and(|def_id| tcx.is_lang_item(def_id, LangItem::Sized)))
{
let (span, separator) = if let [.., last] = bounds {
(last.span().shrink_to_hi(), " +")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use rustc_hir::LangItem;
use rustc_infer::traits::Obligation;
pub use rustc_middle::traits::query::type_op::ProvePredicate;
use rustc_middle::traits::query::NoSolution;
Expand All @@ -20,8 +21,7 @@ impl<'tcx> super::QueryTypeOp<'tcx> for ProvePredicate<'tcx> {
// such cases.
if let ty::PredicateKind::Clause(ty::ClauseKind::Trait(trait_ref)) =
key.value.predicate.kind().skip_binder()
&& let Some(sized_def_id) = tcx.lang_items().sized_trait()
&& trait_ref.def_id() == sized_def_id
&& tcx.is_lang_item(trait_ref.def_id(), LangItem::Sized)
&& trait_ref.self_ty().is_trivially_sized(tcx)
{
return Some(());
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ty_utils/src/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ fn fn_abi_new_uncached<'tcx>(
let rust_abi = matches!(sig.abi, RustIntrinsic | Rust | RustCall);

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

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

0 comments on commit bf5734f

Please sign in to comment.