Allow passing self as an argument to methods

Part of UFCS (#16293)
This commit is contained in:
Nick Cameron 2014-10-13 14:50:10 +13:00
parent af99157489
commit d3f51dcab8
3 changed files with 4 additions and 22 deletions

View File

@ -5751,22 +5751,6 @@ impl<'a> Resolver<'a> {
// Write the result into the def map.
debug!("(resolving expr) resolved `{}`",
self.path_idents_to_string(path));
// First-class methods are not supported yet; error
// out here.
match def {
(DefMethod(..), _) => {
self.resolve_error(expr.span,
"first-class methods \
are not supported");
self.session.span_note(expr.span,
"call the method \
using the `.` \
syntax");
}
_ => {}
}
self.record_def(expr.id, def);
}
None => {

View File

@ -165,7 +165,7 @@ fn trans<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, expr: &ast::Expr)
let def_id = inline::maybe_instantiate_inline(bcx.ccx(), did);
Callee { bcx: bcx, data: Intrinsic(def_id.node, substs) }
}
def::DefFn(did, _, _) |
def::DefFn(did, _, _) | def::DefMethod(did, _) |
def::DefStaticMethod(did, def::FromImpl(_), _) => {
fn_callee(bcx, trans_fn_ref(bcx, did, ExprId(ref_expr.id)))
}
@ -205,7 +205,7 @@ fn trans<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, expr: &ast::Expr)
def::DefTy(..) | def::DefPrimTy(..) | def::DefAssociatedTy(..) |
def::DefUse(..) | def::DefTyParamBinder(..) |
def::DefRegion(..) | def::DefLabel(..) | def::DefTyParam(..) |
def::DefSelfTy(..) | def::DefMethod(..) => {
def::DefSelfTy(..) => {
bcx.tcx().sess.span_bug(
ref_expr.span,
format!("cannot translate def {:?} \

View File

@ -5029,7 +5029,8 @@ pub fn polytype_for_def(fcx: &FnCtxt,
}
def::DefFn(id, _, _) | def::DefStaticMethod(id, _, _) |
def::DefStatic(id, _) | def::DefVariant(_, id, _) |
def::DefStruct(id) | def::DefConst(id) => {
def::DefStruct(id) | def::DefConst(id) |
def::DefMethod(id, _) => {
return ty::lookup_item_type(fcx.ccx.tcx, id);
}
def::DefTrait(_) |
@ -5057,9 +5058,6 @@ pub fn polytype_for_def(fcx: &FnCtxt,
def::DefSelfTy(..) => {
fcx.ccx.tcx.sess.span_bug(sp, "expected value, found self ty");
}
def::DefMethod(..) => {
fcx.ccx.tcx.sess.span_bug(sp, "expected value, found method");
}
}
}