2020-01-30 20:28:16 +00:00
|
|
|
//! Queries for checking whether a type implements one of a few common traits.
|
|
|
|
|
2020-08-18 11:47:27 +01:00
|
|
|
use rustc_hir::lang_items::LangItem;
|
2020-03-29 17:19:48 +02:00
|
|
|
use rustc_infer::infer::TyCtxtInferExt;
|
2023-05-15 06:24:45 +02:00
|
|
|
use rustc_middle::query::Providers;
|
2024-11-19 16:13:55 +01:00
|
|
|
use rustc_middle::ty::{self, Ty, TyCtxt};
|
2020-02-11 21:19:40 +01:00
|
|
|
use rustc_trait_selection::traits;
|
2020-01-30 20:28:16 +00:00
|
|
|
|
2024-11-19 16:13:55 +01:00
|
|
|
fn is_copy_raw<'tcx>(tcx: TyCtxt<'tcx>, query: ty::PseudoCanonicalInput<'tcx, Ty<'tcx>>) -> bool {
|
2020-08-18 11:47:27 +01:00
|
|
|
is_item_raw(tcx, query, LangItem::Copy)
|
2020-01-30 20:28:16 +00:00
|
|
|
}
|
|
|
|
|
2025-02-20 14:34:49 -03:00
|
|
|
fn is_use_cloned_raw<'tcx>(
|
|
|
|
tcx: TyCtxt<'tcx>,
|
|
|
|
query: ty::PseudoCanonicalInput<'tcx, Ty<'tcx>>,
|
|
|
|
) -> bool {
|
|
|
|
is_item_raw(tcx, query, LangItem::UseCloned)
|
|
|
|
}
|
|
|
|
|
2024-11-19 16:13:55 +01:00
|
|
|
fn is_sized_raw<'tcx>(tcx: TyCtxt<'tcx>, query: ty::PseudoCanonicalInput<'tcx, Ty<'tcx>>) -> bool {
|
2020-08-18 11:47:27 +01:00
|
|
|
is_item_raw(tcx, query, LangItem::Sized)
|
2020-01-30 20:28:16 +00:00
|
|
|
}
|
|
|
|
|
2024-11-19 16:13:55 +01:00
|
|
|
fn is_freeze_raw<'tcx>(tcx: TyCtxt<'tcx>, query: ty::PseudoCanonicalInput<'tcx, Ty<'tcx>>) -> bool {
|
2020-08-18 11:47:27 +01:00
|
|
|
is_item_raw(tcx, query, LangItem::Freeze)
|
2020-01-30 20:28:16 +00:00
|
|
|
}
|
|
|
|
|
2024-11-19 16:13:55 +01:00
|
|
|
fn is_unpin_raw<'tcx>(tcx: TyCtxt<'tcx>, query: ty::PseudoCanonicalInput<'tcx, Ty<'tcx>>) -> bool {
|
2021-03-18 22:44:36 +01:00
|
|
|
is_item_raw(tcx, query, LangItem::Unpin)
|
|
|
|
}
|
|
|
|
|
2020-01-30 20:28:16 +00:00
|
|
|
fn is_item_raw<'tcx>(
|
|
|
|
tcx: TyCtxt<'tcx>,
|
2024-11-19 16:13:55 +01:00
|
|
|
query: ty::PseudoCanonicalInput<'tcx, Ty<'tcx>>,
|
2020-08-18 11:47:27 +01:00
|
|
|
item: LangItem,
|
2020-01-30 20:28:16 +00:00
|
|
|
) -> bool {
|
2024-11-19 16:13:55 +01:00
|
|
|
let (infcx, param_env) = tcx.infer_ctxt().build_with_typing_env(query.typing_env);
|
2020-01-30 20:28:16 +00:00
|
|
|
let trait_def_id = tcx.require_lang_item(item, None);
|
2024-11-19 16:13:55 +01:00
|
|
|
traits::type_known_to_meet_bound_modulo_regions(&infcx, param_env, query.value, trait_def_id)
|
2020-01-30 20:28:16 +00:00
|
|
|
}
|
|
|
|
|
2023-05-15 06:24:45 +02:00
|
|
|
pub(crate) fn provide(providers: &mut Providers) {
|
2025-02-20 14:34:49 -03:00
|
|
|
*providers = Providers {
|
|
|
|
is_copy_raw,
|
|
|
|
is_use_cloned_raw,
|
|
|
|
is_sized_raw,
|
|
|
|
is_freeze_raw,
|
|
|
|
is_unpin_raw,
|
|
|
|
..*providers
|
|
|
|
};
|
2020-01-30 20:28:16 +00:00
|
|
|
}
|