Use is_lang_item more
This commit is contained in:
parent
e08b80c0fb
commit
bac19686a5
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
@ -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 {
|
||||
|
@ -114,7 +114,7 @@ fn check_ty(&mut self, cx: &LateContext<'_>, ty: &'tcx hir::Ty<'tcx>) {
|
||||
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 };
|
||||
|
@ -6,10 +6,9 @@
|
||||
|
||||
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::*;
|
||||
|
||||
@ -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;
|
||||
|
||||
|
@ -838,7 +838,7 @@ pub fn try_resolve_item_for_coroutine(
|
||||
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!()
|
||||
|
@ -1145,7 +1145,9 @@ fn pretty_print_opaque_impl_type(
|
||||
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() {
|
||||
|
@ -1915,7 +1915,7 @@ pub fn primitive_symbol(self) -> Option<Symbol> {
|
||||
|
||||
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,
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -230,8 +230,7 @@ pub fn report_selection_error(
|
||||
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(
|
||||
|
@ -2829,7 +2829,7 @@ pub(super) fn note_obligation_cause_code<G: EmissionGuarantee, T>(
|
||||
// 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(), " +")
|
||||
|
@ -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;
|
||||
@ -20,8 +21,7 @@ fn try_fast_path(
|
||||
// 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(());
|
||||
|
@ -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");
|
||||
|
Loading…
Reference in New Issue
Block a user