3 use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
5 use rustc_hir::def_id::{DefId, LocalDefId};
22 pub struct UpvarPath {
23 pub hir_id: hir::HirId,
26 /// Upvars do not get their own `NodeId`. Instead, we use the pair of
27 /// the original var ID (that is, the root variable that is referenced
28 /// by the upvar) and the ID of the closure expression.
29 #[derive(Clone, Copy, PartialEq, Eq, Hash, TyEncodable, TyDecodable, TypeFoldable, HashStable)]
31 pub var_path: UpvarPath,
32 pub closure_expr_id: LocalDefId,
36 pub fn new(var_hir_id: hir::HirId, closure_def_id: LocalDefId) -> UpvarId {
37 UpvarId { var_path: UpvarPath { hir_id: var_hir_id }, closure_expr_id: closure_def_id }
41 /// Information describing the capture of an upvar. This is computed
42 /// during `typeck`, specifically by `regionck`.
43 #[derive(PartialEq, Clone, Debug, Copy, TyEncodable, TyDecodable, TypeFoldable, HashStable)]
44 pub enum UpvarCapture<'tcx> {
45 /// Upvar is captured by value. This is always true when the
46 /// closure is labeled `move`, but can also be true in other cases
47 /// depending on inference.
49 /// If the upvar was inferred to be captured by value (e.g. `move`
50 /// was not used), then the `Span` points to a usage that
51 /// required it. There may be more than one such usage
52 /// (e.g. `|| { a; a; }`), in which case we pick an
54 ByValue(Option<Span>),
56 /// Upvar is captured by reference.
57 ByRef(UpvarBorrow<'tcx>),
60 #[derive(PartialEq, Clone, Copy, TyEncodable, TyDecodable, TypeFoldable, HashStable)]
61 pub struct UpvarBorrow<'tcx> {
62 /// The kind of borrow: by-ref upvars have access to shared
63 /// immutable borrows, which are not part of the normal language
67 /// Region of the resulting reference.
68 pub region: ty::Region<'tcx>,
71 pub type UpvarListMap = FxHashMap<DefId, FxIndexMap<hir::HirId, UpvarId>>;
72 pub type UpvarCaptureMap<'tcx> = FxHashMap<UpvarId, UpvarCapture<'tcx>>;