Skip to content

Commit 5f564fb

Browse files
Ariel Ben-Yehudaarielb1
Ariel Ben-Yehuda
authored andcommitted
split ty.rs into smaller parts
1 parent caa10c3 commit 5f564fb

File tree

25 files changed

+4355
-4155
lines changed

25 files changed

+4355
-4155
lines changed

src/librustc/middle/infer/combine.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ use super::type_variable::{RelationDir, BiTo, EqTo, SubtypeOf, SupertypeOf};
4343

4444
use middle::ty::{TyVar};
4545
use middle::ty::{IntType, UintType};
46-
use middle::ty::{self, Ty, TypeError};
46+
use middle::ty::{self, Ty};
47+
use middle::ty::error::TypeError;
4748
use middle::ty::fold::{TypeFolder, TypeFoldable};
4849
use middle::ty::relate::{Relate, RelateResult, TypeRelation};
4950

@@ -362,12 +363,12 @@ impl<'cx, 'tcx> ty::fold::TypeFolder<'tcx> for Generalizer<'cx, 'tcx> {
362363

363364
pub trait RelateResultCompare<'tcx, T> {
364365
fn compare<F>(&self, t: T, f: F) -> RelateResult<'tcx, T> where
365-
F: FnOnce() -> ty::TypeError<'tcx>;
366+
F: FnOnce() -> TypeError<'tcx>;
366367
}
367368

