Skip to content
Permalink
Browse files

Update inferred_outlives_of

  • Loading branch information...
Zoxc committed Nov 30, 2018
1 parent e305df1 commit 5d67618d4cd325263619b1af704d8929765993b0
Showing with 10 additions and 17 deletions.
  1. +1 −1 src/librustc/query/mod.rs
  2. +1 −5 src/librustc/ty/mod.rs
  3. +8 −11 src/librustc_typeck/outlives/mod.rs
@@ -174,7 +174,7 @@ rustc_queries! {

/// Returns the inferred outlives predicates (e.g., for `struct
/// Foo<'a, T> { x: &'a T }`, this would return `T: 'a`).
query inferred_outlives_of(_: DefId) -> Lrc<Vec<ty::Predicate<'tcx>>> {}
query inferred_outlives_of(_: DefId) -> &'tcx [ty::Predicate<'tcx>] {}

/// Maps from the `DefId` of a trait to the list of
/// super-predicates. This is a subset of the full list of
@@ -1118,11 +1118,7 @@ pub struct CratePredicatesMap<'tcx> {
/// For each struct with outlive bounds, maps to a vector of the
/// predicate of its outlive bounds. If an item has no outlives
/// bounds, it will have no entry.
pub predicates: FxHashMap<DefId, Lrc<Vec<ty::Predicate<'tcx>>>>,

/// An empty vector, useful for cloning.
#[stable_hasher(ignore)]
pub empty_predicate: Lrc<Vec<ty::Predicate<'tcx>>>,
pub predicates: FxHashMap<DefId, &'tcx [ty::Predicate<'tcx>]>,
}

impl<'tcx> AsRef<Predicate<'tcx>> for Predicate<'tcx> {
@@ -23,7 +23,7 @@ pub fn provide(providers: &mut Providers<'_>) {
fn inferred_outlives_of<'a, 'tcx>(
tcx: TyCtxt<'a, 'tcx, 'tcx>,
item_def_id: DefId,
) -> Lrc<Vec<ty::Predicate<'tcx>>> {
) -> &'tcx [ty::Predicate<'tcx>] {
let id = tcx
.hir()
.as_local_hir_id(item_def_id)
@@ -37,8 +37,8 @@ fn inferred_outlives_of<'a, 'tcx>(
let predicates = crate_map
.predicates
.get(&item_def_id)
.unwrap_or(&crate_map.empty_predicate)
.clone();
.map(|p| *p)
.unwrap_or(&[]);

if tcx.has_attr(item_def_id, "rustc_outlives") {
let mut pred: Vec<String> = predicates
@@ -63,10 +63,10 @@ fn inferred_outlives_of<'a, 'tcx>(
predicates
}

_ => Lrc::new(Vec::new()),
_ => &[],
},

_ => Lrc::new(Vec::new()),
_ => &[],
}
}

@@ -96,7 +96,7 @@ fn inferred_outlives_crate<'tcx>(
let predicates = global_inferred_outlives
.iter()
.map(|(&def_id, set)| {
let vec: Vec<ty::Predicate<'tcx>> = set
let predicates = tcx.arena.alloc_from_iter(set
.iter()
.filter_map(
|ty::OutlivesPredicate(kind1, region2)| match kind1.unpack() {
@@ -115,14 +115,11 @@ fn inferred_outlives_crate<'tcx>(
None
}
},
).collect();
(def_id, Lrc::new(vec))
));
(def_id, &*predicates)
}).collect();

let empty_predicate = Lrc::new(Vec::new());

Lrc::new(ty::CratePredicatesMap {
predicates,
empty_predicate,
})
}

0 comments on commit 5d67618

Please sign in to comment.
You can’t perform that action at this time.