]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_middle/src/middle/resolve_lifetime.rs
Auto merge of #100869 - nnethercote:replace-ThinVec, r=spastorino
[rust.git] / compiler / rustc_middle / src / middle / resolve_lifetime.rs
1 //! Name resolution for lifetimes: type declarations.
2
3 use crate::ty;
4
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;
9
10 #[derive(Clone, Copy, PartialEq, Eq, Hash, TyEncodable, TyDecodable, Debug, HashStable)]
11 pub enum Region {
12     Static,
13     EarlyBound(/* lifetime decl */ DefId),
14     LateBound(ty::DebruijnIndex, /* late-bound index */ u32, /* lifetime decl */ DefId),
15     Free(DefId, /* lifetime decl */ DefId),
16 }
17
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)]
22 pub enum Set1<T> {
23     Empty,
24     One(T),
25     Many,
26 }
27
28 impl<T: PartialEq> Set1<T> {
29     pub fn insert(&mut self, value: T) {
30         *self = match self {
31             Set1::Empty => Set1::One(value),
32             Set1::One(old) if *old == value => return,
33             _ => Set1::Many,
34         };
35     }
36 }
37
38 #[derive(Copy, Clone, Debug, HashStable, Encodable, Decodable)]
39 pub enum ObjectLifetimeDefault {
40     Empty,
41     Static,
42     Ambiguous,
43     Param(DefId),
44 }
45
46 /// Maps the id of each lifetime reference to the lifetime decl
47 /// that it corresponds to.
48 #[derive(Default, HashStable, Debug)]
49 pub struct ResolveLifetimes {
50     /// Maps from every use of a named (not anonymous) lifetime to a
51     /// `Region` describing how that region is bound
52     pub defs: FxHashMap<LocalDefId, FxHashMap<ItemLocalId, Region>>,
53
54     /// Set of lifetime def ids that are late-bound; a region can
55     /// be late-bound if (a) it does NOT appear in a where-clause and
56     /// (b) it DOES appear in the arguments.
57     pub late_bound: FxHashMap<LocalDefId, FxHashSet<LocalDefId>>,
58
59     pub late_bound_vars: FxHashMap<LocalDefId, FxHashMap<ItemLocalId, Vec<ty::BoundVariableKind>>>,
60 }