Skip to content

Commit 429d9cc

Browse files
committed
Be more tolerant of errors in EUV so we can run it during typeck.
1 parent 9c54d86 commit 429d9cc

File tree

1 file changed

+41
-17
lines changed

1 file changed

+41
-17
lines changed

src/librustc/middle/expr_use_visitor.rs

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,7 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
673673
}
674674
}
675675
}
676+
ty::ty_err => { }
676677
_ => {
677678
let overloaded_call_type =
678679
match self.typer.node_method_origin(MethodCall::expr(call.id)) {
@@ -792,9 +793,17 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
792793
ty::struct_fields(self.tcx(), did, substs)
793794
}
794795
_ => {
795-
self.tcx().sess.span_bug(
796-
with_expr.span,
797-
"with expression doesn't evaluate to a struct");
796+
// the base expression should always evaluate to a
797+
// struct; however, when EUV is run during typeck, it
798+
// may not. This will generate an error earlier in typeck,
799+
// so we can just ignore it.
800+
if !self.tcx().sess.has_errors() {
801+
self.tcx().sess.span_bug(
802+
with_expr.span,
803+
"with expression doesn't evaluate to a struct");
804+
}
805+
assert!(self.tcx().sess.has_errors());
806+
vec!()
798807
}
799808
};
800809

@@ -1004,8 +1013,8 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
10041013
debug!("determine_pat_move_mode cmt_discr={} pat={}", cmt_discr.repr(self.tcx()),
10051014
pat.repr(self.tcx()));
10061015
return_if_err!(self.mc.cat_pattern(cmt_discr, pat, |_mc, cmt_pat, pat| {
1007-
let tcx = self.typer.tcx();
1008-
let def_map = &self.typer.tcx().def_map;
1016+
let tcx = self.tcx();
1017+
let def_map = &self.tcx().def_map;
10091018
if pat_util::pat_is_binding(def_map, pat) {
10101019
match pat.node {
10111020
ast::PatIdent(ast::BindByRef(_), _, _) =>
@@ -1041,7 +1050,7 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
10411050

10421051
let mc = &self.mc;
10431052
let typer = self.typer;
1044-
let def_map = &self.typer.tcx().def_map;
1053+
let def_map = &self.tcx().def_map;
10451054
let delegate = &mut self.delegate;
10461055
return_if_err!(mc.cat_pattern(cmt_discr.clone(), pat, |mc, cmt_pat, pat| {
10471056
if pat_util::pat_is_binding(def_map, pat) {
@@ -1058,8 +1067,12 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
10581067
// Each match binding is effectively an assignment to the
10591068
// binding being produced.
10601069
let def = def_map.borrow()[pat.id].clone();
1061-
let binding_cmt = mc.cat_def(pat.id, pat.span, pat_ty, def);
1062-
delegate.mutate(pat.id, pat.span, binding_cmt, Init);
1070+
match mc.cat_def(pat.id, pat.span, pat_ty, def) {
1071+
Ok(binding_cmt) => {
1072+
delegate.mutate(pat.id, pat.span, binding_cmt, Init);
1073+
}
1074+
Err(_) => { }
1075+
}
10631076

10641077
// It is also a borrow or copy/move of the value being matched.
10651078
match pat.node {
@@ -1080,7 +1093,7 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
10801093
delegate.consume_pat(pat, cmt_pat, mode);
10811094
}
10821095
_ => {
1083-
typer.tcx().sess.span_bug(
1096+
tcx.sess.span_bug(
10841097
pat.span,
10851098
"binding pattern not an identifier");
10861099
}
@@ -1181,17 +1194,29 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
11811194
// An enum's type -- should never be in a
11821195
// pattern.
11831196

1184-
let msg = format!("Pattern has unexpected type: {}", def);
1185-
tcx.sess.span_bug(pat.span, msg[])
1197+
if !tcx.sess.has_errors() {
1198+
let msg = format!("Pattern has unexpected type: {} and type {}",
1199+
def,
1200+
cmt_pat.ty.repr(tcx));
1201+
tcx.sess.span_bug(pat.span, msg[])
1202+
}
11861203
}
11871204

11881205
Some(def) => {
11891206
// Remaining cases are e.g. DefFn, to
11901207
// which identifiers within patterns
1191-
// should not resolve.
1192-
1193-
let msg = format!("Pattern has unexpected def: {}", def);
1194-
tcx.sess.span_bug(pat.span, msg[])
1208+
// should not resolve. However, we do
1209+
// encouter this when using the
1210+
// expr-use-visitor during typeck. So just
1211+
// ignore it, an error should have been
1212+
// reported.
1213+
1214+
if !tcx.sess.has_errors() {
1215+
let msg = format!("Pattern has unexpected def: {} and type {}",
1216+
def,
1217+
cmt_pat.ty.repr(tcx));
1218+
tcx.sess.span_bug(pat.span, msg[])
1219+
}
11951220
}
11961221
}
11971222
}
@@ -1217,8 +1242,7 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
12171242
fn walk_captures(&mut self, closure_expr: &ast::Expr) {
12181243
debug!("walk_captures({})", closure_expr.repr(self.tcx()));
12191244

1220-
let tcx = self.typer.tcx();
1221-
ty::with_freevars(tcx, closure_expr.id, |freevars| {
1245+
ty::with_freevars(self.tcx(), closure_expr.id, |freevars| {
12221246
match self.tcx().capture_mode(closure_expr.id) {
12231247
ast::CaptureByRef => {
12241248
self.walk_by_ref_captures(closure_expr, freevars);

0 commit comments

Comments
 (0)