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