Skip to content

Commit f9f3ba5

Browse files
committed
rustc: move infer::coercion to rustc_typeck.
1 parent 265a233 commit f9f3ba5

File tree

3 files changed

+43
-60
lines changed

3 files changed

+43
-60
lines changed

src/librustc/middle/infer/mod.rs

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,10 @@ use std::rc::Rc;
3333
use syntax::ast;
3434
use syntax::codemap;
3535
use syntax::codemap::Span;
36-
use util::common::indent;
3736
use util::nodemap::FnvHashMap;
3837
use util::ppaux::{ty_to_string};
3938
use util::ppaux::{Repr, UserString};
4039

41-
use self::coercion::Coerce;
4240
use self::combine::{Combine, Combineable, CombineFields};
4341
use self::region_inference::{RegionVarBindings, RegionSnapshot};
4442
use self::equate::Equate;
@@ -47,7 +45,6 @@ use self::lub::Lub;
4745
use self::unify::{UnificationTable, InferCtxtMethodsForSimplyUnifiableTypes};
4846
use self::error_reporting::ErrorReporting;
4947

50-
pub mod coercion;
5148
pub mod combine;
5249
pub mod doc;
5350
pub mod equate;
@@ -68,7 +65,6 @@ pub type Bound<T> = Option<T>;
6865
pub type cres<'tcx, T> = Result<T,ty::type_err<'tcx>>; // "combine result"
6966
pub type ures<'tcx> = cres<'tcx, ()>; // "unify result"
7067
pub type fres<T> = Result<T, fixup_err>; // "fixup result"
71-
pub type CoerceResult<'tcx> = cres<'tcx, Option<ty::AutoAdjustment<'tcx>>>;
7268

7369
pub struct InferCtxt<'a, 'tcx: 'a> {
7470
pub tcx: &'a ty::ctxt<'tcx>,
@@ -409,24 +405,6 @@ fn expected_found<T>(a_is_expected: bool,
409405
}
410406
}
411407

412-
pub fn mk_coercety<'a, 'tcx>(cx: &InferCtxt<'a, 'tcx>,
413-
a_is_expected: bool,
414-
origin: TypeOrigin,
415-
a: Ty<'tcx>,
416-
b: Ty<'tcx>)
417-
-> CoerceResult<'tcx> {
418-
debug!("mk_coercety({} -> {})", a.repr(cx.tcx), b.repr(cx.tcx));
419-
indent(|| {
420-
cx.commit_if_ok(|| {
421-
let trace = TypeTrace {
422-
origin: origin,
423-
values: Types(expected_found(a_is_expected, a, b))
424-
};
425-
Coerce(cx.combine_fields(a_is_expected, trace)).tys(a, b)
426-
})
427-
})
428-
}
429-
430408
trait then<'tcx> {
431409
fn then<T, F>(&self, f: F) -> Result<T, ty::type_err<'tcx>> where
432410
T: Clone,
@@ -689,10 +667,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
689667
{
690668
debug!("sub_types({} <: {})", a.repr(self.tcx), b.repr(self.tcx));
691669
self.commit_if_ok(|| {
692-
let trace = TypeTrace {
693-
origin: origin,
694-
values: Types(expected_found(a_is_expected, a, b))
695-
};
670+
let trace = TypeTrace::types(origin, a_is_expected, a, b);
696671
self.sub(a_is_expected, trace).tys(a, b).to_ures()
697672
})
698673
}
@@ -705,10 +680,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
705680
-> ures<'tcx>
706681
{
707682
self.commit_if_ok(|| {
708-
let trace = TypeTrace {
709-
origin: origin,
710-
values: Types(expected_found(a_is_expected, a, b))
711-
};
683+
let trace = TypeTrace::types(origin, a_is_expected, a, b);
712684
self.equate(a_is_expected, trace).tys(a, b).to_ures()
713685
})
714686
}
@@ -1118,6 +1090,17 @@ impl<'tcx> TypeTrace<'tcx> {
11181090
self.origin.span()
11191091
}
11201092

