Skip to content

Commit afd9a75

Browse files
committed
rustc: Fix cross-crate max/min-class-style constructors
1 parent 5cf99c5 commit afd9a75

File tree

12 files changed

+40
-22
lines changed

12 files changed

+40
-22
lines changed

src/libsyntax/ast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ enum def {
8787
def_upvar(node_id /* local id of closed over var */,
8888
@def /* closed over def */,
8989
node_id /* expr node that creates the closure */),
90-
def_class(def_id),
90+
def_class(def_id, bool /* has constructor */),
9191
def_region(node_id)
9292
}
9393

src/libsyntax/ast_util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pure fn def_id_of_def(d: def) -> def_id {
5353
def_fn(id, _) | def_mod(id) |
5454
def_foreign_mod(id) | def_const(id) |
5555
def_variant(_, id) | def_ty(id) | def_ty_param(id, _) |
56-
def_use(id) | def_class(id) { id }
56+
def_use(id) | def_class(id, _) { id }
5757
def_arg(id, _) | def_local(id, _) | def_self(id) |
5858
def_upvar(id, _, _) | def_binding(id) | def_region(id) {
5959
local_def(id)

src/rustc/metadata/decoder.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,8 @@ fn item_to_def_like(item: ebml::doc, did: ast::def_id, cnum: ast::crate_num)
283283
let fam_ch = item_family(item);
284284
alt fam_ch {
285285
'c' { dl_def(ast::def_const(did)) }
286-
'C' { dl_def(ast::def_class(did)) }
286+
'C' { dl_def(ast::def_class(did, true)) }
287+
'S' { dl_def(ast::def_class(did, false)) }
287288
'u' { dl_def(ast::def_fn(did, ast::unsafe_fn)) }
288289
'f' { dl_def(ast::def_fn(did, ast::impure_fn)) }
289290
'p' { dl_def(ast::def_fn(did, ast::pure_fn)) }
@@ -707,7 +708,7 @@ fn family_has_type_params(fam_ch: char) -> bool {
707708
alt check fam_ch {
708709
'c' | 'T' | 'm' | 'n' | 'g' | 'h' | 'j' { false }
709710
'f' | 'u' | 'p' | 'F' | 'U' | 'P' | 'y' | 't' | 'v' | 'i' | 'I' | 'C'
710-
| 'a'
711+
| 'a' | 'S'
711712
{ true }
712713
}
713714
}
@@ -751,6 +752,7 @@ fn item_family_to_str(fam: char) -> ~str {
751752
'i' { ret ~"impl"; }
752753
'I' { ret ~"trait"; }
753754
'C' { ret ~"class"; }
755+
'S' { ret ~"struct"; }
754756
'g' { ret ~"public field"; }
755757
'j' { ret ~"private field"; }
756758
}

src/rustc/metadata/encoder.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,16 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
663663
/* Now, make an item for the class itself */
664664
ebml_w.start_tag(tag_items_data_item);
665665
encode_def_id(ebml_w, local_def(item.id));
666-
encode_family(ebml_w, 'C');
666+
667+
alt ctor {
668+
none {
669+
encode_family(ebml_w, 'S');
670+
}
671+
some(_) {
672+
encode_family(ebml_w, 'C');
673+
}
674+
}
675+
667676
encode_type_param_bounds(ebml_w, ecx, tps);
668677
encode_type(ecx, ebml_w, node_id_to_type(tcx, item.id));
669678
encode_name(ebml_w, item.ident);

src/rustc/middle/astencode.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,8 +369,8 @@ impl of tr for ast::def {
369369
ast::def_upvar(nid1, def, nid2) {
370370
ast::def_upvar(xcx.tr_id(nid1), @(*def).tr(xcx), xcx.tr_id(nid2))
371371
}
372-
ast::def_class(did) {
373-
ast::def_class(did.tr(xcx))
372+
ast::def_class(did, has_constructor) {
373+
ast::def_class(did.tr(xcx), has_constructor)
374374
}
375375
ast::def_region(nid) { ast::def_region(xcx.tr_id(nid)) }
376376
}

src/rustc/middle/borrowck/categorization.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ impl public_methods for borrowck_ctxt {
196196
ast::def_foreign_mod(_) | ast::def_const(_) |
197197
ast::def_use(_) | ast::def_variant(_, _) |
198198
ast::def_ty(_) | ast::def_prim_ty(_) |
199-
ast::def_ty_param(_, _) | ast::def_class(_) |
199+
ast::def_ty_param(_, _) | ast::def_class(_, _) |
200200
ast::def_region(_) {
201201
@{id:id, span:span,
202202
cat:cat_special(sk_static_item), lp:none,

src/rustc/middle/region.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ fn determine_rp_in_ty(ty: @ast::ty,
467467
alt ty.node {
468468
ast::ty_path(_, id) {
469469
alt cx.def_map.get(id) {
470-
ast::def_ty(did) | ast::def_class(did) {
470+
ast::def_ty(did) | ast::def_class(did, _) {
471471
if did.crate == ast::local_crate {
472472
cx.add_dep(did.node, cx.item_id);
473473
} else {

src/rustc/middle/resolve3.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import syntax::visit::{visit_mod, visit_ty, vt};
4141

4242
import box::ptr_eq;
4343
import dvec::{dvec, extensions};
44-
import option::get;
44+
import option::{get, is_some};
4545
import str::{connect, split_str};
4646
import vec::pop;
4747

@@ -604,7 +604,7 @@ class Resolver {
604604
let unused_import_lint_level: level;
605605

606606
let trait_info: hashmap<def_id,@hashmap<Atom,()>>;
607-
let structs: hashmap<def_id,()>;
607+
let structs: hashmap<def_id,bool>;
608608

609609
// The number of imports that are currently unresolved.
610610
let mut unresolved_imports: uint;
@@ -926,7 +926,8 @@ class Resolver {
926926
(*name_bindings).define_impl(impl_info);
927927

928928
// Record the def ID of this struct.
929-
self.structs.insert(local_def(item.id), ());
929+
self.structs.insert(local_def(item.id),
930+
is_some(optional_ctor));
930931

931932
visit_item(item, new_parent, visitor);
932933
}
@@ -1378,12 +1379,16 @@ class Resolver {
13781379

13791380
(*child_name_bindings).define_type(def);
13801381
}
1381-
def_class(def_id) {
1382+
def_class(def_id, has_constructor) {
13821383
#debug("(building reduced graph for external \
1383-
crate) building value and type %s",
1384-
final_ident);
1385-
(*child_name_bindings).define_value(def);
1384+
crate) building type %s (value? %d)",
1385+
final_ident,
1386+
if has_constructor { 1 } else { 0 });
13861387
(*child_name_bindings).define_type(def);
1388+
1389+
if has_constructor {
1390+
(*child_name_bindings).define_value(def);
1391+
}
13871392
}
13881393
def_self(*) | def_arg(*) | def_local(*) |
13891394
def_prim_ty(*) | def_ty_param(*) | def_binding(*) |
@@ -4201,7 +4206,9 @@ class Resolver {
42014206
some(definition @ def_ty(class_id))
42024207
if self.structs.contains_key(class_id) {
42034208

4204-
self.record_def(expr.id, def_class(class_id));
4209+
let has_constructor = self.structs.get(class_id);
4210+
let class_def = def_class(class_id, has_constructor);
4211+
self.record_def(expr.id, class_def);
42054212
}
42064213
_ {
42074214
self.session.span_err(path.span,

src/rustc/middle/ty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2587,7 +2587,7 @@ fn type_err_to_str(cx: ctxt, err: type_err) -> ~str {
25872587

25882588
fn def_has_ty_params(def: ast::def) -> bool {
25892589
alt def {
2590-
ast::def_fn(_, _) | ast::def_variant(_, _) | ast::def_class(_)
2590+
ast::def_fn(_, _) | ast::def_variant(_, _) | ast::def_class(_, _)
25912591
{ true }
25922592
_ { false }
25932593
}

src/rustc/middle/typeck/astconv.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ fn ast_ty_to_ty<AC: ast_conv, RS: region_scope copy owned>(
270270
path_to_str(path))); }
271271
some(d) { d }};
272272
alt a_def {
273-
ast::def_ty(did) | ast::def_class(did) {
273+
ast::def_ty(did) | ast::def_class(did, _) {
274274
ast_path_to_ty(self, rscope, did, path, id).ty
275275
}
276276
ast::def_prim_ty(nty) {

src/rustc/middle/typeck/check.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1649,7 +1649,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt,
16491649
// Resolve the path.
16501650
let class_id;
16511651
alt tcx.def_map.find(id) {
1652-
some(ast::def_class(type_def_id)) => {
1652+
some(ast::def_class(type_def_id, _)) => {
16531653
class_id = type_def_id;
16541654
}
16551655
_ => {
@@ -2160,7 +2160,7 @@ fn ty_param_bounds_and_ty_for_def(fcx: @fn_ctxt, sp: span, defn: ast::def) ->
21602160
}
21612161

21622162
ast::def_fn(id, _) | ast::def_const(id) |
2163-
ast::def_variant(_, id) | ast::def_class(id) {
2163+
ast::def_variant(_, id) | ast::def_class(id, _) {
21642164
ret ty::lookup_item_type(fcx.ccx.tcx, id);
21652165
}
21662166
ast::def_binding(nid) {

src/rustc/middle/typeck/check/regionmanip.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ fn region_of(fcx: @fn_ctxt, expr: @ast::expr) -> ty::region {
200200
ast::def_foreign_mod(_) | ast::def_const(_) |
201201
ast::def_use(_) | ast::def_variant(_, _) |
202202
ast::def_ty(_) | ast::def_prim_ty(_) |
203-
ast::def_ty_param(_, _) | ast::def_class(_) |
203+
ast::def_ty_param(_, _) | ast::def_class(_, _) |
204204
ast::def_region(_) {
205205
ty::re_static
206206
}

0 commit comments

Comments
 (0)