Skip to content

Commit 5a95acb

Browse files
committed
split ty::util and ty::adjustment
1 parent 2ad5a61 commit 5a95acb

File tree

27 files changed

+1387
-1320
lines changed

27 files changed

+1387
-1320
lines changed

src/librustc/metadata/csearch.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,11 @@ pub fn get_impl_polarity<'tcx>(tcx: &ty::ctxt<'tcx>,
247247
decoder::get_impl_polarity(&*cdata, def.node)
248248
}
249249

250-
pub fn get_custom_coerce_unsized_kind<'tcx>(tcx: &ty::ctxt<'tcx>,
251-
def: DefId)
252-
-> Option<ty::CustomCoerceUnsized> {
250+
pub fn get_custom_coerce_unsized_kind<'tcx>(
251+
tcx: &ty::ctxt<'tcx>,
252+
def: DefId)
253+
-> Option<ty::adjustment::CustomCoerceUnsized>
254+
{
253255
let cstore = &tcx.sess.cstore;
254256
let cdata = cstore.get_crate_data(def.krate);
255257
decoder::get_custom_coerce_unsized_kind(&*cdata, def.node)

src/librustc/metadata/decoder.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -540,9 +540,11 @@ pub fn get_impl_polarity<'tcx>(cdata: Cmd,
540540
}
541541
}
542542