1093+
pub fn types(origin: TypeOrigin,
1094+
a_is_expected: bool,
1095+
a: Ty<'tcx>,
1096+
b: Ty<'tcx>)
1097+
-> TypeTrace<'tcx> {
1098+
TypeTrace {
1099+
origin: origin,
1100+
values: Types(expected_found(a_is_expected, a, b))
1101+
}
1102+
}
1103+
11211104
pub fn dummy(tcx: &ty::ctxt<'tcx>) -> TypeTrace<'tcx> {
11221105
TypeTrace {
11231106
origin: Misc(codemap::DUMMY_SP),

src/librustc/middle/infer/coercion.rs renamed to src/librustc_typeck/check/coercion.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,15 @@
6060
//! sort of a minor point so I've opted to leave it for later---after all
6161
//! we may want to adjust precisely when coercions occur.
6262
63-
use super::{CoerceResult, Coercion};
64-
use super::combine::{CombineFields, Combine};
65-
use super::sub::Sub;
63+
use middle::infer::{cres, Coercion, InferCtxt, TypeOrigin, TypeTrace};
64+
use middle::infer::combine::{CombineFields, Combine};
65+
use middle::infer::sub::Sub;
6666

6767
use middle::subst;
6868
use middle::ty::{AutoPtr, AutoDerefRef, AdjustDerefRef, AutoUnsize, AutoUnsafe};
6969
use middle::ty::{mt};
7070
use middle::ty::{self, Ty};
71+
use util::common::indent;
7172
use util::ppaux;
7273
use util::ppaux::Repr;
7374

@@ -472,24 +473,6 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
472473
}
473474
}
474475

475-
pub fn coerce_borrowed_fn(&self,
476-
a: Ty<'tcx>,
477-
b: Ty<'tcx>)
478-
-> CoerceResult<'tcx> {
479-
debug!("coerce_borrowed_fn(a={}, b={})",
480-
a.repr(self.tcx()),
481-
b.repr(self.tcx()));
482-
483-
match a.sty {
484-
ty::ty_bare_fn(Some(a_def_id), f) => {
485-
self.coerce_from_fn_item(a, a_def_id, f, b)
486-
}
487-
_ => {
488-
self.subtype(a, b)
489-
}
490-
}
491-
}
492-
493476
fn coerce_from_fn_item(&self,
494477
a: Ty<'tcx>,
495478
fn_def_id_a: ast::DefId,
@@ -551,6 +534,23 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
551534
}
552535
}
553536

537+
pub type CoerceResult<'tcx> = cres<'tcx, Option<ty::AutoAdjustment<'tcx>>>;
538+
539+
pub fn mk_coercety<'a, 'tcx>(cx: &InferCtxt<'a, 'tcx>,
540+
a_is_expected: bool,
541+
origin: TypeOrigin,
542+
a: Ty<'tcx>,
543+
b: Ty<'tcx>)
544+
-> CoerceResult<'tcx> {
545+
debug!("mk_coercety({} -> {})", a.repr(cx.tcx), b.repr(cx.tcx));
546+
indent(|| {
547+
cx.commit_if_ok(|| {
548+
let trace = TypeTrace::types(origin, a_is_expected, a, b);
549+
Coerce(cx.combine_fields(a_is_expected, trace)).tys(a, b)
550+
})
551+
})
552+
}
553+
554554
fn can_coerce_mutbls(from_mutbl: ast::Mutability,
555555
to_mutbl: ast::Mutability)
556556
-> bool {

src/librustc_typeck/check/mod.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ pub mod vtable;
132132
pub mod writeback;
133133
pub mod regionmanip;
134134
pub mod regionck;
135+
pub mod coercion;
135136
pub mod demand;
136137
pub mod method;
137138
mod upvar;
@@ -1730,18 +1731,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
17301731
sub: Ty<'tcx>,
17311732
sup: Ty<'tcx>)
17321733
-> Result<(), ty::type_err<'tcx>> {
1733-
match infer::mk_coercety(self.infcx(),
1734-
false,
1735-
infer::ExprAssignable(expr.span),
1736-
sub,
1737-
sup) {
1738-
Ok(None) => Ok(()),
1739-
Err(ref e) => Err((*e)),
1740-
Ok(Some(adjustment)) => {
1734+
match try!(coercion::mk_coercety(self.infcx(),
1735+
false,
1736+
infer::ExprAssignable(expr.span),
1737+
sub,
1738+
sup)) {
1739+
None => {}
1740+
Some(adjustment) => {
17411741
self.write_adjustment(expr.id, expr.span, adjustment);
1742-
Ok(())
17431742
}
17441743
}
1744+
Ok(())
17451745
}
17461746

17471747
pub fn mk_eqty(&self,

0 commit comments

Comments
 (0)