]> git.lizzy.rs Git - rust.git/blob - src/librustc_ty/common_traits.rs
Rollup merge of #68475 - Aaron1011:fix/forest-caching, r=nikomatsakis
[rust.git] / src / librustc_ty / common_traits.rs
1 //! Queries for checking whether a type implements one of a few common traits.
2
3 use rustc::middle::lang_items;
4 use rustc::traits;
5 use rustc::ty::{self, Ty, TyCtxt};
6 use rustc_span::DUMMY_SP;
7
8 fn is_copy_raw<'tcx>(tcx: TyCtxt<'tcx>, query: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
9     is_item_raw(tcx, query, lang_items::CopyTraitLangItem)
10 }
11
12 fn is_sized_raw<'tcx>(tcx: TyCtxt<'tcx>, query: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
13     is_item_raw(tcx, query, lang_items::SizedTraitLangItem)
14 }
15
16 fn is_freeze_raw<'tcx>(tcx: TyCtxt<'tcx>, query: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
17     is_item_raw(tcx, query, lang_items::FreezeTraitLangItem)
18 }
19
20 fn is_item_raw<'tcx>(
21     tcx: TyCtxt<'tcx>,
22     query: ty::ParamEnvAnd<'tcx, Ty<'tcx>>,
23     item: lang_items::LangItem,
24 ) -> bool {
25     let (param_env, ty) = query.into_parts();
26     let trait_def_id = tcx.require_lang_item(item, None);
27     tcx.infer_ctxt().enter(|infcx| {
28         traits::type_known_to_meet_bound_modulo_regions(
29             &infcx,
30             param_env,
31             ty,
32             trait_def_id,
33             DUMMY_SP,
34         )
35     })
36 }
37
38 pub(crate) fn provide(providers: &mut ty::query::Providers<'_>) {
39     *providers = ty::query::Providers { is_copy_raw, is_sized_raw, is_freeze_raw, ..*providers };
40 }