Skip to content

Commit a583ba2

Browse files
committed
Remove McResult from the mem-categorization interface.
1 parent 8f770f1 commit a583ba2

File tree

8 files changed

+135
-202
lines changed

8 files changed

+135
-202
lines changed

src/librustc/middle/expr_use_visitor.rs

Lines changed: 35 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -302,22 +302,6 @@ pub struct ExprUseVisitor<'d,'t,'tcx,TYPER:'t> {
302302
param_env: ParameterEnvironment<'tcx>,
303303
}
304304

305-
// If the TYPER results in an error, it's because the type check
306-
// failed (or will fail, when the error is uncovered and reported
307-
// during writeback). In this case, we just ignore this part of the
308-
// code.
309-
//
310-
// Note that this macro appears similar to try!(), but, unlike try!(),
311-
// it does not propagate the error.
312-
macro_rules! return_if_err {
313-
($inp: expr) => (
314-
match $inp {
315-
Ok(v) => v,
316-
Err(()) => return
317-
}
318-
)
319-
}
320-
321305
/// Whether the elements of an overloaded operation are passed by value or by reference
322306
enum PassArgs {
323307
ByValue,
@@ -348,7 +332,7 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
348332
decl: &ast::FnDecl,
349333
body: &ast::Block) {
350334
for arg in decl.inputs.iter() {
351-
let arg_ty = return_if_err!(self.typer.node_ty(arg.pat.id));
335+
let arg_ty = self.typer.node_ty(arg.pat.id);
352336

353337
let fn_body_scope = region::CodeExtent::from_node_id(body.id);
354338
let arg_cmt = self.mc.cat_rvalue(
@@ -385,7 +369,7 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
385369
pub fn consume_expr(&mut self, expr: &ast::Expr) {
386370
debug!("consume_expr(expr={})", expr.repr(self.tcx()));
387371

388-
let cmt = return_if_err!(self.mc.cat_expr(expr));
372+
let cmt = self.mc.cat_expr(expr);
389373
self.delegate_consume(expr.id, expr.span, cmt);
390374
self.walk_expr(expr);
391375
}
@@ -394,7 +378,7 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
394378
assignment_expr: &ast::Expr,
395379
expr: &ast::Expr,
396380
mode: MutateMode) {
397-
let cmt = return_if_err!(self.mc.cat_expr(expr));
381+
let cmt = self.mc.cat_expr(expr);
398382
self.delegate.mutate(assignment_expr.id, assignment_expr.span, cmt, mode);
399383
self.walk_expr(expr);
400384
}
@@ -407,7 +391,7 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
407391
debug!("borrow_expr(expr={}, r={}, bk={})",
408392
expr.repr(self.tcx()), r.repr(self.tcx()), bk.repr(self.tcx()));
409393

410-
let cmt = return_if_err!(self.mc.cat_expr(expr));
394+
let cmt = self.mc.cat_expr(expr);
411395
self.delegate.borrow(expr.id, expr.span, cmt, r, bk, cause);
412396

413397
// Note: Unlike consume, we can ignore ExprParen. cat_expr
@@ -500,7 +484,7 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
500484
}
501485

502486
ast::ExprMatch(ref discr, ref arms, _) => {
503-
let discr_cmt = return_if_err!(self.mc.cat_expr(&**discr));
487+
let discr_cmt = self.mc.cat_expr(&**discr);
504488
self.borrow_expr(&**discr, ty::ReEmpty, ty::ImmBorrow, MatchDiscriminant);
505489

506490
// treatment of the discriminant is handled while walking the arms.
@@ -559,7 +543,7 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
559543

560544
// Fetch the type of the value that the iteration yields to
561545
// produce the pattern's categorized mutable type.
562-
let pattern_type = return_if_err!(self.typer.node_ty(pat.id));
546+
let pattern_type = self.typer.node_ty(pat.id);
563547
let blk_scope = region::CodeExtent::from_node_id(blk.id);
564548
let pat_cmt = self.mc.cat_rvalue(pat.id,
565549
pat.span,
@@ -647,7 +631,7 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
647631
}
648632

649633
fn walk_callee(&mut self, call: &ast::Expr, callee: &ast::Expr) {
650-
let callee_ty = return_if_err!(self.typer.expr_ty_adjusted(callee));
634+
let callee_ty = self.typer.expr_ty_adjusted(callee);
651635
debug!("walk_callee: callee={} callee_ty={}",
652636
callee.repr(self.tcx()), callee_ty.repr(self.tcx()));
653637
let call_scope = region::CodeExtent::from_node_id(call.id);
@@ -747,7 +731,7 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
747731
// "assigns", which is handled by
748732
// `walk_pat`:
749733
self.walk_expr(&**expr);
750-
let init_cmt = return_if_err!(self.mc.cat_expr(&**expr));
734+
let init_cmt = self.mc.cat_expr(&**expr);
751735
self.walk_irrefutable_pat(init_cmt, &*local.pat);
752736
}
753737
}
@@ -781,7 +765,7 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
781765
None => { return; }
782766
};
783767

