Skip to content

Commit 0e764ec

Browse files
committed
extract autoderef type adjustment code into a reusable
helper
1 parent 714f2a8 commit 0e764ec

File tree

1 file changed

+39
-22
lines changed

1 file changed

+39
-22
lines changed

src/librustc/middle/ty.rs

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5191,28 +5191,12 @@ impl<'tcx> TyS<'tcx> {
51915191

51925192
if !adjusted_ty.references_error() {
51935193
for i in 0..adj.autoderefs {
5194-
let method_call = MethodCall::autoderef(expr_id, i as u32);
5195-
match method_type(method_call) {
5196-
Some(method_ty) => {
5197-
// Overloaded deref operators have all late-bound
5198-
// regions fully instantiated and coverge.
5199-
let fn_ret =
5200-
cx.no_late_bound_regions(&method_ty.fn_ret()).unwrap();
5201-
adjusted_ty = fn_ret.unwrap();
5202-
}
5203-
None => {}
5204-
}
5205-
match adjusted_ty.builtin_deref(true, NoPreference) {
5206-
Some(mt) => { adjusted_ty = mt.ty; }
5207-
None => {
5208-
cx.sess.span_bug(
5209-
span,
5210-
&format!("the {}th autoderef failed: {}",
5211-
i,
5212-
adjusted_ty)
5213-
);
5214-
}
5215-
}
5194+
adjusted_ty =
5195+
adjusted_ty.adjust_for_autoderef(cx,
5196+
expr_id,
5197+
span,
5198+
i as u32,
5199+
&mut method_type);
52165200
}
52175201
}
52185202

@@ -5228,6 +5212,39 @@ impl<'tcx> TyS<'tcx> {
52285212
};
52295213
}
52305214

5215+
pub fn adjust_for_autoderef<F>(&'tcx self,
5216+
cx: &ctxt<'tcx>,
5217+
expr_id: ast::NodeId,
5218+
expr_span: Span,
5219+
autoderef: u32, // how many autoderefs so far?
5220+
mut method_type: F)
5221+
-> Ty<'tcx> where
5222+
F: FnMut(MethodCall) -> Option<Ty<'tcx>>,
5223+
{
5224+
let method_call = MethodCall::autoderef(expr_id, autoderef);
5225+
let mut adjusted_ty = self;
5226+
match method_type(method_call) {
5227+
Some(method_ty) => {
5228+
// Method calls always have all late-bound regions
5229+
// fully instantiated.
5230+
let fn_ret = cx.no_late_bound_regions(&method_ty.fn_ret()).unwrap();
5231+
adjusted_ty = fn_ret.unwrap();
5232+
}
5233+
None => {}
5234+
}
5235+
match adjusted_ty.builtin_deref(true, NoPreference) {
5236+
Some(mt) => mt.ty,
5237+
None => {
5238+
cx.sess.span_bug(
5239+
expr_span,
5240+
&format!("the {}th autoderef failed: {}",
5241+
autoderef,
5242+
adjusted_ty)
5243+
);
5244+
}
5245+
}
5246+
}
5247+
52315248
pub fn adjust_for_autoref(&'tcx self, cx: &ctxt<'tcx>,
52325249
autoref: Option<AutoRef<'tcx>>)
52335250
-> Ty<'tcx> {

0 commit comments

Comments
 (0)