Skip to content

Commit 9d63330

Browse files
committed
region_inference: tighten up pub, stop re-exporting enum variants
1 parent ef5de07 commit 9d63330

File tree

4 files changed

+75
-82
lines changed

4 files changed

+75
-82
lines changed

src/librustc/infer/error_reporting/mod.rs

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@
5757
5858
use infer;
5959
use super::{InferCtxt, TypeTrace, SubregionOrigin, RegionVariableOrigin, ValuePairs};
60-
use super::region_inference::{RegionResolutionError, ConcreteFailure, SubSupConflict,
61-
GenericBoundFailure, GenericKind};
60+
use super::region_inference::{RegionResolutionError, GenericKind};
6261

6362
use std::fmt;
6463
use hir;
@@ -293,33 +292,37 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
293292
debug!("report_region_errors: error = {:?}", error);
294293

295294
if !self.try_report_named_anon_conflict(&error) &&
296-
!self.try_report_anon_anon_conflict(&error) {
297-
298-
match error.clone() {
299-
// These errors could indicate all manner of different
300-
// problems with many different solutions. Rather
301-
// than generate a "one size fits all" error, what we
302-
// attempt to do is go through a number of specific
303-
// scenarios and try to find the best way to present
304-
// the error. If all of these fails, we fall back to a rather
305-
// general bit of code that displays the error information
306-
ConcreteFailure(origin, sub, sup) => {
307-
self.report_concrete_failure(region_scope_tree, origin, sub, sup).emit();
308-
}
309-
310-
GenericBoundFailure(kind, param_ty, sub) => {
311-
self.report_generic_bound_failure(region_scope_tree, kind, param_ty, sub);
312-
}
313-
314-
SubSupConflict(var_origin, sub_origin, sub_r, sup_origin, sup_r) => {
295+
!self.try_report_anon_anon_conflict(&error)
296+
{
297+
match error.clone() {
298+
// These errors could indicate all manner of different
299+
// problems with many different solutions. Rather
300+
// than generate a "one size fits all" error, what we
301+
// attempt to do is go through a number of specific
302+
// scenarios and try to find the best way to present
303+
// the error. If all of these fails, we fall back to a rather
304+
// general bit of code that displays the error information
305+
RegionResolutionError::ConcreteFailure(origin, sub, sup) => {
306+
self.report_concrete_failure(region_scope_tree, origin, sub, sup).emit();
307+
}
308+
309+
RegionResolutionError::GenericBoundFailure(kind, param_ty, sub) => {
310+
self.report_generic_bound_failure(region_scope_tree, kind, param_ty, sub);
311+
}
312+
313+
RegionResolutionError::SubSupConflict(var_origin,
314+
sub_origin,
315+
sub_r,
316+
sup_origin,
317+
sup_r) => {
315318
self.report_sub_sup_conflict(region_scope_tree,
316319
var_origin,
317320
sub_origin,
318321
sub_r,
319322
sup_origin,
320323
sup_r);
321-
}
322-
}
324+
}
325+
}
323326
}
324327
}
325328
}
@@ -351,9 +354,9 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
351354
// the only thing in the list.
352355

353356
let is_bound_failure = |e: &RegionResolutionError<'tcx>| match *e {
354-
ConcreteFailure(..) => false,
355-
SubSupConflict(..) => false,
356-
GenericBoundFailure(..) => true,
357+
RegionResolutionError::GenericBoundFailure(..) => true,
358+
RegionResolutionError::ConcreteFailure(..) |
359+
RegionResolutionError::SubSupConflict(..) => false,
357360
};
358361

359362

@@ -365,9 +368,9 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
365368

366369
// sort the errors by span, for better error message stability.
367370
errors.sort_by_key(|u| match *u {
368-
ConcreteFailure(ref sro, _, _) => sro.span(),
369-
GenericBoundFailure(ref sro, _, _) => sro.span(),
370-
SubSupConflict(ref rvo, _, _, _, _) => rvo.span(),
371+
RegionResolutionError::ConcreteFailure(ref sro, _, _) => sro.span(),
372+
RegionResolutionError::GenericBoundFailure(ref sro, _, _) => sro.span(),
373+
RegionResolutionError::SubSupConflict(ref rvo, _, _, _, _) => rvo.span(),
371374
});
372375
errors
373376
}

src/librustc/infer/lexical_region_resolve/graphviz.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,13 +212,13 @@ impl<'a, 'gcx, 'tcx> dot::Labeller<'a> for ConstraintGraph<'a, 'gcx, 'tcx> {
212212