784-
let with_cmt = return_if_err!(self.mc.cat_expr(&*with_expr));
768+
let with_cmt = self.mc.cat_expr(&*with_expr);
785769

786770
// Select just those fields of the `with`
787771
// expression that will actually be used
@@ -836,7 +820,7 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
836820
// rvalue.
837821
debug!("walk_adjustment(AutoAddEnv|AdjustReifyFnPointer)");
838822
let cmt_unadjusted =
839-
return_if_err!(self.mc.cat_expr_unadjusted(expr));
823+
self.mc.cat_expr_unadjusted(expr);
840824
self.delegate_consume(expr.id, expr.span, cmt_unadjusted);
841825
}
842826
ty::AdjustDerefRef(ty::AutoDerefRef {
@@ -870,7 +854,7 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
870854
match self.typer.node_method_ty(deref_id) {
871855
None => {}
872856
Some(method_ty) => {
873-
let cmt = return_if_err!(self.mc.cat_expr_autoderefd(expr, i));
857+
let cmt = self.mc.cat_expr_autoderefd(expr, i);
874858
let self_ty = ty::ty_fn_args(method_ty)[0];
875859
let (m, r) = match self_ty.sty {
876860
ty::ty_rptr(r, ref m) => (m.mutbl, r),
@@ -900,15 +884,14 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
900884
assert!(n == 1, format!("Expected exactly 1 deref with Uniq \
901885
AutoRefs, found: {}", n));
902886
let cmt_unadjusted =
903-
return_if_err!(self.mc.cat_expr_unadjusted(expr));
887+
self.mc.cat_expr_unadjusted(expr);
904888
self.delegate_consume(expr.id, expr.span, cmt_unadjusted);
905889
return;
906890
}
907891
_ => {}
908892
}
909893

910-
let cmt_derefd = return_if_err!(
911-
self.mc.cat_expr_autoderefd(expr, n));
894+
let cmt_derefd = self.mc.cat_expr_autoderefd(expr, n);
912895
debug!("walk_adjustment: cmt_derefd={}",
913896
cmt_derefd.repr(self.tcx()));
914897

@@ -1001,7 +984,7 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
1001984
mode: &mut TrackMatchMode<Span>) {
1002985
debug!("determine_pat_move_mode cmt_discr={} pat={}", cmt_discr.repr(self.tcx()),
1003986
pat.repr(self.tcx()));
1004-
return_if_err!(self.mc.cat_pattern(cmt_discr, pat, |_mc, cmt_pat, pat| {
987+
self.mc.cat_pattern(cmt_discr, pat, |_mc, cmt_pat, pat| {
1005988
let tcx = self.typer.tcx();
1006989
let def_map = &self.typer.tcx().def_map;
1007990
if pat_util::pat_is_binding(def_map, pat) {
@@ -1024,7 +1007,7 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
10241007
}
10251008
}
10261009
}
1027-
}));
1010+
});
10281011
}
10291012

10301013
/// The core driver for walking a pattern; `match_mode` must be
@@ -1039,11 +1022,11 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
10391022

10401023
let mc = &self.mc;
10411024
let typer = self.typer;
1042-
let tcx = typer.tcx();
10431025
let def_map = &self.typer.tcx().def_map;
10441026
let delegate = &mut self.delegate;
10451027
let param_env = &mut self.param_env;
1046-
return_if_err!(mc.cat_pattern(cmt_discr.clone(), pat, |mc, cmt_pat, pat| {
1028+
1029+
mc.cat_pattern(cmt_discr.clone(), pat, |mc, cmt_pat, pat| {
10471030
if pat_util::pat_is_binding(def_map, pat) {
10481031
let tcx = typer.tcx();
10491032

@@ -1053,17 +1036,13 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
10531036
match_mode);
10541037

10551038
// pat_ty: the type of the binding being produced.
1056-
let pat_ty = return_if_err!(typer.node_ty(pat.id));
1039+
let pat_ty = typer.node_ty(pat.id);
10571040

10581041
// Each match binding is effectively an assignment to the
10591042
// binding being produced.
10601043
let def = def_map.borrow()[pat.id].clone();
1061-
match mc.cat_def(pat.id, pat.span, pat_ty, def) {
1062-
Ok(binding_cmt) => {
1063-
delegate.mutate(pat.id, pat.span, binding_cmt, Init);
1064-
}
1065-
Err(_) => { }
1066-
}
1044+
let binding_cmt = mc.cat_def(pat.id, pat.span, pat_ty, def);
1045+
delegate.mutate(pat.id, pat.span, binding_cmt, Init);
10671046

10681047
// It is also a borrow or copy/move of the value being matched.
10691048
match pat.node {
@@ -1097,15 +1076,8 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
10971076
// borrow of the elements of the vector being
10981077
// matched.
10991078

1100-
let (slice_cmt, slice_mutbl, slice_r) = {
1101-
match mc.cat_slice_pattern(cmt_pat, &**slice_pat) {
1102-
Ok(v) => v,
1103-
Err(()) => {
1104-
tcx.sess.span_bug(slice_pat.span,
1105-
"Err from mc")
1106-
}
1107-
}
1108-
};
1079+
let (slice_cmt, slice_mutbl, slice_r) =
1080+
mc.cat_slice_pattern(cmt_pat, &**slice_pat);
11091081

11101082
// Note: We declare here that the borrow
11111083
// occurs upon entering the `[...]`
@@ -1135,13 +1107,13 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
11351107
_ => { }
11361108
}
11371109
}
1138-
}));
1110+
});
11391111

11401112
// Do a second pass over the pattern, calling `matched_pat` on
11411113
// the interior nodes (enum variants and structs), as opposed
11421114
// to the above loop's visit of than the bindings that form
11431115
// the leaves of the pattern tree structure.
1144-
return_if_err!(mc.cat_pattern(cmt_discr, pat, |mc, cmt_pat, pat| {
1116+
mc.cat_pattern(cmt_discr, pat, |mc, cmt_pat, pat| {
11451117
let def_map = def_map.borrow();
11461118
let tcx = typer.tcx();
11471119

@@ -1222,7 +1194,7 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
12221194
// cases either.
12231195
}
12241196
}
1225-
}));
1197+
});
12261198
}
12271199

