Skip to content

Commit 78e8a00

Browse files
committed
Auto merge of #32306 - nikomatsakis:issue-32278, r=eddyb
create fewer region variables in coercions Fixes #32278. r? @eddyb
2 parents 02310fd + 43aed96 commit 78e8a00

23 files changed

+396
-189
lines changed

src/librustc/middle/infer/error_reporting.rs

+138-76
Large diffs are not rendered by default.

src/librustc/middle/infer/mod.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ pub fn common_supertype<'a, 'tcx>(cx: &InferCtxt<'a, 'tcx>,
407407
match result {
408408
Ok(t) => t,
409409
Err(ref err) => {
410-
cx.report_and_explain_type_error(trace, err);
410+
cx.report_and_explain_type_error(trace, err).emit();
411411
cx.tcx.types.err
412412
}
413413
}
@@ -1396,7 +1396,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
13961396
found: actual
13971397
})
13981398
};
1399-
self.report_and_explain_type_error(trace, &err);
1399+
self.report_and_explain_type_error(trace, &err).emit();
14001400
}
14011401

14021402
pub fn report_conflicting_default_types(&self,
@@ -1411,11 +1411,13 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
14111411
})
14121412
};
14131413

1414-
self.report_and_explain_type_error(trace,
1414+
self.report_and_explain_type_error(
1415+
trace,
14151416
&TypeError::TyParamDefaultMismatch(ExpectedFound {
14161417
expected: expected,
14171418
found: actual
1418-
}));
1419+
}))
1420+
.emit();
14191421
}
14201422

14211423
pub fn replace_late_bound_regions_with_fresh_var<T>(

src/librustc/middle/infer/region_inference/mod.rs

+21-16
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub use self::CombineMapType::*;
1717
pub use self::RegionResolutionError::*;
1818
pub use self::VarValue::*;
1919

20-
use super::{RegionVariableOrigin, SubregionOrigin, TypeTrace, MiscVariable};
20+
use super::{RegionVariableOrigin, SubregionOrigin, MiscVariable};
2121
use super::unify_key;
2222

2323
use rustc_data_structures::graph::{self, Direction, NodeIndex};
@@ -27,7 +27,6 @@ use middle::ty::{self, Ty, TyCtxt};
2727
use middle::ty::{BoundRegion, Region, RegionVid};
2828
use middle::ty::{ReEmpty, ReStatic, ReFree, ReEarlyBound};
2929
use middle::ty::{ReLateBound, ReScope, ReVar, ReSkolemized, BrFresh};
30-
use middle::ty::error::TypeError;
3130
use util::common::indenter;
3231
use util::nodemap::{FnvHashMap, FnvHashSet};
3332

@@ -152,11 +151,16 @@ pub enum RegionResolutionError<'tcx> {
152151
/// more specific errors message by suggesting to the user where they
153152
/// should put a lifetime. In those cases we process and put those errors
154153
/// into `ProcessedErrors` before we do any reporting.
155-
ProcessedErrors(Vec<RegionVariableOrigin>,
156-
Vec<(TypeTrace<'tcx>, TypeError<'tcx>)>,
154+
ProcessedErrors(Vec<ProcessedErrorOrigin<'tcx>>,
157155
Vec<SameRegions>),
158156
}
159157

158+
#[derive(Clone, Debug)]
159+
pub enum ProcessedErrorOrigin<'tcx> {
160+
ConcreteFailure(SubregionOrigin<'tcx>, Region, Region),
161+
VariableFailure(RegionVariableOrigin),
162+
}
163+
160164
/// SameRegions is used to group regions that we think are the same and would
161165
/// like to indicate so to the user.
162166
/// For example, the following function
@@ -530,16 +534,14 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
530534
assert!(self.values_are_none());
531535

532536
debug!("RegionVarBindings: lub_regions({:?}, {:?})", a, b);
533-
match (a, b) {
534-
(ReStatic, _) | (_, ReStatic) => {
535-
ReStatic // nothing lives longer than static
536-
}
537-
538-
_ => {
539-
self.combine_vars(Lub, a, b, origin.clone(), |this, old_r, new_r| {
540-
this.make_subregion(origin.clone(), old_r, new_r)
541-
})
542-
}
537+
if a == ty::ReStatic || b == ty::ReStatic {
538+
ReStatic // nothing lives longer than static
539+
} else if a == b {
540+
a // LUB(a,a) = a
541+
} else {
542+
self.combine_vars(Lub, a, b, origin.clone(), |this, old_r, new_r| {
543+
this.make_subregion(origin.clone(), old_r, new_r)
544+
})
543545
}
544546
}
545547

@@ -550,8 +552,11 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
550552
debug!("RegionVarBindings: glb_regions({:?}, {:?})", a, b);
551553
match (a, b) {
552554
(ReStatic, r) | (r, ReStatic) => {
553-
// static lives longer than everything else
554-
r
555+
r // static lives longer than everything else
556+
}
557+
558+
_ if a == b => {
559+
a // GLB(a,a) = a
555560
}
556561

557562
_ => {

0 commit comments

Comments
 (0)