213213
fn constraint_to_nodes(c: &Constraint) -> (Node, Node) {
214214
match *c {
215-
Constraint::ConstrainVarSubVar(rv_1, rv_2) =>
215+
Constraint::VarSubVar(rv_1, rv_2) =>
216216
(Node::RegionVid(rv_1), Node::RegionVid(rv_2)),
217-
Constraint::ConstrainRegSubVar(r_1, rv_2) =>
217+
Constraint::RegSubVar(r_1, rv_2) =>
218218
(Node::Region(*r_1), Node::RegionVid(rv_2)),
219-
Constraint::ConstrainVarSubReg(rv_1, r_2) =>
219+
Constraint::VarSubReg(rv_1, r_2) =>
220220
(Node::RegionVid(rv_1), Node::Region(*r_2)),
221-
Constraint::ConstrainRegSubReg(r_1, r_2) =>
221+
Constraint::RegSubReg(r_1, r_2) =>
222222
(Node::Region(*r_1), Node::Region(*r_2)),
223223
}
224224
}

src/librustc/infer/lexical_region_resolve/mod.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
1313
use infer::SubregionOrigin;
1414
use infer::region_inference::Constraint;
15-
use infer::region_inference::Constraint::*;
1615
use infer::region_inference::RegionVarBindings;
1716
use infer::region_inference::RegionResolutionError;
1817
use infer::region_inference::VarValue;
@@ -230,18 +229,18 @@ impl<'a, 'gcx, 'tcx> RegionVarBindings<'a, 'gcx, 'tcx> {
230229
self.iterate_until_fixed_point("Expansion", |constraint, origin| {
231230
debug!("expansion: constraint={:?} origin={:?}", constraint, origin);
232231
match *constraint {
233-
ConstrainRegSubVar(a_region, b_vid) => {
232+
Constraint::RegSubVar(a_region, b_vid) => {
234233
let b_data = &mut var_values[b_vid.index as usize];
235234
self.expand_node(region_rels, a_region, b_vid, b_data)
236235
}
237-
ConstrainVarSubVar(a_vid, b_vid) => match var_values[a_vid.index as usize] {
236+
Constraint::VarSubVar(a_vid, b_vid) => match var_values[a_vid.index as usize] {
238237
VarValue::ErrorValue => false,
239238
VarValue::Value(a_region) => {
240239
let b_node = &mut var_values[b_vid.index as usize];
241240
self.expand_node(region_rels, a_region, b_vid, b_node)
242241
}
243242
},
244-
ConstrainRegSubReg(..) | ConstrainVarSubReg(..) => {
243+
Constraint::RegSubReg(..) | Constraint::VarSubReg(..) => {
245244
// These constraints are checked after expansion
246245
// is done, in `collect_errors`.
247246
false
@@ -311,11 +310,11 @@ impl<'a, 'gcx, 'tcx> RegionVarBindings<'a, 'gcx, 'tcx> {
311310
origin
312311
);
313312
match *constraint {
314-
ConstrainRegSubVar(..) | ConstrainVarSubVar(..) => {
313+
Constraint::RegSubVar(..) | Constraint::VarSubVar(..) => {
315314
// Expansion will ensure that these constraints hold. Ignore.
316315
}
317316

318-
ConstrainRegSubReg(sub, sup) => {
317+
Constraint::RegSubReg(sub, sup) => {
319318
if region_rels.is_subregion_of(sub, sup) {
320319
continue;
321320
}
@@ -331,7 +330,7 @@ impl<'a, 'gcx, 'tcx> RegionVarBindings<'a, 'gcx, 'tcx> {
331330
errors.push(RegionResolutionError::ConcreteFailure((*origin).clone(), sub, sup));
332331
}
333332

334-
ConstrainVarSubReg(a_vid, b_region) => {
333+
Constraint::VarSubReg(a_vid, b_region) => {
335334
let a_data = &mut var_data[a_vid.index as usize];
336335
debug!("contraction: {:?} == {:?}, {:?}", a_vid, a_data, b_region);
337336

@@ -473,20 +472,20 @@ impl<'a, 'gcx, 'tcx> RegionVarBindings<'a, 'gcx, 'tcx> {
473472

474473
for (constraint, _) in constraints.iter() {
475474
match *constraint {
476-
ConstrainVarSubVar(a_id, b_id) => {
475+
Constraint::VarSubVar(a_id, b_id) => {
477476
graph.add_edge(
478477
NodeIndex(a_id.index as usize),
479478
NodeIndex(b_id.index as usize),
480479
*constraint,
481480
);
482481
}
483-
ConstrainRegSubVar(_, b_id) => {
482+
Constraint::RegSubVar(_, b_id) => {
484483
graph.add_edge(dummy_source, NodeIndex(b_id.index as usize), *constraint);
485484
}
486-
ConstrainVarSubReg(a_id, _) => {
485+
Constraint::VarSubReg(a_id, _) => {
487486
graph.add_edge(NodeIndex(a_id.index as usize), dummy_sink, *constraint);
488487
}
489-
ConstrainRegSubReg(..) => {
488+
Constraint::RegSubReg(..) => {
490489
// this would be an edge from `dummy_source` to
491490
// `dummy_sink`; just ignore it.
492491
}
@@ -624,7 +623,7 @@ impl<'a, 'gcx, 'tcx> RegionVarBindings<'a, 'gcx, 'tcx> {
624623
let source_node_index = NodeIndex(source_vid.index as usize);
625624
for (_, edge) in graph.adjacent_edges(source_node_index, dir) {
626625
match edge.data {
627-
ConstrainVarSubVar(from_vid, to_vid) => {
626+
Constraint::VarSubVar(from_vid, to_vid) => {
628627
let opp_vid = if from_vid == source_vid {
629628
to_vid
630629
} else {
@@ -635,14 +634,14 @@ impl<'a, 'gcx, 'tcx> RegionVarBindings<'a, 'gcx, 'tcx> {
635634
}
636635
}
637636

638-
ConstrainRegSubVar(region, _) | ConstrainVarSubReg(_, region) => {
637+
Constraint::RegSubVar(region, _) | Constraint::VarSubReg(_, region) => {
639638
state.result.push(RegionAndOrigin {
640639
region,
641640
origin: this.constraints.borrow().get(&edge.data).unwrap().clone(),
642641
});
643642
}
644643

645-
ConstrainRegSubReg(..) => panic!(
644+
Constraint::RegSubReg(..) => panic!(
646645
"cannot reach reg-sub-reg edge in region inference \
647646
post-processing"
648647
),

src/librustc/infer/region_inference/mod.rs

Lines changed: 26 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,8 @@
1010

1111
//! See README.md
1212
13-
pub use self::Constraint::*;
14-
pub use self::UndoLogEntry::*;
15-
pub use self::CombineMapType::*;
16-
pub use self::RegionResolutionError::*;
17-
pub use self::VarValue::*;
13+
use self::UndoLogEntry::*;
14+
use self::CombineMapType::*;
1815

1916
use super::{RegionVariableOrigin, SubregionOrigin, MiscVariable};
2017
use super::unify_key;
@@ -36,20 +33,20 @@ use std::u32;
3633
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, PartialOrd, Ord)]
3734
pub enum Constraint<'tcx> {
3835
/// One region variable is subregion of another
39-
ConstrainVarSubVar(RegionVid, RegionVid),
36+
VarSubVar(RegionVid, RegionVid),
4037

4138
/// Concrete region is subregion of region variable
42-
ConstrainRegSubVar(Region<'tcx>, RegionVid),
39+
RegSubVar(Region<'tcx>, RegionVid),
4340

4441
/// Region variable is subregion of concrete region. This does not
4542
/// directly affect inference, but instead is checked after
4643
/// inference is complete.
47-
ConstrainVarSubReg(RegionVid, Region<'tcx>),
44+
VarSubReg(RegionVid, Region<'tcx>),
4845

4946
/// A constraint where neither side is a variable. This does not
5047
/// directly affect inference, but instead is checked after
5148
/// inference is complete.
52-
ConstrainRegSubReg(Region<'tcx>, Region<'tcx>),
49+
RegSubReg(Region<'tcx>, Region<'tcx>),
5350
}
5451

5552
/// VerifyGenericBound(T, _, R, RS): The parameter type `T` (or
@@ -98,13 +95,13 @@ pub enum VerifyBound<'tcx> {
9895
}
9996

10097
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
101-
pub struct TwoRegions<'tcx> {
98+
struct TwoRegions<'tcx> {
10299
a: Region<'tcx>,
103100
b: Region<'tcx>,
104101
}
105102

106103
#[derive(Copy, Clone, PartialEq)]
107-
pub enum UndoLogEntry<'tcx> {
104+
enum UndoLogEntry<'tcx> {
108105
/// Pushed when we start a snapshot.
109106
OpenSnapshot,
110107

@@ -138,7 +135,7 @@ pub enum UndoLogEntry<'tcx> {
138135
}
139136

140137
#[derive(Copy, Clone, PartialEq)]
141-
pub enum CombineMapType {
138+
enum CombineMapType {
142139
Lub,
143140
Glb,
144141
}
@@ -168,19 +165,13 @@ pub enum RegionResolutionError<'tcx> {
168165
Region<'tcx>),
169166
}
170167

171-
#[derive(Clone, Debug)]
172-
pub enum ProcessedErrorOrigin<'tcx> {
173-
ConcreteFailure(SubregionOrigin<'tcx>, Region<'tcx>, Region<'tcx>),
174-
VariableFailure(RegionVariableOrigin),
175-
}
176-
177168
#[derive(Copy, Clone, Debug)]
178169
pub enum VarValue<'tcx> {
179170
Value(Region<'tcx>),
180171
ErrorValue,
181172
}
182173

183-
pub type CombineMap<'tcx> = FxHashMap<TwoRegions<'tcx>, RegionVid>;
174+
type CombineMap<'tcx> = FxHashMap<TwoRegions<'tcx>, RegionVid>;
184175

185176
pub struct RegionVarBindings<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
186177
pub(in infer) tcx: TyCtxt<'a, 'gcx, 'tcx>,
@@ -426,7 +417,7 @@ impl<'a, 'gcx, 'tcx> RegionVarBindings<'a, 'gcx, 'tcx> {
426417
.rollback_to(snapshot.region_snapshot);
427418
}
428419

429-
pub fn rollback_undo_entry(&self, undo_entry: UndoLogEntry<'tcx>) {
420+
fn rollback_undo_entry(&self, undo_entry: UndoLogEntry<'tcx>) {
430421
match undo_entry {
431422
OpenSnapshot => {
432423
panic!("Failure to observe stack discipline");
@@ -578,13 +569,13 @@ impl<'a, 'gcx, 'tcx> RegionVarBindings<'a, 'gcx, 'tcx> {
578569
undo_entry: &UndoLogEntry<'tcx>)
579570
-> bool {
580571
match undo_entry {
581-
&AddConstraint(ConstrainVarSubVar(..)) =>
572+
&AddConstraint(Constraint::VarSubVar(..)) =>
582573
false,
583-
&AddConstraint(ConstrainRegSubVar(a, _)) =>
574+
&AddConstraint(Constraint::RegSubVar(a, _)) =>
584575
skols.contains(&a),
585-
&AddConstraint(ConstrainVarSubReg(_, b)) =>
576+
&AddConstraint(Constraint::VarSubReg(_, b)) =>
586577
skols.contains(&b),
587-
&AddConstraint(ConstrainRegSubReg(a, b)) =>
578+
&AddConstraint(Constraint::RegSubReg(a, b)) =>
588579
skols.contains(&a) || skols.contains(&b),
589580
&AddGiven(..) =>
590581
false,
@@ -725,16 +716,16 @@ impl<'a, 'gcx, 'tcx> RegionVarBindings<'a, 'gcx, 'tcx> {
725716
// all regions are subregions of static, so we can ignore this
726717
}
727718
(&ReVar(sub_id), &ReVar(sup_id)) => {
728-
self.add_constraint(ConstrainVarSubVar(sub_id, sup_id), origin);
719+
self.add_constraint(Constraint::VarSubVar(sub_id, sup_id), origin);
729720
}
730721
(_, &ReVar(sup_id)) => {
731-
self.add_constraint(ConstrainRegSubVar(sub, sup_id), origin);
722+
self.add_constraint(Constraint::RegSubVar(sub, sup_id), origin);
732723
}
733724
(&ReVar(sub_id), _) => {
734-
self.add_constraint(ConstrainVarSubReg(sub_id, sup), origin);
725+
self.add_constraint(Constraint::VarSubReg(sub_id, sup), origin);
735726
}
736727
_ => {
737-
self.add_constraint(ConstrainRegSubReg(sub, sup), origin);
728+
self.add_constraint(Constraint::RegSubReg(sub, sup), origin);
738729
}
739730
}
740731
}
@@ -817,13 +808,13 @@ impl<'a, 'gcx, 'tcx> RegionVarBindings<'a, 'gcx, 'tcx> {
817808
}
818809
}
819810

820-
pub fn combine_vars<F>(&self,
821-
t: CombineMapType,
822-
a: Region<'tcx>,
823-
b: Region<'tcx>,
824-
origin: SubregionOrigin<'tcx>,
825-
mut relate: F)
826-
-> Region<'tcx>
811+
fn combine_vars<F>(&self,
812+
t: CombineMapType,
813+
a: Region<'tcx>,
814+
b: Region<'tcx>,
815+
origin: SubregionOrigin<'tcx>,
816+
mut relate: F)
817+
-> Region<'tcx>
827818
where F: FnMut(&RegionVarBindings<'a, 'gcx, 'tcx>, Region<'tcx>, Region<'tcx>)
828819
{
829820
let vars = TwoRegions { a: a, b: b };

0 commit comments

Comments
 (0)