Skip to content

Commit 1e112e9

Browse files
committed
Move typeck logically in the module tree out to the root and clamp
down on its exports. Remove some dead code that is revealed.
1 parent 55470ab commit 1e112e9

File tree

19 files changed

+90
-108
lines changed

19 files changed

+90
-108
lines changed

src/librustc/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,12 @@ pub mod middle {
9595
pub mod traits;
9696
pub mod ty;
9797
pub mod ty_fold;
98-
pub mod typeck;
9998
pub mod weak_lang_items;
10099
}
101100

101+
#[path="middle/typeck/mod.rs"]
102+
pub mod typeck;
103+
102104
pub mod metadata;
103105

104106
pub mod session;

src/librustc/middle/ty.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6192,3 +6192,29 @@ impl<'tcx> Repr<'tcx> for vtable_origin<'tcx> {
61926192
}
61936193
}
61946194
}
6195+
6196+
pub fn make_substs_for_receiver_types<'tcx>(tcx: &ty::ctxt<'tcx>,
6197+
trait_ref: &ty::TraitRef<'tcx>,
6198+
method: &ty::Method<'tcx>)
6199+
-> subst::Substs<'tcx>
6200+
{
6201+
/*!
6202+
* Substitutes the values for the receiver's type parameters
6203+
* that are found in method, leaving the method's type parameters
6204+
* intact.
6205+
*/
6206+
6207+
let meth_tps: Vec<Ty> =
6208+
method.generics.types.get_slice(subst::FnSpace)
6209+
.iter()
6210+
.map(|def| ty::mk_param_from_def(tcx, def))
6211+
.collect();
6212+
let meth_regions: Vec<ty::Region> =
6213+
method.generics.regions.get_slice(subst::FnSpace)
6214+
.iter()
6215+
.map(|def| ty::ReEarlyBound(def.def_id.node, def.space,
6216+
def.index, def.name))
6217+
.collect();
6218+
trait_ref.substs.clone().with_method(meth_tps, meth_regions)
6219+
}
6220+

src/librustc/middle/typeck/astconv.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,10 @@ use middle::resolve_lifetime as rl;
5454
use middle::subst::{FnSpace, TypeSpace, AssocSpace, SelfSpace, Subst, Substs};
5555
use middle::subst::{VecPerParamSpace};
5656
use middle::ty::{mod, Ty};
57-
use middle::typeck::lookup_def_tcx;
58-
use middle::typeck::rscope::{UnelidableRscope, RegionScope, SpecificRscope,
59-
ShiftedRscope, BindingRscope};
60-
use middle::typeck::rscope;
61-
use middle::typeck::TypeAndSubsts;
57+
use typeck::lookup_def_tcx;
58+
use typeck::rscope::{mod, UnelidableRscope, RegionScope, SpecificRscope,
59+
ShiftedRscope, BindingRscope};
60+
use typeck::TypeAndSubsts;
6261
use util::common::ErrorReported;
6362
use util::nodemap::DefIdMap;
6463
use util::ppaux::{mod, Repr, UserString};

src/librustc/middle/typeck/check/_match.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ use middle::def;
1212
use middle::pat_util::{PatIdMap, pat_id_map, pat_is_binding, pat_is_const};
1313
use middle::subst::{Subst, Substs};
1414
use middle::ty::{mod, Ty};
15-
use middle::typeck::check::{check_expr, check_expr_has_type, demand, FnCtxt};
16-
use middle::typeck::check::{instantiate_path, structurally_resolved_type, valid_range_bounds};
15+
use typeck::check::{check_expr, check_expr_has_type, demand, FnCtxt};
16+
use typeck::check::{instantiate_path, structurally_resolved_type, valid_range_bounds};
1717
use middle::infer::{mod, resolve};
18-
use middle::typeck::require_same_types;
18+
use typeck::require_same_types;
1919
use util::nodemap::FnvHashMap;
2020

2121
use std::cmp;

src/librustc/middle/typeck/check/closure.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ use super::FnCtxt;
1717
use middle::infer;
1818
use middle::subst;
1919
use middle::ty::{mod, Ty};
20-
use middle::typeck::astconv;
21-
use middle::typeck::rscope::RegionScope;
20+
use typeck::astconv;
21+
use typeck::rscope::RegionScope;
2222
use syntax::abi;
2323
use syntax::ast;
2424
use syntax::ast_util;