12281200
fn walk_captures(&mut self, closure_expr: &ast::Expr) {
@@ -1246,9 +1218,9 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
12461218
freevars: &[ty::Freevar]) {
12471219
for freevar in freevars.iter() {
12481220
let id_var = freevar.def.def_id().node;
1249-
let cmt_var = return_if_err!(self.cat_captured_var(closure_expr.id,
1250-
closure_expr.span,
1251-
freevar.def));
1221+
let cmt_var = self.cat_captured_var(closure_expr.id,
1222+
closure_expr.span,
1223+
freevar.def);
12521224

12531225
// Lookup the kind of borrow the callee requires, as
12541226
// inferred by regionbk
@@ -1269,13 +1241,11 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
12691241
closure_expr: &ast::Expr,
12701242
freevars: &[ty::Freevar]) {
12711243
for freevar in freevars.iter() {
1272-
let cmt_var = return_if_err!(self.cat_captured_var(closure_expr.id,
1273-
closure_expr.span,
1274-
freevar.def));
1275-
let mode = copy_or_move(self.tcx(),
1276-
cmt_var.ty,
1277-
&self.param_env,
1278-
CaptureMove);
1244+
let cmt_var = self.cat_captured_var(closure_expr.id,
1245+
closure_expr.span,
1246+
freevar.def);
1247+
let mode = copy_or_move(self.tcx(), cmt_var.ty,
1248+
&self.param_env, CaptureMove);
12791249
self.delegate.consume(closure_expr.id, freevar.span, cmt_var, mode);
12801250
}
12811251
}
@@ -1284,11 +1254,11 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
12841254
closure_id: ast::NodeId,
12851255
closure_span: Span,
12861256
upvar_def: def::Def)
1287-
-> mc::McResult<mc::cmt<'tcx>> {
1257+
-> mc::cmt<'tcx> {
12881258
// Create the cmt for the variable being borrowed, from the
12891259
// caller's perspective
12901260
let var_id = upvar_def.def_id().node;
1291-
let var_ty = try!(self.typer.node_ty(var_id));
1261+
let var_ty = self.typer.node_ty(var_id);
12921262
self.mc.cat_def(closure_id, closure_span, var_ty, upvar_def)
12931263
}
12941264
}

0 commit comments

Comments
 (0)