From 70b9ad1748748d93ccef95b59435a7357b350d11 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Tue, 30 Apr 2013 14:09:14 -0400 Subject: [PATCH] rustc: work around issue with default-method-simple, fix some rebase errors --- src/librustc/middle/ty.rs | 7 +++++++ src/librustc/middle/typeck/check/method.rs | 16 ++++++++++++++++ src/librustc/middle/typeck/check/mod.rs | 3 ++- src/librustc/middle/typeck/check/regionck.rs | 10 ++++------ 4 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 28705ac4932..b17dac82048 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -1553,6 +1553,13 @@ pub fn type_is_ty_var(ty: t) -> bool { pub fn type_is_bool(ty: t) -> bool { get(ty).sty == ty_bool } +pub fn type_is_self(ty: t) -> bool { + match get(ty).sty { + ty_self(*) => true, + _ => false + } +} + pub fn type_is_structural(ty: t) -> bool { match get(ty).sty { ty_struct(*) | ty_tup(_) | ty_enum(*) | ty_closure(_) | ty_trait(*) | diff --git a/src/librustc/middle/typeck/check/method.rs b/src/librustc/middle/typeck/check/method.rs index 0cc2ddd32b4..de6530fb464 100644 --- a/src/librustc/middle/typeck/check/method.rs +++ b/src/librustc/middle/typeck/check/method.rs @@ -658,6 +658,12 @@ pub impl<'self> LookupContext<'self> { let tcx = self.tcx(); return match ty::get(self_ty).sty { + ty::ty_rptr(_, self_mt) if default_method_hack(self_mt) => { + (self_ty, + ty::AutoDerefRef(ty::AutoDerefRef { + autoderefs: autoderefs, + autoref: None})) + } ty::ty_rptr(_, self_mt) => { let region = self.infcx().next_region_var_nb(self.expr.span); (ty::mk_rptr(tcx, region, self_mt), @@ -679,6 +685,16 @@ pub impl<'self> LookupContext<'self> { autoref: None})) } }; + + fn default_method_hack(self_mt: ty::mt) -> bool { + // FIXME(#6129). Default methods can't deal with autoref. + // + // I am a horrible monster and I pray for death. Currently + // the default method code fails when you try to reborrow + // because it is not handling types correctly. In lieu of + // fixing that, I am introducing this horrible hack. - ndm + self_mt.mutbl == m_imm && ty::type_is_self(self_mt.ty) + } } fn search_for_autosliced_method( diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs index 84fc40f6954..fb58df3d55c 100644 --- a/src/librustc/middle/typeck/check/mod.rs +++ b/src/librustc/middle/typeck/check/mod.rs @@ -2966,7 +2966,8 @@ pub fn check_block(fcx0: @mut FnCtxt, blk: &ast::blk) { pub fn check_block_with_expected(fcx: @mut FnCtxt, blk: &ast::blk, expected: Option) { - let prev = replace(&mut fcx.ps, fcx.ps.recurse(blk)); + let purity_state = fcx.ps.recurse(blk); + let prev = replace(&mut fcx.ps, purity_state); do fcx.with_region_lb(blk.node.id) { let mut warned = false; diff --git a/src/librustc/middle/typeck/check/regionck.rs b/src/librustc/middle/typeck/check/regionck.rs index 1c35c911b14..be513cbb0f3 100644 --- a/src/librustc/middle/typeck/check/regionck.rs +++ b/src/librustc/middle/typeck/check/regionck.rs @@ -457,20 +457,18 @@ fn constrain_call(rcx: @mut Rcx, let callee_scope = call_expr.id; let callee_region = ty::re_scope(callee_scope); - for fn_sig.inputs.eachi |i, input| { + for arg_exprs.each |&arg_expr| { // ensure that any regions appearing in the argument type are // valid for at least the lifetime of the function: constrain_regions_in_type_of_node( - rcx, arg_exprs[i].id, callee_region, arg_exprs[i].span); + rcx, arg_expr.id, callee_region, arg_expr.span); // unfortunately, there are two means of taking implicit // references, and we need to propagate constraints as a // result. modes are going away and the "DerefArgs" code // should be ported to use adjustments - ty::set_default_mode(tcx, input.mode, ast::by_copy); - let is_by_ref = ty::resolved_mode(tcx, input.mode) == ast::by_ref; - if implicitly_ref_args || is_by_ref { - guarantor::for_by_ref(rcx, arg_exprs[i], callee_scope); + if implicitly_ref_args { + guarantor::for_by_ref(rcx, arg_expr, callee_scope); } }