368369
impl<'tcx, T:Clone + PartialEq> RelateResultCompare<'tcx, T> for RelateResult<'tcx, T> {
369370
fn compare<F>(&self, t: T, f: F) -> RelateResult<'tcx, T> where
370-
F: FnOnce() -> ty::TypeError<'tcx>,
371+
F: FnOnce() -> TypeError<'tcx>,
371372
{
372373
self.clone().and_then(|s| {
373374
if s == t {
@@ -380,15 +381,15 @@ impl<'tcx, T:Clone + PartialEq> RelateResultCompare<'tcx, T> for RelateResult<'t
380381
}
381382

382383
fn int_unification_error<'tcx>(a_is_expected: bool, v: (ty::IntVarValue, ty::IntVarValue))
383-
-> ty::TypeError<'tcx>
384+
-> TypeError<'tcx>
384385
{
385386
let (a, b) = v;
386387
TypeError::IntMismatch(ty::relate::expected_found_bool(a_is_expected, &a, &b))
387388
}
388389

389390
fn float_unification_error<'tcx>(a_is_expected: bool,
390391
v: (hir::FloatTy, hir::FloatTy))
391-
-> ty::TypeError<'tcx>
392+
-> TypeError<'tcx>
392393
{
393394
let (a, b) = v;
394395
TypeError::FloatMismatch(ty::relate::expected_found_bool(a_is_expected, &a, &b))

src/librustc/middle/infer/error_reporting.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,9 @@ use middle::def_id::DefId;
8282
use middle::infer;
8383
use middle::region;
8484
use middle::subst;
85-
use middle::ty::{self, Ty, TypeError, HasTypeFlags};
85+
use middle::ty::{self, Ty, HasTypeFlags};
8686
use middle::ty::{Region, ReFree};
87+
use middle::ty::error::TypeError;
8788

8889
use std::cell::{Cell, RefCell};
8990
use std::char::from_u32;
@@ -225,19 +226,19 @@ pub trait ErrorReporting<'tcx> {
225226
fn process_errors(&self, errors: &Vec<RegionResolutionError<'tcx>>)
226227
-> Vec<RegionResolutionError<'tcx>>;
227228

228-
fn report_type_error(&self, trace: TypeTrace<'tcx>, terr: &ty::TypeError<'tcx>);
229+
fn report_type_error(&self, trace: TypeTrace<'tcx>, terr: &TypeError<'tcx>);
229230

230-
fn check_and_note_conflicting_crates(&self, terr: &ty::TypeError<'tcx>, sp: Span);
231+
fn check_and_note_conflicting_crates(&self, terr: &TypeError<'tcx>, sp: Span);
231232

232233
fn report_and_explain_type_error(&self,
233234
trace: TypeTrace<'tcx>,
234-
terr: &ty::TypeError<'tcx>);
235+
terr: &TypeError<'tcx>);
235236

236237
fn values_str(&self, values: &ValuePairs<'tcx>) -> Option<String>;
237238

238239
fn expected_found_str<T: fmt::Display + Resolvable<'tcx> + HasTypeFlags>(
239240
&self,
240-
exp_found: &ty::ExpectedFound<T>)
241+
exp_found: &ty::error::ExpectedFound<T>)
241242
-> Option<String>;
242243

243244
fn report_concrete_failure(&self,
@@ -266,7 +267,7 @@ pub trait ErrorReporting<'tcx> {
266267

267268
fn report_processed_errors(&self,
268269
var_origin: &[RegionVariableOrigin],
269-
trace_origin: &[(TypeTrace<'tcx>, ty::TypeError<'tcx>)],
270+
trace_origin: &[(TypeTrace<'tcx>, TypeError<'tcx>)],
270271
same_regions: &[SameRegions]);
271272

272273
fn give_suggestion(&self, same_regions: &[SameRegions]);
@@ -473,7 +474,7 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
473474
}
474475
}
475476

476-
fn report_type_error(&self, trace: TypeTrace<'tcx>, terr: &ty::TypeError<'tcx>) {
477+
fn report_type_error(&self, trace: TypeTrace<'tcx>, terr: &TypeError<'tcx>) {
477478
let expected_found_str = match self.values_str(&trace.values) {
478479
Some(v) => v,
479480
None => {
@@ -497,7 +498,7 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
497498
}
498499

499500
/// Adds a note if the types come from similarly named crates
500-
fn check_and_note_conflicting_crates(&self, terr: &ty::TypeError<'tcx>, sp: Span) {
501+
fn check_and_note_conflicting_crates(&self, terr: &TypeError<'tcx>, sp: Span) {
501502
let report_path_match = |did1: DefId, did2: DefId| {
502503
// Only external crates, if either is from a local
503504
// module we could have false positives
@@ -520,7 +521,7 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
520521
}
521522
};
522523
match *terr {
523-
ty::TypeError::Sorts(ref exp_found) => {
524+
TypeError::Sorts(ref exp_found) => {
524525
// if they are both "path types", there's a chance of ambiguity
525526
// due to different versions of the same crate
526527
match (&exp_found.expected.sty, &exp_found.found.sty) {
@@ -533,7 +534,7 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
533534
_ => ()
534535
}
535536
},
536-
ty::TypeError::Traits(ref exp_found) => {
537+
TypeError::Traits(ref exp_found) => {
537538
self.tcx.sess.note("errrr0");
538539
report_path_match(exp_found.expected, exp_found.found);
539540
},
@@ -543,7 +544,7 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
543544

544545
fn report_and_explain_type_error(&self,
545546
trace: TypeTrace<'tcx>,
546-
terr: &ty::TypeError<'tcx>) {
547+
terr: &TypeError<'tcx>) {
547548
let span = trace.origin.span();
548549
self.report_type_error(trace, terr);
549550
self.tcx.note_and_explain_type_err(terr, span);
@@ -561,7 +562,7 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
561562

562563
fn expected_found_str<T: fmt::Display + Resolvable<'tcx> + HasTypeFlags>(
563564
&self,
564-
exp_found: &ty::ExpectedFound<T>)
565+
exp_found: &ty::error::ExpectedFound<T>)
565566
-> Option<String>
566567
{
567568
let expected = exp_found.expected.resolve(self);
@@ -975,7 +976,7 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
975976

976977
fn report_processed_errors(&self,
977978
var_origins: &[RegionVariableOrigin],
978-
trace_origins: &[(TypeTrace<'tcx>, ty::TypeError<'tcx>)],
979+
trace_origins: &[(TypeTrace<'tcx>, TypeError<'tcx>)],
979980
same_regions: &[SameRegions]) {
980981
for vo in var_origins {
981982
self.report_inference_failure(vo.clone());

src/librustc/middle/infer/higher_ranked/mod.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
use super::{CombinedSnapshot, InferCtxt, HigherRankedType, SkolemizationMap};
1515
use super::combine::CombineFields;
1616

17-
use middle::ty::{self, TypeError, Binder};
17+
use middle::ty::{self, Binder};
18+
use middle::ty::error::TypeError;
1819
use middle::ty::fold::TypeFoldable;
1920
use middle::ty::relate::{Relate, RelateResult, TypeRelation};
2021
use syntax::codemap::Span;
@@ -358,7 +359,7 @@ fn fold_regions_in<'tcx, T, F>(tcx: &ty::ctxt<'tcx>,
358359
where T: TypeFoldable<'tcx>,
359360
F: FnMut(ty::Region, ty::DebruijnIndex) -> ty::Region,
360361
{
361-
ty::fold::fold_regions(tcx, unbound_value, &mut false, |region, current_depth| {
362+
tcx.fold_regions(unbound_value, &mut false, |region, current_depth| {
362363
// we should only be encountering "escaping" late-bound regions here,
363364
// because the ones at the current level should have been replaced
364365
// with fresh variables
@@ -438,7 +439,7 @@ impl<'a,'tcx> InferCtxtExt for InferCtxt<'a,'tcx> {
438439

439440
let mut escaping_region_vars = FnvHashSet();
440441
for ty in &escaping_types {
441-
ty::fold::collect_regions(self.tcx, ty, &mut escaping_region_vars);
442+
self.tcx.collect_regions(ty, &mut escaping_region_vars);
442443
}
443444

444445
region_vars.retain(|&region_vid| {
@@ -468,7 +469,7 @@ pub fn skolemize_late_bound_regions<'a,'tcx,T>(infcx: &InferCtxt<'a,'tcx>,
468469
* details.
469470
*/
470471

471-
let (result, map) = ty::fold::replace_late_bound_regions(infcx.tcx, binder, |br| {
472+
let (result, map) = infcx.tcx.replace_late_bound_regions(binder, |br| {
472473
infcx.region_vars.new_skolemized(br, &snapshot.region_vars_snapshot)
473474
});
474475

@@ -590,7 +591,7 @@ pub fn plug_leaks<'a,'tcx,T>(infcx: &InferCtxt<'a,'tcx>,
590591
// binder is that we encountered in `value`. The caller is
591592
// responsible for ensuring that (a) `value` contains at least one
592593
// binder and (b) that binder is the one we want to use.
593-
let result = ty::fold::fold_regions(infcx.tcx, &value, &mut false, |r, current_depth| {
594+
let result = infcx.tcx.fold_regions(&value, &mut false, |r, current_depth| {
594595
match inv_skol_map.get(&r) {
595596
None => r,
596597
Some(br) => {

src/librustc/middle/infer/mod.rs

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ use middle::subst::Substs;
3030
use middle::subst::Subst;
3131
use middle::traits::{self, FulfillmentContext, Normalized,
3232
SelectionContext, ObligationCause};
33-
use middle::ty::{TyVid, IntVid, FloatVid, RegionVid, UnconstrainedNumeric};
34-
use middle::ty::{self, Ty, TypeError, HasTypeFlags};
33+
use middle::ty::{TyVid, IntVid, FloatVid, RegionVid};
34+
use middle::ty::{self, Ty, HasTypeFlags};
35+
use middle::ty::error::{ExpectedFound, TypeError, UnconstrainedNumeric};
3536
use middle::ty::fold::{TypeFolder, TypeFoldable};
3637
use middle::ty::relate::{Relate, RelateResult, TypeRelation};
3738
use rustc_data_structures::unify::{self, UnificationTable};
@@ -171,9 +172,9 @@ impl fmt::Display for TypeOrigin {
171172
/// See `error_reporting.rs` for more details
172173
#[derive(Clone, Debug)]
173174
pub enum ValuePairs<'tcx> {
174-
Types(ty::ExpectedFound<Ty<'tcx>>),
175-
TraitRefs(ty::ExpectedFound<ty::TraitRef<'tcx>>),
176-
PolyTraitRefs(ty::ExpectedFound<ty::PolyTraitRef<'tcx>>),
175+
Types(ExpectedFound<Ty<'tcx>>),
176+
TraitRefs(ExpectedFound<ty::TraitRef<'tcx>>),
177+
PolyTraitRefs(ExpectedFound<ty::PolyTraitRef<'tcx>>),
177178
}
178179

179180
/// The trace designates the path through inference that we took to
@@ -479,12 +480,12 @@ pub fn mk_sub_poly_trait_refs<'a, 'tcx>(cx: &InferCtxt<'a, 'tcx>,
479480
fn expected_found<T>(a_is_expected: bool,
480481
a: T,
481482
b: T)
482-
-> ty::ExpectedFound<T>
483+
-> ExpectedFound<T>
483484
{
484485
if a_is_expected {
485-
ty::ExpectedFound {expected: a, found: b}
486+
ExpectedFound {expected: a, found: b}
486487
} else {
487-
ty::ExpectedFound {expected: b, found: a}
488+
ExpectedFound {expected: b, found: a}
488489
}
489490
}
490491

@@ -656,7 +657,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
656657
}
657658

658659
pub fn type_is_unconstrained_numeric(&'a self, ty: Ty) -> UnconstrainedNumeric {
659-
use middle::ty::UnconstrainedNumeric::{Neither, UnconstrainedInt, UnconstrainedFloat};
660+
use middle::ty::error::UnconstrainedNumeric::Neither;
661+
use middle::ty::error::UnconstrainedNumeric::{UnconstrainedInt, UnconstrainedFloat};
660662
match ty.sty {
661663
ty::TyInfer(ty::IntVar(vid)) => {
662664
if self.int_unification_table.borrow_mut().has_value(vid) {
@@ -1312,7 +1314,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
13121314
sp: Span,
13131315
mk_msg: M,
13141316
actual_ty: String,
1315-
err: Option<&ty::TypeError<'tcx>>) where
1317+
err: Option<&TypeError<'tcx>>) where
13161318
M: FnOnce(Option<String>, String) -> String,
13171319
{
13181320
self.type_error_message_str_with_expected(sp, mk_msg, None, actual_ty, err)
@@ -1323,7 +1325,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
13231325
mk_msg: M,
13241326
expected_ty: Option<Ty<'tcx>>,
13251327
actual_ty: String,
1326-
err: Option<&ty::TypeError<'tcx>>) where
1328+
err: Option<&TypeError<'tcx>>) where
13271329
M: FnOnce(Option<String>, String) -> String,
13281330
{
13291331
debug!("hi! expected_ty = {:?}, actual_ty = {}", expected_ty, actual_ty);
@@ -1349,7 +1351,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
13491351
sp: Span,
13501352
mk_msg: M,
13511353
actual_ty: Ty<'tcx>,
1352-
err: Option<&ty::TypeError<'tcx>>) where
1354+
err: Option<&TypeError<'tcx>>) where
13531355
M: FnOnce(String) -> String,
13541356
{
13551357
let actual_ty = self.resolve_type_vars_if_possible(&actual_ty);
@@ -1368,10 +1370,10 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
13681370
span: Span,
13691371
expected: Ty<'tcx>,
13701372
actual: Ty<'tcx>,
1371-
err: &ty::TypeError<'tcx>) {
1373+
err: &TypeError<'tcx>) {
13721374
let trace = TypeTrace {
13731375
origin: Misc(span),
1374-
values: Types(ty::ExpectedFound {
1376+
values: Types(ExpectedFound {
13751377
expected: expected,
13761378
found: actual
13771379
})
@@ -1385,14 +1387,14 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
13851387
actual: type_variable::Default<'tcx>) {
13861388
let trace = TypeTrace {
13871389
origin: Misc(span),
1388-
values: Types(ty::ExpectedFound {
1390+
values: Types(ExpectedFound {
13891391
expected: expected.ty,
13901392
found: actual.ty
13911393
})
13921394
};
13931395

13941396
self.report_and_explain_type_error(trace,
1395-
&TypeError::TyParamDefaultMismatch(ty::ExpectedFound {
1397+
&TypeError::TyParamDefaultMismatch(ExpectedFound {
13961398
expected: expected,
13971399
found: actual
13981400
}));
@@ -1406,8 +1408,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
14061408
-> (T, FnvHashMap<ty::BoundRegion,ty::Region>)
14071409
where T : TypeFoldable<'tcx>
14081410
{
1409-
ty::fold::replace_late_bound_regions(
1410-
self.tcx,
1411+
self.tcx.replace_late_bound_regions(
14111412
value,
14121413
|br| self.next_region_var(LateBoundRegion(span, br, lbrct)))
14131414
}
@@ -1555,7 +1556,7 @@ impl<'tcx> TypeTrace<'tcx> {
15551556
pub fn dummy(tcx: &ty::ctxt<'tcx>) -> TypeTrace<'tcx> {
15561557
TypeTrace {
15571558
origin: Misc(codemap::DUMMY_SP),
1558-
values: Types(ty::ExpectedFound {
1559+
values: Types(ExpectedFound {
15591560
expected: tcx.types.err,
15601561
found: tcx.types.err,
15611562
})

src/librustc/middle/infer/region_inference/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ use super::{RegionVariableOrigin, SubregionOrigin, TypeTrace, MiscVariable};
2323
use rustc_data_structures::graph::{self, Direction, NodeIndex};
2424
use middle::free_region::FreeRegionMap;
2525
use middle::region;
26-
use middle::ty::{self, Ty, TypeError};
26+
use middle::ty::{self, Ty};
2727
use middle::ty::{BoundRegion, FreeRegion, Region, RegionVid};
2828
use middle::ty::{ReEmpty, ReStatic, ReFree, ReEarlyBound};
2929
use middle::ty::{ReLateBound, ReScope, ReVar, ReSkolemized, BrFresh};
30+
use middle::ty::error::TypeError;
3031
use middle::ty::relate::RelateResult;
3132
use util::common::indenter;
3233
use util::nodemap::{FnvHashMap, FnvHashSet};
@@ -157,7 +158,7 @@ pub enum RegionResolutionError<'tcx> {
157158
/// should put a lifetime. In those cases we process and put those errors
158159
/// into `ProcessedErrors` before we do any reporting.
159160
ProcessedErrors(Vec<RegionVariableOrigin>,
160-
Vec<(TypeTrace<'tcx>, ty::TypeError<'tcx>)>,
161+
Vec<(TypeTrace<'tcx>, TypeError<'tcx>)>,
161162
Vec<SameRegions>),
162163
}
163164

src/librustc/middle/traits/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ pub enum SelectionError<'tcx> {
168168
Unimplemented,
169169
OutputTypeParameterMismatch(ty::PolyTraitRef<'tcx>,
170170
ty::PolyTraitRef<'tcx>,
171-
ty::TypeError<'tcx>),
171+
ty::error::TypeError<'tcx>),
172172
TraitNotObjectSafe(DefId),
173173
}
174174

src/librustc/middle/traits/project.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pub enum ProjectionTyError<'tcx> {
5151

5252
#[derive(Clone)]
5353
pub struct MismatchedProjectionTypes<'tcx> {
54-
pub err: ty::TypeError<'tcx>
54+
pub err: ty::error::TypeError<'tcx>
5555
}
5656

5757
#[derive(PartialEq, Eq, Debug)]

src/librustc/middle/ty/_match.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// except according to those terms.
1010

1111
use middle::ty::{self, Ty};
12+
use middle::ty::error::TypeError;
1213
use middle::ty::relate::{self, Relate, TypeRelation, RelateResult};
1314

1415
/// A type "A" *matches* "B" if the fresh types in B could be
@@ -73,7 +74,7 @@ impl<'a, 'tcx> TypeRelation<'a, 'tcx> for Match<'a, 'tcx> {
7374

7475
(&ty::TyInfer(_), _) |
7576
(_, &ty::TyInfer(_)) => {
76-
Err(ty::TypeError::Sorts(relate::expected_found(self, &a, &b)))
77+
Err(TypeError::Sorts(relate::expected_found(self, &a, &b)))
7778
}
7879

7980
(&ty::TyError, _) | (_, &ty::TyError) => {

0 commit comments

Comments
 (0)