src/librustc/middle/typeck/check/demand.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111

1212
use middle::ty::{mod, Ty};
13-
use middle::typeck::check::FnCtxt;
13+
use typeck::check::FnCtxt;
1414
use middle::infer;
1515
use middle::infer::resolve_type;
1616
use middle::infer::resolve::try_resolve_tvar_shallow;
@@ -29,12 +29,6 @@ pub fn suptype<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, sp: Span,
2929
|sp, e, a, s| { fcx.report_mismatched_types(sp, e, a, s) })
3030
}
3131

32-
pub fn subtype<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, sp: Span,
33-
expected: Ty<'tcx>, actual: Ty<'tcx>) {
34-
suptype_with_fn(fcx, sp, true, actual, expected,
35-
|sp, a, e, s| { fcx.report_mismatched_types(sp, e, a, s) })
36-
}
37-
3832
pub fn suptype_with_fn<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
3933
sp: Span,
4034
b_is_expected: bool,

src/librustc/middle/typeck/check/method/confirm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use middle::traits;
1515
use middle::ty::{mod, Ty};
1616
use middle::ty::{MethodCall, MethodCallee, MethodObject, MethodOrigin,
1717
MethodParam, MethodStatic, MethodTraitObject, MethodTypeParam};
18-
use middle::typeck::check::{mod, FnCtxt, NoPreference, PreferMutLvalue};
18+
use typeck::check::{mod, FnCtxt, NoPreference, PreferMutLvalue};
1919
use middle::infer;
2020
use middle::infer::InferCtxt;
2121
use middle::ty_fold::HigherRankedFoldable;

src/librustc/middle/typeck/check/method/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ use middle::subst::{Subst};
1515
use middle::traits;
1616
use middle::ty::*;
1717
use middle::ty;
18-
use middle::typeck::astconv::AstConv;
19-
use middle::typeck::check::{FnCtxt};
20-
use middle::typeck::check::{impl_self_ty};
21-
use middle::typeck::check::vtable;
22-
use middle::typeck::check::vtable::select_new_fcx_obligations;
18+
use typeck::astconv::AstConv;
19+
use typeck::check::{FnCtxt};
20+
use typeck::check::{impl_self_ty};
21+
use typeck::check::vtable;
22+
use typeck::check::vtable::select_new_fcx_obligations;
2323
use middle::infer;
2424
use util::ppaux::{Repr, UserString};
2525

src/librustc/middle/typeck/check/method/probe.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ use middle::traits;
1919
use middle::ty::{mod, Ty};
2020
use middle::ty::{MethodObject};
2121
use middle::ty_fold::HigherRankedFoldable;
22-
use middle::typeck::check;
23-
use middle::typeck::check::{FnCtxt, NoPreference};
22+
use typeck::check;
23+
use typeck::check::{FnCtxt, NoPreference};
2424
use middle::infer;
2525
use middle::infer::InferCtxt;
2626
use syntax::ast;

src/librustc/middle/typeck/check/mod.rs

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,11 @@ use middle::ty::{mod, Ty};
9696
use middle::ty::liberate_late_bound_regions;
9797
use middle::ty::{MethodCall, MethodCallee, MethodMap, ObjectCastMap};
9898
use middle::ty_fold::TypeFolder;
99-
use middle::typeck::astconv::{mod, ast_region_to_region, ast_ty_to_ty, AstConv};
100-
use middle::typeck::check::_match::pat_ctxt;
101-
use middle::typeck::rscope::RegionScope;
102-
use middle::typeck::{CrateCtxt, lookup_def_ccx, no_params, require_same_types};
103-
use middle::typeck::TypeAndSubsts;
99+
use typeck::astconv::{mod, ast_region_to_region, ast_ty_to_ty, AstConv};
100+
use typeck::check::_match::pat_ctxt;
101+
use typeck::rscope::RegionScope;
102+
use typeck::{CrateCtxt, lookup_def_ccx, no_params, require_same_types};
103+
use typeck::TypeAndSubsts;
104104
use middle::lang_items::TypeIdLangItem;
105105
use lint;
106106
use util::common::{block_query, indenter, loop_query};
@@ -1873,13 +1873,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
18731873
}
18741874
}
18751875

