diff options
| author | Michael Goulet <michael@errs.io> | 2023-02-06 18:38:52 +0000 |
|---|---|---|
| committer | Michael Goulet <michael@errs.io> | 2023-02-16 03:39:59 +0000 |
| commit | eff2cb7760ffd1ed06fd5a68ba04dcb6689106f6 (patch) | |
| tree | be03b0f70bbf8f87d2ba0ea640edf25ea09a3b98 /compiler/rustc_middle/src/middle/resolve_bound_vars.rs | |
| parent | 262a344d7245f242586d5d5a0cc5c892f45891c4 (diff) | |
| download | rust-eff2cb7760ffd1ed06fd5a68ba04dcb6689106f6.tar.gz rust-eff2cb7760ffd1ed06fd5a68ba04dcb6689106f6.zip | |
Rename some region-specific stuff
Diffstat (limited to 'compiler/rustc_middle/src/middle/resolve_bound_vars.rs')
| -rw-r--r-- | compiler/rustc_middle/src/middle/resolve_bound_vars.rs | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/compiler/rustc_middle/src/middle/resolve_bound_vars.rs b/compiler/rustc_middle/src/middle/resolve_bound_vars.rs new file mode 100644 index 00000000000..cd457696942 --- /dev/null +++ b/compiler/rustc_middle/src/middle/resolve_bound_vars.rs @@ -0,0 +1,55 @@ +//! Name resolution for lifetimes and late-bound type and const variables: type declarations. + +use crate::ty; + +use rustc_data_structures::fx::FxHashMap; +use rustc_hir::def_id::DefId; +use rustc_hir::{ItemLocalId, OwnerId}; +use rustc_macros::HashStable; + +#[derive(Clone, Copy, PartialEq, Eq, Hash, TyEncodable, TyDecodable, Debug, HashStable)] +pub enum ResolvedArg { + StaticLifetime, + EarlyBound(/* lifetime decl */ DefId), + LateBound(ty::DebruijnIndex, /* late-bound index */ u32, /* lifetime decl */ DefId), + Free(DefId, /* lifetime decl */ DefId), +} + +/// A set containing, at most, one known element. +/// If two distinct values are inserted into a set, then it +/// becomes `Many`, which can be used to detect ambiguities. +#[derive(Copy, Clone, PartialEq, Eq, TyEncodable, TyDecodable, Debug, HashStable)] +pub enum Set1<T> { + Empty, + One(T), + Many, +} + +impl<T: PartialEq> Set1<T> { + pub fn insert(&mut self, value: T) { + *self = match self { + Set1::Empty => Set1::One(value), + Set1::One(old) if *old == value => return, + _ => Set1::Many, + }; + } +} + +#[derive(Copy, Clone, Debug, HashStable, Encodable, Decodable)] +pub enum ObjectLifetimeDefault { + Empty, + Static, + Ambiguous, + Param(DefId), +} + +/// Maps the id of each lifetime reference to the lifetime decl +/// that it corresponds to. +#[derive(Default, HashStable, Debug)] +pub struct ResolveBoundVars { + /// Maps from every use of a named (not anonymous) lifetime to a + /// `Region` describing how that region is bound + pub defs: FxHashMap<OwnerId, FxHashMap<ItemLocalId, ResolvedArg>>, + + pub late_bound_vars: FxHashMap<OwnerId, FxHashMap<ItemLocalId, Vec<ty::BoundVariableKind>>>, +} |
