Skip to content

Commit

Permalink
Allow passing self as an argument to methods
Browse files Browse the repository at this point in the history
Part of UFCS (rust-lang#16293)
  • Loading branch information
nrc committed Oct 15, 2014
1 parent af99157 commit d3f51dc
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 22 deletions.
16 changes: 0 additions & 16 deletions src/librustc/middle/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/trans/callee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
}
Expand Down Expand Up @@ -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 {:?} \
Expand Down
6 changes: 2 additions & 4 deletions src/librustc/middle/typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(_) |
Expand Down Expand Up @@ -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");
}
}
}

Expand Down

0 comments on commit d3f51dc

Please sign in to comment.