@@ -673,6 +673,7 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
673
673
}
674
674
}
675
675
}
676
+ ty:: ty_err => { }
676
677
_ => {
677
678
let overloaded_call_type =
678
679
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> {
792
793
ty:: struct_fields ( self . tcx ( ) , did, substs)
793
794
}
794
795
_ => {
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 ! ( )
798
807
}
799
808
} ;
800
809
@@ -1004,8 +1013,8 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
1004
1013
debug ! ( "determine_pat_move_mode cmt_discr={} pat={}" , cmt_discr. repr( self . tcx( ) ) ,
1005
1014
pat. repr( self . tcx( ) ) ) ;
1006
1015
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;
1009
1018
if pat_util:: pat_is_binding( def_map, pat) {
1010
1019
match pat. node {
1011
1020
ast:: PatIdent ( ast:: BindByRef ( _) , _, _) =>
@@ -1041,7 +1050,7 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
1041
1050
1042
1051
let mc = & self . mc ;
1043
1052
let typer = self . typer ;
1044
- let def_map = & self . typer . tcx ( ) . def_map ;
1053
+ let def_map = & self . tcx ( ) . def_map ;
1045
1054
let delegate = & mut self . delegate ;
1046
1055
return_if_err ! ( mc. cat_pattern( cmt_discr. clone( ) , pat, |mc, cmt_pat, pat| {
1047
1056
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> {
1058
1067
// Each match binding is effectively an assignment to the
1059
1068
// binding being produced.
1060
1069
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
+ }
1063
1076
1064
1077
// It is also a borrow or copy/move of the value being matched.
1065
1078
match pat. node {
@@ -1080,7 +1093,7 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
1080
1093
delegate. consume_pat( pat, cmt_pat, mode) ;
1081
1094
}
1082
1095
_ => {
1083
- typer . tcx( ) . sess. span_bug(
1096
+ tcx. sess. span_bug(
1084
1097
pat. span,
1085
1098
"binding pattern not an identifier" ) ;
1086
1099
}
@@ -1181,17 +1194,29 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
1181
1194
// An enum's type -- should never be in a
1182
1195
// pattern.
1183
1196
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
+ }
1186
1203
}
1187
1204
1188
1205
Some ( def) => {
1189
1206
// Remaining cases are e.g. DefFn, to
1190
1207
// 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
+ }
1195
1220
}
1196
1221
}
1197
1222
}
@@ -1217,8 +1242,7 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
1217
1242
fn walk_captures ( & mut self , closure_expr : & ast:: Expr ) {
1218
1243
debug ! ( "walk_captures({})" , closure_expr. repr( self . tcx( ) ) ) ;
1219
1244
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| {
1222
1246
match self . tcx ( ) . capture_mode ( closure_expr. id ) {
1223
1247
ast:: CaptureByRef => {
1224
1248
self . walk_by_ref_captures ( closure_expr, freevars) ;
0 commit comments