Skip to content

Commit

Permalink
Remove proc types/expressions from the parser, compiler, and
Browse files Browse the repository at this point in the history
language. Recommend `move||` instead.
  • Loading branch information
nikomatsakis committed Dec 14, 2014
1 parent 9cc8453 commit d258d68
Show file tree
Hide file tree
Showing 33 changed files with 91 additions and 321 deletions.
9 changes: 0 additions & 9 deletions src/libcore/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,6 @@ pub struct Closure {

impl Copy for Closure {}

/// The representation of a Rust procedure (`proc()`)
#[repr(C)]
pub struct Procedure {
pub code: *mut (),
pub env: *mut (),
}

impl Copy for Procedure {}

/// The representation of a Rust trait object.
///
/// This struct does not have a `Repr` implementation
Expand Down
1 change: 0 additions & 1 deletion src/librustc/middle/cfg/construct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,6 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {

ast::ExprMac(..) |
ast::ExprClosure(..) |
ast::ExprProc(..) |
ast::ExprLit(..) |
ast::ExprPath(..) => {
self.straightline(expr, pred, None::<ast::Expr>.iter())
Expand Down
3 changes: 1 addition & 2 deletions src/librustc/middle/check_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ impl<'a, 'v> Visitor<'v> for CheckLoopVisitor<'a> {
self.visit_expr(&**e);
self.with_context(Loop, |v| v.visit_block(&**b));
}
ast::ExprClosure(_, _, _, ref b) |
ast::ExprProc(_, ref b) => {
ast::ExprClosure(_, _, _, ref b) => {
self.with_context(Closure, |v| v.visit_block(&**b));
}
ast::ExprBreak(_) => self.require_loop("break", e.span),
Expand Down
3 changes: 1 addition & 2 deletions src/librustc/middle/expr_use_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -613,8 +613,7 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
self.consume_expr(&**count);
}

ast::ExprClosure(..) |
ast::ExprProc(..) => {
ast::ExprClosure(..) => {
self.walk_captures(expr)
}

Expand Down
53 changes: 0 additions & 53 deletions src/librustc/middle/infer/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -587,19 +587,6 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
sub,
"");
}
infer::ProcCapture(span, id) => {
self.tcx.sess.span_err(
span,
format!("captured variable `{}` must be 'static \
to be captured in a proc",
ty::local_var_name_str(self.tcx, id).get())
.as_slice());
note_and_explain_region(
self.tcx,
"captured variable is only valid for ",
sup,
"");
}
infer::IndexSlice(span) => {
self.tcx.sess.span_err(span,
"index of slice outside its lifetime");
Expand All @@ -625,28 +612,6 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
sup,
"");
}
infer::RelateProcBound(span, var_node_id, ty) => {
self.tcx.sess.span_err(
span,
format!(
"the type `{}` of captured variable `{}` \
outlives the `proc()` it \
is captured in",
self.ty_to_string(ty),
ty::local_var_name_str(self.tcx,
var_node_id)).as_slice());
note_and_explain_region(
self.tcx,
"`proc()` is valid for ",
sub,
"");
note_and_explain_region(
self.tcx,
format!("the type `{}` is only valid for ",
self.ty_to_string(ty)).as_slice(),
sup,
"");
}
infer::RelateParamBound(span, ty) => {
self.tcx.sess.span_err(
span,
Expand Down Expand Up @@ -1587,15 +1552,6 @@ impl<'a, 'tcx> ErrorReportingHelpers<'tcx> for InferCtxt<'a, 'tcx> {
self.tcx,
id).get().to_string()).as_slice());
}
infer::ProcCapture(span, id) => {
self.tcx.sess.span_note(
span,
format!("...so that captured variable `{}` \
is 'static",
ty::local_var_name_str(
self.tcx,
id).get()).as_slice());
}
infer::IndexSlice(span) => {
self.tcx.sess.span_note(
span,
Expand All @@ -1606,15 +1562,6 @@ impl<'a, 'tcx> ErrorReportingHelpers<'tcx> for InferCtxt<'a, 'tcx> {
span,
"...so that it can be closed over into an object");
}
infer::RelateProcBound(span, var_node_id, _ty) => {
self.tcx.sess.span_note(
span,
format!(
"...so that the variable `{}` can be captured \
into a proc",
ty::local_var_name_str(self.tcx,
var_node_id)).as_slice());
}
infer::CallRcvr(span) => {
self.tcx.sess.span_note(
span,
Expand Down
18 changes: 0 additions & 18 deletions src/librustc/middle/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,20 +175,13 @@ pub enum SubregionOrigin<'tcx> {
// Closure bound must not outlive captured free variables
FreeVariable(Span, ast::NodeId),

// Proc upvars must be 'static
ProcCapture(Span, ast::NodeId),

// Index into slice must be within its lifetime
IndexSlice(Span),

// When casting `&'a T` to an `&'b Trait` object,
// relating `'a` to `'b`
RelateObjectBound(Span),

// When closing over a variable in a closure/proc, ensure that the
// type of the variable outlives the lifetime bound.
RelateProcBound(Span, ast::NodeId, Ty<'tcx>),

// Some type parameter was instantiated with the given type,
// and that type must outlive some region.
RelateParamBound(Span, Ty<'tcx>),
Expand Down Expand Up @@ -1089,10 +1082,8 @@ impl<'tcx> SubregionOrigin<'tcx> {
InvokeClosure(a) => a,
DerefPointer(a) => a,
FreeVariable(a, _) => a,
ProcCapture(a, _) => a,
IndexSlice(a) => a,
RelateObjectBound(a) => a,
RelateProcBound(a, _, _) => a,
RelateParamBound(a, _) => a,
RelateRegionParamBound(a) => a,
RelateDefaultParamBound(a, _) => a,
Expand Down Expand Up @@ -1128,21 +1119,12 @@ impl<'tcx> Repr<'tcx> for SubregionOrigin<'tcx> {
FreeVariable(a, b) => {
format!("FreeVariable({}, {})", a.repr(tcx), b)
}
ProcCapture(a, b) => {
format!("ProcCapture({}, {})", a.repr(tcx), b)
}
IndexSlice(a) => {
format!("IndexSlice({})", a.repr(tcx))
}
RelateObjectBound(a) => {
format!("RelateObjectBound({})", a.repr(tcx))
}
RelateProcBound(a, b, c) => {
format!("RelateProcBound({},{},{})",
a.repr(tcx),
b,
c.repr(tcx))
}
RelateParamBound(a, b) => {
format!("RelateParamBound({},{})",
a.repr(tcx),
Expand Down
10 changes: 4 additions & 6 deletions src/librustc/middle/liveness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ fn visit_expr(ir: &mut IrMaps, expr: &Expr) {
}
visit::walk_expr(ir, expr);
}
ast::ExprClosure(..) | ast::ExprProc(..) => {
ast::ExprClosure(..) => {
// Interesting control flow (for loops can contain labeled
// breaks or continues)
ir.add_live_node_for_node(expr.id, ExprNode(expr.span));
Expand Down Expand Up @@ -981,9 +981,8 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
self.propagate_through_expr(&**e, succ)
}

ast::ExprClosure(_, _, _, ref blk) |
ast::ExprProc(_, ref blk) => {
debug!("{} is an ExprClosure or ExprProc",
ast::ExprClosure(_, _, _, ref blk) => {
debug!("{} is an ExprClosure",
expr_to_string(expr));

/*
Expand Down Expand Up @@ -1502,8 +1501,7 @@ fn check_expr(this: &mut Liveness, expr: &Expr) {
ast::ExprBreak(..) | ast::ExprAgain(..) | ast::ExprLit(_) |
ast::ExprBlock(..) | ast::ExprMac(..) | ast::ExprAddrOf(..) |
ast::ExprStruct(..) | ast::ExprRepeat(..) | ast::ExprParen(..) |
ast::ExprClosure(..) | ast::ExprProc(..) |
ast::ExprPath(..) | ast::ExprBox(..) | ast::ExprSlice(..) => {
ast::ExprClosure(..) | ast::ExprPath(..) | ast::ExprBox(..) | ast::ExprSlice(..) => {
visit::walk_expr(this, expr);
}
ast::ExprIfLet(..) => {
Expand Down
4 changes: 1 addition & 3 deletions src/librustc/middle/mem_categorization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,8 +555,7 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {

ast::ExprAddrOf(..) | ast::ExprCall(..) |
ast::ExprAssign(..) | ast::ExprAssignOp(..) |
ast::ExprClosure(..) | ast::ExprProc(..) |
ast::ExprRet(..) |
ast::ExprClosure(..) | ast::ExprRet(..) |
ast::ExprUnary(..) | ast::ExprSlice(..) |
ast::ExprMethodCall(..) | ast::ExprCast(..) |
ast::ExprVec(..) | ast::ExprTup(..) | ast::ExprIf(..) |
Expand Down Expand Up @@ -728,7 +727,6 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
};

match fn_expr.node {
ast::ExprProc(_, ref body) |
ast::ExprClosure(_, _, _, ref body) => body.id,
_ => unreachable!()
}
Expand Down
13 changes: 3 additions & 10 deletions src/librustc/middle/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ use util::nodemap::{NodeMap, NodeSet, DefIdSet, FnvHashMap};
use syntax::ast::{Arm, BindByRef, BindByValue, BindingMode, Block, Crate, CrateNum};
use syntax::ast::{DeclItem, DefId, Expr, ExprAgain, ExprBreak, ExprField};
use syntax::ast::{ExprClosure, ExprForLoop, ExprLoop, ExprWhile, ExprMethodCall};
use syntax::ast::{ExprPath, ExprProc, ExprStruct, FnDecl};
use syntax::ast::{ExprPath, ExprStruct, FnDecl};
use syntax::ast::{ForeignItem, ForeignItemFn, ForeignItemStatic, Generics};
use syntax::ast::{Ident, ImplItem, Item, ItemEnum, ItemFn, ItemForeignMod};
use syntax::ast::{ItemImpl, ItemMac, ItemMod, ItemStatic, ItemStruct};
Expand All @@ -64,7 +64,7 @@ use syntax::ast::{RegionTyParamBound, StmtDecl, StructField};
use syntax::ast::{StructVariantKind, TraitRef, TraitTyParamBound};
use syntax::ast::{TupleVariantKind, Ty, TyBool, TyChar, TyClosure, TyF32};
use syntax::ast::{TyF64, TyFloat, TyI, TyI8, TyI16, TyI32, TyI64, TyInt, TyObjectSum};
use syntax::ast::{TyParam, TyParamBound, TyPath, TyPtr, TyPolyTraitRef, TyProc, TyQPath};
use syntax::ast::{TyParam, TyParamBound, TyPath, TyPtr, TyPolyTraitRef, TyQPath};
use syntax::ast::{TyRptr, TyStr, TyU, TyU8, TyU16, TyU32, TyU64, TyUint};
use syntax::ast::{TypeImplItem, UnnamedField};
use syntax::ast::{Variant, ViewItem, ViewItemExternCrate};
Expand Down Expand Up @@ -5027,7 +5027,7 @@ impl<'a> Resolver<'a> {
self.resolve_trait_reference(ty.id, &*qpath.trait_ref, TraitQPath);
}

TyClosure(ref c) | TyProc(ref c) => {
TyClosure(ref c) => {
self.resolve_type_parameter_bounds(
ty.id,
&c.bounds,
Expand Down Expand Up @@ -5902,13 +5902,6 @@ impl<'a> Resolver<'a> {
&**block);
}

ExprProc(ref fn_decl, ref block) => {
self.capture_mode_map.insert(expr.id, ast::CaptureByValue);
self.resolve_function(ClosureRibKind(expr.id, block.id),
Some(&**fn_decl), NoTypeParameters,
&**block);
}

ExprStruct(ref path, _, _) => {
// Resolve the path to the structure it goes to. We don't
// check to ensure that the path is actually a structure; that
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/resolve_lifetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ impl<'a, 'v> Visitor<'v> for LifetimeContext<'a> {

fn visit_ty(&mut self, ty: &ast::Ty) {
match ty.node {
ast::TyClosure(ref c) | ast::TyProc(ref c) => {
ast::TyClosure(ref c) => {
// Careful, the bounds on a closure/proc are *not* within its binder.
visit::walk_ty_param_bounds_helper(self, &c.bounds);
visit::walk_lifetime_decls_helper(self, &c.lifetimes);
Expand Down
25 changes: 21 additions & 4 deletions src/librustc/middle/traits/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -746,8 +746,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
_ => { return Ok(()); }
};

debug!("assemble_unboxed_candidates: self_ty={} obligation={}",
debug!("assemble_unboxed_candidates: self_ty={} kind={} obligation={}",
self_ty.repr(self.tcx()),
kind,
obligation.repr(self.tcx()));

let closure_kind = match self.typer.unboxed_closures().borrow().get(&closure_def_id) {
Expand All @@ -760,6 +761,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
}
};

debug!("closure_kind = {}", closure_kind);

if closure_kind == kind {
candidates.vec.push(UnboxedClosureCandidate(closure_def_id, substs.clone()));
}
Expand Down Expand Up @@ -842,14 +845,24 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
candidate: &Candidate<'tcx>)
-> EvaluationResult<'tcx>
{
debug!("winnow_candidate: candidate={}", candidate.repr(self.tcx()));
self.infcx.probe(|| {
/*!
* Further evaluate `candidate` to decide whether all type parameters match
* and whether nested obligations are met. Returns true if `candidate` remains
* viable after this further scrutiny.
*/

debug!("winnow_candidate: depth={} candidate={}",
stack.obligation.recursion_depth, candidate.repr(self.tcx()));
let result = self.infcx.probe(|| {
let candidate = (*candidate).clone();
match self.confirm_candidate(stack.obligation, candidate) {
Ok(selection) => self.winnow_selection(Some(stack), selection),
Err(error) => EvaluatedToErr(error),
}
})
});
debug!("winnow_candidate depth={} result={}",
stack.obligation.recursion_depth, result);
result
}

fn winnow_selection<'o>(&mut self,
Expand Down Expand Up @@ -1562,6 +1575,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
substs: substs,
});

debug!("confirm_unboxed_closure_candidate(closure_def_id={}, trait_ref={})",
closure_def_id.repr(self.tcx()),
trait_ref.repr(self.tcx()));

self.confirm(obligation.cause,
obligation.trait_ref.clone(),
trait_ref)
Expand Down
1 change: 0 additions & 1 deletion src/librustc/middle/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4236,7 +4236,6 @@ pub fn expr_kind(tcx: &ctxt, expr: &ast::Expr) -> ExprKind {
ast::ExprIf(..) |
ast::ExprMatch(..) |
ast::ExprClosure(..) |
ast::ExprProc(..) |
ast::ExprBlock(..) |
ast::ExprRepeat(..) |
ast::ExprVec(..) => {
Expand Down
9 changes: 8 additions & 1 deletion src/librustc/util/ppaux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,14 @@ pub fn ty_to_string<'tcx>(cx: &ctxt<'tcx>, typ: &ty::TyS<'tcx>) -> String {
let unboxed_closures = cx.unboxed_closures.borrow();
unboxed_closures.get(did).map(|cl| {
closure_to_string(cx, &cl.closure_type.subst(cx, substs))
}).unwrap_or_else(|| "closure".to_string())
}).unwrap_or_else(|| {
if did.krate == ast::LOCAL_CRATE {
let span = cx.map.span(did.node);
format!("closure[{}]", span.repr(cx))
} else {
format!("closure")
}
})
}
ty_vec(t, sz) => {
let inner_str = ty_to_string(cx, t);
Expand Down
2 changes: 0 additions & 2 deletions src/librustc_back/svh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ mod svh_visitor {
SawExprWhile,
SawExprMatch,
SawExprClosure,
SawExprProc,
SawExprBlock,
SawExprAssign,
SawExprAssignOp(ast::BinOp),
Expand Down Expand Up @@ -274,7 +273,6 @@ mod svh_visitor {
ExprLoop(_, id) => SawExprLoop(id.map(content)),
ExprMatch(..) => SawExprMatch,
ExprClosure(..) => SawExprClosure,
ExprProc(..) => SawExprProc,
ExprBlock(..) => SawExprBlock,
ExprAssign(..) => SawExprAssign,
ExprAssignOp(op, _, _) => SawExprAssignOp(op),
Expand Down
1 change: 0 additions & 1 deletion src/librustc_borrowck/borrowck/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,6 @@ pub fn closure_to_block(closure_id: ast::NodeId,
tcx: &ty::ctxt) -> ast::NodeId {
match tcx.map.get(closure_id) {
ast_map::NodeExpr(expr) => match expr.node {
ast::ExprProc(_, ref block) |
ast::ExprClosure(_, _, _, ref block) => {
block.id
}
Expand Down
3 changes: 1 addition & 2 deletions src/librustc_trans/trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1396,8 +1396,7 @@ fn has_nested_returns(tcx: &ty::ctxt, id: ast::NodeId) -> bool {
}
Some(ast_map::NodeExpr(e)) => {
match e.node {
ast::ExprClosure(_, _, _, ref blk) |
ast::ExprProc(_, ref blk) => {
ast::ExprClosure(_, _, _, ref blk) => {
let mut explicit = CheckForNestedReturnsVisitor::explicit();
let mut implicit = CheckForNestedReturnsVisitor::implicit();
visit::walk_expr(&mut explicit, e);
Expand Down
Loading

0 comments on commit d258d68

Please sign in to comment.