Skip to content

Commit

Permalink
Auto merge of #32306 - nikomatsakis:issue-32278, r=eddyb
Browse files Browse the repository at this point in the history
create fewer region variables in coercions

Fixes #32278.

r? @eddyb
  • Loading branch information
bors committed Mar 20, 2016
2 parents 02310fd + 43aed96 commit 78e8a00
Show file tree
Hide file tree
Showing 23 changed files with 396 additions and 189 deletions.
214 changes: 138 additions & 76 deletions src/librustc/middle/infer/error_reporting.rs

Large diffs are not rendered by default.

10 changes: 6 additions & 4 deletions src/librustc/middle/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ pub fn common_supertype<'a, 'tcx>(cx: &InferCtxt<'a, 'tcx>,
match result {
Ok(t) => t,
Err(ref err) => {
cx.report_and_explain_type_error(trace, err);
cx.report_and_explain_type_error(trace, err).emit();
cx.tcx.types.err
}
}
Expand Down Expand Up @@ -1396,7 +1396,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
found: actual
})
};
self.report_and_explain_type_error(trace, &err);
self.report_and_explain_type_error(trace, &err).emit();
}

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

self.report_and_explain_type_error(trace,
self.report_and_explain_type_error(
trace,
&TypeError::TyParamDefaultMismatch(ExpectedFound {
expected: expected,
found: actual
}));
}))
.emit();
}

pub fn replace_late_bound_regions_with_fresh_var<T>(
Expand Down
37 changes: 21 additions & 16 deletions src/librustc/middle/infer/region_inference/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub use self::CombineMapType::*;
pub use self::RegionResolutionError::*;
pub use self::VarValue::*;

use super::{RegionVariableOrigin, SubregionOrigin, TypeTrace, MiscVariable};
use super::{RegionVariableOrigin, SubregionOrigin, MiscVariable};
use super::unify_key;

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

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

#[derive(Clone, Debug)]
pub enum ProcessedErrorOrigin<'tcx> {
ConcreteFailure(SubregionOrigin<'tcx>, Region, Region),
VariableFailure(RegionVariableOrigin),
}

/// SameRegions is used to group regions that we think are the same and would
/// like to indicate so to the user.
/// For example, the following function
Expand Down Expand Up @@ -530,16 +534,14 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
assert!(self.values_are_none());

debug!("RegionVarBindings: lub_regions({:?}, {:?})", a, b);
match (a, b) {
(ReStatic, _) | (_, ReStatic) => {
ReStatic // nothing lives longer than static
}

_ => {
self.combine_vars(Lub, a, b, origin.clone(), |this, old_r, new_r| {
this.make_subregion(origin.clone(), old_r, new_r)
})
}
if a == ty::ReStatic || b == ty::ReStatic {
ReStatic // nothing lives longer than static
} else if a == b {
a // LUB(a,a) = a
} else {
self.combine_vars(Lub, a, b, origin.clone(), |this, old_r, new_r| {
this.make_subregion(origin.clone(), old_r, new_r)
})
}
}

Expand All @@ -550,8 +552,11 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
debug!("RegionVarBindings: glb_regions({:?}, {:?})", a, b);
match (a, b) {
(ReStatic, r) | (r, ReStatic) => {
// static lives longer than everything else
r
r // static lives longer than everything else
}

_ if a == b => {
a // GLB(a,a) = a
}

_ => {
Expand Down
Loading

0 comments on commit 78e8a00

Please sign in to comment.