Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create fewer region variables in coercions #32306

Merged
merged 9 commits into from
Mar 20, 2016
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