Skip to content

Commit 3196586

Browse files
committed
rustc: Resolve constructor expressions for variant structs
1 parent 5ce3281 commit 3196586

File tree

1 file changed

+27
-10
lines changed

1 file changed

+27
-10
lines changed

src/rustc/middle/resolve3.rs

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ import syntax::ast::{lt, method, mul, ne, neg, node_id, pat, pat_enum};
3333
import syntax::ast::{pat_ident, path, prim_ty, pat_box, pat_uniq, pat_lit};
3434
import syntax::ast::{pat_range, pat_rec, pat_struct, pat_tup, pat_wild};
3535
import syntax::ast::{provided, required, rem, self_ty_, shl, stmt_decl};
36-
import syntax::ast::{sty_static, subtract, ty};
36+
import syntax::ast::{struct_variant_kind, sty_static, subtract};
37+
import syntax::ast::{tuple_variant_kind, ty};
3738
import syntax::ast::{ty_bool, ty_char, ty_f, ty_f32, ty_f64, ty_float, ty_i};
3839
import syntax::ast::{ty_i16, ty_i32, ty_i64, ty_i8, ty_int, ty_param};
3940
import syntax::ast::{ty_path, ty_str, ty_u, ty_u16, ty_u32, ty_u64, ty_u8};
@@ -1114,10 +1115,8 @@ class Resolver {
11141115
}
11151116
}
11161117

1117-
/**
1118-
* Constructs the reduced graph for one variant. Variants exist in the
1119-
* type namespace.
1120-
*/
1118+
// Constructs the reduced graph for one variant. Variants exist in the
1119+
// type and/or value namespaces.
11211120
fn build_reduced_graph_for_variant(variant: variant,
11221121
item_id: def_id,
11231122
parent: ReducedGraphParent,
@@ -1127,8 +1126,19 @@ class Resolver {
11271126
let (child, _) = self.add_child(atom, parent, ~[ValueNS],
11281127
variant.span);
11291128

1130-
(*child).define_value(def_variant(item_id,
1131-
local_def(variant.node.id)), variant.span);
1129+
match variant.node.kind {
1130+
tuple_variant_kind(_) => {
1131+
(*child).define_value(def_variant(item_id,
1132+
local_def(variant.node.id)),
1133+
variant.span);
1134+
}
1135+
struct_variant_kind(_) => {
1136+
(*child).define_type(def_variant(item_id,
1137+
local_def(variant.node.id)),
1138+
variant.span);
1139+
self.structs.insert(local_def(variant.node.id), false);
1140+
}
1141+
}
11321142
}
11331143

11341144
/**
@@ -4018,13 +4028,17 @@ class Resolver {
40184028
40194029
pat_struct(path, _, _) => {
40204030
match self.resolve_path(path, TypeNS, false, visitor) {
4021-
some(definition @ def_ty(class_id))
4031+
some(def_ty(class_id))
40224032
if self.structs.contains_key(class_id) => {
40234033
let has_constructor = self.structs.get(class_id);
40244034
let class_def = def_class(class_id,
40254035
has_constructor);
40264036
self.record_def(pattern.id, class_def);
40274037
}
4038+
some(definition @ def_variant(_, variant_id))
4039+
if self.structs.contains_key(variant_id) => {
4040+
self.record_def(pattern.id, definition);
4041+
}
40284042
_ => {
40294043
self.session.span_err(path.span,
40304044
fmt!("`%s` does not name a \
@@ -4450,13 +4464,16 @@ class Resolver {
44504464
// let bar = Bar { ... } // no type parameters
44514465
44524466
match self.resolve_path(path, TypeNS, false, visitor) {
4453-
some(definition @ def_ty(class_id))
4467+
some(def_ty(class_id))
44544468
if self.structs.contains_key(class_id) => {
4455-
44564469
let has_constructor = self.structs.get(class_id);
44574470
let class_def = def_class(class_id, has_constructor);
44584471
self.record_def(expr.id, class_def);
44594472
}
4473+
some(definition @ def_variant(_, class_id))
4474+
if self.structs.contains_key(class_id) => {
4475+
self.record_def(expr.id, definition);
4476+
}
44604477
_ => {
44614478
self.session.span_err(path.span,
44624479
fmt!{"`%s` does not name a \

0 commit comments

Comments
 (0)