Skip to content

Commit 69e4918

Browse files
committed
addressing Niko's comments
1 parent 15d8e8f commit 69e4918

File tree

2 files changed

+45
-41
lines changed

2 files changed

+45
-41
lines changed

src/librustc_mir/build/mod.rs

+36-32
Original file line numberDiff line numberDiff line change
@@ -647,42 +647,46 @@ fn construct_fn<'a, 'gcx, 'tcx, A>(hir: Cx<'a, 'gcx, 'tcx>,
647647
let fn_def_id = tcx_hir.local_def_id(fn_id);
648648

649649
// Gather the upvars of a closure, if any.
650-
let upvar_decls: Vec<_> = match hir_tables.upvar_list.get(&fn_def_id) {
651-
Some(upvars) => upvars
652-
.iter()
653-
.map(|upvar_id| {
654-
let var_hir_id = upvar_id.var_path.hir_id;
655-
let var_node_id = tcx_hir.hir_to_node_id(var_hir_id);
656-
let capture = hir_tables.upvar_capture(*upvar_id);
657-
let by_ref = match capture {
658-
ty::UpvarCapture::ByValue => false,
659-
ty::UpvarCapture::ByRef(..) => true,
660-
};
661-
let mut decl = UpvarDecl {
662-
debug_name: keywords::Invalid.name(),
663-
var_hir_id: ClearCrossCrate::Set(var_hir_id),
664-
by_ref,
665-
mutability: Mutability::Not,
666-
};
667-
if let Some(Node::Binding(pat)) = tcx_hir.find(var_node_id) {
668-
if let hir::PatKind::Binding(_, _, ident, _) = pat.node {
669-
decl.debug_name = ident.name;
670-
if let Some(&bm) = hir.tables.pat_binding_modes().get(pat.hir_id) {
671-
if bm == ty::BindByValue(hir::MutMutable) {
672-
decl.mutability = Mutability::Mut;
673-
} else {
674-
decl.mutability = Mutability::Not;
675-
}
650+
// In analyze_closure() in upvar.rs we gathered a list of upvars used by a
651+
// closure and we stored in a map called upvar_list in TypeckTables indexed
652+
// with the closure's DefId. Here, we run through that vec of UpvarIds for
653+
// the given closure and use the necessary information to create UpvarDecl.
654+
let upvar_decls: Vec<_> = hir_tables
655+
.upvar_list
656+
.get(&fn_def_id)
657+
.into_iter()
658+
.flatten()
659+
.map(|upvar_id| {
660+
let var_hir_id = upvar_id.var_path.hir_id;
661+
let var_node_id = tcx_hir.hir_to_node_id(var_hir_id);
662+
let capture = hir_tables.upvar_capture(*upvar_id);
663+
let by_ref = match capture {
664+
ty::UpvarCapture::ByValue => false,
665+
ty::UpvarCapture::ByRef(..) => true,
666+
};
667+
let mut decl = UpvarDecl {
668+
debug_name: keywords::Invalid.name(),
669+
var_hir_id: ClearCrossCrate::Set(var_hir_id),
670+
by_ref,
671+
mutability: Mutability::Not,
672+
};
673+
if let Some(Node::Binding(pat)) = tcx_hir.find(var_node_id) {
674+
if let hir::PatKind::Binding(_, _, ident, _) = pat.node {
675+
decl.debug_name = ident.name;
676+
if let Some(&bm) = hir.tables.pat_binding_modes().get(pat.hir_id) {
677+
if bm == ty::BindByValue(hir::MutMutable) {
678+
decl.mutability = Mutability::Mut;
676679
} else {
677-
tcx.sess.delay_span_bug(pat.span, "missing binding mode");
680+
decl.mutability = Mutability::Not;
678681
}
682+
} else {
683+
tcx.sess.delay_span_bug(pat.span, "missing binding mode");
679684
}
680685
}
681-
decl
682-
})
683-
.collect(),
684-
_ => vec![],
685-
};
686+
}
687+
decl
688+
})
689+
.collect();
686690

687691
let mut builder = Builder::new(hir,
688692
span,

src/librustc_typeck/check/writeback.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ use syntax_pos::Span;
2020

2121
///////////////////////////////////////////////////////////////////////////
2222
// Entry point
23-
/// During type inference, partially inferred types are
24-
/// represented using Type variables (ty::Infer). These don't appear in
25-
/// the final TypeckTables since all of the types should have been
26-
/// inferred once typeck_tables_of is done.
27-
/// When type inference is running however, having to update the typeck
28-
/// tables every time a new type is inferred would be unreasonably slow,
29-
/// so instead all of the replacement happens at the end in
30-
/// resolve_type_vars_in_body, which creates a new TypeTables which
31-
/// doesn't contain any inference types.
3223

24+
// During type inference, partially inferred types are
25+
// represented using Type variables (ty::Infer). These don't appear in
26+
// the final TypeckTables since all of the types should have been
27+
// inferred once typeck_tables_of is done.
28+
// When type inference is running however, having to update the typeck
29+
// tables every time a new type is inferred would be unreasonably slow,
30+
// so instead all of the replacement happens at the end in
31+
// resolve_type_vars_in_body, which creates a new TypeTables which
32+
// doesn't contain any inference types.
3333
impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
3434
pub fn resolve_type_vars_in_body(&self, body: &'gcx hir::Body) -> &'gcx ty::TypeckTables<'gcx> {
3535
let item_id = self.tcx.hir().body_owner(body.id());

0 commit comments

Comments
 (0)