Skip to content

Commit 51ea8ba

Browse files
committed
---
yaml --- r: 32616 b: refs/heads/dist-snap c: 39d33a6 h: refs/heads/master v: v3
1 parent f7d6df1 commit 51ea8ba

File tree

5 files changed

+102
-45
lines changed

5 files changed

+102
-45
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: d0c6ce338884ee21843f4b40bf6bf18d222ce5df
99
refs/heads/incoming: d9317a174e434d4c99fc1a37fd7dc0d2f5328d37
10-
refs/heads/dist-snap: 6332c2d728f82188c415e335142bc042ff1d7ad0
10+
refs/heads/dist-snap: 39d33a653fd4aebae813ec6ad83ea2ea6009c64f
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/dist-snap/src/rustc/middle/borrowck/gather_loans.rs

Lines changed: 46 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -338,39 +338,49 @@ impl gather_loan_ctxt {
338338
};
339339

340340
match result {
341-
Ok(pc_ok) => {
342-
// we were able guarantee the validity of the ptr,
343-
// perhaps by rooting or because it is immutably
344-
// rooted. good.
345-
self.bccx.stable_paths += 1;
346-
}
347-
Ok(pc_if_pure(e)) => {
348-
// we are only able to guarantee the validity if
349-
// the scope is pure
350-
match scope_r {
351-
ty::re_scope(pure_id) => {
352-
// if the scope is some block/expr in the fn,
353-
// then just require that this scope be pure
354-
self.req_maps.pure_map.insert(pure_id, e);
355-
self.bccx.req_pure_paths += 1;
356-
357-
if self.tcx().sess.borrowck_note_pure() {
358-
self.bccx.span_note(
359-
cmt.span,
360-
fmt!("purity required"));
341+
Ok(pc_ok) => {
342+
debug!("result of preserve: pc_ok");
343+
344+
// we were able guarantee the validity of the ptr,
345+
// perhaps by rooting or because it is immutably
346+
// rooted. good.
347+
self.bccx.stable_paths += 1;
348+
}
349+
Ok(pc_if_pure(e)) => {
350+
debug!("result of preserve: %?", pc_if_pure(e));
351+
352+
// we are only able to guarantee the validity if
353+
// the scope is pure
354+
match scope_r {
355+
ty::re_scope(pure_id) => {
356+
// if the scope is some block/expr in the
357+
// fn, then just require that this scope
358+
// be pure
359+
self.req_maps.pure_map.insert(pure_id, e);
360+
self.bccx.req_pure_paths += 1;
361+
362+
debug!("requiring purity for scope %?",
363+
scope_r);
364+
365+
if self.tcx().sess.borrowck_note_pure() {
366+
self.bccx.span_note(
367+
cmt.span,
368+
fmt!("purity required"));
369+
}
370+
}
371+
_ => {
372+
// otherwise, we can't enforce purity for
373+
// that scope, so give up and report an
374+
// error
375+
self.bccx.report(e);
376+
}
361377
}
362-
}
363-
_ => {
364-
// otherwise, we can't enforce purity for that
365-
// scope, so give up and report an error
378+
}
379+
Err(e) => {
380+
// we cannot guarantee the validity of this pointer
381+
debug!("result of preserve: error");
366382
self.bccx.report(e);
367-
}
368383
}
369-
}
370-
Err(e) => {
371-
// we cannot guarantee the validity of this pointer
372-
self.bccx.report(e);
373-
}
374384
}
375385
}
376386
}
@@ -386,13 +396,19 @@ impl gather_loan_ctxt {
386396
// mutable memory.
387397
fn check_mutbl(req_mutbl: ast::mutability,
388398
cmt: cmt) -> bckres<preserve_condition> {
399+
debug!("check_mutbl(req_mutbl=%?, cmt.mutbl=%?)",
400+
req_mutbl, cmt.mutbl);
401+
389402
if req_mutbl == m_const || req_mutbl == cmt.mutbl {
403+
debug!("required is const or they are the same");
390404
Ok(pc_ok)
391405
} else {
392406
let e = {cmt: cmt,
393407
code: err_mutbl(req_mutbl)};
394408
if req_mutbl == m_imm {
395409
// you can treat mutable things as imm if you are pure
410+
debug!("imm required, must be pure");
411+
396412
Ok(pc_if_pure(e))
397413
} else {
398414
Err(e)

branches/dist-snap/src/rustc/middle/typeck/check/method.rs

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,9 @@ impl LookupContext {
758758
}
759759

760760
fn is_relevant(&self, self_ty: ty::t, candidate: &Candidate) -> bool {
761+
debug!("is_relevant(self_ty=%s, candidate=%s)",
762+
self.ty_to_str(self_ty), self.cand_to_str(candidate));
763+
761764
self.fcx.can_mk_subty(self_ty, candidate.rcvr_ty).is_ok()
762765
}
763766

@@ -782,7 +785,7 @@ impl LookupContext {
782785
}
783786
}
784787

785-
fn report_candidate(idx: uint, origin: &method_origin) {
788+
fn report_candidate(&self, idx: uint, origin: &method_origin) {
786789
match *origin {
787790
method_static(impl_did) => {
788791
self.report_static_candidate(idx, impl_did)
@@ -796,7 +799,7 @@ impl LookupContext {
796799
}
797800
}
798801

799-
fn report_static_candidate(idx: uint, did: def_id) {
802+
fn report_static_candidate(&self, idx: uint, did: def_id) {
800803
let span = if did.crate == ast::local_crate {
801804
match self.tcx().items.get(did.node) {
802805
ast_map::node_method(m, _, _) => m.span,
@@ -812,15 +815,15 @@ impl LookupContext {
812815
ty::item_path_str(self.tcx(), did)));
813816
}
814817

815-
fn report_param_candidate(idx: uint, did: def_id) {
818+
fn report_param_candidate(&self, idx: uint, did: def_id) {
816819
self.tcx().sess.span_note(
817820
self.expr.span,
818821
fmt!("candidate #%u derives from the bound `%s`",
819822
(idx+1u),
820823
ty::item_path_str(self.tcx(), did)));
821824
}
822825

823-
fn report_trait_candidate(idx: uint, did: def_id) {
826+
fn report_trait_candidate(&self, idx: uint, did: def_id) {
824827
self.tcx().sess.span_note(
825828
self.expr.span,
826829
fmt!("candidate #%u derives from the type of the receiver, \
@@ -829,23 +832,31 @@ impl LookupContext {
829832
ty::item_path_str(self.tcx(), did)));
830833
}
831834

832-
fn infcx() -> infer::infer_ctxt {
835+
fn infcx(&self) -> infer::infer_ctxt {
833836
self.fcx.inh.infcx
834837
}
835838

836-
fn tcx() -> ty::ctxt {
839+
fn tcx(&self) -> ty::ctxt {
837840
self.fcx.tcx()
838841
}
839842

840-
fn ty_to_str(t: ty::t) -> ~str {
843+
fn ty_to_str(&self, t: ty::t) -> ~str {
841844
self.fcx.infcx().ty_to_str(t)
842845
}
843846

844-
fn did_to_str(did: def_id) -> ~str {
847+
fn cand_to_str(&self, cand: &Candidate) -> ~str {
848+
fmt!("Candidate(rcvr_ty=%s, rcvr_substs=%s, self_mode=%?, origin=%?)",
849+
self.ty_to_str(cand.rcvr_ty),
850+
ty::substs_to_str(self.tcx(), &cand.rcvr_substs),
851+
cand.self_mode,
852+
cand.origin)
853+
}
854+
855+
fn did_to_str(&self, did: def_id) -> ~str {
845856
ty::item_path_str(self.tcx(), did)
846857
}
847858

848-
fn bug(s: ~str) -> ! {
859+
fn bug(&self, s: ~str) -> ! {
849860
self.tcx().sess.bug(s)
850861
}
851862
}

branches/dist-snap/src/rustc/middle/typeck/check/regionck.rs

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,6 @@ fn visit_expr(expr: @ast::expr, &&rcx: @rcx, v: rvt) {
159159
debug!("visit_expr(e=%s)",
160160
pprust::expr_to_str(expr, rcx.fcx.tcx().sess.intr()));
161161

162-
// constrain_auto_ref(rcx, expr);
163-
164162
match expr.node {
165163
ast::expr_path(*) => {
166164
// Avoid checking the use of local variables, as we
@@ -176,6 +174,36 @@ fn visit_expr(expr: @ast::expr, &&rcx: @rcx, v: rvt) {
176174
}
177175
}
178176

177+
ast::expr_call(callee, args, _) => {
178+
// Check for a.b() where b is a method. Ensure that
179+
// any types in the callee are valid for the entire
180+
// method call.
181+
182+
// FIXME(#3387)--we should really invoke
183+
// `constrain_auto_ref()` on all exprs. But that causes a
184+
// lot of spurious errors because of how the region
185+
// hierarchy is setup.
186+
let tcx = rcx.fcx.tcx();
187+
if rcx.fcx.ccx.method_map.contains_key(callee.id) {
188+
match callee.node {
189+
ast::expr_field(base, _, _) => {
190+
constrain_auto_ref(rcx, base);
191+
}
192+
_ => {
193+
tcx.sess.span_bug(
194+
callee.span,
195+
~"call of method that is not a field");
196+
}
197+
}
198+
} else {
199+
constrain_auto_ref(rcx, callee);
200+
}
201+
202+
for args.each |arg| {
203+
constrain_auto_ref(rcx, arg);
204+
}
205+
}
206+
179207
ast::expr_cast(source, _) => {
180208
// Determine if we are casting `source` to an trait
181209
// instance. If so, we have to be sure that the type of
@@ -275,15 +303,17 @@ fn constrain_auto_ref(
275303
* function ensures that the lifetime of the resulting borrowed
276304
* ptr includes at least the expression `expr`. */
277305

306+
debug!("constrain_auto_ref(expr=%s)", rcx.fcx.expr_to_str(expr));
307+
278308
let adjustment = rcx.fcx.inh.adjustments.find(expr.id);
279309
let region = match adjustment {
280310
Some(@{autoref: Some(ref auto_ref), _}) => auto_ref.region,
281311
_ => { return; }
282312
};
283313

284314
let tcx = rcx.fcx.tcx();
285-
let expr_region = ty::re_scope(expr.id);
286-
match rcx.fcx.mk_subr(true, expr.span, expr_region, region) {
315+
let encl_region = ty::encl_region(tcx, expr.id);
316+
match rcx.fcx.mk_subr(true, expr.span, encl_region, region) {
287317
result::Ok(()) => {}
288318
result::Err(_) => {
289319
// In practice, this cannot happen: `region` is always a

branches/dist-snap/src/rustc/middle/typeck/infer/region_var_bindings.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ impl RegionVarBindings {
583583
}
584584

585585
fn resolve_var(rid: RegionVid) -> ty::region {
586-
debug!("RegionVarBindings: resolve_var(%?)", rid);
586+
debug!("RegionVarBindings: resolve_var(%?=%u)", rid, *rid);
587587
if self.values.is_empty() {
588588
self.tcx.sess.span_bug(
589589
self.var_spans[*rid],

0 commit comments

Comments
 (0)