543-
pub fn get_custom_coerce_unsized_kind<'tcx>(cdata: Cmd,
544-
id: ast::NodeId)
545-
-> Option<ty::CustomCoerceUnsized> {
543+
pub fn get_custom_coerce_unsized_kind<'tcx>(
544+
cdata: Cmd,
545+
id: ast::NodeId)
546+
-> Option<ty::adjustment::CustomCoerceUnsized>
547+
{
546548
let item_doc = cdata.lookup_item(id);
547549
reader::maybe_get_doc(item_doc, tag_impl_coerce_unsized_kind).map(|kind_doc| {
548550
let mut decoder = reader::Decoder::new(kind_doc);

src/librustc/middle/astencode.rs

+30-28
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use metadata::tydecode;
2727
use metadata::tydecode::{DefIdSource, NominalType, TypeWithId};
2828
use metadata::tydecode::{RegionParameter, ClosureSource};
2929
use metadata::tyencode;
30+
use middle::ty::adjustment;
3031
use middle::ty::cast;
3132
use middle::check_const::ConstQualif;
3233
use middle::def;
@@ -646,11 +647,11 @@ trait rbml_writer_helpers<'tcx> {
646647
fn emit_builtin_bounds(&mut self, ecx: &e::EncodeContext, bounds: &ty::BuiltinBounds);
647648
fn emit_upvar_capture(&mut self, ecx: &e::EncodeContext, capture: &ty::UpvarCapture);
648649
fn emit_auto_adjustment<'a>(&mut self, ecx: &e::EncodeContext<'a, 'tcx>,
649-
adj: &ty::AutoAdjustment<'tcx>);
650+
adj: &adjustment::AutoAdjustment<'tcx>);
650651
fn emit_autoref<'a>(&mut self, ecx: &e::EncodeContext<'a, 'tcx>,
651-
autoref: &ty::AutoRef<'tcx>);
652+
autoref: &adjustment::AutoRef<'tcx>);
652653
fn emit_auto_deref_ref<'a>(&mut self, ecx: &e::EncodeContext<'a, 'tcx>,
653-
auto_deref_ref: &ty::AutoDerefRef<'tcx>);
654+
auto_deref_ref: &adjustment::AutoDerefRef<'tcx>);
654655
}
655656

656657
impl<'a, 'tcx> rbml_writer_helpers<'tcx> for Encoder<'a> {
@@ -771,22 +772,22 @@ impl<'a, 'tcx> rbml_writer_helpers<'tcx> for Encoder<'a> {
771772
}
772773

773774
fn emit_auto_adjustment<'b>(&mut self, ecx: &e::EncodeContext<'b, 'tcx>,
774-
adj: &ty::AutoAdjustment<'tcx>) {
775+
adj: &adjustment::AutoAdjustment<'tcx>) {
775776
use serialize::Encoder;
776777

777778
self.emit_enum("AutoAdjustment", |this| {
778779
match *adj {
779-
ty::AdjustReifyFnPointer=> {
780+
adjustment::AdjustReifyFnPointer=> {
780781
this.emit_enum_variant("AdjustReifyFnPointer", 1, 0, |_| Ok(()))
781782
}
782783

783-
ty::AdjustUnsafeFnPointer => {
784+
adjustment::AdjustUnsafeFnPointer => {
784785
this.emit_enum_variant("AdjustUnsafeFnPointer", 2, 0, |_| {
785786
Ok(())
786787
})
787788
}
788789

789-
ty::AdjustDerefRef(ref auto_deref_ref) => {
790+
adjustment::AdjustDerefRef(ref auto_deref_ref) => {
790791
this.emit_enum_variant("AdjustDerefRef", 3, 2, |this| {
791792
this.emit_enum_variant_arg(0,
792793
|this| Ok(this.emit_auto_deref_ref(ecx, auto_deref_ref)))
@@ -797,19 +798,19 @@ impl<'a, 'tcx> rbml_writer_helpers<'tcx> for Encoder<'a> {
797798
}
798799

799800
fn emit_autoref<'b>(&mut self, ecx: &e::EncodeContext<'b, 'tcx>,
800-
autoref: &ty::AutoRef<'tcx>) {
801+
autoref: &adjustment::AutoRef<'tcx>) {
801802
use serialize::Encoder;
802803

803804
self.emit_enum("AutoRef", |this| {
804805
match autoref {
805-
&ty::AutoPtr(r, m) => {
806+
&adjustment::AutoPtr(r, m) => {
806807
this.emit_enum_variant("AutoPtr", 0, 2, |this| {
807808
this.emit_enum_variant_arg(0,
808809
|this| Ok(this.emit_region(ecx, *r)));
809810
this.emit_enum_variant_arg(1, |this| m.encode(this))
810811
})
811812
}
812-
&ty::AutoUnsafe(m) => {
813+
&adjustment::AutoUnsafe(m) => {
813814
this.emit_enum_variant("AutoUnsafe", 1, 1, |this| {
814815
this.emit_enum_variant_arg(0, |this| m.encode(this))
815816
})
@@ -819,7 +820,7 @@ impl<'a, 'tcx> rbml_writer_helpers<'tcx> for Encoder<'a> {
819820
}
820821

821822
fn emit_auto_deref_ref<'b>(&mut self, ecx: &e::EncodeContext<'b, 'tcx>,
822-
auto_deref_ref: &ty::AutoDerefRef<'tcx>) {
823+
auto_deref_ref: &adjustment::AutoDerefRef<'tcx>) {
823824
use serialize::Encoder;
824825

825826
self.emit_struct("AutoDerefRef", 2, |this| {
@@ -974,7 +975,7 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext,
974975

975976
if let Some(adjustment) = tcx.tables.borrow().adjustments.get(&id) {
976977
match *adjustment {
977-
ty::AdjustDerefRef(ref adj) => {
978+
adjustment::AdjustDerefRef(ref adj) => {
978979
for autoderef in 0..adj.autoderefs {
979980
let method_call = ty::MethodCall::autoderef(id, autoderef as u32);
980981
if let Some(method) = tcx.tables.borrow().method_map.get(&method_call) {
@@ -1063,17 +1064,17 @@ trait rbml_decoder_decoder_helpers<'tcx> {
10631064
fn read_upvar_capture(&mut self, dcx: &DecodeContext)
10641065
-> ty::UpvarCapture;
10651066
fn read_auto_adjustment<'a, 'b>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>)
1066-
-> ty::AutoAdjustment<'tcx>;
1067+
-> adjustment::AutoAdjustment<'tcx>;
10671068
fn read_cast_kind<'a, 'b>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>)
10681069
-> cast::CastKind;
10691070
fn read_closure_kind<'a, 'b>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>)
10701071
-> ty::ClosureKind;
10711072
fn read_closure_ty<'a, 'b>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>)
10721073
-> ty::ClosureTy<'tcx>;
10731074
fn read_auto_deref_ref<'a, 'b>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>)
1074-
-> ty::AutoDerefRef<'tcx>;
1075+
-> adjustment::AutoDerefRef<'tcx>;
10751076
fn read_autoref<'a, 'b>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>)
1076-
-> ty::AutoRef<'tcx>;
1077+
-> adjustment::AutoRef<'tcx>;
10771078
fn convert_def_id(&mut self,
10781079
dcx: &DecodeContext,
10791080
source: DefIdSource,
@@ -1246,30 +1247,30 @@ impl<'a, 'tcx> rbml_decoder_decoder_helpers<'tcx> for reader::Decoder<'a> {
12461247
}).unwrap()
12471248
}
12481249
fn read_auto_adjustment<'b, 'c>(&mut self, dcx: &DecodeContext<'b, 'c, 'tcx>)
1249-
-> ty::AutoAdjustment<'tcx> {
1250+
-> adjustment::AutoAdjustment<'tcx> {
12501251
self.read_enum("AutoAdjustment", |this| {
12511252
let variants = ["AdjustReifyFnPointer", "AdjustUnsafeFnPointer", "AdjustDerefRef"];
12521253
this.read_enum_variant(&variants, |this, i| {
12531254
Ok(match i {
1254-
1 => ty::AdjustReifyFnPointer,
1255-
2 => ty::AdjustUnsafeFnPointer,
1255+
1 => adjustment::AdjustReifyFnPointer,
1256+
2 => adjustment::AdjustUnsafeFnPointer,
12561257
3 => {
1257-
let auto_deref_ref: ty::AutoDerefRef =
1258+
let auto_deref_ref: adjustment::AutoDerefRef =
12581259
this.read_enum_variant_arg(0,
12591260
|this| Ok(this.read_auto_deref_ref(dcx))).unwrap();
12601261

1261-
ty::AdjustDerefRef(auto_deref_ref)
1262+
adjustment::AdjustDerefRef(auto_deref_ref)
12621263
}
1263-
_ => panic!("bad enum variant for ty::AutoAdjustment")
1264+
_ => panic!("bad enum variant for adjustment::AutoAdjustment")
12641265
})
12651266
})
12661267
}).unwrap()
12671268
}
12681269

12691270
fn read_auto_deref_ref<'b, 'c>(&mut self, dcx: &DecodeContext<'b, 'c, 'tcx>)
1270-
-> ty::AutoDerefRef<'tcx> {
1271+
-> adjustment::AutoDerefRef<'tcx> {
12711272
self.read_struct("AutoDerefRef", 2, |this| {
1272-
Ok(ty::AutoDerefRef {
1273+
Ok(adjustment::AutoDerefRef {
12731274
autoderefs: this.read_struct_field("autoderefs", 0, |this| {
12741275
Decodable::decode(this)
12751276
}).unwrap(),
@@ -1296,7 +1297,7 @@ impl<'a, 'tcx> rbml_decoder_decoder_helpers<'tcx> for reader::Decoder<'a> {
12961297
}
12971298

12981299
fn read_autoref<'b, 'c>(&mut self, dcx: &DecodeContext<'b, 'c, 'tcx>)
1299-
-> ty::AutoRef<'tcx> {
1300+
-> adjustment::AutoRef<'tcx> {
13001301
self.read_enum("AutoRef", |this| {
13011302
let variants = ["AutoPtr", "AutoUnsafe"];
13021303
this.read_enum_variant(&variants, |this, i| {
@@ -1311,15 +1312,15 @@ impl<'a, 'tcx> rbml_decoder_decoder_helpers<'tcx> for reader::Decoder<'a> {
13111312
Decodable::decode(this)
13121313
}).unwrap();
13131314

1314-
ty::AutoPtr(dcx.tcx.mk_region(r), m)
1315+
adjustment::AutoPtr(dcx.tcx.mk_region(r), m)
13151316
}
13161317
1 => {
13171318
let m: hir::Mutability =
13181319
this.read_enum_variant_arg(0, |this| Decodable::decode(this)).unwrap();
13191320

1320-
ty::AutoUnsafe(m)
1321+
adjustment::AutoUnsafe(m)
13211322
}
1322-
_ => panic!("bad enum variant for ty::AutoRef")
1323+
_ => panic!("bad enum variant for adjustment::AutoRef")
13231324
})
13241325
})
13251326
}).unwrap()
@@ -1467,7 +1468,8 @@ fn decode_side_tables(dcx: &DecodeContext,
14671468
dcx.tcx.tables.borrow_mut().method_map.insert(method_call, method);
14681469
}
14691470
c::tag_table_adjustments => {
1470-
let adj: ty::AutoAdjustment = val_dsr.read_auto_adjustment(dcx);
1471+
let adj =
1472+
val_dsr.read_auto_adjustment(dcx);
14711473
dcx.tcx.tables.borrow_mut().adjustments.insert(id, adj);
14721474
}
14731475
c::tag_table_closure_tys => {

src/librustc/middle/check_const.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -798,8 +798,13 @@ fn check_expr<'a, 'tcx>(v: &mut CheckCrateVisitor<'a, 'tcx>,
798798
/// Check the adjustments of an expression
799799
fn check_adjustments<'a, 'tcx>(v: &mut CheckCrateVisitor<'a, 'tcx>, e: &hir::Expr) {
800800
match v.tcx.tables.borrow().adjustments.get(&e.id) {
801-
None | Some(&ty::AdjustReifyFnPointer) | Some(&ty::AdjustUnsafeFnPointer) => {}
802-
Some(&ty::AdjustDerefRef(ty::AutoDerefRef { autoderefs, .. })) => {
801+
None |
802+
Some(&ty::adjustment::AdjustReifyFnPointer) |
803+
Some(&ty::adjustment::AdjustUnsafeFnPointer) => {}
804+
805+
Some(&ty::adjustment::AdjustDerefRef(
806+
ty::adjustment::AutoDerefRef { autoderefs, .. }
807+
)) => {
803808
if (0..autoderefs as u32).any(|autoderef| {
804809
v.tcx.is_overloaded_autoderef(e.id, autoderef)
805810
}) {

src/librustc/middle/expr_use_visitor.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use middle::def_id::{DefId};
2525
use middle::infer;
2626
use middle::mem_categorization as mc;
2727
use middle::ty;
28+
use middle::ty::adjustment;
2829

2930
use rustc_front::hir;
3031

@@ -726,16 +727,16 @@ impl<'d,'t,'a,'tcx> ExprUseVisitor<'d,'t,'a,'tcx> {
726727
let adj = typer.adjustments().get(&expr.id).map(|x| x.clone());
727728
if let Some(adjustment) = adj {
728729
match adjustment {
729-
ty::AdjustReifyFnPointer |
730-
ty::AdjustUnsafeFnPointer => {
730+
adjustment::AdjustReifyFnPointer |
731+
adjustment::AdjustUnsafeFnPointer => {
731732
// Creating a closure/fn-pointer or unsizing consumes
732733
// the input and stores it into the resulting rvalue.
733734
debug!("walk_adjustment(AdjustReifyFnPointer|AdjustUnsafeFnPointer)");
734735
let cmt_unadjusted =
735736
return_if_err!(self.mc.cat_expr_unadjusted(expr));
736737
self.delegate_consume(expr.id, expr.span, cmt_unadjusted);
737738
}
738-
ty::AdjustDerefRef(ref adj) => {
739+
adjustment::AdjustDerefRef(ref adj) => {
739740
self.walk_autoderefref(expr, adj);
740741
}
741742
}
@@ -778,7 +779,7 @@ impl<'d,'t,'a,'tcx> ExprUseVisitor<'d,'t,'a,'tcx> {
778779

779780
fn walk_autoderefref(&mut self,
780781
expr: &hir::Expr,
781-
adj: &ty::AutoDerefRef<'tcx>) {
782+
adj: &adjustment::AutoDerefRef<'tcx>) {
782783
debug!("walk_autoderefref expr={:?} adj={:?}",
783784
expr,
784785
adj);
@@ -809,7 +810,7 @@ impl<'d,'t,'a,'tcx> ExprUseVisitor<'d,'t,'a,'tcx> {
809810
fn walk_autoref(&mut self,
810811
expr: &hir::Expr,
811812
cmt_base: mc::cmt<'tcx>,
812-
opt_autoref: Option<ty::AutoRef<'tcx>>)
813+
opt_autoref: Option<adjustment::AutoRef<'tcx>>)
813814
-> mc::cmt<'tcx>
814815
{
815816
debug!("walk_autoref(expr.id={} cmt_derefd={:?} opt_autoref={:?})",
@@ -828,7 +829,7 @@ impl<'d,'t,'a,'tcx> ExprUseVisitor<'d,'t,'a,'tcx> {
828829
};
829830

830831
match *autoref {
831-
ty::AutoPtr(r, m) => {
832+
adjustment::AutoPtr(r, m) => {
832833
self.delegate.borrow(expr.id,
833834
expr.span,
834835
cmt_base,
@@ -837,7 +838,7 @@ impl<'d,'t,'a,'tcx> ExprUseVisitor<'d,'t,'a,'tcx> {
837838
AutoRef);
838839
}
839840

840-
ty::AutoUnsafe(m) => {
841+
adjustment::AutoUnsafe(m) => {
841842
debug!("walk_autoref: expr.id={} cmt_base={:?}",
842843
expr.id,
843844
cmt_base);

src/librustc/middle/infer/mod.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ use middle::subst::Substs;
3030
use middle::subst::Subst;
3131
use middle::traits::{self, FulfillmentContext, Normalized,
3232
SelectionContext, ObligationCause};
33+
use middle::ty::adjustment;
3334
use middle::ty::{TyVid, IntVid, FloatVid, RegionVid};
3435
use middle::ty::{self, Ty, HasTypeFlags};
3536
use middle::ty::error::{ExpectedFound, TypeError, UnconstrainedNumeric};
@@ -1151,7 +1152,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
11511152
/// Apply `adjustment` to the type of `expr`
11521153
pub fn adjust_expr_ty(&self,
11531154
expr: &hir::Expr,
1154-
adjustment: Option<&ty::AutoAdjustment<'tcx>>)
1155+
adjustment: Option<&adjustment::AutoAdjustment<'tcx>>)
11551156
-> Ty<'tcx>
11561157
{
11571158
let raw_ty = self.expr_ty(expr);
@@ -1485,9 +1486,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
14851486
.map(|method| method.def_id)
14861487
}
14871488

1488-
pub fn adjustments(&self) -> Ref<NodeMap<ty::AutoAdjustment<'tcx>>> {
1489+
pub fn adjustments(&self) -> Ref<NodeMap<adjustment::AutoAdjustment<'tcx>>> {
14891490
fn project_adjustments<'a, 'tcx>(tables: &'a ty::Tables<'tcx>)
1490-
-> &'a NodeMap<ty::AutoAdjustment<'tcx>> {
1491+
-> &'a NodeMap<adjustment::AutoAdjustment<'tcx>> {
14911492
&tables.adjustments
14921493
}
14931494

src/librustc/middle/mem_categorization.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ use front::map as ast_map;
7777
use middle::infer;
7878
use middle::check_const;
7979
use middle::def;
80+
use middle::ty::adjustment;
8081
use middle::ty::{self, Ty};
8182

8283
use rustc_front::hir::{MutImmutable, MutMutable};
@@ -421,16 +422,16 @@ impl<'t, 'a,'tcx> MemCategorizationContext<'t, 'a, 'tcx> {
421422

422423
Some(adjustment) => {
423424
match *adjustment {
424-
ty::AdjustDerefRef(
425-
ty::AutoDerefRef {
425+
adjustment::AdjustDerefRef(
426+
adjustment::AutoDerefRef {
426427
autoref: None, unsize: None, autoderefs, ..}) => {
427428
// Equivalent to *expr or something similar.
428429
self.cat_expr_autoderefd(expr, autoderefs)
429430
}
430431

431-
ty::AdjustReifyFnPointer |
432-
ty::AdjustUnsafeFnPointer |
433-
ty::AdjustDerefRef(_) => {
432+
adjustment::AdjustReifyFnPointer |
433+
adjustment::AdjustUnsafeFnPointer |
434+
adjustment::AdjustDerefRef(_) => {
434435
debug!("cat_expr({:?}): {:?}",
435436
adjustment,
436437
expr);

0 commit comments

Comments
 (0)