Skip to content

Commit ff8ee31

Browse files
committed
Revert obsoleted changes rust-lang#14830 made to MethodCall.
1 parent 928e2e2 commit ff8ee31

File tree

8 files changed

+34
-82
lines changed

8 files changed

+34
-82
lines changed

src/librustc/middle/astencode.rs

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -597,18 +597,18 @@ impl tr for ty::UpvarCapture {
597597

598598
trait read_method_callee_helper<'tcx> {
599599
fn read_method_callee<'a, 'b>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>)
600-
-> (ty::ExprAdjustment, MethodCallee<'tcx>);
600+
-> (u32, MethodCallee<'tcx>);
601601
}
602602

603603
fn encode_method_callee<'a, 'tcx>(ecx: &e::EncodeContext<'a, 'tcx>,
604604
rbml_w: &mut Encoder,
605-
adjustment: ty::ExprAdjustment,
605+
autoderef: u32,
606606
method: &MethodCallee<'tcx>) {
607607
use serialize::Encoder;
608608

609609
rbml_w.emit_struct("MethodCallee", 4, |rbml_w| {
610-
rbml_w.emit_struct_field("adjustment", 0, |rbml_w| {
611-
adjustment.encode(rbml_w)
610+
rbml_w.emit_struct_field("autoderef", 0, |rbml_w| {
611+
autoderef.encode(rbml_w)
612612
});
613613
rbml_w.emit_struct_field("origin", 1, |rbml_w| {
614614
Ok(rbml_w.emit_method_origin(ecx, &method.origin))
@@ -624,13 +624,13 @@ fn encode_method_callee<'a, 'tcx>(ecx: &e::EncodeContext<'a, 'tcx>,
624624

625625
impl<'a, 'tcx> read_method_callee_helper<'tcx> for reader::Decoder<'a> {
626626
fn read_method_callee<'b, 'c>(&mut self, dcx: &DecodeContext<'b, 'c, 'tcx>)
627-
-> (ty::ExprAdjustment, MethodCallee<'tcx>) {
627+
-> (u32, MethodCallee<'tcx>) {
628628

629629
self.read_struct("MethodCallee", 4, |this| {
630-
let adjustment = this.read_struct_field("adjustment", 0, |this| {
630+
let autoderef = this.read_struct_field("autoderef", 0, |this| {
631631
Decodable::decode(this)
632632
}).unwrap();
633-
Ok((adjustment, MethodCallee {
633+
Ok((autoderef, MethodCallee {
634634
origin: this.read_struct_field("origin", 1, |this| {
635635
Ok(this.read_method_origin(dcx))
636636
}).unwrap(),
@@ -684,7 +684,7 @@ pub trait vtable_decoder_helpers<'tcx> {
684684
fn read_vtable_res_with_key(&mut self,
685685
tcx: &ty::ctxt<'tcx>,
686686
cdata: &cstore::crate_metadata)
687-
-> (ty::ExprAdjustment, ty::vtable_res<'tcx>);
687+
-> (u32, ty::vtable_res<'tcx>);
688688
fn read_vtable_res(&mut self,
689689
tcx: &ty::ctxt<'tcx>, cdata: &cstore::crate_metadata)
690690
-> ty::vtable_res<'tcx>;
@@ -709,12 +709,12 @@ impl<'tcx, 'a> vtable_decoder_helpers<'tcx> for reader::Decoder<'a> {
709709
fn read_vtable_res_with_key(&mut self,
710710
tcx: &ty::ctxt<'tcx>,
711711
cdata: &cstore::crate_metadata)
712-
-> (ty::ExprAdjustment, ty::vtable_res<'tcx>) {
712+
-> (u32, ty::vtable_res<'tcx>) {
713713
self.read_struct("VtableWithKey", 2, |this| {
714-
let adjustment = this.read_struct_field("adjustment", 0, |this| {
714+
let autoderef = this.read_struct_field("autoderef", 0, |this| {
715715
Decodable::decode(this)
716716
}).unwrap();
717-
Ok((adjustment, this.read_struct_field("vtable_res", 1, |this| {
717+
Ok((autoderef, this.read_struct_field("vtable_res", 1, |this| {
718718
Ok(this.read_vtable_res(tcx, cdata))
719719
}).unwrap()))
720720
}).unwrap()
@@ -1254,7 +1254,7 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext,
12541254
if let Some(method) = tcx.method_map.borrow().get(&method_call) {
12551255
rbml_w.tag(c::tag_table_method_map, |rbml_w| {
12561256
rbml_w.id(id);
1257-
encode_method_callee(ecx, rbml_w, method_call.adjustment, method)
1257+
encode_method_callee(ecx, rbml_w, method_call.autoderef, method)
12581258
})
12591259
}
12601260

@@ -1267,31 +1267,19 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext,
12671267

12681268
if let Some(adjustment) = tcx.adjustments.borrow().get(&id) {
12691269
match *adjustment {
1270-
_ if ty::adjust_is_object(adjustment) => {
1271-
let method_call = MethodCall::autoobject(id);
1272-
if let Some(method) = tcx.method_map.borrow().get(&method_call) {
1273-
rbml_w.tag(c::tag_table_method_map, |rbml_w| {
1274-
rbml_w.id(id);
1275-
encode_method_callee(ecx, rbml_w, method_call.adjustment, method)
1276-
})
1277-
}
1278-
}
12791270
ty::AdjustDerefRef(ref adj) => {
1280-
assert!(!ty::adjust_is_object(adjustment));
12811271
for autoderef in 0..adj.autoderefs {
1282-
let method_call = MethodCall::autoderef(id, autoderef);
1272+
let method_call = MethodCall::autoderef(id, autoderef as u32);
12831273
if let Some(method) = tcx.method_map.borrow().get(&method_call) {
12841274
rbml_w.tag(c::tag_table_method_map, |rbml_w| {
12851275
rbml_w.id(id);
12861276
encode_method_callee(ecx, rbml_w,
1287-
method_call.adjustment, method)
1277+
method_call.autoderef, method)
12881278
})
12891279
}
12901280
}
12911281
}
1292-
_ => {
1293-
assert!(!ty::adjust_is_object(adjustment));
1294-
}
1282+
_ => {}
12951283
}
12961284

12971285
rbml_w.tag(c::tag_table_adjustments, |rbml_w| {
@@ -1918,10 +1906,10 @@ fn decode_side_tables(dcx: &DecodeContext,
19181906
dcx.tcx.ty_param_defs.borrow_mut().insert(id, bounds);
19191907
}
19201908
c::tag_table_method_map => {
1921-
let (adjustment, method) = val_dsr.read_method_callee(dcx);
1909+
let (autoderef, method) = val_dsr.read_method_callee(dcx);
19221910
let method_call = MethodCall {
19231911
expr_id: id,
1924-
adjustment: adjustment
1912+
autoderef: autoderef
19251913
};
19261914
dcx.tcx.method_map.borrow_mut().insert(method_call, method);
19271915
}

src/librustc/middle/expr_use_visitor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,7 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
827827
debug!("walk_autoderefs expr={} autoderefs={}", expr.repr(self.tcx()), autoderefs);
828828

829829
for i in 0..autoderefs {
830-
let deref_id = ty::MethodCall::autoderef(expr.id, i);
830+
let deref_id = ty::MethodCall::autoderef(expr.id, i as u32);
831831
match self.typer.node_method_ty(deref_id) {
832832
None => {}
833833
Some(method_ty) => {

src/librustc/middle/mem_categorization.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -887,15 +887,9 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
887887
deref_cnt: uint,
888888
deref_context: DerefKindContext)
889889
-> McResult<cmt<'tcx>> {
890-
let adjustment = match self.typer.adjustments().borrow().get(&node.id()) {
891-
Some(adj) if ty::adjust_is_object(adj) => ty::AutoObject,
892-
_ if deref_cnt != 0 => ty::AutoDeref(deref_cnt),
893-
_ => ty::NoAdjustment
894-
};
895-
896890
let method_call = ty::MethodCall {
897891
expr_id: node.id(),
898-
adjustment: adjustment
892+
autoderef: deref_cnt as u32
899893
};
900894
let method_ty = self.typer.node_method_ty(method_call);
901895

src/librustc/middle/ty.rs

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ pub use self::ImplOrTraitItem::*;
3333
pub use self::BoundRegion::*;
3434
pub use self::sty::*;
3535
pub use self::IntVarValue::*;
36-
pub use self::ExprAdjustment::*;
3736
pub use self::vtable_origin::*;
3837
pub use self::MethodOrigin::*;
3938
pub use self::CopyImplementationError::*;
@@ -368,17 +367,6 @@ pub fn adjusted_object_region(adj: &AutoAdjustment) -> Option<Region> {
368367
}
369368
}
370369

371-
// Returns true if there is a trait cast at the bottom of the adjustment.
372-
pub fn adjust_is_object(adj: &AutoAdjustment) -> bool {
373-
match adj {
374-
&AdjustDerefRef(AutoDerefRef{autoref: Some(ref autoref), ..}) => {
375-
let (b, _, _) = autoref_object_region(autoref);
376-
b
377-
}
378-
_ => false
379-
}
380-
}
381-
382370
// If possible, returns the type expected from the given adjustment. This is not
383371
// possible if the adjustment depends on the type of the adjusted expression.
384372
pub fn type_of_adjust<'tcx>(cx: &ctxt<'tcx>, adj: &AutoAdjustment<'tcx>) -> Option<Ty<'tcx>> {
@@ -505,35 +493,21 @@ pub struct MethodCallee<'tcx> {
505493
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
506494
pub struct MethodCall {
507495
pub expr_id: ast::NodeId,
508-
pub adjustment: ExprAdjustment
509-
}
510-
511-
#[derive(Clone, PartialEq, Eq, Hash, Debug, RustcEncodable, RustcDecodable, Copy)]
512-
pub enum ExprAdjustment {
513-
NoAdjustment,
514-
AutoDeref(uint),
515-
AutoObject
496+
pub autoderef: u32
516497
}
517498

518499
impl MethodCall {
519500
pub fn expr(id: ast::NodeId) -> MethodCall {
520501
MethodCall {
521502
expr_id: id,
522-
adjustment: NoAdjustment
523-
}
524-
}
525-
526-
pub fn autoobject(id: ast::NodeId) -> MethodCall {
527-
MethodCall {
528-
expr_id: id,
529-
adjustment: AutoObject
503+
autoderef: 0
530504
}
531505
}
532506

533-
pub fn autoderef(expr_id: ast::NodeId, autoderef: uint) -> MethodCall {
507+
pub fn autoderef(expr_id: ast::NodeId, autoderef: u32) -> MethodCall {
534508
MethodCall {
535509
expr_id: expr_id,
536-
adjustment: AutoDeref(1 + autoderef)
510+
autoderef: 1 + autoderef
537511
}
538512
}
539513
}
@@ -4581,7 +4555,7 @@ pub fn adjust_ty<'tcx, F>(cx: &ctxt<'tcx>,
45814555

45824556
if !ty::type_is_error(adjusted_ty) {
45834557
for i in 0..adj.autoderefs {
4584-
let method_call = MethodCall::autoderef(expr_id, i);
4558+
let method_call = MethodCall::autoderef(expr_id, i as u32);
45854559
match method_type(method_call) {
45864560
Some(method_ty) => {
45874561
// overloaded deref operators have all late-bound

src/librustc_trans/trans/expr.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ fn apply_adjustments<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
402402
match datum.ty.sty {
403403
// Don't skip a conversion from Box<T> to &T, etc.
404404
ty::ty_rptr(..) => {
405-
let method_call = MethodCall::autoderef(expr.id, adj.autoderefs-1);
405+
let method_call = MethodCall::autoderef(expr.id, (adj.autoderefs-1) as u32);
406406
let method = bcx.tcx().method_map.borrow().get(&method_call).is_some();
407407
if method {
408408
// Don't skip an overloaded deref.
@@ -2227,7 +2227,7 @@ fn deref_multiple<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
22272227
let mut bcx = bcx;
22282228
let mut datum = datum;
22292229
for i in 0..times {
2230-
let method_call = MethodCall::autoderef(expr.id, i);
2230+
let method_call = MethodCall::autoderef(expr.id, i as u32);
22312231
datum = unpack_datum!(bcx, deref_once(bcx, expr, datum, method_call));
22322232
}
22332233
DatumBlock { bcx: bcx, datum: datum }
@@ -2259,10 +2259,11 @@ fn deref_once<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
22592259
// converts from the `Smaht<T>` pointer that we have into
22602260
// a `&T` pointer. We can then proceed down the normal
22612261
// path (below) to dereference that `&T`.
2262-
let datum = match method_call.adjustment {
2262+
let datum = if method_call.autoderef == 0 {
2263+
datum
2264+
} else {
22632265
// Always perform an AutoPtr when applying an overloaded auto-deref
2264-
ty::AutoDeref(_) => unpack_datum!(bcx, auto_ref(bcx, datum, expr)),
2265-
_ => datum
2266+
unpack_datum!(bcx, auto_ref(bcx, datum, expr))
22662267
};
22672268

22682269
let ref_ty = // invoked methods have their LB regions instantiated

src/librustc_typeck/check/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2018,7 +2018,8 @@ pub fn autoderef<'a, 'tcx, T, F>(fcx: &FnCtxt<'a, 'tcx>,
20182018
let mt = match ty::deref(resolved_t, false) {
20192019
Some(mt) => Some(mt),
20202020
None => {
2021-
let method_call = opt_expr.map(|expr| MethodCall::autoderef(expr.id, autoderefs));
2021+
let method_call =
2022+
opt_expr.map(|expr| MethodCall::autoderef(expr.id, autoderefs as u32));
20222023

20232024
// Super subtle: it might seem as though we should
20242025
// pass `opt_expr` to `try_overloaded_deref`, so that

src/librustc_typeck/check/regionck.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,7 @@ fn constrain_autoderefs<'a, 'tcx>(rcx: &mut Rcx<'a, 'tcx>,
872872

873873
let r_deref_expr = ty::ReScope(CodeExtent::from_node_id(deref_expr.id));
874874
for i in 0..derefs {
875-
let method_call = MethodCall::autoderef(deref_expr.id, i);
875+
let method_call = MethodCall::autoderef(deref_expr.id, i as u32);
876876
debug!("constrain_autoderefs: method_call={:?} (of {:?} total)", method_call, derefs);
877877

878878
derefd_ty = match rcx.fcx.inh.method_map.borrow().get(&method_call) {

src/librustc_typeck/check/writeback.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,6 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
259259
}
260260

261261
Some(adjustment) => {
262-
let adj_object = ty::adjust_is_object(&adjustment);
263262
let resolved_adjustment = match adjustment {
264263
ty::AdjustReifyFnPointer(def_id) => {
265264
ty::AdjustReifyFnPointer(def_id)
@@ -271,12 +270,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
271270

272271
ty::AdjustDerefRef(adj) => {
273272
for autoderef in 0..adj.autoderefs {
274-
let method_call = MethodCall::autoderef(id, autoderef);
275-
self.visit_method_map_entry(reason, method_call);
276-
}
277-
278-
if adj_object {
279-
let method_call = MethodCall::autoobject(id);
273+
let method_call = MethodCall::autoderef(id, autoderef as u32);
280274
self.visit_method_map_entry(reason, method_call);
281275
}
282276

0 commit comments

Comments
 (0)