Skip to content

Commit 10b1739

Browse files
committed
Auto merge of #40836 - arielb1:issue-32330-copy, r=nikomatsakis
store a copy of the Issue32230 info within TypeError The data can't be looked up from the region variable directly, because the region variable might have been destroyed at the end of a snapshot. Fixes #40000. Fixes #40743. beta-nominating because regression. r? @nikomatsakis
2 parents 07a3429 + 7e0f7a5 commit 10b1739

File tree

5 files changed

+69
-36
lines changed

5 files changed

+69
-36
lines changed

src/librustc/infer/error_reporting/mod.rs

+19-23
Original file line numberDiff line numberDiff line change
@@ -426,30 +426,26 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
426426
{
427427
debug!("note_issue_32330: terr={:?}", terr);
428428
match *terr {
429-
TypeError::RegionsInsufficientlyPolymorphic(_, &Region::ReVar(vid)) |
430-
TypeError::RegionsOverlyPolymorphic(_, &Region::ReVar(vid)) => {
431-
match self.region_vars.var_origin(vid) {
432-
RegionVariableOrigin::EarlyBoundRegion(_, _, Some(Issue32330 {
433-
fn_def_id,
434-
region_name
435-
})) => {
436-
diag.note(
437-
&format!("lifetime parameter `{0}` declared on fn `{1}` \
438-
appears only in the return type, \
439-
but here is required to be higher-ranked, \
440-
which means that `{0}` must appear in both \
441-
argument and return types",
442-
region_name,
443-
self.tcx.item_path_str(fn_def_id)));
444-
diag.note(
445-
&format!("this error is the result of a recent bug fix; \
446-
for more information, see issue #33685 \
447-
<https://github.com/rust-lang/rust/issues/33685>"));
448-
}
449-
_ => { }
450-
}
429+
TypeError::RegionsInsufficientlyPolymorphic(_, _, Some(box Issue32330 {
430+
fn_def_id, region_name
431+
})) |
432+
TypeError::RegionsOverlyPolymorphic(_, _, Some(box Issue32330 {
433+
fn_def_id, region_name
434+
})) => {
435+
diag.note(
436+
&format!("lifetime parameter `{0}` declared on fn `{1}` \
437+
appears only in the return type, \
438+
but here is required to be higher-ranked, \
439+
which means that `{0}` must appear in both \
440+
argument and return types",
441+
region_name,
442+
self.tcx.item_path_str(fn_def_id)));
443+
diag.note(
444+
&format!("this error is the result of a recent bug fix; \
445+
for more information, see issue #33685 \
446+
<https://github.com/rust-lang/rust/issues/33685>"));
451447
}
452-
_ => { }
448+
_ => {}
453449
}
454450
}
455451

src/librustc/infer/higher_ranked/mod.rs

+16-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use super::{CombinedSnapshot,
1515
InferCtxt,
1616
LateBoundRegion,
1717
HigherRankedType,
18+
RegionVariableOrigin,
1819
SubregionOrigin,
1920
SkolemizationMap};
2021
use super::combine::CombineFields;
@@ -656,14 +657,27 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
656657
skol_br,
657658
tainted_region);
658659

660+
let issue_32330 = if let &ty::ReVar(vid) = tainted_region {
661+
match self.region_vars.var_origin(vid) {
662+
RegionVariableOrigin::EarlyBoundRegion(_, _, issue_32330) => {
663+
issue_32330.map(Box::new)
664+
}
665+
_ => None
666+
}
667+
} else {
668+
None
669+
};
670+
659671
if overly_polymorphic {
660672
debug!("Overly polymorphic!");
661673
return Err(TypeError::RegionsOverlyPolymorphic(skol_br,
662-
tainted_region));
674+
tainted_region,
675+
issue_32330));
663676
} else {
664677
debug!("Not as polymorphic!");
665678
return Err(TypeError::RegionsInsufficientlyPolymorphic(skol_br,
666-
tainted_region));
679+
tainted_region,
680+
issue_32330));
667681
}
668682
}
669683
}

