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;
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);
- }
- }
+ }
+ }
}
}
}
// 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,
};
// 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
}
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)),
}
}
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;
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
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;
}
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);
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.
}
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 {
}
}
- 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"
),
//! 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;
#[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
}
#[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,
}
#[derive(Copy, Clone, PartialEq)]
-pub enum CombineMapType {
+enum CombineMapType {
Lub,
Glb,
}
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>,
.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");
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,
// 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);
}
}
}
}
}
- 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 };