@@ -14,15 +14,15 @@ import syntax::ast::{def_prim_ty, def_region, def_self, def_ty, def_ty_param};
14
14
import syntax:: ast:: { def_upvar, def_use, def_variant, expr, expr_assign_op} ;
15
15
import syntax:: ast:: { expr_binary, expr_cast, expr_field, expr_fn} ;
16
16
import syntax:: ast:: { expr_fn_block, expr_index, expr_new, expr_path} ;
17
- import syntax:: ast:: { expr_unary, fn_decl, foreign_item, foreign_item_fn } ;
18
- import syntax:: ast:: { ident, trait_ref, impure_fn, instance_var , item } ;
19
- import syntax:: ast:: { item_class , item_const , item_enum , item_fn , item_mac } ;
20
- import syntax:: ast:: { item_foreign_mod , item_trait , item_impl , item_mod } ;
21
- import syntax:: ast:: { item_ty , local , local_crate , method , node_id , pat } ;
22
- import syntax:: ast:: { pat_enum , pat_ident , path , prim_ty , stmt_decl , ty ,
23
- pat_box, pat_uniq, pat_lit, pat_range, pat_rec ,
24
- pat_tup, pat_wild} ;
25
- import syntax:: ast:: { ty_bool, ty_char, ty_f, ty_f32, ty_f64} ;
17
+ import syntax:: ast:: { expr_struct , expr_unary, fn_decl, foreign_item} ;
18
+ import syntax:: ast:: { foreign_item_fn , ident, trait_ref, impure_fn} ;
19
+ import syntax:: ast:: { instance_var , item , item_class , item_const , item_enum } ;
20
+ import syntax:: ast:: { item_fn , item_mac , item_foreign_mod , item_impl } ;
21
+ import syntax:: ast:: { item_mod , item_trait , item_ty , local , local_crate } ;
22
+ import syntax:: ast:: { method , node_id , pat , pat_enum , pat_ident } ;
23
+ import syntax :: ast :: { path , prim_ty , pat_box, pat_uniq, pat_lit, pat_range} ;
24
+ import syntax :: ast :: { pat_rec , pat_tup, pat_wild, stmt_decl } ;
25
+ import syntax:: ast:: { ty , ty_bool, ty_char, ty_f, ty_f32, ty_f64} ;
26
26
import syntax:: ast:: { ty_float, ty_i, ty_i16, ty_i32, ty_i64, ty_i8, ty_int} ;
27
27
import syntax:: ast:: { ty_param, ty_path, ty_str, ty_u, ty_u16, ty_u32, ty_u64} ;
28
28
import syntax:: ast:: { ty_u8, ty_uint, variant, view_item, view_item_export} ;
@@ -604,6 +604,7 @@ class Resolver {
604
604
let unused_import_lint_level: level ;
605
605
606
606
let trait_info: hashmap < def_id , @hashmap < Atom , ( ) > > ;
607
+ let structs: hashmap < def_id , ( ) > ;
607
608
608
609
// The number of imports that are currently unresolved.
609
610
let mut unresolved_imports: uint ;
@@ -657,6 +658,7 @@ class Resolver {
657
658
self . unused_import_lint_level = unused_import_lint_level ( session) ;
658
659
659
660
self . trait_info = new_def_hash ( ) ;
661
+ self . structs = new_def_hash ( ) ;
660
662
661
663
self . unresolved_imports = 0 u;
662
664
@@ -915,6 +917,9 @@ class Resolver {
915
917
916
918
( * name_bindings) . define_impl ( impl_info) ;
917
919
920
+ // Record the def ID of this struct.
921
+ self . structs . insert ( local_def ( item. id ) , ( ) ) ;
922
+
918
923
visit_item ( item, new_parent, visitor) ;
919
924
}
920
925
@@ -4162,6 +4167,41 @@ class Resolver {
4162
4167
visitor) ;
4163
4168
}
4164
4169
4170
+ expr_struct( path, _) {
4171
+ // Resolve the path to the structure it goes to.
4172
+ //
4173
+ // XXX: We might want to support explicit type parameters in
4174
+ // the path, in which case this gets a little more
4175
+ // complicated:
4176
+ //
4177
+ // 1. Should we go through the ast_path_to_ty() path, which
4178
+ // handles typedefs and the like?
4179
+ //
4180
+ // 2. If so, should programmers be able to write this?
4181
+ //
4182
+ // class Foo<A> { ... }
4183
+ // type Bar<A> = Foo<A>;
4184
+ // let bar = Bar { ... } // no type parameters
4185
+
4186
+ alt self . resolve_path( path, TypeNS , false, visitor) {
4187
+ some( definition @ def_ty( class_id) )
4188
+ if self . structs. contains_key( class_id) {
4189
+
4190
+ self . record_def( expr. id, def_class( class_id) ) ;
4191
+ }
4192
+ _ {
4193
+ self . session. span_err( path. span,
4194
+ #fmt( "`%s` does not name a \
4195
+ structure",
4196
+ connect( path. idents. map
4197
+ ( |x| * x) ,
4198
+ ~":: ") ) ) ;
4199
+ }
4200
+ }
4201
+
4202
+ visit_expr( expr, ( ) , visitor) ;
4203
+ }
4204
+
4165
4205
_ {
4166
4206
visit_expr( expr, ( ) , visitor) ;
4167
4207
}
0 commit comments