1876-
/// Fetch type of `expr` after applying adjustments that have been recorded in the fcx.
1877-
pub fn expr_ty_adjusted(&self, expr: &ast::Expr) -> Ty<'tcx> {
1878-
let adjustments = self.inh.adjustments.borrow();
1879-
let adjustment = adjustments.get(&expr.id);
1880-
self.adjust_expr_ty(expr, adjustment)
1881-
}
1882-
18831876
/// Apply `adjustment` to the type of `expr`
18841877
pub fn adjust_expr_ty(&self,
18851878
expr: &ast::Expr,
@@ -1932,16 +1925,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
19321925
infer::mk_subty(self.infcx(), a_is_expected, origin, sub, sup)
19331926
}
19341927

1935-
pub fn can_mk_subty(&self, sub: Ty<'tcx>, sup: Ty<'tcx>)
1936-
-> Result<(), ty::type_err<'tcx>> {
1937-
infer::can_mk_subty(self.infcx(), sub, sup)
1938-
}
1939-
1940-
pub fn can_mk_eqty(&self, sub: Ty<'tcx>, sup: Ty<'tcx>)
1941-
-> Result<(), ty::type_err<'tcx>> {
1942-
infer::can_mk_eqty(self.infcx(), sub, sup)
1943-
}
1944-
19451928
pub fn mk_assignty(&self,
19461929
expr: &ast::Expr,
19471930
sub: Ty<'tcx>,

src/librustc/middle/typeck/check/regionck.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,10 @@ use middle::region::CodeExtent;
120120
use middle::traits;
121121
use middle::ty::{ReScope};
122122
use middle::ty::{mod, Ty, MethodCall};
123-
use middle::typeck::astconv::AstConv;
124-
use middle::typeck::check::FnCtxt;
125-
use middle::typeck::check::regionmanip;
126-
use middle::typeck::check::vtable;
123+
use typeck::astconv::AstConv;
124+
use typeck::check::FnCtxt;
125+
use typeck::check::regionmanip;
126+
use typeck::check::vtable;
127127
use middle::infer::resolve_and_force_all_but_regions;
128128
use middle::infer::resolve_type;
129129
use middle::infer;

src/librustc/middle/typeck/check/vtable.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use middle::traits::{Obligation, obligation_for_builtin_bound};
1515
use middle::traits::{FulfillmentError, CodeSelectionError, CodeAmbiguity};
1616
use middle::traits::{ObligationCause};
1717
use middle::ty::{mod, Ty};
18-
use middle::typeck::check::{FnCtxt,
18+
use typeck::check::{FnCtxt,
1919
structurally_resolved_type};
2020
use middle::infer;
2121
use std::rc::Rc;

src/librustc/middle/typeck/check/wf.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ use middle::traits;
1515
use middle::ty::{mod, Ty};
1616
use middle::ty::liberate_late_bound_regions;
1717
use middle::ty_fold::{TypeFolder, TypeFoldable};
18-
use middle::typeck::astconv::AstConv;
19-
use middle::typeck::check::{FnCtxt, Inherited, blank_fn_ctxt, vtable, regionck};
20-
use middle::typeck::CrateCtxt;
18+
use typeck::astconv::AstConv;
19+
use typeck::check::{FnCtxt, Inherited, blank_fn_ctxt, vtable, regionck};
20+
use typeck::CrateCtxt;
2121
use util::ppaux::Repr;
2222

2323
use std::collections::HashSet;

src/librustc/middle/typeck/check/writeback.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ use middle::def;
1717
use middle::pat_util;
1818
use middle::ty::{mod, Ty, MethodCall, MethodCallee};
1919
use middle::ty_fold::{TypeFolder,TypeFoldable};
20-
use middle::typeck::astconv::AstConv;
21-
use middle::typeck::check::FnCtxt;
20+
use typeck::astconv::AstConv;
21+
use typeck::check::FnCtxt;
2222
use middle::infer::{force_all, resolve_all, resolve_region};
2323
use middle::infer::resolve_type;
2424
use middle::infer;
25-
use middle::typeck::write_substs_to_tcx;
26-
use middle::typeck::write_ty_to_tcx;
25+
use typeck::write_substs_to_tcx;
26+
use typeck::write_ty_to_tcx;
2727
use util::ppaux::Repr;
2828

2929
use std::cell::Cell;

src/librustc/middle/typeck/coherence/mod.rs

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
use metadata::csearch::{each_impl, get_impl_trait};
2020
use metadata::csearch;
2121
use middle::subst;
22-
use middle::subst::{Substs};
2322
use middle::ty::{ImplContainer, ImplOrTraitItemId, MethodTraitItemId};
2423
use middle::ty::{TypeTraitItemId, lookup_item_type};
2524
use middle::ty::{Ty, ty_bool, ty_char, ty_enum, ty_err};
@@ -31,7 +30,7 @@ use middle::ty::{ty_closure};
3130
use middle::ty::type_is_ty_var;
3231
use middle::subst::Subst;
3332
use middle::ty;
34-
use middle::typeck::CrateCtxt;
33+
use typeck::CrateCtxt;
3534
use middle::infer::combine::Combine;
3635
use middle::infer::InferCtxt;
3736
use middle::infer::{new_infer_ctxt, resolve_ivar, resolve_type};
@@ -477,27 +476,6 @@ impl<'a, 'tcx> CoherenceChecker<'a, 'tcx> {
477476
}
478477
}
479478

480-
/// Substitutes the values for the receiver's type parameters that are found in method, leaving the
481-
/// method's type parameters intact.
482-
pub fn make_substs_for_receiver_types<'tcx>(tcx: &ty::ctxt<'tcx>,
483-
trait_ref: &ty::TraitRef<'tcx>,
484-
method: &ty::Method<'tcx>)
485-
-> subst::Substs<'tcx>
486-
{
487-
let meth_tps: Vec<Ty> =
488-
method.generics.types.get_slice(subst::FnSpace)
489-
.iter()
490-
.map(|def| ty::mk_param_from_def(tcx, def))
491-
.collect();
492-
let meth_regions: Vec<ty::Region> =
493-
method.generics.regions.get_slice(subst::FnSpace)
494-
.iter()
495-
.map(|def| ty::ReEarlyBound(def.def_id.node, def.space,
496-
def.index, def.name))
497-
.collect();
498-
trait_ref.substs.clone().with_method(meth_tps, meth_regions)
499-
}
500-
501479
fn subst_receiver_types_in_method_ty<'tcx>(tcx: &ty::ctxt<'tcx>,
502480
impl_id: ast::DefId,
503481
impl_poly_type: &ty::Polytype<'tcx>,
@@ -507,7 +485,7 @@ fn subst_receiver_types_in_method_ty<'tcx>(tcx: &ty::ctxt<'tcx>,
507485
provided_source: Option<ast::DefId>)
508486
-> ty::Method<'tcx>
509487
{
510-
let combined_substs = make_substs_for_receiver_types(tcx, trait_ref, method);
488+
let combined_substs = ty::make_substs_for_receiver_types(tcx, trait_ref, method);
511489

512490
debug!("subst_receiver_types_in_method_ty: combined_substs={}",
513491
combined_substs.repr(tcx));

src/librustc/middle/typeck/collect.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ use middle::ty::{ImplContainer, ImplOrTraitItemContainer, TraitContainer};
4343
use middle::ty::{Polytype};
4444
use middle::ty::{mod, Ty};
4545
use middle::ty_fold::TypeFolder;
46-
use middle::typeck::astconv::{AstConv, ty_of_arg};
47-
use middle::typeck::astconv::{ast_ty_to_ty, ast_region_to_region};
48-
use middle::typeck::astconv;
46+
use typeck::astconv::{AstConv, ty_of_arg};
47+
use typeck::astconv::{ast_ty_to_ty, ast_region_to_region};
48+
use typeck::astconv;
4949
use middle::infer;
50-
use middle::typeck::rscope::*;
51-
use middle::typeck::{CrateCtxt, lookup_def_tcx, no_params, write_ty_to_tcx};
52-
use middle::typeck;
50+
use typeck::rscope::*;
51+
use typeck::{CrateCtxt, lookup_def_tcx, no_params, write_ty_to_tcx};
52+
use typeck;
5353
use util::nodemap::{FnvHashMap, FnvHashSet};
5454
use util::ppaux;
5555
use util::ppaux::{Repr,UserString};

src/librustc/middle/typeck/mod.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -76,32 +76,32 @@ use syntax::codemap::Span;
7676
use syntax::print::pprust::*;
7777
use syntax::{ast, ast_map, abi};
7878

79-
pub mod check;
80-
pub mod rscope;
81-
pub mod astconv;
82-
pub mod collect;
83-
pub mod coherence;
84-
pub mod variance;
85-
86-
pub struct TypeAndSubsts<'tcx> {
79+
mod check;
80+
mod rscope;
81+
mod astconv;
82+
mod collect;
83+
mod coherence;
84+
mod variance;
85+
86+
struct TypeAndSubsts<'tcx> {
8787
pub substs: subst::Substs<'tcx>,
8888
pub ty: Ty<'tcx>,
8989
}
9090