src/librustc/ty/error.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ pub enum TypeError<'tcx> {
3939
RegionsDoesNotOutlive(&'tcx Region, &'tcx Region),
4040
RegionsNotSame(&'tcx Region, &'tcx Region),
4141
RegionsNoOverlap(&'tcx Region, &'tcx Region),
42-
RegionsInsufficientlyPolymorphic(BoundRegion, &'tcx Region),
43-
RegionsOverlyPolymorphic(BoundRegion, &'tcx Region),
42+
RegionsInsufficientlyPolymorphic(BoundRegion, &'tcx Region, Option<Box<ty::Issue32330>>),
43+
RegionsOverlyPolymorphic(BoundRegion, &'tcx Region, Option<Box<ty::Issue32330>>),
4444
Sorts(ExpectedFound<Ty<'tcx>>),
4545
IntMismatch(ExpectedFound<ty::IntVarValue>),
4646
FloatMismatch(ExpectedFound<ast::FloatTy>),
@@ -116,11 +116,11 @@ impl<'tcx> fmt::Display for TypeError<'tcx> {
116116
RegionsNoOverlap(..) => {
117117
write!(f, "lifetimes do not intersect")
118118
}
119-
RegionsInsufficientlyPolymorphic(br, _) => {
119+
RegionsInsufficientlyPolymorphic(br, _, _) => {
120120
write!(f, "expected bound lifetime parameter {}, \
121121
found concrete lifetime", br)
122122
}
123-
RegionsOverlyPolymorphic(br, _) => {
123+
RegionsOverlyPolymorphic(br, _, _) => {
124124
write!(f, "expected concrete lifetime, \
125125
found bound lifetime parameter {}", br)
126126
}
@@ -253,15 +253,15 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
253253
self.note_and_explain_region(db, "...does not overlap ",
254254
region2, "");
255255
}
256-
RegionsInsufficientlyPolymorphic(_, conc_region) => {
256+
RegionsInsufficientlyPolymorphic(_, conc_region, _) => {
257257
self.note_and_explain_region(db, "concrete lifetime that was found is ",
258258
conc_region, "");
259259
}
260-
RegionsOverlyPolymorphic(_, &ty::ReVar(_)) => {
260+
RegionsOverlyPolymorphic(_, &ty::ReVar(_), _) => {
261261
// don't bother to print out the message below for
262262
// inference variables, it's not very illuminating.
263263
}
264-
RegionsOverlyPolymorphic(_, conc_region) => {
264+
RegionsOverlyPolymorphic(_, conc_region, _) => {
265265
self.note_and_explain_region(db, "expected concrete lifetime is ",
266266
conc_region, "");
267267
}

src/librustc/ty/structural_impls.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -293,11 +293,13 @@ impl<'a, 'tcx> Lift<'tcx> for ty::error::TypeError<'a> {
293293
RegionsNoOverlap(a, b) => {
294294
return tcx.lift(&(a, b)).map(|(a, b)| RegionsNoOverlap(a, b))
295295
}
296-
RegionsInsufficientlyPolymorphic(a, b) => {
297-
return tcx.lift(&b).map(|b| RegionsInsufficientlyPolymorphic(a, b))
296+
RegionsInsufficientlyPolymorphic(a, b, ref c) => {
297+
let c = c.clone();
298+
return tcx.lift(&b).map(|b| RegionsInsufficientlyPolymorphic(a, b, c))
298299
}
299-
RegionsOverlyPolymorphic(a, b) => {
300-
return tcx.lift(&b).map(|b| RegionsOverlyPolymorphic(a, b))
300+
RegionsOverlyPolymorphic(a, b, ref c) => {
301+
let c = c.clone();
302+
return tcx.lift(&b).map(|b| RegionsOverlyPolymorphic(a, b, c))
301303
}
302304
IntMismatch(x) => IntMismatch(x),
303305
FloatMismatch(x) => FloatMismatch(x),

src/test/compile-fail/issue-40000.rs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![feature(closure_to_fn_coercion)]
12+
13+
fn main() {
14+
let bar: fn(&mut u32) = |_| {}; //~ ERROR mismatched types
15+
//~| expected concrete lifetime, found bound lifetime parameter
16+
17+
fn foo(x: Box<Fn(&i32)>) {}
18+
let bar = Box::new(|x: &i32| {}) as Box<Fn(_)>;
19+
foo(bar); //~ ERROR mismatched types
20+
//~| expected concrete lifetime, found bound lifetime parameter
21+
}

0 commit comments

Comments
 (0)