Skip to content

Commit 5743107

Browse files
committed
---
yaml --- r: 108186 b: refs/heads/dist-snap c: 7286e35 h: refs/heads/master v: v3
1 parent 8d4e53c commit 5743107

File tree

4 files changed

+56
-10
lines changed

4 files changed

+56
-10
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: f64fdf524a434f0e5cd0bc91d09c144723f3c90d
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
9-
refs/heads/dist-snap: 64c9b5c3aeb037f8113948da2c098bb8c86b9d8a
9+
refs/heads/dist-snap: 7286e35c6b840763012db2ca4b0655b8344f02ba
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1212
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

branches/dist-snap/src/librustc/middle/typeck/infer/error_reporting.rs

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,24 @@ impl ErrorReporting for InferCtxt {
237237
sup,
238238
"");
239239
}
240+
infer::ReborrowUpvar(span, ref upvar_id) => {
241+
self.tcx.sess.span_err(
242+
span,
243+
format!("lifetime of borrowed pointer outlives \
244+
lifetime of captured variable `{}`...",
245+
ty::local_var_name_str(self.tcx, upvar_id.var_id).get().to_str()));
246+
note_and_explain_region(
247+
self.tcx,
248+
"...the borrowed pointer is valid for ",
249+
sub,
250+
"...");
251+
note_and_explain_region(
252+
self.tcx,
253+
format!("...but `{}` is only valid for ",
254+
ty::local_var_name_str(self.tcx, upvar_id.var_id).get().to_str()),
255+
sup,
256+
"");
257+
}
240258
infer::InfStackClosure(span) => {
241259
self.tcx.sess.span_err(
242260
span,
@@ -272,10 +290,12 @@ impl ErrorReporting for InferCtxt {
272290
sup,
273291
"");
274292
}
275-
infer::FreeVariable(span) => {
293+
infer::FreeVariable(span, id) => {
276294
self.tcx.sess.span_err(
277295
span,
278-
"captured variable does not outlive the enclosing closure");
296+
format!("captured variable `{}` does not \
297+
outlive the enclosing closure",
298+
ty::local_var_name_str(self.tcx, id).get().to_str()));
279299
note_and_explain_region(
280300
self.tcx,
281301
"captured variable is valid for ",
@@ -473,6 +493,10 @@ impl ErrorReportingHelpers for InferCtxt {
473493
infer::BoundRegionInCoherence(..) => {
474494
format!(" for coherence check")
475495
}
496+
infer::UpvarRegion(ref upvar_id, _) => {
497+
format!(" for capture of `{}` by closure",
498+
ty::local_var_name_str(self.tcx, upvar_id.var_id).get().to_str())
499+
}
476500
};
477501

478502
self.tcx.sess.span_err(
@@ -533,6 +557,12 @@ impl ErrorReportingHelpers for InferCtxt {
533557
"...so that reference does not outlive \
534558
borrowed content");
535559
}
560+
infer::ReborrowUpvar(span, ref upvar_id) => {
561+
self.tcx.sess.span_note(
562+
span,
563+
format!("...so that closure can access `{}`",
564+
ty::local_var_name_str(self.tcx, upvar_id.var_id).get().to_str()))
565+
}
536566
infer::InfStackClosure(span) => {
537567
self.tcx.sess.span_note(
538568
span,
@@ -549,11 +579,12 @@ impl ErrorReportingHelpers for InferCtxt {
549579
"...so that pointer is not dereferenced \
550580
outside its lifetime");
551581
}
552-
infer::FreeVariable(span) => {
582+
infer::FreeVariable(span, id) => {
553583
self.tcx.sess.span_note(
554584
span,
555-
"...so that captured variable does not outlive the \
556-
enclosing closure");
585+
format!("...so that captured variable `{}` \
586+
does not outlive the enclosing closure",
587+
ty::local_var_name_str(self.tcx, id).get().to_str()));
557588
}
558589
infer::IndexSlice(span) => {
559590
self.tcx.sess.span_note(

branches/dist-snap/src/librustc/middle/typeck/infer/mod.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ pub enum SubregionOrigin {
160160
DerefPointer(Span),
161161

162162
// Closure bound must not outlive captured free variables
163-
FreeVariable(Span),
163+
FreeVariable(Span, ast::NodeId),
164164

165165
// Index into slice must be within its lifetime
166166
IndexSlice(Span),
@@ -172,6 +172,9 @@ pub enum SubregionOrigin {
172172
// Creating a pointer `b` to contents of another reference
173173
Reborrow(Span),
174174

175+
// Creating a pointer `b` to contents of an upvar
176+
ReborrowUpvar(Span, ty::UpvarId),
177+
175178
// (&'a &'b T) where a >= b
176179
ReferenceOutlivesReferent(ty::t, Span),
177180

@@ -225,6 +228,8 @@ pub enum RegionVariableOrigin {
225228
// when doing subtyping/lub/glb computations
226229
BoundRegionInFnType(Span, ty::BoundRegion),
227230

231+
UpvarRegion(ty::UpvarId, Span),
232+
228233
BoundRegionInTypeOrImpl(Span),
229234

230235
BoundRegionInCoherence,
@@ -876,10 +881,11 @@ impl SubregionOrigin {
876881
InfStackClosure(a) => a,
877882
InvokeClosure(a) => a,
878883
DerefPointer(a) => a,
879-
FreeVariable(a) => a,
884+
FreeVariable(a, _) => a,
880885
IndexSlice(a) => a,
881886
RelateObjectBound(a) => a,
882887
Reborrow(a) => a,
888+
ReborrowUpvar(a, _) => a,
883889
ReferenceOutlivesReferent(_, a) => a,
884890
BindingTypeIsNotValidAtDecl(a) => a,
885891
CallRcvr(a) => a,
@@ -898,10 +904,11 @@ impl Repr for SubregionOrigin {
898904
InfStackClosure(a) => format!("InfStackClosure({})", a.repr(tcx)),
899905
InvokeClosure(a) => format!("InvokeClosure({})", a.repr(tcx)),
900906
DerefPointer(a) => format!("DerefPointer({})", a.repr(tcx)),
901-
FreeVariable(a) => format!("FreeVariable({})", a.repr(tcx)),
907+
FreeVariable(a, b) => format!("FreeVariable({}, {})", a.repr(tcx), b),
902908
IndexSlice(a) => format!("IndexSlice({})", a.repr(tcx)),
903909
RelateObjectBound(a) => format!("RelateObjectBound({})", a.repr(tcx)),
904910
Reborrow(a) => format!("Reborrow({})", a.repr(tcx)),
911+
ReborrowUpvar(a, b) => format!("ReborrowUpvar({},{:?})", a.repr(tcx), b),
905912
ReferenceOutlivesReferent(_, a) =>
906913
format!("ReferenceOutlivesReferent({})", a.repr(tcx)),
907914
BindingTypeIsNotValidAtDecl(a) =>
@@ -928,6 +935,7 @@ impl RegionVariableOrigin {
928935
BoundRegionInFnType(a, _) => a,
929936
BoundRegionInTypeOrImpl(a) => a,
930937
BoundRegionInCoherence => codemap::DUMMY_SP,
938+
UpvarRegion(_, a) => a
931939
}
932940
}
933941
}
@@ -948,6 +956,9 @@ impl Repr for RegionVariableOrigin {
948956
BoundRegionInTypeOrImpl(a) => format!("bound_regionInTypeOrImpl({})",
949957
a.repr(tcx)),
950958
BoundRegionInCoherence => format!("bound_regionInCoherence"),
959+
UpvarRegion(a, b) => format!("UpvarRegion({}, {})",
960+
a.repr(tcx),
961+
b.repr(tcx)),
951962
}
952963
}
953964
}

branches/dist-snap/src/librustc/middle/typeck/infer/region_inference/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,11 @@ impl RegionVarBindings {
270270
// cannot add constraints once regions are resolved
271271
assert!(self.values_are_none());
272272

273-
debug!("RegionVarBindings: make_subregion({:?}, {:?})", sub, sup);
273+
debug!("RegionVarBindings: make_subregion({}, {}) due to {}",
274+
sub.repr(self.tcx),
275+
sup.repr(self.tcx),
276+
origin.repr(self.tcx));
277+
274278
match (sub, sup) {
275279
(ReEarlyBound(..), _) |
276280
(ReLateBound(..), _) |

0 commit comments

Comments
 (0)