diff options
| -rw-r--r-- | src/librustc/infer/error_reporting/mod.rs | 61 | ||||
| -rw-r--r-- | src/librustc/infer/lexical_region_resolve/graphviz.rs | 8 | ||||
| -rw-r--r-- | src/librustc/infer/lexical_region_resolve/mod.rs | 27 | ||||
| -rw-r--r-- | src/librustc/infer/region_inference/mod.rs | 61 |
4 files changed, 75 insertions, 82 deletions
diff --git a/src/librustc/infer/error_reporting/mod.rs b/src/librustc/infer/error_reporting/mod.rs index c262e966576..072f76eb6aa 100644 --- a/src/librustc/infer/error_reporting/mod.rs +++ b/src/librustc/infer/error_reporting/mod.rs @@ -57,8 +57,7 @@ use infer; use super::{InferCtxt, TypeTrace, SubregionOrigin, RegionVariableOrigin, ValuePairs}; -use super::region_inference::{RegionResolutionError, ConcreteFailure, SubSupConflict, - GenericBoundFailure, GenericKind}; +use super::region_inference::{RegionResolutionError, GenericKind}; use std::fmt; use hir; @@ -293,33 +292,37 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { debug!("report_region_errors: error = {:?}", error); if !self.try_report_named_anon_conflict(&error) && - !self.try_report_anon_anon_conflict(&error) { - - match error.clone() { - // These errors could indicate all manner of different - // problems with many different solutions. Rather - // than generate a "one size fits all" error, what we - // attempt to do is go through a number of specific - // scenarios and try to find the best way to present - // the error. If all of these fails, we fall back to a rather - // general bit of code that displays the error information - ConcreteFailure(origin, sub, sup) => { - self.report_concrete_failure(region_scope_tree, origin, sub, sup).emit(); - } - - GenericBoundFailure(kind, param_ty, sub) => { - self.report_generic_bound_failure(region_scope_tree, kind, param_ty, sub); - } - - SubSupConflict(var_origin, sub_origin, sub_r, sup_origin, sup_r) => { + !self.try_report_anon_anon_conflict(&error) + { + match error.clone() { + // These errors could indicate all manner of different + // problems with many different solutions. Rather + // than generate a "one size fits all" error, what we + // attempt to do is go through a number of specific + // scenarios and try to find the best way to present + // the error. If all of these fails, we fall back to a rather + // general bit of code that displays the error information + RegionResolutionError::ConcreteFailure(origin, sub, sup) => { + self.report_concrete_failure(region_scope_tree, origin, sub, sup).emit(); + } + + RegionResolutionError::GenericBoundFailure(kind, param_ty, sub) => { + self.report_generic_bound_failure(region_scope_tree, kind, param_ty, sub); + } + + RegionResolutionError::SubSupConflict(var_origin, + sub_origin, + sub_r, + sup_origin, + sup_r) => { self.report_sub_sup_conflict(region_scope_tree, var_origin, sub_origin, sub_r, sup_origin, sup_r); - } - } + } + } } } } @@ -351,9 +354,9 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { // the only thing in the list. let is_bound_failure = |e: &RegionResolutionError<'tcx>| match *e { - ConcreteFailure(..) => false, - SubSupConflict(..) => false, - GenericBoundFailure(..) => true, + RegionResolutionError::GenericBoundFailure(..) => true, + RegionResolutionError::ConcreteFailure(..) | + RegionResolutionError::SubSupConflict(..) => false, }; @@ -365,9 +368,9 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { // sort the errors by span, for better error message stability. errors.sort_by_key(|u| match *u { - ConcreteFailure(ref sro, _, _) => sro.span(), - GenericBoundFailure(ref sro, _, _) => sro.span(), - SubSupConflict(ref rvo, _, _, _, _) => rvo.span(), + RegionResolutionError::ConcreteFailure(ref sro, _, _) => sro.span(), + RegionResolutionError::GenericBoundFailure(ref sro, _, _) => sro.span(), + RegionResolutionError::SubSupConflict(ref rvo, _, _, _, _) => rvo.span(), }); errors } diff --git a/src/librustc/infer/lexical_region_resolve/graphviz.rs b/src/librustc/infer/lexical_region_resolve/graphviz.rs index efe364166e4..403ff3c4dfa 100644 --- a/src/librustc/infer/lexical_region_resolve/graphviz.rs +++ b/src/librustc/infer/lexical_region_resolve/graphviz.rs @@ -212,13 +212,13 @@ impl<'a, 'gcx, 'tcx> dot::Labeller<'a> for ConstraintGraph<'a, 'gcx, 'tcx> { fn constraint_to_nodes(c: &Constraint) -> (Node, Node) { match *c { - Constraint::ConstrainVarSubVar(rv_1, rv_2) => + Constraint::VarSubVar(rv_1, rv_2) => (Node::RegionVid(rv_1), Node::RegionVid(rv_2)), - Constraint::ConstrainRegSubVar(r_1, rv_2) => + Constraint::RegSubVar(r_1, rv_2) => (Node::Region(*r_1), Node::RegionVid(rv_2)), - Constraint::ConstrainVarSubReg(rv_1, r_2) => + Constraint::VarSubReg(rv_1, r_2) => (Node::RegionVid(rv_1), Node::Region(*r_2)), - Constraint::ConstrainRegSubReg(r_1, r_2) => + Constraint::RegSubReg(r_1, r_2) => (Node::Region(*r_1), Node::Region(*r_2)), } } diff --git a/src/librustc/infer/lexical_region_resolve/mod.rs b/src/librustc/infer/lexical_region_resolve/mod.rs index 8c5d7a7fc9b..682f5743e4b 100644 --- a/src/librustc/infer/lexical_region_resolve/mod.rs +++ b/src/librustc/infer/lexical_region_resolve/mod.rs @@ -12,7 +12,6 @@ use infer::SubregionOrigin; use infer::region_inference::Constraint; -use infer::region_inference::Constraint::*; use infer::region_inference::RegionVarBindings; use infer::region_inference::RegionResolutionError; use infer::region_inference::VarValue; @@ -230,18 +229,18 @@ impl<'a, 'gcx, 'tcx> RegionVarBindings<'a, 'gcx, 'tcx> { self.iterate_until_fixed_point("Expansion", |constraint, origin| { debug!("expansion: constraint={:?} origin={:?}", constraint, origin); match *constraint { - ConstrainRegSubVar(a_region, b_vid) => { + Constraint::RegSubVar(a_region, b_vid) => { let b_data = &mut var_values[b_vid.index as usize]; self.expand_node(region_rels, a_region, b_vid, b_data) } - ConstrainVarSubVar(a_vid, b_vid) => match var_values[a_vid.index as usize] { + Constraint::VarSubVar(a_vid, b_vid) => match var_values[a_vid.index as usize] { VarValue::ErrorValue => false, VarValue::Value(a_region) => { let b_node = &mut var_values[b_vid.index as usize]; self.expand_node(region_rels, a_region, b_vid, b_node) } }, - ConstrainRegSubReg(..) | ConstrainVarSubReg(..) => { + Constraint::RegSubReg(..) | Constraint::VarSubReg(..) => { // These constraints are checked after expansion // is done, in `collect_errors`. false @@ -311,11 +310,11 @@ impl<'a, 'gcx, 'tcx> RegionVarBindings<'a, 'gcx, 'tcx> { origin ); match *constraint { - ConstrainRegSubVar(..) | ConstrainVarSubVar(..) => { + Constraint::RegSubVar(..) | Constraint::VarSubVar(..) => { // Expansion will ensure that these constraints hold. Ignore. } - ConstrainRegSubReg(sub, sup) => { + Constraint::RegSubReg(sub, sup) => { if region_rels.is_subregion_of(sub, sup) { continue; } @@ -331,7 +330,7 @@ impl<'a, 'gcx, 'tcx> RegionVarBindings<'a, 'gcx, 'tcx> { errors.push(RegionResolutionError::ConcreteFailure((*origin).clone(), sub, sup)); } - ConstrainVarSubReg(a_vid, b_region) => { + Constraint::VarSubReg(a_vid, b_region) => { let a_data = &mut var_data[a_vid.index as usize]; debug!("contraction: {:?} == {:?}, {:?}", a_vid, a_data, b_region); @@ -473,20 +472,20 @@ impl<'a, 'gcx, 'tcx> RegionVarBindings<'a, 'gcx, 'tcx> { for (constraint, _) in constraints.iter() { match *constraint { - ConstrainVarSubVar(a_id, b_id) => { + Constraint::VarSubVar(a_id, b_id) => { graph.add_edge( NodeIndex(a_id.index as usize), NodeIndex(b_id.index as usize), *constraint, ); } - ConstrainRegSubVar(_, b_id) => { + Constraint::RegSubVar(_, b_id) => { graph.add_edge(dummy_source, NodeIndex(b_id.index as usize), *constraint); } - ConstrainVarSubReg(a_id, _) => { + Constraint::VarSubReg(a_id, _) => { graph.add_edge(NodeIndex(a_id.index as usize), dummy_sink, *constraint); } - ConstrainRegSubReg(..) => { + Constraint::RegSubReg(..) => { // this would be an edge from `dummy_source` to // `dummy_sink`; just ignore it. } @@ -624,7 +623,7 @@ impl<'a, 'gcx, 'tcx> RegionVarBindings<'a, 'gcx, 'tcx> { let source_node_index = NodeIndex(source_vid.index as usize); for (_, edge) in graph.adjacent_edges(source_node_index, dir) { match edge.data { - ConstrainVarSubVar(from_vid, to_vid) => { + Constraint::VarSubVar(from_vid, to_vid) => { let opp_vid = if from_vid == source_vid { to_vid } else { @@ -635,14 +634,14 @@ impl<'a, 'gcx, 'tcx> RegionVarBindings<'a, 'gcx, 'tcx> { } } - ConstrainRegSubVar(region, _) | ConstrainVarSubReg(_, region) => { + Constraint::RegSubVar(region, _) | Constraint::VarSubReg(_, region) => { state.result.push(RegionAndOrigin { region, origin: this.constraints.borrow().get(&edge.data).unwrap().clone(), }); } - ConstrainRegSubReg(..) => panic!( + Constraint::RegSubReg(..) => panic!( "cannot reach reg-sub-reg edge in region inference \ post-processing" ), diff --git a/src/librustc/infer/region_inference/mod.rs b/src/librustc/infer/region_inference/mod.rs index e197f4f27ef..ef888ea4b9f 100644 --- a/src/librustc/infer/region_inference/mod.rs +++ b/src/librustc/infer/region_inference/mod.rs @@ -10,11 +10,8 @@ //! See README.md -pub use self::Constraint::*; -pub use self::UndoLogEntry::*; -pub use self::CombineMapType::*; -pub use self::RegionResolutionError::*; -pub use self::VarValue::*; +use self::UndoLogEntry::*; +use self::CombineMapType::*; use super::{RegionVariableOrigin, SubregionOrigin, MiscVariable}; use super::unify_key; @@ -36,20 +33,20 @@ use std::u32; #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, PartialOrd, Ord)] pub enum Constraint<'tcx> { /// One region variable is subregion of another - ConstrainVarSubVar(RegionVid, RegionVid), + VarSubVar(RegionVid, RegionVid), /// Concrete region is subregion of region variable - ConstrainRegSubVar(Region<'tcx>, RegionVid), + RegSubVar(Region<'tcx>, RegionVid), /// Region variable is subregion of concrete region. This does not /// directly affect inference, but instead is checked after /// inference is complete. - ConstrainVarSubReg(RegionVid, Region<'tcx>), + VarSubReg(RegionVid, Region<'tcx>), /// A constraint where neither side is a variable. This does not /// directly affect inference, but instead is checked after /// inference is complete. - ConstrainRegSubReg(Region<'tcx>, Region<'tcx>), + RegSubReg(Region<'tcx>, Region<'tcx>), } /// VerifyGenericBound(T, _, R, RS): The parameter type `T` (or @@ -98,13 +95,13 @@ pub enum VerifyBound<'tcx> { } #[derive(Copy, Clone, PartialEq, Eq, Hash)] -pub struct TwoRegions<'tcx> { +struct TwoRegions<'tcx> { a: Region<'tcx>, b: Region<'tcx>, } #[derive(Copy, Clone, PartialEq)] -pub enum UndoLogEntry<'tcx> { +enum UndoLogEntry<'tcx> { /// Pushed when we start a snapshot. OpenSnapshot, @@ -138,7 +135,7 @@ pub enum UndoLogEntry<'tcx> { } #[derive(Copy, Clone, PartialEq)] -pub enum CombineMapType { +enum CombineMapType { Lub, Glb, } @@ -168,19 +165,13 @@ pub enum RegionResolutionError<'tcx> { Region<'tcx>), } -#[derive(Clone, Debug)] -pub enum ProcessedErrorOrigin<'tcx> { - ConcreteFailure(SubregionOrigin<'tcx>, Region<'tcx>, Region<'tcx>), - VariableFailure(RegionVariableOrigin), -} - #[derive(Copy, Clone, Debug)] pub enum VarValue<'tcx> { Value(Region<'tcx>), ErrorValue, } -pub type CombineMap<'tcx> = FxHashMap<TwoRegions<'tcx>, RegionVid>; +type CombineMap<'tcx> = FxHashMap<TwoRegions<'tcx>, RegionVid>; pub struct RegionVarBindings<'a, 'gcx: 'a+'tcx, 'tcx: 'a> { pub(in infer) tcx: TyCtxt<'a, 'gcx, 'tcx>, @@ -426,7 +417,7 @@ impl<'a, 'gcx, 'tcx> RegionVarBindings<'a, 'gcx, 'tcx> { .rollback_to(snapshot.region_snapshot); } - pub fn rollback_undo_entry(&self, undo_entry: UndoLogEntry<'tcx>) { + fn rollback_undo_entry(&self, undo_entry: UndoLogEntry<'tcx>) { match undo_entry { OpenSnapshot => { panic!("Failure to observe stack discipline"); @@ -578,13 +569,13 @@ impl<'a, 'gcx, 'tcx> RegionVarBindings<'a, 'gcx, 'tcx> { undo_entry: &UndoLogEntry<'tcx>) -> bool { match undo_entry { - &AddConstraint(ConstrainVarSubVar(..)) => + &AddConstraint(Constraint::VarSubVar(..)) => false, - &AddConstraint(ConstrainRegSubVar(a, _)) => + &AddConstraint(Constraint::RegSubVar(a, _)) => skols.contains(&a), - &AddConstraint(ConstrainVarSubReg(_, b)) => + &AddConstraint(Constraint::VarSubReg(_, b)) => skols.contains(&b), - &AddConstraint(ConstrainRegSubReg(a, b)) => + &AddConstraint(Constraint::RegSubReg(a, b)) => skols.contains(&a) || skols.contains(&b), &AddGiven(..) => false, @@ -725,16 +716,16 @@ impl<'a, 'gcx, 'tcx> RegionVarBindings<'a, 'gcx, 'tcx> { // all regions are subregions of static, so we can ignore this } (&ReVar(sub_id), &ReVar(sup_id)) => { - self.add_constraint(ConstrainVarSubVar(sub_id, sup_id), origin); + self.add_constraint(Constraint::VarSubVar(sub_id, sup_id), origin); } (_, &ReVar(sup_id)) => { - self.add_constraint(ConstrainRegSubVar(sub, sup_id), origin); + self.add_constraint(Constraint::RegSubVar(sub, sup_id), origin); } (&ReVar(sub_id), _) => { - self.add_constraint(ConstrainVarSubReg(sub_id, sup), origin); + self.add_constraint(Constraint::VarSubReg(sub_id, sup), origin); } _ => { - self.add_constraint(ConstrainRegSubReg(sub, sup), origin); + self.add_constraint(Constraint::RegSubReg(sub, sup), origin); } } } @@ -817,13 +808,13 @@ impl<'a, 'gcx, 'tcx> RegionVarBindings<'a, 'gcx, 'tcx> { } } - pub fn combine_vars<F>(&self, - t: CombineMapType, - a: Region<'tcx>, - b: Region<'tcx>, - origin: SubregionOrigin<'tcx>, - mut relate: F) - -> Region<'tcx> + fn combine_vars<F>(&self, + t: CombineMapType, + a: Region<'tcx>, + b: Region<'tcx>, + origin: SubregionOrigin<'tcx>, + mut relate: F) + -> Region<'tcx> where F: FnMut(&RegionVarBindings<'a, 'gcx, 'tcx>, Region<'tcx>, Region<'tcx>) { let vars = TwoRegions { a: a, b: b }; |
