Skip to content

Commit b7a6cf8

Browse files
committed
rustc_typeck: fix compilation
1 parent 8c8257a commit b7a6cf8

File tree

7 files changed

+94
-70
lines changed

7 files changed

+94
-70
lines changed

src/librustc_typeck/check/closure.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
2323
expr: &hir::Expr,
2424
_capture: hir::CaptureClause,
2525
decl: &'gcx hir::FnDecl,
26-
body: &'gcx hir::Expr,
26+
body_id: hir::ExprId,
2727
expected: Expectation<'tcx>)
2828
-> Ty<'tcx> {
2929
debug!("check_expr_closure(expr={:?},expected={:?})",
@@ -37,6 +37,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
3737
Some(ty) => self.deduce_expectations_from_expected_type(ty),
3838
None => (None, None),
3939
};
40+
let body = self.tcx.map.expr(body_id);
4041
self.check_closure(expr, expected_kind, decl, body, expected_sig)
4142
}
4243

src/librustc_typeck/check/mod.rs

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ use syntax::symbol::{Symbol, InternedString, keywords};
119119
use syntax::util::lev_distance::find_best_match_for_name;
120120
use syntax_pos::{self, BytePos, Span};
121121

122-
use rustc::hir::intravisit::{self, Visitor};
122+
use rustc::hir::intravisit::{self, Visitor, NestedVisitMode};
123123
use rustc::hir::itemlikevisit::ItemLikeVisitor;
124124
use rustc::hir::{self, PatKind};
125125
use rustc::hir::print as pprust;
@@ -538,6 +538,10 @@ struct CheckItemTypesVisitor<'a, 'tcx: 'a> { ccx: &'a CrateCtxt<'a, 'tcx> }
538538
struct CheckItemBodiesVisitor<'a, 'tcx: 'a> { ccx: &'a CrateCtxt<'a, 'tcx> }
539539

