@@ -114,37 +114,53 @@ pub fn check_pat_variant(pcx: &pat_ctxt, pat: @ast::pat, path: @ast::Path,
114
114
ty:: ty_enum( _, ref expected_substs) => {
115
115
// Lookup the enum and variant def ids:
116
116
let v_def = lookup_def ( pcx. fcx , pat. span , pat. id ) ;
117
- let ( enm, var) = ast_util:: variant_def_ids ( v_def) ;
118
-
119
- // Assign the pattern the type of the *enum*, not the variant.
120
- let enum_tpt = ty:: lookup_item_type ( tcx, enm) ;
121
- instantiate_path ( pcx. fcx , path, enum_tpt, pat. span , pat. id ,
122
- pcx. block_region ) ;
123
-
124
- // check that the type of the value being matched is a subtype
125
- // of the type of the pattern:
126
- let pat_ty = fcx. node_ty ( pat. id ) ;
127
- demand:: subtype ( fcx, pat. span , expected, pat_ty) ;
128
-
129
- // Get the expected types of the arguments.
130
- arg_types = {
131
- let vinfo =
132
- ty:: enum_variant_with_id ( tcx, enm, var) ;
133
- let var_tpt = ty:: lookup_item_type ( tcx, var) ;
134
- vinfo. args . map ( |t| {
135
- if var_tpt. generics . type_param_defs . len ( ) ==
136
- expected_substs. tps . len ( )
137
- {
138
- ty:: subst ( tcx, expected_substs, * t)
139
- }
140
- else {
141
- * t // In this case, an error was already signaled
142
- // anyway
143
- }
144
- } )
145
- } ;
146
-
147
- kind_name = "variant" ;
117
+ match ast_util:: variant_def_ids ( v_def) {
118
+ Some ( ( enm, var) ) => {
119
+ // Assign the pattern the type of the *enum*, not the variant.
120
+ let enum_tpt = ty:: lookup_item_type ( tcx, enm) ;
121
+ instantiate_path ( pcx. fcx , path, enum_tpt, pat. span , pat. id ,
122
+ pcx. block_region ) ;
123
+
124
+ // check that the type of the value being matched is a subtype
125
+ // of the type of the pattern:
126
+ let pat_ty = fcx. node_ty ( pat. id ) ;
127
+ demand:: subtype ( fcx, pat. span , expected, pat_ty) ;
128
+
129
+ // Get the expected types of the arguments.
130
+ arg_types = {
131
+ let vinfo =
132
+ ty:: enum_variant_with_id ( tcx, enm, var) ;
133
+ let var_tpt = ty:: lookup_item_type ( tcx, var) ;
134
+ vinfo. args . map ( |t| {
135
+ if var_tpt. generics . type_param_defs . len ( ) ==
136
+ expected_substs. tps . len ( )
137
+ {
138
+ ty:: subst ( tcx, expected_substs, * t)
139
+ }
140
+ else {
141
+ * t // In this case, an error was already signaled
142
+ // anyway
143
+ }
144
+ } )
145
+ } ;
146
+
147
+ kind_name = "variant" ;
148
+ }
149
+ None => {
150
+ let resolved_expected =
151
+ fcx. infcx ( ) . ty_to_str ( fcx. infcx ( ) . resolve_type_vars_if_possible ( expected) ) ;
152
+ fcx. infcx ( ) . type_error_message_str ( pat. span ,
153
+ |actual| {
154
+ fmt ! ( "mismatched types: expected `%s` but found %s" ,
155
+ resolved_expected, actual) } ,
156
+ ~"a structure pattern",
157
+ None ) ;
158
+ fcx. write_error ( pat. id ) ;
159
+ kind_name = "[error]" ;
160
+ arg_types = ( copy subpats) . get_or_default ( ~[ ] ) . map ( |_|
161
+ ty:: mk_err ( ) ) ;
162
+ }
163
+ }
148
164
}
149
165
ty:: ty_struct( struct_def_id, ref expected_substs) => {
150
166
// Lookup the struct ctor def id
0 commit comments