Skip to content

Commit f0264a0

Browse files
committed
rename ty_match to ty_recur, and move it into the traits module
since it is only used there
1 parent edf2198 commit f0264a0

File tree

4 files changed

+25
-17
lines changed

4 files changed

+25
-17
lines changed

src/librustc/middle/traits/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ mod project;
6767
mod object_safety;
6868
mod select;
6969
mod structural_impls;
70+
mod ty_recur;
7071
mod util;
7172

7273
/// An `Obligation` represents some trait reference (e.g. `int:Eq`) for

src/librustc/middle/traits/select.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ use super::TraitNotObjectSafe;
2929
use super::RFC1214Warning;
3030
use super::Selection;
3131
use super::SelectionResult;
32+
use super::ty_recur;
3233
use super::{VtableBuiltin, VtableImpl, VtableParam, VtableClosure,
3334
VtableFnPointer, VtableObject, VtableDefaultImpl};
3435
use super::{VtableImplData, VtableObjectData, VtableBuiltinData,
@@ -2781,8 +2782,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
27812782
current: &ty::PolyTraitRef<'tcx>)
27822783
-> bool
27832784
{
2784-
let mut matcher = ty::_match::Match::new(self.tcx());
2785-
matcher.relate(previous, current).is_ok()
2785+
ty_recur::is_recurrence(self.tcx(), previous, current)
27862786
}
27872787

27882788
fn push_stack<'o,'s:'o>(&mut self,

src/librustc/middle/ty/_match.rs renamed to src/librustc/middle/traits/ty_recur.rs

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ use middle::ty::{self, Ty};
1212
use middle::ty::error::TypeError;
1313
use middle::ty::relate::{self, Relate, TypeRelation, RelateResult};
1414

15-
/// A type "A" *matches* "B" if the fresh types in B could be
16-
/// substituted with values so as to make it equal to A. Matching is
17-
/// intended to be used only on freshened types, and it basically
18-
/// indicates if the non-freshened versions of A and B could have been
19-
/// unified.
15+
/// A type "B" is a "recurrence" of "A" if the fresh types in B could
16+
/// be substituted with values so as to make it equal to A. Recurrence
17+
/// checking is intended to be used only on freshened types, and it
18+
/// basically indicates if the non-freshened versions of A and B could
19+
/// have been unified. We use it as part of trait match evaluation to
20+
/// detect and sidestep infinite recursion.
2021
///
2122
/// It is only an approximation. If it yields false, unification would
2223
/// definitely fail, but a true result doesn't mean unification would
@@ -25,21 +26,28 @@ use middle::ty::relate::{self, Relate, TypeRelation, RelateResult};
2526
/// more than once. To some extent these approximations could be
2627
/// fixed, given effort.
2728
///
28-
/// Like subtyping, matching is really a binary relation, so the only
29-
/// important thing about the result is Ok/Err. Also, matching never
30-
/// affects any type variables or unification state.
31-
pub struct Match<'a, 'tcx: 'a> {
29+
/// Like subtyping, recurrence is really a binary relation, so the
30+
/// only important thing about the result is Ok/Err. Also, recurrence
31+
/// never affects any type variables or unification state.
32+
pub fn is_recurrence<'a,'tcx,T>(tcx: &'a ty::ctxt<'tcx>, a: &T, b: &T) -> bool
33+
where T: Relate<'a, 'tcx>
34+
{
35+
let mut recur = Recurrence::new(tcx);
36+
T::relate(&mut recur, a, b).is_ok()
37+
}
38+
39+
struct Recurrence<'a, 'tcx: 'a> {
3240
tcx: &'a ty::ctxt<'tcx>
3341
}
3442

35-
impl<'a, 'tcx> Match<'a, 'tcx> {
36-
pub fn new(tcx: &'a ty::ctxt<'tcx>) -> Match<'a, 'tcx> {
37-
Match { tcx: tcx }
43+
impl<'a, 'tcx> Recurrence<'a, 'tcx> {
44+
pub fn new(tcx: &'a ty::ctxt<'tcx>) -> Recurrence<'a, 'tcx> {
45+
Recurrence { tcx: tcx }
3846
}
3947
}
4048

41-
impl<'a, 'tcx> TypeRelation<'a, 'tcx> for Match<'a, 'tcx> {
42-
fn tag(&self) -> &'static str { "Match" }
49+
impl<'a, 'tcx> TypeRelation<'a, 'tcx> for Recurrence<'a, 'tcx> {
50+
fn tag(&self) -> &'static str { "Recurrence" }
4351
fn tcx(&self) -> &'a ty::ctxt<'tcx> { self.tcx }
4452
fn a_is_expected(&self) -> bool { true } // irrelevant
4553

src/librustc/middle/ty/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ pub mod cast;
8181
pub mod error;
8282
pub mod fast_reject;
8383
pub mod fold;
84-
pub mod _match;
8584
pub mod outlives;
8685
pub mod relate;
8786
pub mod walk;

0 commit comments

Comments
 (0)