]>
git.proxmox.com Git - rustc.git/blob - src/librustc_typeck/outlives/explicit.rs
1 // Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
12 use rustc
::hir
::def_id
::{CrateNum, DefId}
;
13 use rustc
::hir
::itemlikevisit
::ItemLikeVisitor
;
14 use rustc
::ty
::{self, TyCtxt}
;
15 use util
::nodemap
::FxHashMap
;
19 pub fn explicit_predicates
<'tcx
>(
20 tcx
: TyCtxt
<'_
, 'tcx
, 'tcx
>,
22 ) -> FxHashMap
<DefId
, RequiredPredicates
<'tcx
>> {
23 let mut predicates
= FxHashMap
::default();
25 // iterate over the entire crate
26 tcx
.hir
.krate().visit_all_item_likes(&mut ExplicitVisitor
{
28 explicit_predicates
: &mut predicates
,
35 pub struct ExplicitVisitor
<'cx
, 'tcx
: 'cx
> {
36 tcx
: TyCtxt
<'cx
, 'tcx
, 'tcx
>,
37 explicit_predicates
: &'cx
mut FxHashMap
<DefId
, RequiredPredicates
<'tcx
>>,
41 impl<'cx
, 'tcx
> ItemLikeVisitor
<'tcx
> for ExplicitVisitor
<'cx
, 'tcx
> {
42 fn visit_item(&mut self, item
: &'tcx hir
::Item
) {
44 krate
: self.crate_num
,
45 index
: item
.hir_id
.owner
,
48 let mut required_predicates
= RequiredPredicates
::default();
49 let local_explicit_predicate
= self.tcx
.explicit_predicates_of(def_id
).predicates
;
51 for pred
in local_explicit_predicate
.into_iter() {
53 ty
::Predicate
::TypeOutlives(predicate
) => {
54 let ty
::OutlivesPredicate(ref ty
, ref reg
) = predicate
.skip_binder();
55 insert_outlives_predicate(self.tcx
, (*ty
).into(), reg
, &mut required_predicates
)
58 ty
::Predicate
::RegionOutlives(predicate
) => {
59 let ty
::OutlivesPredicate(ref reg1
, ref reg2
) = predicate
.skip_binder();
60 insert_outlives_predicate(
64 &mut required_predicates
,
68 ty
::Predicate
::Trait(..)
69 | ty
::Predicate
::Projection(..)
70 | ty
::Predicate
::WellFormed(..)
71 | ty
::Predicate
::ObjectSafe(..)
72 | ty
::Predicate
::ClosureKind(..)
73 | ty
::Predicate
::Subtype(..)
74 | ty
::Predicate
::ConstEvaluatable(..) => (),
78 self.explicit_predicates
.insert(def_id
, required_predicates
);
81 fn visit_trait_item(&mut self, _trait_item
: &'tcx hir
::TraitItem
) {}
83 fn visit_impl_item(&mut self, _impl_item
: &'tcx hir
::ImplItem
) {}