about summary refs log tree commit diff
path: root/compiler/rustc_mir_build/src
diff options
context:
space:
mode:
authorlrh2000 <lrh2000@pku.edu.cn>2021-05-15 19:01:13 +0800
committerlrh2000 <lrh2000@pku.edu.cn>2021-07-09 23:09:48 +0800
commitcda90f55419ce449f3a9db327465d9b2ae7dfce9 (patch)
tree16325f4b16e3865b249ebcc2182eaea1a2ca54b1 /compiler/rustc_mir_build/src
parent29856acffeb87541bb167c33f4fdb13c31ba6de0 (diff)
downloadrust-cda90f55419ce449f3a9db327465d9b2ae7dfce9.tar.gz
rust-cda90f55419ce449f3a9db327465d9b2ae7dfce9.zip
Store names of captured variables in `optimized_mir`
- Closures in external crates may get compiled in because of
  monomorphization. We should store names of captured variables
  in `optimized_mir`, so that they are written into the metadata
  file and we can use them to generate debuginfo.

- If there are breakpoints inside closures, the names of captured
  variables stored in `optimized_mir` can be used to print them.
  Now the name is more precise when disjoint fields are captured.
Diffstat (limited to 'compiler/rustc_mir_build/src')
-rw-r--r--compiler/rustc_mir_build/src/build/mod.rs10
1 files changed, 2 insertions, 8 deletions
diff --git a/compiler/rustc_mir_build/src/build/mod.rs b/compiler/rustc_mir_build/src/build/mod.rs
index f5f6da3ec0b..e13dcadeb56 100644
--- a/compiler/rustc_mir_build/src/build/mod.rs
+++ b/compiler/rustc_mir_build/src/build/mod.rs
@@ -16,7 +16,7 @@ use rustc_middle::mir::*;
 use rustc_middle::thir::{BindingMode, Expr, ExprId, LintLevel, PatKind, Thir};
 use rustc_middle::ty::subst::Subst;
 use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable, TypeckResults};
-use rustc_span::symbol::{kw, sym};
+use rustc_span::symbol::sym;
 use rustc_span::Span;
 use rustc_target::spec::abi::Abi;
 use rustc_target::spec::PanicStrategy;
@@ -974,13 +974,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
 
                     let mutability = captured_place.mutability;
 
-                    // FIXME(project-rfc-2229#8): Store more precise information
-                    let mut name = kw::Empty;
-                    if let Some(Node::Binding(pat)) = tcx_hir.find(var_id) {
-                        if let hir::PatKind::Binding(_, _, ident, _) = pat.kind {
-                            name = ident.name;
-                        }
-                    }
+                    let name = captured_place.to_symbol(tcx);
 
                     let mut projs = closure_env_projs.clone();
                     projs.push(ProjectionElem::Field(Field::new(i), ty));