1 //! Queries for checking whether a type implements one of a few common traits.
3 use rustc_hir::lang_items::LangItem;
4 use rustc_infer::infer::TyCtxtInferExt;
5 use rustc_middle::ty::{self, Ty, TyCtxt};
6 use rustc_span::DUMMY_SP;
7 use rustc_trait_selection::traits;
9 fn is_copy_raw<'tcx>(tcx: TyCtxt<'tcx>, query: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
10 is_item_raw(tcx, query, LangItem::Copy)
13 fn is_sized_raw<'tcx>(tcx: TyCtxt<'tcx>, query: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
14 is_item_raw(tcx, query, LangItem::Sized)
17 fn is_freeze_raw<'tcx>(tcx: TyCtxt<'tcx>, query: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
18 is_item_raw(tcx, query, LangItem::Freeze)
21 fn is_unpin_raw<'tcx>(tcx: TyCtxt<'tcx>, query: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
22 is_item_raw(tcx, query, LangItem::Unpin)
27 query: ty::ParamEnvAnd<'tcx, Ty<'tcx>>,
30 let (param_env, ty) = query.into_parts();
31 let trait_def_id = tcx.require_lang_item(item, None);
32 let infcx = tcx.infer_ctxt().build();
33 traits::type_known_to_meet_bound_modulo_regions(&infcx, param_env, ty, trait_def_id, DUMMY_SP)
36 pub(crate) fn provide(providers: &mut ty::query::Providers) {
37 *providers = ty::query::Providers {