1 //! Name resolution for lifetimes: type declarations.
5 use rustc_data_structures::fx::{FxHashMap, FxHashSet};
6 use rustc_hir::def_id::{DefId, LocalDefId};
7 use rustc_hir::ItemLocalId;
8 use rustc_macros::HashStable;
10 #[derive(Clone, Copy, PartialEq, Eq, Hash, TyEncodable, TyDecodable, Debug, HashStable)]
13 EarlyBound(/* index */ u32, /* lifetime decl */ DefId),
14 LateBound(ty::DebruijnIndex, /* late-bound index */ u32, /* lifetime decl */ DefId),
15 Free(DefId, /* lifetime decl */ DefId),
18 /// A set containing, at most, one known element.
19 /// If two distinct values are inserted into a set, then it
20 /// becomes `Many`, which can be used to detect ambiguities.
21 #[derive(Copy, Clone, PartialEq, Eq, TyEncodable, TyDecodable, Debug, HashStable)]
28 impl<T: PartialEq> Set1<T> {
29 pub fn insert(&mut self, value: T) {
31 Set1::Empty => Set1::One(value),
32 Set1::One(old) if *old == value => return,
38 pub type ObjectLifetimeDefault = Set1<Region>;
40 /// Maps the id of each lifetime reference to the lifetime decl
41 /// that it corresponds to.
42 #[derive(Default, HashStable, Debug)]
43 pub struct ResolveLifetimes {
44 /// Maps from every use of a named (not anonymous) lifetime to a
45 /// `Region` describing how that region is bound
46 pub defs: FxHashMap<LocalDefId, FxHashMap<ItemLocalId, Region>>,
48 /// Set of lifetime def ids that are late-bound; a region can
49 /// be late-bound if (a) it does NOT appear in a where-clause and
50 /// (b) it DOES appear in the arguments.
51 pub late_bound: FxHashMap<LocalDefId, FxHashSet<LocalDefId>>,
53 pub late_bound_vars: FxHashMap<LocalDefId, FxHashMap<ItemLocalId, Vec<ty::BoundVariableKind>>>,