540540
impl<'a, 'tcx> Visitor<'tcx> for CheckItemTypesVisitor<'a, 'tcx> {
541+
fn nested_visit_map(&mut self) -> Option<(&hir::map::Map<'tcx>, NestedVisitMode)> {
542+
Some((&self.ccx.tcx.map, NestedVisitMode::OnlyBodies))
543+
}
544+
541545
fn visit_item(&mut self, i: &'tcx hir::Item) {
542546
check_item_type(self.ccx, i);
543547
intravisit::walk_item(self, i);
@@ -630,9 +634,11 @@ pub fn check_drop_impls(ccx: &CrateCtxt) -> CompileResult {
630634

631635
fn check_bare_fn<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
632636
decl: &'tcx hir::FnDecl,
633-
body: &'tcx hir::Expr,
637+
body_id: hir::ExprId,
634638
fn_id: ast::NodeId,
635639
span: Span) {
640+
let body = ccx.tcx.map.expr(body_id);
641+
636642
let raw_fty = ccx.tcx.item_type(ccx.tcx.map.local_def_id(fn_id));
637643
let fn_ty = match raw_fty.sty {
638644
ty::TyFnDef(.., f) => f,
@@ -643,13 +649,13 @@ fn check_bare_fn<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
643649

644650
ccx.inherited(fn_id).enter(|inh| {
645651
// Compute the fty from point of view of inside fn.
646-
let fn_scope = inh.tcx.region_maps.call_site_extent(fn_id, body.id);
652+
let fn_scope = inh.tcx.region_maps.call_site_extent(fn_id, body_id.node_id());
647653
let fn_sig =
648654
fn_ty.sig.subst(inh.tcx, &inh.parameter_environment.free_substs);
649655
let fn_sig =
650656
inh.tcx.liberate_late_bound_regions(fn_scope, &fn_sig);
651657
let fn_sig =
652-
inh.normalize_associated_types_in(body.span, body.id, &fn_sig);
658+
inh.normalize_associated_types_in(body.span, body_id.node_id(), &fn_sig);
653659

654660
let fcx = check_fn(&inh, fn_ty.unsafety, fn_id, &fn_sig, decl, fn_id, body);
655661

@@ -659,7 +665,7 @@ fn check_bare_fn<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
659665
fcx.check_casts();
660666
fcx.select_all_obligations_or_error(); // Casts can introduce new obligations.
661667

662-
fcx.regionck_fn(fn_id, decl, body);
668+
fcx.regionck_fn(fn_id, decl, body_id);
663669
fcx.resolve_type_vars_in_fn(decl, body, fn_id);
664670
});
665671
}
@@ -750,7 +756,7 @@ impl<'a, 'gcx, 'tcx> Visitor<'gcx> for GatherLocalsVisitor<'a, 'gcx, 'tcx> {
750756

751757
// Don't descend into the bodies of nested closures
752758
fn visit_fn(&mut self, _: intravisit::FnKind<'gcx>, _: &'gcx hir::FnDecl,
753-
_: &'gcx hir::Expr, _: Span, _: ast::NodeId) { }
759+
_: hir::ExprId, _: Span, _: ast::NodeId) { }
754760
}
755761

756762
/// Helper used by check_bare_fn and check_expr_fn. Does the grungy work of checking a function
@@ -911,8 +917,8 @@ pub fn check_item_body<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>, it: &'tcx hir::Item) {
911917
ccx.tcx.item_path_str(ccx.tcx.map.local_def_id(it.id)));
912918
let _indenter = indenter();
913919
match it.node {
914-
hir::ItemFn(ref decl, .., ref body) => {
915-
check_bare_fn(ccx, &decl, &body, it.id, it.span);
920+
hir::ItemFn(ref decl, .., body_id) => {
921+
check_bare_fn(ccx, &decl, body_id, it.id, it.span);
916922
}
917923
hir::ItemImpl(.., ref impl_item_refs) => {
918924
debug!("ItemImpl {} with id {}", it.name, it.id);
@@ -923,8 +929,8 @@ pub fn check_item_body<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>, it: &'tcx hir::Item) {
923929
hir::ImplItemKind::Const(_, ref expr) => {
924930
check_const(ccx, &expr, impl_item.id)
925931
}
926-
hir::ImplItemKind::Method(ref sig, ref body) => {
927-
check_bare_fn(ccx, &sig.decl, body, impl_item.id, impl_item.span);
932+
hir::ImplItemKind::Method(ref sig, body_id) => {
933+
check_bare_fn(ccx, &sig.decl, body_id, impl_item.id, impl_item.span);
928934
}
929935
hir::ImplItemKind::Type(_) => {
930936
// Nothing to do here.
@@ -938,8 +944,8 @@ pub fn check_item_body<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>, it: &'tcx hir::Item) {
938944
hir::ConstTraitItem(_, Some(ref expr)) => {
939945
check_const(ccx, &expr, trait_item.id)
940946
}
941-
hir::MethodTraitItem(ref sig, Some(ref body)) => {
942-
check_bare_fn(ccx, &sig.decl, body, trait_item.id, trait_item.span);
947+
hir::MethodTraitItem(ref sig, Some(body_id)) => {
948+
check_bare_fn(ccx, &sig.decl, body_id, trait_item.id, trait_item.span);
943949
}
944950
hir::MethodTraitItem(_, None) |
945951
hir::ConstTraitItem(_, None) |
@@ -1102,14 +1108,14 @@ fn check_impl_items_against_trait<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
11021108
err.emit()
11031109
}
11041110
}
1105-
hir::ImplItemKind::Method(_, ref body) => {
1111+
hir::ImplItemKind::Method(_, body_id) => {
11061112
let trait_span = tcx.map.span_if_local(ty_trait_item.def_id);
11071113
if ty_trait_item.kind == ty::AssociatedKind::Method {
11081114
let err_count = tcx.sess.err_count();
11091115
compare_impl_method(ccx,
11101116
&ty_impl_item,
11111117
impl_item.span,
1112-
body.id,
1118+
body_id.node_id(),
11131119
&ty_trait_item,
11141120
impl_trait_ref,
11151121
trait_span,
@@ -1119,7 +1125,7 @@ fn check_impl_items_against_trait<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
11191125
compare_impl_method(ccx,
11201126
&ty_impl_item,
11211127
impl_item.span,
1122-
body.id,
1128+
body_id.node_id(),
11231129
&ty_trait_item,
11241130
impl_trait_ref,
11251131
trait_span,
@@ -3791,8 +3797,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
37913797
hir::ExprMatch(ref discrim, ref arms, match_src) => {
37923798
self.check_match(expr, &discrim, arms, expected, match_src)
37933799
}
3794-
hir::ExprClosure(capture, ref decl, ref body, _) => {
3795-
self.check_expr_closure(expr, capture, &decl, &body, expected)
3800+
hir::ExprClosure(capture, ref decl, body_id, _) => {
3801+
self.check_expr_closure(expr, capture, &decl, body_id, expected)
37963802
}
37973803
hir::ExprBlock(ref b) => {
37983804
self.check_block_with_expected(&b, expected)

src/librustc_typeck/check/regionck.rs

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ use std::mem;
9999
use std::ops::Deref;
100100
use syntax::ast;
101101
use syntax_pos::Span;
102-
use rustc::hir::intravisit::{self, Visitor};
102+
use rustc::hir::intravisit::{self, Visitor, NestedVisitMode};
103103
use rustc::hir::{self, PatKind};
104104

105105
use self::SubjectNode::Subject;
@@ -113,7 +113,7 @@ macro_rules! ignore_err {
113113
// PUBLIC ENTRY POINTS
114114

115115
impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
116-
pub fn regionck_expr(&self, e: &hir::Expr) {
116+
pub fn regionck_expr(&self, e: &'gcx hir::Expr) {
117117
let mut rcx = RegionCtxt::new(self, RepeatingScope(e.id), e.id, Subject(e.id));
118118
if self.err_count_since_creation() == 0 {
119119
// regionck assumes typeck succeeded
@@ -141,13 +141,13 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
141141
pub fn regionck_fn(&self,
142142
fn_id: ast::NodeId,
143143
decl: &hir::FnDecl,
144-
body: &hir::Expr) {
144+
body_id: hir::ExprId) {
145145
debug!("regionck_fn(id={})", fn_id);
146-
let mut rcx = RegionCtxt::new(self, RepeatingScope(body.id), body.id, Subject(fn_id));
146+
let mut rcx = RegionCtxt::new(self, RepeatingScope(body_id.node_id()), body_id.node_id(), Subject(fn_id));
147147

148148
if self.err_count_since_creation() == 0 {
149149
// regionck assumes typeck succeeded
150-
rcx.visit_fn_body(fn_id, decl, body, self.tcx.map.span(fn_id));
150+
rcx.visit_fn_body(fn_id, decl, body_id, self.tcx.map.span(fn_id));
151151
}
152152

153153
rcx.free_region_map.relate_free_regions_from_predicates(
@@ -267,14 +267,14 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> {
267267
fn visit_fn_body(&mut self,
268268
id: ast::NodeId, // the id of the fn itself
269269
fn_decl: &hir::FnDecl,
270-
body: &hir::Expr,
270+
body_id: hir::ExprId,
271271
span: Span)
272272
{
273273
// When we enter a function, we can derive
274274
debug!("visit_fn_body(id={})", id);
275275

276276
let call_site = self.tcx.region_maps.lookup_code_extent(
277-
region::CodeExtentData::CallSiteScope { fn_id: id, body_id: body.id });
277+
region::CodeExtentData::CallSiteScope { fn_id: id, body_id: body_id.node_id() });
278278
let old_call_site_scope = self.set_call_site_scope(Some(call_site));
279279

280280
let fn_sig = {
@@ -300,19 +300,20 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> {
300300
.chain(Some(fn_sig.output))
301301
.collect();
302302

303-
let old_body_id = self.set_body_id(body.id);
304-
self.relate_free_regions(&fn_sig_tys[..], body.id, span);
305-
self.link_fn_args(self.tcx.region_maps.node_extent(body.id),
303+
let old_body_id = self.set_body_id(body_id.node_id());
304+
self.relate_free_regions(&fn_sig_tys[..], body_id.node_id(), span);
305+
self.link_fn_args(self.tcx.region_maps.node_extent(body_id.node_id()),
306306
&fn_decl.inputs[..]);
307+
let body = self.tcx.map.expr(body_id);
307308
self.visit_expr(body);
308-
self.visit_region_obligations(body.id);
309+
self.visit_region_obligations(body_id.node_id());
309310

310311
let call_site_scope = self.call_site_scope.unwrap();
311312
debug!("visit_fn_body body.id {} call_site_scope: {:?}",
312313
body.id, call_site_scope);
313314
let call_site_region = self.tcx.mk_region(ty::ReScope(call_site_scope));
314315
self.type_of_node_must_outlive(infer::CallReturn(span),
315-
body.id,
316+
body_id.node_id(),
316317
call_site_region);
317318

318319
self.region_bound_pairs.truncate(old_region_bounds_pairs_len);
@@ -469,7 +470,7 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> {
469470
}
470471
}
471472

472-
impl<'a, 'gcx, 'tcx, 'v> Visitor<'v> for RegionCtxt<'a, 'gcx, 'tcx> {
473+
impl<'a, 'gcx, 'tcx> Visitor<'gcx> for RegionCtxt<'a, 'gcx, 'tcx> {
473474
// (..) FIXME(#3238) should use visit_pat, not visit_arm/visit_local,
474475
// However, right now we run into an issue whereby some free
475476
// regions are not properly related if they appear within the
@@ -478,29 +479,33 @@ impl<'a, 'gcx, 'tcx, 'v> Visitor<'v> for RegionCtxt<'a, 'gcx, 'tcx> {
478479
// hierarchy, and in particular the relationships between free
479480
// regions, until regionck, as described in #3238.
480481

481-
fn visit_fn(&mut self, _fk: intravisit::FnKind<'v>, fd: &'v hir::FnDecl,
482-
b: &'v hir::Expr, span: Span, id: ast::NodeId) {
482+
fn nested_visit_map(&mut self) -> Option<(&hir::map::Map<'gcx>, NestedVisitMode)> {
483+
Some((&self.tcx.map, NestedVisitMode::OnlyBodies))
484+
}
485+
486+
fn visit_fn(&mut self, _fk: intravisit::FnKind<'gcx>, fd: &'gcx hir::FnDecl,
487+
b: hir::ExprId, span: Span, id: ast::NodeId) {
483488
self.visit_fn_body(id, fd, b, span)
484489
}
485490

486491
//visit_pat: visit_pat, // (..) see above
487492

488-
fn visit_arm(&mut self, arm: &hir::Arm) {
493+
fn visit_arm(&mut self, arm: &'gcx hir::Arm) {
489494
// see above
490495
for p in &arm.pats {
491496
self.constrain_bindings_in_pat(p);
492497
}
493498
intravisit::walk_arm(self, arm);
494499
}
495500

496-
fn visit_local(&mut self, l: &hir::Local) {
501+
fn visit_local(&mut self, l: &'gcx hir::Local) {
497502
// see above
498503
self.constrain_bindings_in_pat(&l.pat);
499504
self.link_local(l);
500505
intravisit::walk_local(self, l);
501506
}
502507

503-
fn visit_expr(&mut self, expr: &hir::Expr) {
508+
fn visit_expr(&mut self, expr: &'gcx hir::Expr) {
504509
debug!("regionck::visit_expr(e={:?}, repeating_scope={})",
505510
expr, self.repeating_scope);
506511

@@ -737,8 +742,8 @@ impl<'a, 'gcx, 'tcx, 'v> Visitor<'v> for RegionCtxt<'a, 'gcx, 'tcx> {
737742
intravisit::walk_expr(self, expr);
738743
}
739744

740-
hir::ExprClosure(.., ref body, _) => {
741-
self.check_expr_fn_block(expr, &body);
745+
hir::ExprClosure(.., body_id, _) => {
746+
self.check_expr_fn_block(expr, body_id);
742747
}
743748

744749
hir::ExprLoop(ref body, _, _) => {
@@ -823,9 +828,9 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> {
823828
}
824829

825830
fn check_expr_fn_block(&mut self,
826-
expr: &hir::Expr,
827-
body: &hir::Expr) {
828-
let repeating_scope = self.set_repeating_scope(body.id);
831+
expr: &'gcx hir::Expr,
832+
body_id: hir::ExprId) {
833+
let repeating_scope = self.set_repeating_scope(body_id.node_id());
829834
intravisit::walk_expr(self, expr);
830835
self.set_repeating_scope(repeating_scope);
831836
}

src/librustc_typeck/check/upvar.rs

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@ use rustc::infer::UpvarRegion;
5050
use syntax::ast;
5151
use syntax_pos::Span;
5252
use rustc::hir;
53-
use rustc::hir::intravisit::{self, Visitor};
53+
use rustc::hir::intravisit::{self, Visitor, NestedVisitMode};
5454
use rustc::util::nodemap::NodeMap;
5555

5656
///////////////////////////////////////////////////////////////////////////
5757
// PUBLIC ENTRY POINTS
5858

5959
impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
60-
pub fn closure_analyze(&self, body: &hir::Expr) {
60+
pub fn closure_analyze(&self, body: &'gcx hir::Expr) {
6161
let mut seed = SeedBorrowKind::new(self);
6262
seed.visit_expr(body);
6363

@@ -77,11 +77,15 @@ struct SeedBorrowKind<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
7777
temp_closure_kinds: NodeMap<ty::ClosureKind>,
7878
}
7979

80-
impl<'a, 'gcx, 'tcx, 'v> Visitor<'v> for SeedBorrowKind<'a, 'gcx, 'tcx> {
81-
fn visit_expr(&mut self, expr: &hir::Expr) {
80+
impl<'a, 'gcx, 'tcx> Visitor<'gcx> for SeedBorrowKind<'a, 'gcx, 'tcx> {
81+
fn nested_visit_map(&mut self) -> Option<(&hir::map::Map<'gcx>, NestedVisitMode)> {
82+
Some((&self.fcx.tcx.map, NestedVisitMode::OnlyBodies))
83+
}
84+
85+
fn visit_expr(&mut self, expr: &'gcx hir::Expr) {
8286
match expr.node {
83-
hir::ExprClosure(cc, _, ref body, _) => {
84-
self.check_closure(expr, cc, &body);
87+
hir::ExprClosure(cc, _, body_id, _) => {
88+
self.check_closure(expr, cc, body_id);
8589
}
8690

8791
_ => { }
@@ -99,7 +103,7 @@ impl<'a, 'gcx, 'tcx> SeedBorrowKind<'a, 'gcx, 'tcx> {
99103
fn check_closure(&mut self,
100104
expr: &hir::Expr,
101105
capture_clause: hir::CaptureClause,
102-
_body: &hir::Expr)
106+
_body_id: hir::ExprId)
103107
{
104108
let closure_def_id = self.fcx.tcx.map.local_def_id(expr.id);
105109
if !self.fcx.tables.borrow().closure_kinds.contains_key(&closure_def_id) {
@@ -153,14 +157,15 @@ impl<'a, 'gcx, 'tcx> AdjustBorrowKind<'a, 'gcx, 'tcx> {
153157
id: ast::NodeId,
154158
span: Span,
155159
decl: &hir::FnDecl,
156-
body: &hir::Expr) {
160+
body_id: hir::ExprId) {
157161
/*!
158162
* Analysis starting point.
159163
*/
160164

161-
debug!("analyze_closure(id={:?}, body.id={:?})", id, body.id);
165+
debug!("analyze_closure(id={:?}, body.id={:?})", id, body_id);
162166

163167
{
168+
let body = self.fcx.tcx.map.expr(body_id);
164169
let mut euv =
165170
euv::ExprUseVisitor::with_options(self,
166171
self.fcx,
@@ -484,11 +489,15 @@ impl<'a, 'gcx, 'tcx> AdjustBorrowKind<'a, 'gcx, 'tcx> {
484489
}
485490
}
486491

487-
impl<'a, 'gcx, 'tcx, 'v> Visitor<'v> for AdjustBorrowKind<'a, 'gcx, 'tcx> {
492+
impl<'a, 'gcx, 'tcx> Visitor<'gcx> for AdjustBorrowKind<'a, 'gcx, 'tcx> {
493+
fn nested_visit_map(&mut self) -> Option<(&hir::map::Map<'gcx>, NestedVisitMode)> {
494+
Some((&self.fcx.tcx.map, NestedVisitMode::OnlyBodies))
495+
}
496+
488497
fn visit_fn(&mut self,
489-
fn_kind: intravisit::FnKind<'v>,
490-
decl: &'v hir::FnDecl,
491-
body: &'v hir::Expr,
498+
fn_kind: intravisit::FnKind<'gcx>,
499+
decl: &'gcx hir::FnDecl,
500+
body: hir::ExprId,
492501
span: Span,
493502
id: ast::NodeId)
494503
{

0 commit comments

Comments
 (0)