Rollup merge of #129061 - compiler-errors:lang-item, r=Urgau
Use `is_lang_item` more Few places that I missed since introducing `TyCtxt::is_lang_item`.
This commit is contained in:
commit
cd6852b9ea
12 changed files with 26 additions and 24 deletions
|
@ -160,15 +160,11 @@ pub(super) fn check_fn<'a, 'tcx>(
|
||||||
fcx.demand_suptype(span, ret_ty, actual_return_ty);
|
fcx.demand_suptype(span, ret_ty, actual_return_ty);
|
||||||
|
|
||||||
// Check that a function marked as `#[panic_handler]` has signature `fn(&PanicInfo) -> !`
|
// Check that a function marked as `#[panic_handler]` has signature `fn(&PanicInfo) -> !`
|
||||||
if let Some(panic_impl_did) = tcx.lang_items().panic_impl()
|
if tcx.is_lang_item(fn_def_id.to_def_id(), LangItem::PanicImpl) {
|
||||||
&& panic_impl_did == fn_def_id.to_def_id()
|
check_panic_info_fn(tcx, fn_def_id, fn_sig);
|
||||||
{
|
|
||||||
check_panic_info_fn(tcx, panic_impl_did.expect_local(), fn_sig);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(lang_start_defid) = tcx.lang_items().start_fn()
|
if tcx.is_lang_item(fn_def_id.to_def_id(), LangItem::Start) {
|
||||||
&& lang_start_defid == fn_def_id.to_def_id()
|
|
||||||
{
|
|
||||||
check_lang_start_fn(tcx, fn_sig, fn_def_id);
|
check_lang_start_fn(tcx, fn_sig, fn_def_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use hir::{Expr, Pat};
|
use hir::{Expr, Pat};
|
||||||
use rustc_hir as hir;
|
use rustc_hir::{self as hir, LangItem};
|
||||||
use rustc_infer::infer::TyCtxtInferExt;
|
use rustc_infer::infer::TyCtxtInferExt;
|
||||||
use rustc_infer::traits::ObligationCause;
|
use rustc_infer::traits::ObligationCause;
|
||||||
use rustc_middle::ty;
|
use rustc_middle::ty;
|
||||||
|
@ -126,7 +126,10 @@ fn extract_iterator_next_call<'tcx>(
|
||||||
) -> Option<&'tcx Expr<'tcx>> {
|
) -> Option<&'tcx Expr<'tcx>> {
|
||||||
// This won't work for `Iterator::next(iter)`, is this an issue?
|
// This won't work for `Iterator::next(iter)`, is this an issue?
|
||||||
if let hir::ExprKind::MethodCall(_, recv, _, _) = expr.kind
|
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)
|
Some(recv)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -114,7 +114,7 @@ impl<'tcx> LateLintPass<'tcx> for DropTraitConstraints {
|
||||||
let hir::TyKind::TraitObject(bounds, _lifetime, _syntax) = &ty.kind else { return };
|
let hir::TyKind::TraitObject(bounds, _lifetime, _syntax) = &ty.kind else { return };
|
||||||
for (bound, modifier) in &bounds[..] {
|
for (bound, modifier) in &bounds[..] {
|
||||||
let def_id = bound.trait_ref.trait_def_id();
|
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
|
&& *modifier != hir::TraitBoundModifier::Maybe
|
||||||
{
|
{
|
||||||
let Some(def_id) = cx.tcx.get_diagnostic_item(sym::needs_drop) else { return };
|
let Some(def_id) = cx.tcx.get_diagnostic_item(sym::needs_drop) else { return };
|
||||||
|
|
|
@ -6,10 +6,9 @@ use std::ops::ControlFlow;
|
||||||
|
|
||||||
use rustc_data_structures::fx::FxHashMap;
|
use rustc_data_structures::fx::FxHashMap;
|
||||||
use rustc_errors::{into_diag_arg_using_display, Applicability, Diag, DiagArgValue, IntoDiagArg};
|
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::DefKind;
|
||||||
use rustc_hir::def_id::DefId;
|
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_span::{BytePos, Span};
|
||||||
use rustc_type_ir::TyKind::*;
|
use rustc_type_ir::TyKind::*;
|
||||||
|
|
||||||
|
@ -290,8 +289,9 @@ pub fn suggest_constraining_type_params<'a>(
|
||||||
let Some(param) = param else { return false };
|
let Some(param) = param else { return false };
|
||||||
|
|
||||||
{
|
{
|
||||||
let mut sized_constraints =
|
let mut sized_constraints = constraints.extract_if(|(_, def_id)| {
|
||||||
constraints.extract_if(|(_, def_id)| *def_id == tcx.lang_items().sized_trait());
|
def_id.is_some_and(|def_id| tcx.is_lang_item(def_id, LangItem::Sized))
|
||||||
|
});
|
||||||
if let Some((_, def_id)) = sized_constraints.next() {
|
if let Some((_, def_id)) = sized_constraints.next() {
|
||||||
applicability = Applicability::MaybeIncorrect;
|
applicability = Applicability::MaybeIncorrect;
|
||||||
|
|
||||||
|
|
|
@ -838,7 +838,7 @@ impl<'tcx> Instance<'tcx> {
|
||||||
return None;
|
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()
|
let ty::Coroutine(_, id_args) = *tcx.type_of(coroutine_def_id).skip_binder().kind()
|
||||||
else {
|
else {
|
||||||
bug!()
|
bug!()
|
||||||
|
|
|
@ -1145,7 +1145,9 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
|
||||||
let term = if let Some(ty) = term.skip_binder().as_type()
|
let term = if let Some(ty) = term.skip_binder().as_type()
|
||||||
&& let ty::Alias(ty::Projection, proj) = ty.kind()
|
&& let ty::Alias(ty::Projection, proj) = ty.kind()
|
||||||
&& let Some(assoc) = tcx.opt_associated_item(proj.def_id)
|
&& 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
|
&& assoc.name == rustc_span::sym::Return
|
||||||
{
|
{
|
||||||
if let ty::Coroutine(_, args) = args.type_at(0).kind() {
|
if let ty::Coroutine(_, args) = args.type_at(0).kind() {
|
||||||
|
|
|
@ -1915,7 +1915,7 @@ impl<'tcx> Ty<'tcx> {
|
||||||
|
|
||||||
pub fn is_c_void(self, tcx: TyCtxt<'_>) -> bool {
|
pub fn is_c_void(self, tcx: TyCtxt<'_>) -> bool {
|
||||||
match self.kind() {
|
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,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 let Some(impl_def_id) = tcx.impl_of_method(def_id) {
|
||||||
if tcx.sess.opts.incremental.is_some()
|
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`
|
// Put `Drop::drop` into the same cgu as `drop_in_place`
|
||||||
// since `drop_in_place` is the only thing that can
|
// since `drop_in_place` is the only thing that can
|
||||||
|
|
|
@ -230,8 +230,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
||||||
post_message,
|
post_message,
|
||||||
);
|
);
|
||||||
|
|
||||||
let (err_msg, safe_transmute_explanation) = if Some(main_trait_ref.def_id())
|
let (err_msg, safe_transmute_explanation) = if self.tcx.is_lang_item(main_trait_ref.def_id(), LangItem::TransmuteTrait)
|
||||||
== self.tcx.lang_items().transmute_trait()
|
|
||||||
{
|
{
|
||||||
// Recompute the safe transmute reason and use that for the error reporting
|
// Recompute the safe transmute reason and use that for the error reporting
|
||||||
match self.get_safe_transmute_error_and_reason(
|
match self.get_safe_transmute_error_and_reason(
|
||||||
|
|
|
@ -2829,7 +2829,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
||||||
// Do not suggest relaxing if there is an explicit `Sized` obligation.
|
// Do not suggest relaxing if there is an explicit `Sized` obligation.
|
||||||
&& !bounds.iter()
|
&& !bounds.iter()
|
||||||
.filter_map(|bound| bound.trait_ref())
|
.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 {
|
let (span, separator) = if let [.., last] = bounds {
|
||||||
(last.span().shrink_to_hi(), " +")
|
(last.span().shrink_to_hi(), " +")
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use rustc_hir::LangItem;
|
||||||
use rustc_infer::traits::Obligation;
|
use rustc_infer::traits::Obligation;
|
||||||
pub use rustc_middle::traits::query::type_op::ProvePredicate;
|
pub use rustc_middle::traits::query::type_op::ProvePredicate;
|
||||||
use rustc_middle::traits::query::NoSolution;
|
use rustc_middle::traits::query::NoSolution;
|
||||||
|
@ -20,8 +21,7 @@ impl<'tcx> super::QueryTypeOp<'tcx> for ProvePredicate<'tcx> {
|
||||||
// such cases.
|
// such cases.
|
||||||
if let ty::PredicateKind::Clause(ty::ClauseKind::Trait(trait_ref)) =
|
if let ty::PredicateKind::Clause(ty::ClauseKind::Trait(trait_ref)) =
|
||||||
key.value.predicate.kind().skip_binder()
|
key.value.predicate.kind().skip_binder()
|
||||||
&& let Some(sized_def_id) = tcx.lang_items().sized_trait()
|
&& tcx.is_lang_item(trait_ref.def_id(), LangItem::Sized)
|
||||||
&& trait_ref.def_id() == sized_def_id
|
|
||||||
&& trait_ref.self_ty().is_trivially_sized(tcx)
|
&& trait_ref.self_ty().is_trivially_sized(tcx)
|
||||||
{
|
{
|
||||||
return Some(());
|
return Some(());
|
||||||
|
|
|
@ -621,7 +621,7 @@ fn fn_abi_new_uncached<'tcx>(
|
||||||
let rust_abi = matches!(sig.abi, RustIntrinsic | Rust | RustCall);
|
let rust_abi = matches!(sig.abi, RustIntrinsic | Rust | RustCall);
|
||||||
|
|
||||||
let is_drop_in_place =
|
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 arg_of = |ty: Ty<'tcx>, arg_idx: Option<usize>| -> Result<_, &'tcx FnAbiError<'tcx>> {
|
||||||
let span = tracing::debug_span!("arg_of");
|
let span = tracing::debug_span!("arg_of");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue