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 LateBoundAnon(ty::DebruijnIndex, /* late-bound index */ u32, /* anon index */ u32),
16 Free(DefId, /* lifetime decl */ DefId),
19 /// A set containing, at most, one known element.
20 /// If two distinct values are inserted into a set, then it
21 /// becomes `Many`, which can be used to detect ambiguities.
22 #[derive(Copy, Clone, PartialEq, Eq, TyEncodable, TyDecodable, Debug, HashStable)]
29 impl<T: PartialEq> Set1<T> {
30 pub fn insert(&mut self, value: T) {
32 Set1::Empty => Set1::One(value),
33 Set1::One(old) if *old == value => return,
39 pub type ObjectLifetimeDefault = Set1<Region>;
41 /// Maps the id of each lifetime reference to the lifetime decl
42 /// that it corresponds to.
43 #[derive(Default, HashStable, Debug)]
44 pub struct ResolveLifetimes {
45 /// Maps from every use of a named (not anonymous) lifetime to a
46 /// `Region` describing how that region is bound
47 pub defs: FxHashMap<LocalDefId, FxHashMap<ItemLocalId, Region>>,
49 /// Set of lifetime def ids that are late-bound; a region can
50 /// be late-bound if (a) it does NOT appear in a where-clause and
51 /// (b) it DOES appear in the arguments.
52 pub late_bound: FxHashMap<LocalDefId, FxHashSet<LocalDefId>>,
54 pub late_bound_vars: FxHashMap<LocalDefId, FxHashMap<ItemLocalId, Vec<ty::BoundVariableKind>>>,