91-
pub struct CrateCtxt<'a, 'tcx: 'a> {
91+
struct CrateCtxt<'a, 'tcx: 'a> {
9292
// A mapping from method call sites to traits that have that method.
9393
trait_map: resolve::TraitMap,
9494
tcx: &'a ty::ctxt<'tcx>
9595
}
9696

9797
// Functions that write types into the node type table
98-
pub fn write_ty_to_tcx<'tcx>(tcx: &ty::ctxt<'tcx>, node_id: ast::NodeId, ty: Ty<'tcx>) {
98+
fn write_ty_to_tcx<'tcx>(tcx: &ty::ctxt<'tcx>, node_id: ast::NodeId, ty: Ty<'tcx>) {
9999
debug!("write_ty_to_tcx({}, {})", node_id, ppaux::ty_to_string(tcx, ty));
100100
assert!(!ty::type_needs_infer(ty));
101101
tcx.node_types.borrow_mut().insert(node_id, ty);
102102
}
103103

104-
pub fn write_substs_to_tcx<'tcx>(tcx: &ty::ctxt<'tcx>,
104+
fn write_substs_to_tcx<'tcx>(tcx: &ty::ctxt<'tcx>,
105105
node_id: ast::NodeId,
106106
item_substs: ty::ItemSubsts<'tcx>) {
107107
if !item_substs.is_noop() {
@@ -114,7 +114,7 @@ pub fn write_substs_to_tcx<'tcx>(tcx: &ty::ctxt<'tcx>,
114114
tcx.item_substs.borrow_mut().insert(node_id, item_substs);
115115
}
116116
}
117-
pub fn lookup_def_tcx(tcx:&ty::ctxt, sp: Span, id: ast::NodeId) -> def::Def {
117+
fn lookup_def_tcx(tcx:&ty::ctxt, sp: Span, id: ast::NodeId) -> def::Def {
118118
match tcx.def_map.borrow().get(&id) {
119119
Some(x) => x.clone(),
120120
_ => {
@@ -123,20 +123,20 @@ pub fn lookup_def_tcx(tcx:&ty::ctxt, sp: Span, id: ast::NodeId) -> def::Def {
123123
}
124124
}
125125

126-
pub fn lookup_def_ccx(ccx: &CrateCtxt, sp: Span, id: ast::NodeId)
126+
fn lookup_def_ccx(ccx: &CrateCtxt, sp: Span, id: ast::NodeId)
127127
-> def::Def {
128128
lookup_def_tcx(ccx.tcx, sp, id)
129129
}
130130

131-
pub fn no_params<'tcx>(t: Ty<'tcx>) -> ty::Polytype<'tcx> {
131+
fn no_params<'tcx>(t: Ty<'tcx>) -> ty::Polytype<'tcx> {
132132
ty::Polytype {
133133
generics: ty::Generics {types: VecPerParamSpace::empty(),
134134
regions: VecPerParamSpace::empty()},
135135
ty: t
136136
}
137137
}
138138

139-
pub fn require_same_types<'a, 'tcx>(tcx: &ty::ctxt<'tcx>,
139+
fn require_same_types<'a, 'tcx>(tcx: &ty::ctxt<'tcx>,
140140
maybe_infcx: Option<&infer::InferCtxt<'a, 'tcx>>,
141141
t1_is_expected: bool,
142142
span: Span,

0 commit comments

Comments
 (0)