Remove un-needed code for obsolete classes
and rename "class" to "struct" everywhere possible (except local vars, I was too lazy for that) -- that is why this commit is so big. No review, just dead code removal and renaming. Closes #3515
This commit is contained in:
parent
3fcdb7d6a7
commit
0046ed9462
@ -84,7 +84,7 @@ const tag_path_len: uint = 0x41u;
|
||||
const tag_path_elt_mod: uint = 0x42u;
|
||||
const tag_path_elt_name: uint = 0x43u;
|
||||
const tag_item_field: uint = 0x44u;
|
||||
const tag_class_mut: uint = 0x45u;
|
||||
const tag_struct_mut: uint = 0x45u;
|
||||
|
||||
const tag_region_param: uint = 0x46u;
|
||||
const tag_mod_impl_trait: uint = 0x47u;
|
||||
|
@ -24,10 +24,9 @@ use common::*;
|
||||
use std::map::HashMap;
|
||||
use dvec::DVec;
|
||||
|
||||
export class_dtor;
|
||||
export struct_dtor;
|
||||
export get_symbol;
|
||||
export get_class_fields;
|
||||
export get_class_method;
|
||||
export get_struct_fields;
|
||||
export get_field_type;
|
||||
export get_type_param_count;
|
||||
export get_region_param;
|
||||
@ -170,10 +169,10 @@ fn get_item_attrs(cstore: cstore::CStore,
|
||||
decoder::get_item_attrs(cdata, def_id.node, f)
|
||||
}
|
||||
|
||||
fn get_class_fields(tcx: ty::ctxt, def: ast::def_id) -> ~[ty::field_ty] {
|
||||
fn get_struct_fields(tcx: ty::ctxt, def: ast::def_id) -> ~[ty::field_ty] {
|
||||
let cstore = tcx.cstore;
|
||||
let cdata = cstore::get_crate_data(cstore, def.crate);
|
||||
decoder::get_class_fields(cstore.intr, cdata, def.node)
|
||||
decoder::get_struct_fields(cstore.intr, cdata, def.node)
|
||||
}
|
||||
|
||||
fn get_type(tcx: ty::ctxt, def: ast::def_id) -> ty::ty_param_bounds_and_ty {
|
||||
@ -226,22 +225,11 @@ fn get_impl_method(cstore: cstore::CStore,
|
||||
decoder::get_impl_method(cstore.intr, cdata, def.node, mname)
|
||||
}
|
||||
|
||||
/* Because classes use the trait format rather than the impl format
|
||||
for their methods (so that get_trait_methods can be reused to get
|
||||
class methods), classes require a slightly different version of
|
||||
get_impl_method. Sigh. */
|
||||
fn get_class_method(cstore: cstore::CStore,
|
||||
def: ast::def_id, mname: ast::ident)
|
||||
-> ast::def_id {
|
||||
let cdata = cstore::get_crate_data(cstore, def.crate);
|
||||
decoder::get_class_method(cstore.intr, cdata, def.node, mname)
|
||||
}
|
||||
|
||||
/* If def names a class with a dtor, return it. Otherwise, return none. */
|
||||
fn class_dtor(cstore: cstore::CStore, def: ast::def_id)
|
||||
fn struct_dtor(cstore: cstore::CStore, def: ast::def_id)
|
||||
-> Option<ast::def_id> {
|
||||
let cdata = cstore::get_crate_data(cstore, def.crate);
|
||||
decoder::class_dtor(cdata, def.node)
|
||||
decoder::struct_dtor(cdata, def.node)
|
||||
}
|
||||
// Local Variables:
|
||||
// mode: rust
|
||||
|
@ -32,15 +32,14 @@ use syntax::parse::token::ident_interner;
|
||||
use hash::{Hash, HashUtil};
|
||||
use csearch::{ProvidedTraitMethodInfo, StaticMethodInfo};
|
||||
|
||||
export class_dtor;
|
||||
export get_class_fields;
|
||||
export struct_dtor;
|
||||
export get_struct_fields;
|
||||
export get_symbol;
|
||||
export get_enum_variants;
|
||||
export get_type;
|
||||
export get_region_param;
|
||||
export get_type_param_count;
|
||||
export get_impl_traits;
|
||||
export get_class_method;
|
||||
export get_impl_method;
|
||||
export get_static_methods_if_impl;
|
||||
export lookup_def;
|
||||
@ -228,15 +227,15 @@ fn each_reexport(d: ebml::Doc, f: fn(ebml::Doc) -> bool) {
|
||||
}
|
||||
}
|
||||
|
||||
fn field_mutability(d: ebml::Doc) -> ast::class_mutability {
|
||||
fn field_mutability(d: ebml::Doc) -> ast::struct_mutability {
|
||||
// Use maybe_get_doc in case it's a method
|
||||
option::map_default(
|
||||
&reader::maybe_get_doc(d, tag_class_mut),
|
||||
ast::class_immutable,
|
||||
&reader::maybe_get_doc(d, tag_struct_mut),
|
||||
ast::struct_immutable,
|
||||
|d| {
|
||||
match reader::doc_as_u8(*d) as char {
|
||||
'm' => ast::class_mutable,
|
||||
_ => ast::class_immutable
|
||||
'm' => ast::struct_mutable,
|
||||
_ => ast::struct_immutable
|
||||
}
|
||||
})
|
||||
}
|
||||
@ -338,7 +337,7 @@ fn item_to_def_like(item: ebml::Doc, did: ast::def_id, cnum: ast::crate_num)
|
||||
let fam = item_family(item);
|
||||
match fam {
|
||||
Const => dl_def(ast::def_const(did)),
|
||||
Struct => dl_def(ast::def_class(did)),
|
||||
Struct => dl_def(ast::def_struct(did)),
|
||||
UnsafeFn => dl_def(ast::def_fn(did, ast::unsafe_fn)),
|
||||
Fn => dl_def(ast::def_fn(did, ast::impure_fn)),
|
||||
PureFn => dl_def(ast::def_fn(did, ast::pure_fn)),
|
||||
@ -419,34 +418,12 @@ fn get_impl_method(intr: @ident_interner, cdata: cmd, id: ast::node_id,
|
||||
found.get()
|
||||
}
|
||||
|
||||
fn get_class_method(intr: @ident_interner, cdata: cmd, id: ast::node_id,
|
||||
name: ast::ident) -> ast::def_id {
|
||||
let items = reader::get_doc(reader::Doc(cdata.data), tag_items);
|
||||
let mut found = None;
|
||||
let cls_items = match maybe_find_item(id, items) {
|
||||
Some(it) => it,
|
||||
None => fail (fmt!("get_class_method: class id not found \
|
||||
when looking up method %s", *intr.get(name)))
|
||||
};
|
||||
for reader::tagged_docs(cls_items, tag_item_trait_method) |mid| {
|
||||
let m_did = item_def_id(mid, cdata);
|
||||
if item_name(intr, mid) == name {
|
||||
found = Some(m_did);
|
||||
}
|
||||
}
|
||||
match found {
|
||||
Some(found) => found,
|
||||
None => fail (fmt!("get_class_method: no method named %s",
|
||||
*intr.get(name)))
|
||||
}
|
||||
}
|
||||
|
||||
fn class_dtor(cdata: cmd, id: ast::node_id) -> Option<ast::def_id> {
|
||||
fn struct_dtor(cdata: cmd, id: ast::node_id) -> Option<ast::def_id> {
|
||||
let items = reader::get_doc(reader::Doc(cdata.data), tag_items);
|
||||
let mut found = None;
|
||||
let cls_items = match maybe_find_item(id, items) {
|
||||
Some(it) => it,
|
||||
None => fail (fmt!("class_dtor: class id not found \
|
||||
None => fail (fmt!("struct_dtor: class id not found \
|
||||
when looking up dtor for %d", id))
|
||||
};
|
||||
for reader::tagged_docs(cls_items, tag_item_dtor) |doc| {
|
||||
@ -905,25 +882,6 @@ fn get_item_attrs(cdata: cmd,
|
||||
}
|
||||
}
|
||||
|
||||
// Helper function that gets either fields or methods
|
||||
fn get_class_members(intr: @ident_interner, cdata: cmd, id: ast::node_id,
|
||||
p: fn(Family) -> bool) -> ~[ty::field_ty] {
|
||||
let data = cdata.data;
|
||||
let item = lookup_item(id, data);
|
||||
let mut result = ~[];
|
||||
for reader::tagged_docs(item, tag_item_field) |an_item| {
|
||||
let f = item_family(an_item);
|
||||
if p(f) {
|
||||
let name = item_name(intr, an_item);
|
||||
let did = item_def_id(an_item, cdata);
|
||||
let mt = field_mutability(an_item);
|
||||
result.push({ident: name, id: did, vis:
|
||||
family_to_visibility(f), mutability: mt});
|
||||
}
|
||||
}
|
||||
result
|
||||
}
|
||||
|
||||
pure fn family_to_visibility(family: Family) -> ast::visibility {
|
||||
match family {
|
||||
PublicField => ast::public,
|
||||
@ -933,10 +891,22 @@ pure fn family_to_visibility(family: Family) -> ast::visibility {
|
||||
}
|
||||
}
|
||||
|
||||
fn get_class_fields(intr: @ident_interner, cdata: cmd, id: ast::node_id)
|
||||
fn get_struct_fields(intr: @ident_interner, cdata: cmd, id: ast::node_id)
|
||||
-> ~[ty::field_ty] {
|
||||
get_class_members(intr, cdata, id, |f| f == PublicField
|
||||
|| f == PrivateField || f == InheritedField)
|
||||
let data = cdata.data;
|
||||
let item = lookup_item(id, data);
|
||||
let mut result = ~[];
|
||||
for reader::tagged_docs(item, tag_item_field) |an_item| {
|
||||
let f = item_family(an_item);
|
||||
if f == PublicField || f == PrivateField || f == InheritedField {
|
||||
let name = item_name(intr, an_item);
|
||||
let did = item_def_id(an_item, cdata);
|
||||
let mt = field_mutability(an_item);
|
||||
result.push({ident: name, id: did, vis:
|
||||
family_to_visibility(f), mutability: mt});
|
||||
}
|
||||
}
|
||||
result
|
||||
}
|
||||
|
||||
fn family_has_type_params(fam: Family) -> bool {
|
||||
|
@ -120,11 +120,11 @@ fn encode_region_param(ecx: @encode_ctxt, ebml_w: writer::Serializer,
|
||||
}
|
||||
}
|
||||
|
||||
fn encode_mutability(ebml_w: writer::Serializer, mt: class_mutability) {
|
||||
do ebml_w.wr_tag(tag_class_mut) {
|
||||
fn encode_mutability(ebml_w: writer::Serializer, mt: struct_mutability) {
|
||||
do ebml_w.wr_tag(tag_struct_mut) {
|
||||
let val = match mt {
|
||||
class_immutable => 'a',
|
||||
class_mutable => 'm'
|
||||
struct_immutable => 'a',
|
||||
struct_mutable => 'm'
|
||||
};
|
||||
ebml_w.writer.write(&[val as u8]);
|
||||
}
|
||||
@ -318,7 +318,7 @@ fn encode_info_for_mod(ecx: @encode_ctxt, ebml_w: writer::Serializer,
|
||||
// Encode info about all the module children.
|
||||
for md.items.each |item| {
|
||||
match item.node {
|
||||
item_impl(*) | item_class(*) => {
|
||||
item_impl(*) | item_struct(*) => {
|
||||
let (ident, did) = (item.ident, item.id);
|
||||
debug!("(encoding info for module) ... encoding impl %s \
|
||||
(%?/%?), exported? %?",
|
||||
@ -412,11 +412,9 @@ fn encode_method_sort(ebml_w: writer::Serializer, sort: char) {
|
||||
}
|
||||
|
||||
/* Returns an index of items in this class */
|
||||
fn encode_info_for_class(ecx: @encode_ctxt, ebml_w: writer::Serializer,
|
||||
id: node_id, path: ast_map::path,
|
||||
class_tps: ~[ty_param],
|
||||
fn encode_info_for_struct(ecx: @encode_ctxt, ebml_w: writer::Serializer,
|
||||
path: ast_map::path,
|
||||
fields: ~[@struct_field],
|
||||
methods: ~[@method],
|
||||
global_index: @mut~[entry<int>]) -> ~[entry<int>] {
|
||||
/* Each class has its own index, since different classes
|
||||
may have fields with the same name */
|
||||
@ -432,7 +430,7 @@ fn encode_info_for_class(ecx: @encode_ctxt, ebml_w: writer::Serializer,
|
||||
global_index.push({val: id,
|
||||
pos: ebml_w.writer.tell()});
|
||||
ebml_w.start_tag(tag_items_data_item);
|
||||
debug!("encode_info_for_class: doing %s %d",
|
||||
debug!("encode_info_for_struct: doing %s %d",
|
||||
tcx.sess.str_of(nm), id);
|
||||
encode_visibility(ebml_w, vis);
|
||||
encode_name(ecx, ebml_w, nm);
|
||||
@ -445,25 +443,6 @@ fn encode_info_for_class(ecx: @encode_ctxt, ebml_w: writer::Serializer,
|
||||
unnamed_field => {}
|
||||
}
|
||||
}
|
||||
|
||||
for methods.each |m| {
|
||||
match m.vis {
|
||||
public | inherited => {
|
||||
index.push({val: m.id, pos: ebml_w.writer.tell()});
|
||||
global_index.push(
|
||||
{val: m.id, pos: ebml_w.writer.tell()});
|
||||
let impl_path = vec::append_one(path,
|
||||
ast_map::path_name(m.ident));
|
||||
debug!("encode_info_for_class: doing %s %d",
|
||||
ecx.tcx.sess.str_of(m.ident), m.id);
|
||||
encode_info_for_method(ecx, ebml_w, impl_path,
|
||||
should_inline(m.attrs), id, *m,
|
||||
vec::append(class_tps, m.tps));
|
||||
}
|
||||
_ => { /* don't encode private methods */ }
|
||||
}
|
||||
}
|
||||
|
||||
*index
|
||||
}
|
||||
|
||||
@ -556,7 +535,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: writer::Serializer,
|
||||
let must_write =
|
||||
match item.node {
|
||||
item_enum(_, _) | item_impl(*)
|
||||
| item_trait(*) | item_class(*) => true,
|
||||
| item_trait(*) | item_struct(*) => true,
|
||||
_ => false
|
||||
};
|
||||
if !must_write && !reachable(ecx, item.id) { return; }
|
||||
@ -645,14 +624,13 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: writer::Serializer,
|
||||
index,
|
||||
tps);
|
||||
}
|
||||
item_class(struct_def, tps) => {
|
||||
/* First, encode the fields and methods
|
||||
item_struct(struct_def, tps) => {
|
||||
/* First, encode the fields
|
||||
These come first because we need to write them to make
|
||||
the index, and the index needs to be in the item for the
|
||||
class itself */
|
||||
let idx = encode_info_for_class(ecx, ebml_w, item.id, path, tps,
|
||||
struct_def.fields, struct_def.methods,
|
||||
index);
|
||||
let idx = encode_info_for_struct(ecx, ebml_w, path,
|
||||
struct_def.fields, index);
|
||||
/* Encode the dtor */
|
||||
do struct_def.dtor.iter |dtor| {
|
||||
index.push({val: dtor.node.id, pos: ebml_w.writer.tell()});
|
||||
@ -677,9 +655,6 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: writer::Serializer,
|
||||
encode_name(ecx, ebml_w, item.ident);
|
||||
encode_path(ecx, ebml_w, path, ast_map::path_name(item.ident));
|
||||
encode_region_param(ecx, ebml_w, item);
|
||||
for struct_def.traits.each |t| {
|
||||
encode_trait_ref(ebml_w, ecx, *t);
|
||||
}
|
||||
/* Encode the dtor */
|
||||
/* Encode id for dtor */
|
||||
do struct_def.dtor.iter |dtor| {
|
||||
@ -704,28 +679,6 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: writer::Serializer,
|
||||
}
|
||||
}
|
||||
|
||||
for struct_def.methods.each |m| {
|
||||
match m.vis {
|
||||
private => { /* do nothing */ }
|
||||
public | inherited => {
|
||||
/* Write the info that's needed when viewing this class
|
||||
as a trait */
|
||||
ebml_w.start_tag(tag_item_trait_method);
|
||||
encode_family(ebml_w, purity_fn_family(m.purity));
|
||||
encode_name(ecx, ebml_w, m.ident);
|
||||
encode_type_param_bounds(ebml_w, ecx, m.tps);
|
||||
encode_type(ecx, ebml_w, node_id_to_type(tcx, m.id));
|
||||
encode_def_id(ebml_w, local_def(m.id));
|
||||
encode_self_type(ebml_w, m.self_ty.node);
|
||||
ebml_w.end_tag();
|
||||
/* Write the info that's needed when viewing this class
|
||||
as an impl (just the method def_id and self type) */
|
||||
ebml_w.start_tag(tag_item_impl_method);
|
||||
ebml_w.writer.write(to_bytes(def_to_str(local_def(m.id))));
|
||||
ebml_w.end_tag();
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Each class has its own index -- encode it */
|
||||
let bkts = create_index(idx);
|
||||
encode_index(ebml_w, bkts, write_int);
|
||||
|
@ -337,7 +337,7 @@ fn parse_ty(st: @pstate, conv: conv_did) -> ty::t {
|
||||
debug!("parsed a def_id %?", did);
|
||||
let substs = parse_substs(st, conv);
|
||||
assert (next(st) == ']');
|
||||
return ty::mk_class(st.tcx, did, substs);
|
||||
return ty::mk_struct(st.tcx, did, substs);
|
||||
}
|
||||
c => { error!("unexpected char in type string: %c", c); fail;}
|
||||
}
|
||||
|
@ -316,7 +316,7 @@ fn enc_sty(w: io::Writer, cx: @ctxt, st: ty::sty) {
|
||||
enc_proto(w, p);
|
||||
}
|
||||
ty::ty_opaque_box => w.write_char('B'),
|
||||
ty::ty_class(def, ref substs) => {
|
||||
ty::ty_struct(def, ref substs) => {
|
||||
debug!("~~~~ %s", ~"a[");
|
||||
w.write_str(&"a[");
|
||||
let s = (cx.ds)(def);
|
||||
|
@ -372,8 +372,8 @@ impl ast::def: tr {
|
||||
xcx.tr_id(nid2),
|
||||
xcx.tr_id(nid3))
|
||||
}
|
||||
ast::def_class(did) => {
|
||||
ast::def_class(did.tr(xcx))
|
||||
ast::def_struct(did) => {
|
||||
ast::def_struct(did.tr(xcx))
|
||||
}
|
||||
ast::def_region(nid) => ast::def_region(xcx.tr_id(nid)),
|
||||
ast::def_typaram_binder(nid) => {
|
||||
|
@ -305,7 +305,7 @@ fn missing_ctor(cx: @AltCheckCtxt,
|
||||
-> Option<ctor> {
|
||||
match ty::get(left_ty).sty {
|
||||
ty::ty_box(_) | ty::ty_uniq(_) | ty::ty_rptr(*) | ty::ty_tup(_) |
|
||||
ty::ty_rec(_) | ty::ty_class(*) => {
|
||||
ty::ty_rec(_) | ty::ty_struct(*) => {
|
||||
for m.each |r| {
|
||||
if !is_wild(cx, r[0]) { return None; }
|
||||
}
|
||||
@ -362,7 +362,7 @@ fn ctor_arity(cx: @AltCheckCtxt, ctor: ctor, ty: ty::t) -> uint {
|
||||
None => fail ~"impossible case"
|
||||
}
|
||||
}
|
||||
ty::ty_class(cid, _) => ty::lookup_class_fields(cx.tcx, cid).len(),
|
||||
ty::ty_struct(cid, _) => ty::lookup_struct_fields(cx.tcx, cid).len(),
|
||||
_ => 0u
|
||||
}
|
||||
}
|
||||
@ -410,7 +410,7 @@ fn specialize(cx: @AltCheckCtxt, r: ~[@pat], ctor_id: ctor, arity: uint,
|
||||
Some(vec::append(args, vec::tail(r)))
|
||||
}
|
||||
def_variant(_, _) => None,
|
||||
def_class(*) => {
|
||||
def_struct(*) => {
|
||||
// XXX: Is this right? --pcw
|
||||
let new_args;
|
||||
match args {
|
||||
@ -456,9 +456,9 @@ fn specialize(cx: @AltCheckCtxt, r: ~[@pat], ctor_id: ctor, arity: uint,
|
||||
// Grab the class data that we care about.
|
||||
let class_fields, class_id;
|
||||
match ty::get(left_ty).sty {
|
||||
ty::ty_class(cid, _) => {
|
||||
ty::ty_struct(cid, _) => {
|
||||
class_id = cid;
|
||||
class_fields = ty::lookup_class_fields(cx.tcx,
|
||||
class_fields = ty::lookup_struct_fields(cx.tcx,
|
||||
class_id);
|
||||
}
|
||||
_ => {
|
||||
|
@ -106,7 +106,7 @@ fn check_expr(sess: Session, def_map: resolve::DefMap,
|
||||
Some(def_const(def_id)) |
|
||||
Some(def_fn(def_id, _)) |
|
||||
Some(def_variant(_, def_id)) |
|
||||
Some(def_class(def_id)) => {
|
||||
Some(def_struct(def_id)) => {
|
||||
if !ast_util::is_local(def_id) {
|
||||
sess.span_err(
|
||||
e.span, ~"paths in constants may only refer to \
|
||||
@ -128,7 +128,7 @@ fn check_expr(sess: Session, def_map: resolve::DefMap,
|
||||
}
|
||||
expr_call(callee, _, false) => {
|
||||
match def_map.find(callee.id) {
|
||||
Some(def_class(*)) => {} // OK.
|
||||
Some(def_struct(*)) => {} // OK.
|
||||
_ => {
|
||||
sess.span_err(
|
||||
e.span,
|
||||
|
@ -319,8 +319,8 @@ fn check_expr(e: @expr, cx: ctx, v: visit::vt<ctx>) {
|
||||
let t = ty::expr_ty(cx.tcx, ex);
|
||||
let ty_fields = match ty::get(t).sty {
|
||||
ty::ty_rec(f) => f,
|
||||
ty::ty_class(did, ref substs) =>
|
||||
ty::class_items_as_fields(cx.tcx, did, &(*substs)),
|
||||
ty::ty_struct(did, ref substs) =>
|
||||
ty::struct_fields(cx.tcx, did, &(*substs)),
|
||||
_ => cx.tcx.sess.span_bug(ex.span,
|
||||
~"bad base expr type in record")
|
||||
};
|
||||
|
@ -676,7 +676,7 @@ fn check_item_heap(cx: ty::ctxt, it: @ast::item) {
|
||||
ast::item_fn(*) |
|
||||
ast::item_ty(*) |
|
||||
ast::item_enum(*) |
|
||||
ast::item_class(*) |
|
||||
ast::item_struct(*) |
|
||||
ast::item_trait(*) => check_type(cx, it.id, it.id, it.span,
|
||||
ty::node_id_to_type(cx, it.id)),
|
||||
_ => ()
|
||||
@ -752,7 +752,7 @@ fn check_item_non_camel_case_types(cx: ty::ctxt, it: @ast::item) {
|
||||
}
|
||||
|
||||
match it.node {
|
||||
ast::item_ty(*) | ast::item_class(*) |
|
||||
ast::item_ty(*) | ast::item_struct(*) |
|
||||
ast::item_trait(*) => {
|
||||
check_case(cx, it.ident, it.id, it.id, it.span)
|
||||
}
|
||||
|
@ -564,7 +564,7 @@ impl &mem_categorization_ctxt {
|
||||
ast::def_foreign_mod(_) | ast::def_const(_) |
|
||||
ast::def_use(_) | ast::def_variant(*) |
|
||||
ast::def_ty(_) | ast::def_prim_ty(_) |
|
||||
ast::def_ty_param(*) | ast::def_class(*) |
|
||||
ast::def_ty_param(*) | ast::def_struct(*) |
|
||||
ast::def_typaram_binder(*) | ast::def_region(_) |
|
||||
ast::def_label(_) => {
|
||||
@{id:id, span:span,
|
||||
@ -913,7 +913,7 @@ impl &mem_categorization_ctxt {
|
||||
self.cat_pattern(subcmt, *subpat, op);
|
||||
}
|
||||
}
|
||||
Some(ast::def_class(*)) => {
|
||||
Some(ast::def_struct(*)) => {
|
||||
for subpats.each |subpat| {
|
||||
let cmt_field = self.cat_anon_struct_field(*subpat,
|
||||
cmt);
|
||||
@ -1104,12 +1104,12 @@ fn field_mutbl(tcx: ty::ctxt,
|
||||
}
|
||||
}
|
||||
}
|
||||
ty::ty_class(did, _) => {
|
||||
for ty::lookup_class_fields(tcx, did).each |fld| {
|
||||
ty::ty_struct(did, _) => {
|
||||
for ty::lookup_struct_fields(tcx, did).each |fld| {
|
||||
if fld.ident == f_name {
|
||||
let m = match fld.mutability {
|
||||
ast::class_mutable => ast::m_mutbl,
|
||||
ast::class_immutable => ast::m_imm
|
||||
ast::struct_mutable => ast::m_mutbl,
|
||||
ast::struct_immutable => ast::m_imm
|
||||
};
|
||||
return Some(m);
|
||||
}
|
||||
@ -1118,11 +1118,11 @@ fn field_mutbl(tcx: ty::ctxt,
|
||||
ty::ty_enum(*) => {
|
||||
match tcx.def_map.get(node_id) {
|
||||
ast::def_variant(_, variant_id) => {
|
||||
for ty::lookup_class_fields(tcx, variant_id).each |fld| {
|
||||
for ty::lookup_struct_fields(tcx, variant_id).each |fld| {
|
||||
if fld.ident == f_name {
|
||||
let m = match fld.mutability {
|
||||
ast::class_mutable => ast::m_mutbl,
|
||||
ast::class_immutable => ast::m_imm
|
||||
ast::struct_mutable => ast::m_mutbl,
|
||||
ast::struct_immutable => ast::m_imm
|
||||
};
|
||||
return Some(m);
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ fn pat_is_variant_or_struct(dm: resolve::DefMap, pat: @pat) -> bool {
|
||||
match pat.node {
|
||||
pat_enum(_, _) | pat_ident(_, _, None) | pat_struct(*) => {
|
||||
match dm.find(pat.id) {
|
||||
Some(def_variant(*)) | Some(def_class(*)) => true,
|
||||
Some(def_variant(*)) | Some(def_struct(*)) => true,
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
|
@ -15,13 +15,13 @@ use /*mod*/ syntax::ast;
|
||||
use /*mod*/ syntax::visit;
|
||||
use syntax::ast_map;
|
||||
use syntax::ast::{def_variant, expr_field, expr_method_call, expr_struct};
|
||||
use syntax::ast::{expr_unary, ident, item_class, item_enum, item_impl};
|
||||
use syntax::ast::{expr_unary, ident, item_struct, item_enum, item_impl};
|
||||
use syntax::ast::{item_trait, local_crate, node_id, pat_struct, private};
|
||||
use syntax::ast::{provided, required};
|
||||
use syntax::ast_map::{node_item, node_method};
|
||||
use syntax::ast_util::{Private, Public, has_legacy_export_attr, is_local};
|
||||
use syntax::ast_util::{visibility_to_privacy};
|
||||
use ty::{ty_class, ty_enum};
|
||||
use ty::{ty_struct, ty_enum};
|
||||
use typeck::{method_map, method_origin, method_param, method_self};
|
||||
use typeck::{method_static, method_trait};
|
||||
|
||||
@ -37,7 +37,7 @@ fn check_crate(tcx: ty::ctxt, method_map: &method_map, crate: @ast::crate) {
|
||||
let mut count = 0;
|
||||
for items.each |item| {
|
||||
match item.node {
|
||||
item_class(*) | item_trait(*) | item_impl(*)
|
||||
item_struct(*) | item_trait(*) | item_impl(*)
|
||||
| item_enum(*) => {
|
||||
privileged_items.push(item.id);
|
||||
count += 1;
|
||||
@ -78,7 +78,7 @@ fn check_crate(tcx: ty::ctxt, method_map: &method_map, crate: @ast::crate) {
|
||||
|
||||
// Checks that a private field is in scope.
|
||||
let check_field = |span, id, ident| {
|
||||
let fields = ty::lookup_class_fields(tcx, id);
|
||||
let fields = ty::lookup_struct_fields(tcx, id);
|
||||
for fields.each |field| {
|
||||
if field.ident != ident { loop; }
|
||||
if field.vis == private {
|
||||
@ -200,7 +200,7 @@ fn check_crate(tcx: ty::ctxt, method_map: &method_map, crate: @ast::crate) {
|
||||
match expr.node {
|
||||
expr_field(base, ident, _) => {
|
||||
match ty::get(ty::expr_ty(tcx, base)).sty {
|
||||
ty_class(id, _)
|
||||
ty_struct(id, _)
|
||||
if id.crate != local_crate ||
|
||||
!privileged_items.contains(&(id.node)) => {
|
||||
match method_map.find(expr.id) {
|
||||
@ -221,7 +221,7 @@ fn check_crate(tcx: ty::ctxt, method_map: &method_map, crate: @ast::crate) {
|
||||
}
|
||||
expr_method_call(base, _, _, _, _) => {
|
||||
match ty::get(ty::expr_ty(tcx, base)).sty {
|
||||
ty_class(id, _)
|
||||
ty_struct(id, _)
|
||||
if id.crate != local_crate ||
|
||||
!privileged_items.contains(&(id.node)) => {
|
||||
match method_map.find(expr.id) {
|
||||
@ -242,7 +242,7 @@ fn check_crate(tcx: ty::ctxt, method_map: &method_map, crate: @ast::crate) {
|
||||
}
|
||||
expr_struct(_, ref fields, _) => {
|
||||
match ty::get(ty::expr_ty(tcx, expr)).sty {
|
||||
ty_class(id, _) => {
|
||||
ty_struct(id, _) => {
|
||||
if id.crate != local_crate ||
|
||||
!privileged_items.contains(&(id.node)) {
|
||||
for (*fields).each |field| {
|
||||
@ -308,7 +308,7 @@ fn check_crate(tcx: ty::ctxt, method_map: &method_map, crate: @ast::crate) {
|
||||
match pattern.node {
|
||||
pat_struct(_, fields, _) => {
|
||||
match ty::get(ty::pat_ty(tcx, pattern)).sty {
|
||||
ty_class(id, _) => {
|
||||
ty_struct(id, _) => {
|
||||
if id.crate != local_crate ||
|
||||
!privileged_items.contains(&(id.node)) {
|
||||
for fields.each |field| {
|
||||
|
@ -666,7 +666,7 @@ fn determine_rp_in_ty(ty: @ast::Ty,
|
||||
match ty.node {
|
||||
ast::ty_path(path, id) => {
|
||||
match cx.def_map.find(id) {
|
||||
Some(ast::def_ty(did)) | Some(ast::def_class(did)) => {
|
||||
Some(ast::def_ty(did)) | Some(ast::def_struct(did)) => {
|
||||
if did.crate == ast::local_crate {
|
||||
if cx.opt_region_is_relevant(path.rp) {
|
||||
cx.add_dep(did.node);
|
||||
@ -749,12 +749,12 @@ fn determine_rp_in_struct_field(cm: @ast::struct_field,
|
||||
&&cx: determine_rp_ctxt,
|
||||
visitor: visit::vt<determine_rp_ctxt>) {
|
||||
match cm.node.kind {
|
||||
ast::named_field(_, ast::class_mutable, _) => {
|
||||
ast::named_field(_, ast::struct_mutable, _) => {
|
||||
do cx.with_ambient_variance(rv_invariant) {
|
||||
visit::visit_struct_field(cm, cx, visitor);
|
||||
}
|
||||
}
|
||||
ast::named_field(_, ast::class_immutable, _) |
|
||||
ast::named_field(_, ast::struct_immutable, _) |
|
||||
ast::unnamed_field => {
|
||||
visit::visit_struct_field(cm, cx, visitor);
|
||||
}
|
||||
|
@ -18,9 +18,9 @@ use middle::lint::{deny, allow, forbid, level, unused_imports, warn};
|
||||
use middle::pat_util::{pat_bindings};
|
||||
use syntax::ast::{_mod, add, arm};
|
||||
use syntax::ast::{bitand, bitor, bitxor};
|
||||
use syntax::ast::{binding_mode, blk, capture_clause, class_ctor, class_dtor};
|
||||
use syntax::ast::{binding_mode, blk, capture_clause, struct_dtor};
|
||||
use syntax::ast::{crate, crate_num, decl_item};
|
||||
use syntax::ast::{def, def_arg, def_binding, def_class, def_const, def_fn};
|
||||
use syntax::ast::{def, def_arg, def_binding, def_struct, def_const, def_fn};
|
||||
use syntax::ast::{def_foreign_mod, def_id, def_label, def_local, def_mod};
|
||||
use syntax::ast::{def_prim_ty, def_region, def_self, def_ty, def_ty_param};
|
||||
use syntax::ast::{def_typaram_binder, def_static_method};
|
||||
@ -33,7 +33,7 @@ use syntax::ast::{enum_variant_kind, expr, expr_again, expr_assign_op};
|
||||
use syntax::ast::{expr_fn_block, expr_index, expr_loop};
|
||||
use syntax::ast::{expr_path, expr_struct, expr_unary, fn_decl};
|
||||
use syntax::ast::{foreign_item, foreign_item_const, foreign_item_fn, ge};
|
||||
use syntax::ast::{gt, ident, impure_fn, inherited, item, item_class};
|
||||
use syntax::ast::{gt, ident, impure_fn, inherited, item, item_struct};
|
||||
use syntax::ast::{item_const, item_enum, item_fn, item_foreign_mod};
|
||||
use syntax::ast::{item_impl, item_mac, item_mod, item_trait, item_ty, le};
|
||||
use syntax::ast::{local, local_crate, lt, method, mode, module_ns, mul, ne};
|
||||
@ -281,8 +281,8 @@ enum RibKind {
|
||||
// upvars as appropriate.
|
||||
FunctionRibKind(node_id /* func id */, node_id /* body id */),
|
||||
|
||||
// We passed through a class, impl, or trait and are now in one of its
|
||||
// methods. Allow references to ty params that that class, impl or trait
|
||||
// We passed through an impl or trait and are now in one of its
|
||||
// methods. Allow references to ty params that that impl or trait
|
||||
// binds. Disallow any other upvars (including other ty params that are
|
||||
// upvars).
|
||||
// parent; method itself
|
||||
@ -1183,7 +1183,7 @@ impl Resolver {
|
||||
}
|
||||
|
||||
// These items live in both the type and value namespaces.
|
||||
item_class(struct_def, _) => {
|
||||
item_struct(struct_def, _) => {
|
||||
let (name_bindings, new_parent) =
|
||||
self.add_child(ident, parent, ForbidDuplicateTypes, sp);
|
||||
|
||||
@ -1197,7 +1197,7 @@ impl Resolver {
|
||||
Some(ctor_id) => {
|
||||
name_bindings.define_value(
|
||||
privacy,
|
||||
def_class(local_def(ctor_id)),
|
||||
def_struct(local_def(ctor_id)),
|
||||
sp);
|
||||
}
|
||||
}
|
||||
@ -1733,7 +1733,7 @@ impl Resolver {
|
||||
|
||||
child_name_bindings.define_type(Public, def, dummy_sp());
|
||||
}
|
||||
def_class(def_id) => {
|
||||
def_struct(def_id) => {
|
||||
debug!("(building reduced graph for external \
|
||||
crate) building type %s",
|
||||
final_ident);
|
||||
@ -3662,12 +3662,10 @@ impl Resolver {
|
||||
(*self.type_ribs).pop();
|
||||
}
|
||||
|
||||
item_class(struct_def, ty_params) => {
|
||||
self.resolve_class(item.id,
|
||||
item_struct(struct_def, ty_params) => {
|
||||
self.resolve_struct(item.id,
|
||||
@copy ty_params,
|
||||
struct_def.traits,
|
||||
struct_def.fields,
|
||||
struct_def.methods,
|
||||
struct_def.dtor,
|
||||
visitor);
|
||||
}
|
||||
@ -3905,15 +3903,12 @@ impl Resolver {
|
||||
}
|
||||
}
|
||||
|
||||
fn resolve_class(id: node_id,
|
||||
fn resolve_struct(id: node_id,
|
||||
type_parameters: @~[ty_param],
|
||||
traits: ~[@trait_ref],
|
||||
fields: ~[@struct_field],
|
||||
methods: ~[@method],
|
||||
optional_destructor: Option<class_dtor>,
|
||||
optional_destructor: Option<struct_dtor>,
|
||||
visitor: ResolveVisitor) {
|
||||
// If applicable, create a rib for the type parameters.
|
||||
let outer_type_parameter_count = (*type_parameters).len();
|
||||
let borrowed_type_parameters: &~[ty_param] = &*type_parameters;
|
||||
do self.with_type_parameter_rib(HasTypeParameters
|
||||
(borrowed_type_parameters, id, 0,
|
||||
@ -3922,39 +3917,6 @@ impl Resolver {
|
||||
// Resolve the type parameters.
|
||||
self.resolve_type_parameters(*type_parameters, visitor);
|
||||
|
||||
// Resolve implemented traits.
|
||||
for traits.each |trt| {
|
||||
match self.resolve_path(trt.path, TypeNS, true, visitor) {
|
||||
None => {
|
||||
self.session.span_err(trt.path.span,
|
||||
~"attempt to implement a \
|
||||
nonexistent trait");
|
||||
}
|
||||
Some(def) => {
|
||||
// Write a mapping from the trait ID to the
|
||||
// definition of the trait into the definition
|
||||
// map.
|
||||
|
||||
debug!("(resolving class) found trait def: %?", def);
|
||||
|
||||
self.record_def(trt.ref_id, def);
|
||||
|
||||
// XXX: This is wrong but is needed for tests to
|
||||
// pass.
|
||||
|
||||
self.record_def(id, def);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Resolve methods.
|
||||
for methods.each |method| {
|
||||
self.resolve_method(MethodRibKind(id, Provided(method.id)),
|
||||
*method,
|
||||
outer_type_parameter_count,
|
||||
visitor);
|
||||
}
|
||||
|
||||
// Resolve fields.
|
||||
for fields.each |field| {
|
||||
self.resolve_type(field.node.ty, visitor);
|
||||
@ -4416,7 +4378,7 @@ impl Resolver {
|
||||
// These two must be enum variants or structs.
|
||||
match self.resolve_path(path, ValueNS, false, visitor) {
|
||||
Some(def @ def_variant(*)) |
|
||||
Some(def @ def_class(*)) => {
|
||||
Some(def @ def_struct(*)) => {
|
||||
self.record_def(pattern.id, def);
|
||||
}
|
||||
Some(_) => {
|
||||
@ -4451,10 +4413,10 @@ impl Resolver {
|
||||
match self.resolve_path(path, TypeNS, false, visitor) {
|
||||
Some(def_ty(class_id))
|
||||
if self.structs.contains_key(class_id) => {
|
||||
let class_def = def_class(class_id);
|
||||
let class_def = def_struct(class_id);
|
||||
self.record_def(pattern.id, class_def);
|
||||
}
|
||||
Some(definition @ def_class(class_id))
|
||||
Some(definition @ def_struct(class_id))
|
||||
if self.structs.contains_key(class_id) => {
|
||||
self.record_def(pattern.id, definition);
|
||||
}
|
||||
@ -4495,7 +4457,7 @@ impl Resolver {
|
||||
}
|
||||
Some(def) => {
|
||||
match def.def {
|
||||
def @ def_variant(*) | def @ def_class(*) => {
|
||||
def @ def_variant(*) | def @ def_struct(*) => {
|
||||
return FoundStructOrEnumVariant(def);
|
||||
}
|
||||
def @ def_const(*) => {
|
||||
@ -4811,7 +4773,7 @@ impl Resolver {
|
||||
}
|
||||
}
|
||||
|
||||
fn name_exists_in_scope_class(name: &str) -> bool {
|
||||
fn name_exists_in_scope_struct(name: &str) -> bool {
|
||||
let mut i = self.type_ribs.len();
|
||||
while i != 0 {
|
||||
i -= 1;
|
||||
@ -4821,7 +4783,7 @@ impl Resolver {
|
||||
for vec::each(self.crate.node.module.items) |item| {
|
||||
if item.id == node_id {
|
||||
match item.node {
|
||||
item_class(class_def, _) => {
|
||||
item_struct(class_def, _) => {
|
||||
for vec::each(class_def.fields) |field| {
|
||||
match field.node.kind {
|
||||
syntax::ast::unnamed_field
|
||||
@ -4835,12 +4797,6 @@ impl Resolver {
|
||||
}
|
||||
}
|
||||
}
|
||||
for vec::each(class_def.methods) |method| {
|
||||
if str::eq_slice(self.session.str_of(method.ident),
|
||||
name) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
@ -4879,7 +4835,7 @@ impl Resolver {
|
||||
let wrong_name =
|
||||
connect(path.idents.map(
|
||||
|x| self.session.str_of(*x)), ~"::") ;
|
||||
if self.name_exists_in_scope_class(wrong_name) {
|
||||
if self.name_exists_in_scope_struct(wrong_name) {
|
||||
self.session.span_err(expr.span,
|
||||
fmt!("unresolved name: `%s`. \
|
||||
Did you mean: `self.%s`?",
|
||||
@ -4925,9 +4881,9 @@ impl Resolver {
|
||||
// let bar = Bar { ... } // no type parameters
|
||||
|
||||
match self.resolve_path(path, TypeNS, false, visitor) {
|
||||
Some(def_ty(class_id)) | Some(def_class(class_id))
|
||||
Some(def_ty(class_id)) | Some(def_struct(class_id))
|
||||
if self.structs.contains_key(class_id) => {
|
||||
let class_def = def_class(class_id);
|
||||
let class_def = def_struct(class_id);
|
||||
self.record_def(expr.id, class_def);
|
||||
}
|
||||
Some(definition @ def_variant(_, class_id))
|
||||
|
@ -269,7 +269,7 @@ fn variant_opt(tcx: ty::ctxt, pat_id: ast::node_id) -> Opt {
|
||||
}
|
||||
core::util::unreachable();
|
||||
}
|
||||
ast::def_class(_) => {
|
||||
ast::def_struct(_) => {
|
||||
return lit(UnitLikeStructLit(pat_id));
|
||||
}
|
||||
_ => {
|
||||
@ -531,11 +531,13 @@ fn enter_opt(bcx: block, m: &[@Match/&r], opt: &Opt, col: uint,
|
||||
// specified in the struct definition. Also fill in
|
||||
// unspecified fields with dummy.
|
||||
let reordered_patterns = dvec::DVec();
|
||||
for ty::lookup_class_fields(tcx, struct_id).each |field| {
|
||||
match field_pats.find(|p| p.ident == field.ident) {
|
||||
None => reordered_patterns.push(dummy),
|
||||
Some(fp) => reordered_patterns.push(fp.pat)
|
||||
}
|
||||
for ty::lookup_struct_fields(tcx, struct_id).each
|
||||
|field| {
|
||||
match field_pats.find(|p|
|
||||
p.ident == field.ident) {
|
||||
None => reordered_patterns.push(dummy),
|
||||
Some(fp) => reordered_patterns.push(fp.pat)
|
||||
}
|
||||
}
|
||||
Some(dvec::unwrap(move reordered_patterns))
|
||||
} else {
|
||||
@ -727,7 +729,7 @@ fn get_options(ccx: @crate_ctxt, m: &[@Match], col: uint) -> ~[Opt] {
|
||||
add_to_set(ccx.tcx, &found,
|
||||
variant_opt(ccx.tcx, cur.id));
|
||||
}
|
||||
Some(ast::def_class(*)) => {
|
||||
Some(ast::def_struct(*)) => {
|
||||
add_to_set(ccx.tcx, &found,
|
||||
lit(UnitLikeStructLit(cur.id)));
|
||||
}
|
||||
@ -796,7 +798,7 @@ fn collect_record_or_struct_fields(bcx: block, m: &[@Match], col: uint) ->
|
||||
ast::pat_rec(fs, _) => extend(&mut fields, fs),
|
||||
ast::pat_struct(_, fs, _) => {
|
||||
match ty::get(node_id_type(bcx, br.pats[col].id)).sty {
|
||||
ty::ty_class(*) => extend(&mut fields, fs),
|
||||
ty::ty_struct(*) => extend(&mut fields, fs),
|
||||
_ => ()
|
||||
}
|
||||
}
|
||||
@ -874,7 +876,7 @@ fn any_tuple_struct_pat(bcx: block, m: &[@Match], col: uint) -> bool {
|
||||
match pat.node {
|
||||
ast::pat_enum(_, Some(_)) => {
|
||||
match bcx.tcx().def_map.find(pat.id) {
|
||||
Some(ast::def_class(*)) => true,
|
||||
Some(ast::def_struct(*)) => true,
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
@ -1182,9 +1184,9 @@ fn compile_submatch(bcx: block,
|
||||
let struct_ty = node_id_type(bcx, pat_id);
|
||||
let struct_element_count;
|
||||
match ty::get(struct_ty).sty {
|
||||
ty::ty_class(struct_id, _) => {
|
||||
ty::ty_struct(struct_id, _) => {
|
||||
struct_element_count =
|
||||
ty::lookup_class_fields(tcx, struct_id).len();
|
||||
ty::lookup_struct_fields(tcx, struct_id).len();
|
||||
}
|
||||
_ => {
|
||||
ccx.sess.bug(~"non-struct type in tuple struct pattern");
|
||||
@ -1562,7 +1564,7 @@ fn bind_irrefutable_pat(bcx: block,
|
||||
}
|
||||
}
|
||||
}
|
||||
Some(ast::def_class(*)) => {
|
||||
Some(ast::def_struct(*)) => {
|
||||
match sub_pats {
|
||||
None => {
|
||||
// This is a unit-like struct. Nothing to do here.
|
||||
|
@ -557,7 +557,7 @@ fn iter_structural_ty(cx: block, av: ValueRef, t: ty::t,
|
||||
*/
|
||||
let mut cx = cx;
|
||||
match ty::get(t).sty {
|
||||
ty::ty_rec(*) | ty::ty_class(*) => {
|
||||
ty::ty_rec(*) | ty::ty_struct(*) => {
|
||||
do expr::with_field_tys(cx.tcx(), t, None) |_has_dtor, field_tys| {
|
||||
for vec::eachi(field_tys) |i, field_ty| {
|
||||
let llfld_a = GEPi(cx, av, struct_field(i));
|
||||
@ -1776,7 +1776,7 @@ fn trans_tuple_struct(ccx: @crate_ctxt,
|
||||
finish_fn(fcx, lltop);
|
||||
}
|
||||
|
||||
fn trans_class_dtor(ccx: @crate_ctxt, path: path,
|
||||
fn trans_struct_dtor(ccx: @crate_ctxt, path: path,
|
||||
body: ast::blk, dtor_id: ast::node_id,
|
||||
psubsts: Option<param_substs>,
|
||||
hash_id: Option<mono_id>, parent_id: ast::def_id)
|
||||
@ -1829,7 +1829,7 @@ fn trans_enum_def(ccx: @crate_ctxt, enum_definition: ast::enum_def,
|
||||
}
|
||||
ast::struct_variant_kind(struct_def) => {
|
||||
trans_struct_def(ccx, struct_def, tps, path,
|
||||
variant.node.name, variant.node.id);
|
||||
variant.node.id);
|
||||
}
|
||||
ast::enum_variant_kind(ref enum_definition) => {
|
||||
trans_enum_def(ccx,
|
||||
@ -1905,8 +1905,8 @@ fn trans_item(ccx: @crate_ctxt, item: ast::item) {
|
||||
};
|
||||
foreign::trans_foreign_mod(ccx, foreign_mod, abi);
|
||||
}
|
||||
ast::item_class(struct_def, tps) => {
|
||||
trans_struct_def(ccx, struct_def, tps, path, item.ident, item.id);
|
||||
ast::item_struct(struct_def, tps) => {
|
||||
trans_struct_def(ccx, struct_def, tps, path, item.id);
|
||||
}
|
||||
_ => {/* fall through */ }
|
||||
}
|
||||
@ -1914,13 +1914,13 @@ fn trans_item(ccx: @crate_ctxt, item: ast::item) {
|
||||
|
||||
fn trans_struct_def(ccx: @crate_ctxt, struct_def: @ast::struct_def,
|
||||
tps: ~[ast::ty_param], path: @ast_map::path,
|
||||
ident: ast::ident, id: ast::node_id) {
|
||||
id: ast::node_id) {
|
||||
// If there are type parameters, the destructor and constructor will be
|
||||
// monomorphized, so we don't translate them here.
|
||||
if tps.len() == 0u {
|
||||
// Translate the destructor.
|
||||
do option::iter(&struct_def.dtor) |dtor| {
|
||||
trans_class_dtor(ccx, *path, dtor.node.body,
|
||||
trans_struct_dtor(ccx, *path, dtor.node.body,
|
||||
dtor.node.id, None, None, local_def(id));
|
||||
};
|
||||
|
||||
@ -1936,9 +1936,6 @@ fn trans_struct_def(ccx: @crate_ctxt, struct_def: @ast::struct_def,
|
||||
Some(_) | None => {}
|
||||
}
|
||||
}
|
||||
|
||||
// Translate methods.
|
||||
meth::trans_impl(ccx, *path, ident, struct_def.methods, tps, None, id);
|
||||
}
|
||||
|
||||
// Translate a module. Doing this amounts to translating the items in the
|
||||
|
@ -100,7 +100,7 @@ fn trans(bcx: block, expr: @ast::expr) -> Callee {
|
||||
vid).args.len() > 0u;
|
||||
fn_callee(bcx, trans_fn_ref(bcx, vid, ref_expr.id))
|
||||
}
|
||||
ast::def_class(def_id) => {
|
||||
ast::def_struct(def_id) => {
|
||||
fn_callee(bcx, trans_fn_ref(bcx, def_id, ref_expr.id))
|
||||
}
|
||||
ast::def_arg(*) |
|
||||
|
@ -420,7 +420,7 @@ fn const_expr(cx: @crate_ctxt, e: @ast::expr) -> ValueRef {
|
||||
|
||||
C_named_struct(llty, ~[ lldiscrim, C_null(llstructtys[1]) ])
|
||||
}
|
||||
Some(ast::def_class(_)) => {
|
||||
Some(ast::def_struct(_)) => {
|
||||
let ety = ty::expr_ty(cx.tcx, e);
|
||||
let llty = type_of::type_of(cx, ety);
|
||||
C_null(llty)
|
||||
@ -433,7 +433,7 @@ fn const_expr(cx: @crate_ctxt, e: @ast::expr) -> ValueRef {
|
||||
}
|
||||
ast::expr_call(callee, args, _) => {
|
||||
match cx.tcx.def_map.find(callee.id) {
|
||||
Some(ast::def_class(def_id)) => {
|
||||
Some(ast::def_struct(def_id)) => {
|
||||
let ety = ty::expr_ty(cx.tcx, e);
|
||||
let llty = type_of::type_of(cx, ety);
|
||||
let llstructbody = C_struct(args.map(|a| const_expr(cx, *a)));
|
||||
|
@ -665,9 +665,9 @@ impl Datum {
|
||||
}
|
||||
};
|
||||
}
|
||||
ty::ty_class(did, ref substs) => {
|
||||
ty::ty_struct(did, ref substs) => {
|
||||
// Check whether this struct is a newtype struct.
|
||||
let fields = ty::class_items_as_fields(ccx.tcx, did, substs);
|
||||
let fields = ty::struct_fields(ccx.tcx, did, substs);
|
||||
if fields.len() != 1 || fields[0].ident !=
|
||||
syntax::parse::token::special_idents::unnamed_field {
|
||||
return None;
|
||||
|
@ -102,7 +102,7 @@ pub fn trans_deriving_impl(ccx: @crate_ctxt,
|
||||
derived_method_info.method_info.self_type);
|
||||
|
||||
match ty::get(self_ty.ty).sty {
|
||||
ty::ty_class(*) => {
|
||||
ty::ty_struct(*) => {
|
||||
trans_deriving_struct_method(ccx,
|
||||
llfn,
|
||||
impl_def_id,
|
||||
@ -175,8 +175,8 @@ fn trans_deriving_struct_method(ccx: @crate_ctxt,
|
||||
|
||||
let struct_field_tys;
|
||||
match ty::get(self_ty).sty {
|
||||
ty::ty_class(struct_id, ref struct_substs) => {
|
||||
struct_field_tys = ty::class_items_as_fields(
|
||||
ty::ty_struct(struct_id, ref struct_substs) => {
|
||||
struct_field_tys = ty::struct_fields(
|
||||
ccx.tcx, struct_id, struct_substs);
|
||||
}
|
||||
_ => {
|
||||
|
@ -111,7 +111,7 @@ lvalues are *never* stored by value.
|
||||
|
||||
*/
|
||||
|
||||
use ty::class_items_as_mutable_fields;
|
||||
use ty::struct_mutable_fields;
|
||||
use lib::llvm::ValueRef;
|
||||
use common::*;
|
||||
use datum::*;
|
||||
@ -695,7 +695,7 @@ fn trans_def_dps_unadjusted(bcx: block, ref_expr: @ast::expr,
|
||||
return bcx;
|
||||
}
|
||||
}
|
||||
ast::def_class(*) => {
|
||||
ast::def_struct(*) => {
|
||||
// Nothing to do here.
|
||||
// XXX: May not be true in the case of classes with destructors.
|
||||
return bcx;
|
||||
@ -926,9 +926,9 @@ fn with_field_tys<R>(tcx: ty::ctxt,
|
||||
op(false, *fields)
|
||||
}
|
||||
|
||||
ty::ty_class(did, ref substs) => {
|
||||
ty::ty_struct(did, ref substs) => {
|
||||
let has_dtor = ty::ty_dtor(tcx, did).is_present();
|
||||
op(has_dtor, class_items_as_mutable_fields(tcx, did, substs))
|
||||
op(has_dtor, struct_mutable_fields(tcx, did, substs))
|
||||
}
|
||||
|
||||
ty::ty_enum(_, ref substs) => {
|
||||
@ -943,7 +943,7 @@ fn with_field_tys<R>(tcx: ty::ctxt,
|
||||
Some(node_id) => {
|
||||
match tcx.def_map.get(node_id) {
|
||||
ast::def_variant(_, variant_id) => {
|
||||
op(false, class_items_as_mutable_fields(
|
||||
op(false, struct_mutable_fields(
|
||||
tcx, variant_id, substs))
|
||||
}
|
||||
_ => {
|
||||
@ -1103,7 +1103,7 @@ fn trans_rec_or_struct(bcx: block,
|
||||
GEPi(bcx, addr, [0, 0]));
|
||||
GEPi(bcx, addr, [0, 1])
|
||||
};
|
||||
let fields = ty::class_items_as_mutable_fields(
|
||||
let fields = ty::struct_mutable_fields(
|
||||
tcx, variant_id, substs);
|
||||
let field_lltys = do fields.map |field| {
|
||||
type_of(bcx.ccx(),
|
||||
|
@ -405,15 +405,15 @@ fn make_free_glue(bcx: block, v: ValueRef, t: ty::t) {
|
||||
ty::ty_opaque_closure_ptr(ck) => {
|
||||
closure::make_opaque_cbox_free_glue(bcx, ck, v)
|
||||
}
|
||||
ty::ty_class(did, ref substs) => {
|
||||
ty::ty_struct(did, ref substs) => {
|
||||
// Call the dtor if there is one
|
||||
match ty::ty_dtor(bcx.tcx(), did) {
|
||||
ty::NoDtor => bcx,
|
||||
ty::LegacyDtor(ref dt_id) => {
|
||||
trans_class_drop(bcx, v, *dt_id, did, substs, false)
|
||||
trans_struct_drop(bcx, v, *dt_id, did, substs, false)
|
||||
}
|
||||
ty::TraitDtor(ref dt_id) => {
|
||||
trans_class_drop(bcx, v, *dt_id, did, substs, true)
|
||||
trans_struct_drop(bcx, v, *dt_id, did, substs, true)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -422,7 +422,7 @@ fn make_free_glue(bcx: block, v: ValueRef, t: ty::t) {
|
||||
build_return(bcx);
|
||||
}
|
||||
|
||||
fn trans_class_drop(bcx: block,
|
||||
fn trans_struct_drop(bcx: block,
|
||||
v0: ValueRef,
|
||||
dtor_did: ast::def_id,
|
||||
class_did: ast::def_id,
|
||||
@ -461,7 +461,7 @@ fn trans_class_drop(bcx: block,
|
||||
|
||||
// Drop the fields
|
||||
let field_tys =
|
||||
ty::class_items_as_mutable_fields(bcx.tcx(), class_did,
|
||||
ty::struct_mutable_fields(bcx.tcx(), class_did,
|
||||
substs);
|
||||
for vec::eachi(field_tys) |i, fld| {
|
||||
let llfld_a = GEPi(bcx, v0, struct_field(i));
|
||||
@ -490,14 +490,14 @@ fn make_drop_glue(bcx: block, v0: ValueRef, t: ty::t) {
|
||||
ty::ty_unboxed_vec(_) => {
|
||||
tvec::make_drop_glue_unboxed(bcx, v0, t)
|
||||
}
|
||||
ty::ty_class(did, ref substs) => {
|
||||
ty::ty_struct(did, ref substs) => {
|
||||
let tcx = bcx.tcx();
|
||||
match ty::ty_dtor(tcx, did) {
|
||||
ty::TraitDtor(dtor) => {
|
||||
trans_class_drop(bcx, v0, dtor, did, substs, true)
|
||||
trans_struct_drop(bcx, v0, dtor, did, substs, true)
|
||||
}
|
||||
ty::LegacyDtor(dtor) => {
|
||||
trans_class_drop(bcx, v0, dtor, did, substs, false)
|
||||
trans_struct_drop(bcx, v0, dtor, did, substs, false)
|
||||
}
|
||||
ty::NoDtor => {
|
||||
// No dtor? Just the default case
|
||||
|
@ -36,14 +36,14 @@ pub fn simplify_type(tcx: ty::ctxt, typ: ty::t) -> ty::t {
|
||||
}
|
||||
// Reduce a class type to a record type in which all the fields are
|
||||
// simplified
|
||||
ty::ty_class(did, ref substs) => {
|
||||
ty::ty_struct(did, ref substs) => {
|
||||
let simpl_fields = (if ty::ty_dtor(tcx, did).is_present() {
|
||||
// remember the drop flag
|
||||
~[{ident: syntax::parse::token::special_idents::dtor,
|
||||
mt: {ty: ty::mk_u8(tcx),
|
||||
mutbl: ast::m_mutbl}}] }
|
||||
else { ~[] }) +
|
||||
do ty::lookup_class_fields(tcx, did).map |f| {
|
||||
do ty::lookup_struct_fields(tcx, did).map |f| {
|
||||
let t = ty::lookup_field_type(tcx, did, f.id, substs);
|
||||
{ident: f.ident,
|
||||
mt: {ty: simplify_type(tcx, t), mutbl: ast::m_const}}
|
||||
|
@ -320,10 +320,6 @@ fn method_with_name(ccx: @crate_ctxt, impl_id: ast::def_id,
|
||||
ast_map::node_item(@{node: ast::item_impl(_, _, _, ms), _}, _) => {
|
||||
method_from_methods(ms, name).get()
|
||||
}
|
||||
ast_map::node_item(@{node:
|
||||
ast::item_class(struct_def, _), _}, _) => {
|
||||
method_from_methods(struct_def.methods, name).get()
|
||||
}
|
||||
_ => fail ~"method_with_name"
|
||||
}
|
||||
} else {
|
||||
@ -365,7 +361,7 @@ fn method_with_name_or_default(ccx: @crate_ctxt, impl_id: ast::def_id,
|
||||
|
||||
fn method_ty_param_count(ccx: @crate_ctxt, m_id: ast::def_id,
|
||||
i_id: ast::def_id) -> uint {
|
||||
debug!("mythod_ty_param_count: m_id: %?, i_id: %?", m_id, i_id);
|
||||
debug!("method_ty_param_count: m_id: %?, i_id: %?", m_id, i_id);
|
||||
if m_id.crate == ast::local_crate {
|
||||
match ccx.tcx.items.find(m_id.node) {
|
||||
Some(ast_map::node_method(m, _, _)) => m.tps.len(),
|
||||
@ -378,10 +374,11 @@ fn method_ty_param_count(ccx: @crate_ctxt, m_id: ast::def_id,
|
||||
None => fail
|
||||
}
|
||||
}
|
||||
Some(ast_map::node_trait_method(@ast::provided(@m), _, _)) => {
|
||||
Some(ast_map::node_trait_method(@ast::provided(@ref m), _, _))
|
||||
=> {
|
||||
m.tps.len()
|
||||
}
|
||||
e => fail fmt!("method_ty_param_count %?", e)
|
||||
copy e => fail fmt!("method_ty_param_count %?", e)
|
||||
}
|
||||
} else {
|
||||
csearch::get_type_param_count(ccx.sess.cstore, m_id) -
|
||||
|
@ -15,7 +15,7 @@ use syntax::ast_map::{path, path_mod, path_name};
|
||||
use base::{trans_item, get_item_val, no_self, self_arg, trans_fn,
|
||||
impl_self, decl_internal_cdecl_fn,
|
||||
set_inline_hint_if_appr, set_inline_hint,
|
||||
trans_enum_variant, trans_class_dtor,
|
||||
trans_enum_variant, trans_struct_dtor,
|
||||
get_insn_ctxt};
|
||||
use syntax::parse::token::special_idents;
|
||||
use type_of::type_of_fn_from_ty;
|
||||
@ -211,7 +211,7 @@ fn monomorphic_fn(ccx: @crate_ctxt,
|
||||
None => ccx.sess.span_bug(dtor.span, ~"Bad self ty in \
|
||||
dtor")
|
||||
};
|
||||
trans_class_dtor(ccx, *pt, dtor.node.body,
|
||||
trans_struct_dtor(ccx, *pt, dtor.node.body,
|
||||
dtor.node.id, psubsts, Some(hash_id), parent_id)
|
||||
}
|
||||
ast_map::node_trait_method(@ast::provided(mth), _, pt) => {
|
||||
|
@ -111,7 +111,7 @@ fn traverse_public_item(cx: ctx, item: @item) {
|
||||
}
|
||||
}
|
||||
}
|
||||
item_class(struct_def, tps) => {
|
||||
item_struct(struct_def, tps) => {
|
||||
do option::iter(&struct_def.dtor) |dtor| {
|
||||
cx.rmap.insert(dtor.node.id, ());
|
||||
if tps.len() > 0u || attr::find_inline_attr(dtor.node.attrs)
|
||||
@ -119,13 +119,6 @@ fn traverse_public_item(cx: ctx, item: @item) {
|
||||
traverse_inline_body(cx, dtor.node.body);
|
||||
}
|
||||
}
|
||||
for vec::each(struct_def.methods) |m| {
|
||||
cx.rmap.insert(m.id, ());
|
||||
if tps.len() > 0 ||
|
||||
attr::find_inline_attr(m.attrs) != attr::ia_none {
|
||||
traverse_inline_body(cx, m.body);
|
||||
}
|
||||
}
|
||||
}
|
||||
item_ty(t, _) => {
|
||||
traverse_ty(t, cx, mk_ty_visitor());
|
||||
@ -217,7 +210,7 @@ fn traverse_all_resources_and_impls(cx: ctx, crate_mod: _mod) {
|
||||
visit_item: |i, cx, v| {
|
||||
visit::visit_item(i, cx, v);
|
||||
match i.node {
|
||||
item_class(struct_def, _) if struct_def.dtor.is_some() => {
|
||||
item_struct(struct_def, _) if struct_def.dtor.is_some() => {
|
||||
traverse_public_item(cx, i);
|
||||
}
|
||||
item_impl(*) => {
|
||||
|
@ -67,9 +67,10 @@ impl reflector {
|
||||
|
||||
fn visit(ty_name: ~str, args: ~[ValueRef]) {
|
||||
let tcx = self.bcx.tcx();
|
||||
let mth_idx = option::get(ty::method_idx(
|
||||
let mth_idx = ty::method_idx(
|
||||
tcx.sess.ident_of(~"visit_" + ty_name),
|
||||
*self.visitor_methods));
|
||||
*self.visitor_methods).expect(fmt!("Couldn't find visit method \
|
||||
for %s", ty_name));
|
||||
let mth_ty = ty::mk_fn(tcx, self.visitor_methods[mth_idx].fty);
|
||||
let v = self.visitor_val;
|
||||
debug!("passing %u args:", vec::len(args));
|
||||
@ -230,12 +231,12 @@ impl reflector {
|
||||
self.visit(~"leave_fn", extra);
|
||||
}
|
||||
|
||||
ty::ty_class(did, ref substs) => {
|
||||
ty::ty_struct(did, ref substs) => {
|
||||
let bcx = self.bcx;
|
||||
let tcx = bcx.ccx().tcx;
|
||||
let fields = ty::class_items_as_fields(tcx, did, substs);
|
||||
let fields = ty::struct_fields(tcx, did, substs);
|
||||
|
||||
do self.bracketed(~"class", ~[self.c_uint(vec::len(fields))]
|
||||
do self.bracketed(~"class", ~[self.c_uint(fields.len())]
|
||||
+ self.c_size_and_align(t)) {
|
||||
for fields.eachi |i, field| {
|
||||
self.visit(~"class_field",
|
||||
|
@ -179,12 +179,12 @@ fn type_of(cx: @crate_ctxt, t: ty::t) -> TypeRef {
|
||||
T_struct(tys)
|
||||
}
|
||||
ty::ty_opaque_closure_ptr(_) => T_opaque_box_ptr(cx),
|
||||
ty::ty_class(did, ref substs) => {
|
||||
ty::ty_struct(did, ref substs) => {
|
||||
// Only create the named struct, but don't fill it in. We fill it
|
||||
// in *after* placing it into the type cache. This prevents
|
||||
// infinite recursion with recursive class types.
|
||||
// infinite recursion with recursive struct types.
|
||||
|
||||
common::T_named_struct(llvm_type_name(cx, a_class, did, substs.tps))
|
||||
common::T_named_struct(llvm_type_name(cx, a_struct, did, substs.tps))
|
||||
}
|
||||
ty::ty_self => cx.tcx.sess.unimpl(~"type_of: ty_self"),
|
||||
ty::ty_infer(*) => cx.tcx.sess.bug(~"type_of with ty_infer"),
|
||||
@ -194,14 +194,14 @@ fn type_of(cx: @crate_ctxt, t: ty::t) -> TypeRef {
|
||||
|
||||
cx.lltypes.insert(t, llty);
|
||||
|
||||
// If this was an enum or class, fill in the type now.
|
||||
// If this was an enum or struct, fill in the type now.
|
||||
match ty::get(t).sty {
|
||||
ty::ty_enum(did, _) => {
|
||||
fill_type_of_enum(cx, did, t, llty);
|
||||
}
|
||||
ty::ty_class(did, ref substs) => {
|
||||
ty::ty_struct(did, ref substs) => {
|
||||
// Only instance vars are record fields at runtime.
|
||||
let fields = ty::lookup_class_fields(cx.tcx, did);
|
||||
let fields = ty::lookup_struct_fields(cx.tcx, did);
|
||||
let mut tys = do vec::map(fields) |f| {
|
||||
let t = ty::lookup_field_type(cx.tcx, did, f.id, substs);
|
||||
type_of(cx, t)
|
||||
@ -244,14 +244,17 @@ fn fill_type_of_enum(cx: @crate_ctxt, did: ast::def_id, t: ty::t,
|
||||
}
|
||||
|
||||
// Want refinements! (Or case classes, I guess
|
||||
enum named_ty { a_class, an_enum }
|
||||
enum named_ty { a_struct, an_enum }
|
||||
|
||||
fn llvm_type_name(cx: @crate_ctxt,
|
||||
what: named_ty,
|
||||
did: ast::def_id,
|
||||
tps: ~[ty::t]
|
||||
) -> ~str {
|
||||
let name = match what { a_class => { "~class" } an_enum => { "~enum" } };
|
||||
let name = match what {
|
||||
a_struct => { "~struct" }
|
||||
an_enum => { "~enum" }
|
||||
};
|
||||
return fmt!(
|
||||
"%s %s[#%d]",
|
||||
name,
|
||||
|
@ -42,7 +42,7 @@ export node_id_to_type_params;
|
||||
export arg;
|
||||
export args_eq;
|
||||
export block_ty;
|
||||
export class_items_as_fields, class_items_as_mutable_fields;
|
||||
export struct_fields, struct_mutable_fields;
|
||||
export ctxt;
|
||||
export deref, deref_sty;
|
||||
export index, index_sty;
|
||||
@ -64,14 +64,13 @@ export get_element_type;
|
||||
export has_dtor;
|
||||
export is_binopable;
|
||||
export is_pred_ty;
|
||||
export lookup_class_field, lookup_class_fields;
|
||||
export lookup_class_method_by_name;
|
||||
export lookup_struct_field, lookup_struct_fields;
|
||||
export lookup_field_type;
|
||||
export lookup_item_type;
|
||||
export lookup_public_fields;
|
||||
export method;
|
||||
export method_idx;
|
||||
export mk_class, mk_err;
|
||||
export mk_struct, mk_err;
|
||||
export mk_ctxt;
|
||||
export mk_with_id, type_def_id;
|
||||
export mt;
|
||||
@ -123,7 +122,7 @@ export ty_infer, mk_infer, type_is_ty_var, mk_var, mk_int_var, mk_float_var;
|
||||
export InferTy, TyVar, IntVar, FloatVar;
|
||||
export ValueMode, ReadValue, CopyValue, MoveValue;
|
||||
export ty_self, mk_self, type_has_self;
|
||||
export ty_class;
|
||||
export ty_struct;
|
||||
export Region, bound_region, encl_region;
|
||||
export re_bound, re_free, re_scope, re_static, re_infer;
|
||||
export ReVar, ReSkolemized;
|
||||
@ -254,7 +253,7 @@ type field_ty = {
|
||||
ident: ident,
|
||||
id: def_id,
|
||||
vis: ast::visibility,
|
||||
mutability: ast::class_mutability
|
||||
mutability: ast::struct_mutability
|
||||
};
|
||||
|
||||
/// How an lvalue is to be used.
|
||||
@ -604,7 +603,7 @@ enum Region {
|
||||
#[auto_serialize]
|
||||
#[auto_deserialize]
|
||||
enum bound_region {
|
||||
/// The self region for classes, impls (&T in a type defn or &self/T)
|
||||
/// The self region for structs, impls (&T in a type defn or &self/T)
|
||||
br_self,
|
||||
|
||||
/// An anonymous region parameter for a given fn (&T)
|
||||
@ -636,7 +635,7 @@ type opt_region = Option<Region>;
|
||||
* according to the order in which they were declared.
|
||||
*
|
||||
* - `self_r` indicates the region parameter `self` that is present on nominal
|
||||
* types (enums, classes) declared as having a region parameter. `self_r`
|
||||
* types (enums, structs) declared as having a region parameter. `self_r`
|
||||
* should always be none for types that are not region-parameterized and
|
||||
* Some(_) for types that are. The only bound region parameter that should
|
||||
* appear within a region-parameterized type is `self`.
|
||||
@ -669,7 +668,7 @@ enum sty {
|
||||
ty_rec(~[field]),
|
||||
ty_fn(FnTy),
|
||||
ty_trait(def_id, substs, vstore),
|
||||
ty_class(def_id, substs),
|
||||
ty_struct(def_id, substs),
|
||||
ty_tup(~[t]),
|
||||
|
||||
ty_param(param_ty), // type parameter
|
||||
@ -1054,7 +1053,7 @@ fn mk_t_with_id(cx: ctxt, +st: sty, o_def_id: Option<ast::def_id>) -> t {
|
||||
ty_param(_) => flags |= has_params as uint,
|
||||
ty_infer(_) => flags |= needs_infer as uint,
|
||||
ty_self => flags |= has_self as uint,
|
||||
ty_enum(_, ref substs) | ty_class(_, ref substs)
|
||||
ty_enum(_, ref substs) | ty_struct(_, ref substs)
|
||||
| ty_trait(_, ref substs, _) => {
|
||||
flags |= sflags(substs);
|
||||
}
|
||||
@ -1187,9 +1186,9 @@ fn mk_trait(cx: ctxt, did: ast::def_id, +substs: substs, vstore: vstore)
|
||||
mk_t(cx, ty_trait(did, substs, vstore))
|
||||
}
|
||||
|
||||
fn mk_class(cx: ctxt, class_id: ast::def_id, +substs: substs) -> t {
|
||||
fn mk_struct(cx: ctxt, struct_id: ast::def_id, +substs: substs) -> t {
|
||||
// take a copy of substs so that we own the vectors inside
|
||||
mk_t(cx, ty_class(class_id, substs))
|
||||
mk_t(cx, ty_struct(struct_id, substs))
|
||||
}
|
||||
|
||||
fn mk_var(cx: ctxt, v: TyVid) -> t { mk_infer(cx, TyVar(v)) }
|
||||
@ -1297,7 +1296,7 @@ fn maybe_walk_ty(ty: t, f: fn(t) -> bool) {
|
||||
ty_ptr(tm) | ty_rptr(_, tm) => {
|
||||
maybe_walk_ty(tm.ty, f);
|
||||
}
|
||||
ty_enum(_, ref substs) | ty_class(_, ref substs) |
|
||||
ty_enum(_, ref substs) | ty_struct(_, ref substs) |
|
||||
ty_trait(_, ref substs, _) => {
|
||||
for (*substs).tps.each |subty| { maybe_walk_ty(*subty, f); }
|
||||
}
|
||||
@ -1372,8 +1371,8 @@ fn fold_sty(sty: &sty, fldop: fn(t) -> t) -> sty {
|
||||
ty_rptr(r, tm) => {
|
||||
ty_rptr(r, {ty: fldop(tm.ty), mutbl: tm.mutbl})
|
||||
}
|
||||
ty_class(did, ref substs) => {
|
||||
ty_class(did, fold_substs(substs, fldop))
|
||||
ty_struct(did, ref substs) => {
|
||||
ty_struct(did, fold_substs(substs, fldop))
|
||||
}
|
||||
ty_nil | ty_bot | ty_bool | ty_int(_) | ty_uint(_) | ty_float(_) |
|
||||
ty_estr(_) | ty_type | ty_opaque_closure_ptr(_) | ty_err |
|
||||
@ -1440,8 +1439,8 @@ fn fold_regions_and_ty(
|
||||
ty_enum(def_id, ref substs) => {
|
||||
ty::mk_enum(cx, def_id, fold_substs(substs, fldr, fldt))
|
||||
}
|
||||
ty_class(def_id, ref substs) => {
|
||||
ty::mk_class(cx, def_id, fold_substs(substs, fldr, fldt))
|
||||
ty_struct(def_id, ref substs) => {
|
||||
ty::mk_struct(cx, def_id, fold_substs(substs, fldr, fldt))
|
||||
}
|
||||
ty_trait(def_id, ref substs, vst) => {
|
||||
ty::mk_trait(cx, def_id, fold_substs(substs, fldr, fldt), vst)
|
||||
@ -1657,7 +1656,7 @@ fn type_is_bool(ty: t) -> bool { get(ty).sty == ty_bool }
|
||||
|
||||
fn type_is_structural(ty: t) -> bool {
|
||||
match get(ty).sty {
|
||||
ty_rec(_) | ty_class(*) | ty_tup(_) | ty_enum(*) | ty_fn(_) |
|
||||
ty_rec(_) | ty_struct(*) | ty_tup(_) | ty_enum(*) | ty_fn(_) |
|
||||
ty_trait(*) |
|
||||
ty_evec(_, vstore_fixed(_)) | ty_estr(vstore_fixed(_)) |
|
||||
ty_evec(_, vstore_slice(_)) | ty_estr(vstore_slice(_))
|
||||
@ -1818,10 +1817,10 @@ fn type_needs_drop(cx: ctxt, ty: t) -> bool {
|
||||
}
|
||||
accum
|
||||
}
|
||||
ty_class(did, ref substs) => {
|
||||
// Any class with a dtor needs a drop
|
||||
ty_struct(did, ref substs) => {
|
||||
// Any struct with a dtor needs a drop
|
||||
ty_dtor(cx, did).is_present() || {
|
||||
for vec::each(ty::class_items_as_fields(cx, did, substs)) |f| {
|
||||
for vec::each(ty::struct_fields(cx, did, substs)) |f| {
|
||||
if type_needs_drop(cx, f.mt.ty) { accum = true; }
|
||||
}
|
||||
accum
|
||||
@ -2229,16 +2228,16 @@ fn type_kind(cx: ctxt, ty: t) -> Kind {
|
||||
lowest
|
||||
}
|
||||
|
||||
ty_class(did, ref substs) => {
|
||||
// Classes are sendable if all their fields are sendable,
|
||||
ty_struct(did, ref substs) => {
|
||||
// Structs are sendable if all their fields are sendable,
|
||||
// likewise for copyable...
|
||||
// also factor out this code, copied from the records case
|
||||
let mut lowest = kind_top();
|
||||
let flds = class_items_as_fields(cx, did, substs);
|
||||
let flds = struct_fields(cx, did, substs);
|
||||
for flds.each |f| {
|
||||
lowest = lower_kind(lowest, mutable_type_kind(cx, f.mt));
|
||||
}
|
||||
// ...but classes with dtors are never copyable (they can be
|
||||
// ...but structs with dtors are never copyable (they can be
|
||||
// sendable)
|
||||
if ty::has_dtor(cx, did) {
|
||||
lowest = remove_copyable(lowest);
|
||||
@ -2334,8 +2333,8 @@ fn type_size(cx: ctxt, ty: t) -> uint {
|
||||
flds.foldl(0, |s, f| *s + type_size(cx, f.mt.ty))
|
||||
}
|
||||
|
||||
ty_class(did, ref substs) => {
|
||||
let flds = class_items_as_fields(cx, did, substs);
|
||||
ty_struct(did, ref substs) => {
|
||||
let flds = struct_fields(cx, did, substs);
|
||||
flds.foldl(0, |s, f| *s + type_size(cx, f.mt.ty))
|
||||
}
|
||||
|
||||
@ -2433,13 +2432,13 @@ fn is_instantiable(cx: ctxt, r_ty: t) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
ty_class(ref did, _) if vec::contains(*seen, did) => {
|
||||
ty_struct(ref did, _) if vec::contains(*seen, did) => {
|
||||
false
|
||||
}
|
||||
|
||||
ty_class(did, ref substs) => {
|
||||
ty_struct(did, ref substs) => {
|
||||
seen.push(did);
|
||||
let r = vec::any(class_items_as_fields(cx, did, substs),
|
||||
let r = vec::any(struct_fields(cx, did, substs),
|
||||
|f| type_requires(cx, seen, r_ty, f.mt.ty));
|
||||
seen.pop();
|
||||
r
|
||||
@ -2502,8 +2501,8 @@ fn type_structurally_contains(cx: ctxt, ty: t, test: fn(x: &sty) -> bool) ->
|
||||
}
|
||||
return false;
|
||||
}
|
||||
ty_class(did, ref substs) => {
|
||||
for lookup_class_fields(cx, did).each |field| {
|
||||
ty_struct(did, ref substs) => {
|
||||
for lookup_struct_fields(cx, did).each |field| {
|
||||
let ft = lookup_field_type(cx, did, field.id, substs);
|
||||
if type_structurally_contains(cx, ft, test) { return true; }
|
||||
}
|
||||
@ -2597,8 +2596,8 @@ fn type_is_pod(cx: ctxt, ty: t) -> bool {
|
||||
}
|
||||
ty_param(_) => result = false,
|
||||
ty_opaque_closure_ptr(_) => result = true,
|
||||
ty_class(did, ref substs) => {
|
||||
result = vec::any(lookup_class_fields(cx, did), |f| {
|
||||
ty_struct(did, ref substs) => {
|
||||
result = vec::any(lookup_struct_fields(cx, did), |f| {
|
||||
let fty = ty::lookup_item_type(cx, f.id);
|
||||
let sty = subst(cx, substs, fty.ty);
|
||||
type_is_pod(cx, sty)
|
||||
@ -2673,8 +2672,8 @@ fn deref_sty(cx: ctxt, sty: &sty, explicit: bool) -> Option<mt> {
|
||||
}
|
||||
}
|
||||
|
||||
ty_class(did, ref substs) => {
|
||||
let fields = class_items_as_fields(cx, did, substs);
|
||||
ty_struct(did, ref substs) => {
|
||||
let fields = struct_fields(cx, did, substs);
|
||||
if fields.len() == 1 && fields[0].ident ==
|
||||
syntax::parse::token::special_idents::unnamed_field {
|
||||
Some({ty: fields[0].mt.ty, mutbl: ast::m_imm})
|
||||
@ -2877,7 +2876,7 @@ impl sty : to_bytes::IterBytes {
|
||||
|
||||
ty_opaque_box => 22u8.iter_bytes(lsb0, f),
|
||||
|
||||
ty_class(ref did, ref substs) =>
|
||||
ty_struct(ref did, ref substs) =>
|
||||
to_bytes::iter_bytes_3(&23u8, did, substs, lsb0, f),
|
||||
|
||||
ty_rptr(ref r, ref mt) =>
|
||||
@ -3014,8 +3013,8 @@ fn method_call_bounds(tcx: ctxt, method_map: typeck::method_map,
|
||||
do method_map.find(id).map |method| {
|
||||
match method.origin {
|
||||
typeck::method_static(did) => {
|
||||
// n.b.: When we encode class/impl methods, the bounds
|
||||
// that we encode include both the class/impl bounds
|
||||
// n.b.: When we encode impl methods, the bounds
|
||||
// that we encode include both the impl bounds
|
||||
// and then the method bounds themselves...
|
||||
ty::lookup_item_type(tcx, did).bounds
|
||||
}
|
||||
@ -3083,7 +3082,7 @@ fn expr_kind(tcx: ctxt,
|
||||
ast::expr_path(*) => {
|
||||
match resolve_expr(tcx, expr) {
|
||||
ast::def_fn(*) | ast::def_static_method(*) |
|
||||
ast::def_variant(*) | ast::def_class(*) => RvalueDpsExpr,
|
||||
ast::def_variant(*) | ast::def_struct(*) => RvalueDpsExpr,
|
||||
|
||||
// Note: there is actually a good case to be made that
|
||||
// def_args, particularly those of immediate type, ought to
|
||||
@ -3377,7 +3376,7 @@ fn ty_sort_str(cx: ctxt, t: t) -> ~str {
|
||||
ty_rec(_) => ~"record",
|
||||
ty_fn(_) => ~"fn",
|
||||
ty_trait(id, _, _) => fmt!("trait %s", item_path_str(cx, id)),
|
||||
ty_class(id, _) => fmt!("class %s", item_path_str(cx, id)),
|
||||
ty_struct(id, _) => fmt!("struct %s", item_path_str(cx, id)),
|
||||
ty_tup(_) => ~"tuple",
|
||||
ty_infer(TyVar(_)) => ~"inferred type",
|
||||
ty_infer(IntVar(_)) => ~"integral variable",
|
||||
@ -3550,7 +3549,7 @@ fn note_and_explain_type_err(cx: ctxt, err: &type_err) {
|
||||
|
||||
fn def_has_ty_params(def: ast::def) -> bool {
|
||||
match def {
|
||||
ast::def_fn(_, _) | ast::def_variant(_, _) | ast::def_class(_)
|
||||
ast::def_fn(_, _) | ast::def_variant(_, _) | ast::def_struct(_)
|
||||
=> true,
|
||||
_ => false
|
||||
}
|
||||
@ -3655,13 +3654,6 @@ fn impl_traits(cx: ctxt, id: ast::def_id, vstore: vstore) -> ~[t] {
|
||||
vstore)]
|
||||
}
|
||||
}
|
||||
Some(ast_map::node_item(@{node: ast::item_class(sd,_),
|
||||
_},_)) => {
|
||||
do vec::map(sd.traits) |trait_ref| {
|
||||
vstoreify(cx, node_id_to_type(cx, trait_ref.ref_id),
|
||||
vstore)
|
||||
}
|
||||
}
|
||||
_ => ~[]
|
||||
}
|
||||
} else {
|
||||
@ -3672,7 +3664,7 @@ fn impl_traits(cx: ctxt, id: ast::def_id, vstore: vstore) -> ~[t] {
|
||||
|
||||
fn ty_to_def_id(ty: t) -> Option<ast::def_id> {
|
||||
match get(ty).sty {
|
||||
ty_trait(id, _, _) | ty_class(id, _) | ty_enum(id, _) => Some(id),
|
||||
ty_trait(id, _, _) | ty_struct(id, _) | ty_enum(id, _) => Some(id),
|
||||
_ => None
|
||||
}
|
||||
}
|
||||
@ -3689,7 +3681,7 @@ fn struct_ctor_id(cx: ctxt, struct_did: ast::def_id) -> Option<ast::def_id> {
|
||||
match cx.items.find(struct_did.node) {
|
||||
Some(ast_map::node_item(item, _)) => {
|
||||
match item.node {
|
||||
ast::item_class(struct_def, _) => {
|
||||
ast::item_struct(struct_def, _) => {
|
||||
struct_def.ctor_id.map(|ctor_id|
|
||||
ast_util::local_def(*ctor_id))
|
||||
}
|
||||
@ -3748,18 +3740,18 @@ impl DtorKind {
|
||||
}
|
||||
}
|
||||
|
||||
/* If class_id names a class with a dtor, return Some(the dtor's id).
|
||||
/* If struct_id names a struct with a dtor, return Some(the dtor's id).
|
||||
Otherwise return none. */
|
||||
fn ty_dtor(cx: ctxt, class_id: def_id) -> DtorKind {
|
||||
match cx.destructor_for_type.find(class_id) {
|
||||
fn ty_dtor(cx: ctxt, struct_id: def_id) -> DtorKind {
|
||||
match cx.destructor_for_type.find(struct_id) {
|
||||
Some(method_def_id) => return TraitDtor(method_def_id),
|
||||
None => {} // Continue.
|
||||
}
|
||||
|
||||
if is_local(class_id) {
|
||||
match cx.items.find(class_id.node) {
|
||||
if is_local(struct_id) {
|
||||
match cx.items.find(struct_id.node) {
|
||||
Some(ast_map::node_item(@{
|
||||
node: ast::item_class(@{ dtor: Some(ref dtor), _ }, _),
|
||||
node: ast::item_struct(@{ dtor: Some(ref dtor), _ }, _),
|
||||
_
|
||||
}, _)) =>
|
||||
LegacyDtor(local_def((*dtor).node.id)),
|
||||
@ -3768,15 +3760,15 @@ fn ty_dtor(cx: ctxt, class_id: def_id) -> DtorKind {
|
||||
}
|
||||
}
|
||||
else {
|
||||
match csearch::class_dtor(cx.sess.cstore, class_id) {
|
||||
match csearch::struct_dtor(cx.sess.cstore, struct_id) {
|
||||
None => NoDtor,
|
||||
Some(did) => LegacyDtor(did),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn has_dtor(cx: ctxt, class_id: def_id) -> bool {
|
||||
ty_dtor(cx, class_id).is_present()
|
||||
fn has_dtor(cx: ctxt, struct_id: def_id) -> bool {
|
||||
ty_dtor(cx, struct_id).is_present()
|
||||
}
|
||||
|
||||
fn item_path(cx: ctxt, id: ast::def_id) -> ast_map::path {
|
||||
@ -3943,8 +3935,8 @@ fn lookup_item_type(cx: ctxt, did: ast::def_id) -> ty_param_bounds_and_ty {
|
||||
}
|
||||
|
||||
// Look up a field ID, whether or not it's local
|
||||
// Takes a list of type substs in case the class is generic
|
||||
fn lookup_field_type(tcx: ctxt, class_id: def_id, id: def_id,
|
||||
// Takes a list of type substs in case the struct is generic
|
||||
fn lookup_field_type(tcx: ctxt, struct_id: def_id, id: def_id,
|
||||
substs: &substs) -> ty::t {
|
||||
|
||||
let t = if id.crate == ast::local_crate {
|
||||
@ -3954,7 +3946,7 @@ fn lookup_field_type(tcx: ctxt, class_id: def_id, id: def_id,
|
||||
match tcx.tcache.find(id) {
|
||||
Some(tpt) => tpt.ty,
|
||||
None => {
|
||||
let tpt = csearch::get_field_type(tcx, class_id, id);
|
||||
let tpt = csearch::get_field_type(tcx, struct_id, id);
|
||||
tcx.tcache.insert(id, tpt);
|
||||
tpt.ty
|
||||
}
|
||||
@ -3963,23 +3955,23 @@ fn lookup_field_type(tcx: ctxt, class_id: def_id, id: def_id,
|
||||
subst(tcx, substs, t)
|
||||
}
|
||||
|
||||
// Look up the list of field names and IDs for a given class
|
||||
// Fails if the id is not bound to a class.
|
||||
fn lookup_class_fields(cx: ctxt, did: ast::def_id) -> ~[field_ty] {
|
||||
// Look up the list of field names and IDs for a given struct
|
||||
// Fails if the id is not bound to a struct.
|
||||
fn lookup_struct_fields(cx: ctxt, did: ast::def_id) -> ~[field_ty] {
|
||||
if did.crate == ast::local_crate {
|
||||
match cx.items.find(did.node) {
|
||||
Some(ast_map::node_item(i,_)) => {
|
||||
match i.node {
|
||||
ast::item_class(struct_def, _) => {
|
||||
class_field_tys(struct_def.fields)
|
||||
ast::item_struct(struct_def, _) => {
|
||||
struct_field_tys(struct_def.fields)
|
||||
}
|
||||
_ => cx.sess.bug(~"class ID bound to non-class")
|
||||
_ => cx.sess.bug(~"struct ID bound to non-struct")
|
||||
}
|
||||
}
|
||||
Some(ast_map::node_variant(ref variant, _, _)) => {
|
||||
match (*variant).node.kind {
|
||||
ast::struct_variant_kind(struct_def) => {
|
||||
class_field_tys(struct_def.fields)
|
||||
struct_field_tys(struct_def.fields)
|
||||
}
|
||||
_ => {
|
||||
cx.sess.bug(~"struct ID bound to enum variant that isn't \
|
||||
@ -3989,23 +3981,23 @@ fn lookup_class_fields(cx: ctxt, did: ast::def_id) -> ~[field_ty] {
|
||||
}
|
||||
_ => {
|
||||
cx.sess.bug(
|
||||
fmt!("class ID not bound to an item: %s",
|
||||
fmt!("struct ID not bound to an item: %s",
|
||||
ast_map::node_id_to_str(cx.items, did.node,
|
||||
cx.sess.parse_sess.interner)));
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
return csearch::get_class_fields(cx, did);
|
||||
return csearch::get_struct_fields(cx, did);
|
||||
}
|
||||
}
|
||||
|
||||
fn lookup_class_field(cx: ctxt, parent: ast::def_id, field_id: ast::def_id)
|
||||
fn lookup_struct_field(cx: ctxt, parent: ast::def_id, field_id: ast::def_id)
|
||||
-> field_ty {
|
||||
match vec::find(lookup_class_fields(cx, parent),
|
||||
match vec::find(lookup_struct_fields(cx, parent),
|
||||
|f| f.id.node == field_id.node) {
|
||||
Some(t) => t,
|
||||
None => cx.sess.bug(~"class ID not found in parent's fields")
|
||||
None => cx.sess.bug(~"struct ID not found in parent's fields")
|
||||
}
|
||||
}
|
||||
|
||||
@ -4017,50 +4009,7 @@ pure fn is_public(f: field_ty) -> bool {
|
||||
}
|
||||
}
|
||||
|
||||
/* Given a class def_id and a method name, return the method's
|
||||
def_id. Needed so we can do static dispatch for methods
|
||||
Doesn't care about the method's privacy. (It's assumed that
|
||||
the caller already checked that.)
|
||||
*/
|
||||
fn lookup_class_method_by_name(cx:ctxt, did: ast::def_id, name: ident,
|
||||
sp: span) -> def_id {
|
||||
|
||||
// Look up the list of method names and IDs for a given class
|
||||
// Fails if the id is not bound to a class.
|
||||
fn lookup_class_method_ids(cx: ctxt, did: ast::def_id)
|
||||
-> ~[{name: ident, id: node_id, vis: visibility}] {
|
||||
|
||||
assert is_local(did);
|
||||
match cx.items.find(did.node) {
|
||||
Some(ast_map::node_item(@{
|
||||
node: item_class(struct_def, _), _
|
||||
}, _)) => {
|
||||
vec::map(struct_def.methods, |m| {name: m.ident,
|
||||
id: m.id,
|
||||
vis: m.vis})
|
||||
}
|
||||
_ => {
|
||||
cx.sess.bug(~"lookup_class_method_ids: id not bound to a class");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if is_local(did) {
|
||||
let ms = lookup_class_method_ids(cx, did);
|
||||
for ms.each |m| {
|
||||
if m.name == name {
|
||||
return ast_util::local_def(m.id);
|
||||
}
|
||||
}
|
||||
cx.sess.span_fatal(sp, fmt!("Class doesn't have a method \
|
||||
named %s", cx.sess.str_of(name)));
|
||||
}
|
||||
else {
|
||||
csearch::get_class_method(cx.sess.cstore, did, name)
|
||||
}
|
||||
}
|
||||
|
||||
fn class_field_tys(fields: ~[@struct_field]) -> ~[field_ty] {
|
||||
fn struct_field_tys(fields: ~[@struct_field]) -> ~[field_ty] {
|
||||
let mut rslt = ~[];
|
||||
for fields.each |field| {
|
||||
match field.node.kind {
|
||||
@ -4075,43 +4024,43 @@ fn class_field_tys(fields: ~[@struct_field]) -> ~[field_ty] {
|
||||
syntax::parse::token::special_idents::unnamed_field,
|
||||
id: ast_util::local_def(field.node.id),
|
||||
vis: ast::public,
|
||||
mutability: ast::class_immutable});
|
||||
mutability: ast::struct_immutable});
|
||||
}
|
||||
}
|
||||
}
|
||||
rslt
|
||||
}
|
||||
|
||||
// Return a list of fields corresponding to the class's items
|
||||
// (as if the class was a record). trans uses this
|
||||
// Return a list of fields corresponding to the struct's items
|
||||
// (as if the struct was a record). trans uses this
|
||||
// Takes a list of substs with which to instantiate field types
|
||||
// Keep in mind that this function reports that all fields are
|
||||
// mutable, regardless of how they were declared. It's meant to
|
||||
// be used in trans.
|
||||
fn class_items_as_mutable_fields(cx:ctxt,
|
||||
fn struct_mutable_fields(cx:ctxt,
|
||||
did: ast::def_id,
|
||||
substs: &substs) -> ~[field] {
|
||||
class_item_fields(cx, did, substs, |_mt| m_mutbl)
|
||||
struct_item_fields(cx, did, substs, |_mt| m_mutbl)
|
||||
}
|
||||
|
||||
// Same as class_items_as_mutable_fields, but doesn't change
|
||||
// Same as struct_mutable_fields, but doesn't change
|
||||
// mutability.
|
||||
fn class_items_as_fields(cx:ctxt,
|
||||
fn struct_fields(cx:ctxt,
|
||||
did: ast::def_id,
|
||||
substs: &substs) -> ~[field] {
|
||||
class_item_fields(cx, did, substs, |mt| match mt {
|
||||
class_mutable => m_mutbl,
|
||||
class_immutable => m_imm })
|
||||
struct_item_fields(cx, did, substs, |mt| match mt {
|
||||
struct_mutable => m_mutbl,
|
||||
struct_immutable => m_imm })
|
||||
}
|
||||
|
||||
|
||||
fn class_item_fields(cx:ctxt,
|
||||
fn struct_item_fields(cx:ctxt,
|
||||
did: ast::def_id,
|
||||
substs: &substs,
|
||||
frob_mutability: fn(class_mutability) -> mutability)
|
||||
frob_mutability: fn(struct_mutability) -> mutability)
|
||||
-> ~[field] {
|
||||
let mut rslt = ~[];
|
||||
for lookup_class_fields(cx, did).each |f| {
|
||||
for lookup_struct_fields(cx, did).each |f| {
|
||||
// consider all instance vars mut, because the
|
||||
// constructor may mutate all vars
|
||||
rslt.push({ident: f.ident, mt:
|
||||
@ -4247,12 +4196,13 @@ fn normalize_ty(cx: ctxt, t: t) -> t {
|
||||
t
|
||||
},
|
||||
|
||||
ty_class(did, ref r) =>
|
||||
ty_struct(did, ref r) =>
|
||||
match (*r).self_r {
|
||||
Some(_) =>
|
||||
// Ditto.
|
||||
mk_class(cx, did, {self_r: Some(ty::re_static), self_ty: None,
|
||||
tps: (*r).tps}),
|
||||
mk_struct(cx, did, {self_r: Some(ty::re_static),
|
||||
self_ty: None,
|
||||
tps: (*r).tps}),
|
||||
None =>
|
||||
t
|
||||
},
|
||||
@ -4654,9 +4604,9 @@ impl sty : cmp::Eq {
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
ty_class(e0a, ref e1a) => {
|
||||
ty_struct(e0a, ref e1a) => {
|
||||
match (*other) {
|
||||
ty_class(e0b, ref e1b) => e0a == e0b && (*e1a) == (*e1b),
|
||||
ty_struct(e0b, ref e1b) => e0a == e0b && (*e1a) == (*e1b),
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
|
@ -320,7 +320,7 @@ fn ast_ty_to_ty<AC: ast_conv, RS: region_scope Copy Owned>(
|
||||
Some(d) => d
|
||||
};
|
||||
match a_def {
|
||||
ast::def_ty(did) | ast::def_class(did) => {
|
||||
ast::def_ty(did) | ast::def_struct(did) => {
|
||||
ast_path_to_ty(self, rscope, did, path, id).ty
|
||||
}
|
||||
ast::def_prim_ty(nty) => {
|
||||
|
@ -100,7 +100,7 @@ fn check_pat_variant(pcx: pat_ctxt, pat: @ast::pat, path: @ast::path,
|
||||
|
||||
kind_name = "variant";
|
||||
}
|
||||
ty::ty_class(struct_def_id, ref expected_substs) => {
|
||||
ty::ty_struct(struct_def_id, ref expected_substs) => {
|
||||
// Assign the pattern the type of the struct.
|
||||
let struct_tpt = ty::lookup_item_type(tcx, struct_def_id);
|
||||
instantiate_path(pcx.fcx, path, struct_tpt, pat.span, pat.id,
|
||||
@ -112,7 +112,7 @@ fn check_pat_variant(pcx: pat_ctxt, pat: @ast::pat, path: @ast::path,
|
||||
demand::suptype(fcx, pat.span, pat_ty, expected);
|
||||
|
||||
// Get the expected types of the arguments.
|
||||
let class_fields = ty::class_items_as_fields(
|
||||
let class_fields = ty::struct_fields(
|
||||
tcx, struct_def_id, expected_substs);
|
||||
arg_types = class_fields.map(|field| field.mt.ty);
|
||||
|
||||
@ -232,15 +232,15 @@ fn check_struct_pat(pcx: pat_ctxt, pat_id: ast::node_id, span: span,
|
||||
let fcx = pcx.fcx;
|
||||
let tcx = pcx.fcx.ccx.tcx;
|
||||
|
||||
let class_fields = ty::lookup_class_fields(tcx, class_id);
|
||||
let class_fields = ty::lookup_struct_fields(tcx, class_id);
|
||||
|
||||
// Check to ensure that the struct is the one specified.
|
||||
match tcx.def_map.find(pat_id) {
|
||||
Some(ast::def_class(supplied_def_id))
|
||||
Some(ast::def_struct(supplied_def_id))
|
||||
if supplied_def_id == class_id => {
|
||||
// OK.
|
||||
}
|
||||
Some(ast::def_class(*)) | Some(ast::def_variant(*)) => {
|
||||
Some(ast::def_struct(*)) | Some(ast::def_variant(*)) => {
|
||||
let name = pprust::path_to_str(path, tcx.sess.intr());
|
||||
tcx.sess.span_err(span,
|
||||
fmt!("mismatched types: expected `%s` but \
|
||||
@ -280,12 +280,12 @@ fn check_struct_like_enum_variant_pat(pcx: pat_ctxt,
|
||||
Some(ast::def_variant(found_enum_id, variant_id))
|
||||
if found_enum_id == enum_id => {
|
||||
// Get the struct fields from this struct-like enum variant.
|
||||
let class_fields = ty::lookup_class_fields(tcx, variant_id);
|
||||
let class_fields = ty::lookup_struct_fields(tcx, variant_id);
|
||||
|
||||
check_struct_pat_fields(pcx, span, path, fields, class_fields,
|
||||
variant_id, substitutions, etc);
|
||||
}
|
||||
Some(ast::def_class(*)) | Some(ast::def_variant(*)) => {
|
||||
Some(ast::def_struct(*)) | Some(ast::def_variant(*)) => {
|
||||
let name = pprust::path_to_str(path, tcx.sess.intr());
|
||||
tcx.sess.span_err(span,
|
||||
fmt!("mismatched types: expected `%s` but \
|
||||
@ -423,7 +423,7 @@ fn check_pat(pcx: pat_ctxt, pat: @ast::pat, expected: ty::t) {
|
||||
// Grab the class data that we care about.
|
||||
let structure = structure_of(fcx, pat.span, expected);
|
||||
match structure {
|
||||
ty::ty_class(cid, ref substs) => {
|
||||
ty::ty_struct(cid, ref substs) => {
|
||||
check_struct_pat(pcx, pat.id, pat.span, expected, path,
|
||||
fields, etc, cid, substs);
|
||||
}
|
||||
|
@ -277,7 +277,7 @@ impl LookupContext {
|
||||
self.push_inherent_candidates_from_self(
|
||||
self_ty, self_did, &substs);
|
||||
}
|
||||
ty_enum(did, _) | ty_class(did, _) => {
|
||||
ty_enum(did, _) | ty_struct(did, _) => {
|
||||
self.push_inherent_impl_candidates_for_type(did);
|
||||
}
|
||||
_ => { /* No inherent methods in these types */ }
|
||||
@ -778,7 +778,7 @@ impl LookupContext {
|
||||
ty_self | ty_param(*) | ty_nil | ty_bot | ty_bool |
|
||||
ty_int(*) | ty_uint(*) |
|
||||
ty_float(*) | ty_enum(*) | ty_ptr(*) | ty_rec(*) |
|
||||
ty_class(*) | ty_tup(*) | ty_estr(*) | ty_evec(*) |
|
||||
ty_struct(*) | ty_tup(*) | ty_estr(*) | ty_evec(*) |
|
||||
ty_trait(*) | ty_fn(*) => {
|
||||
self.search_for_some_kind_of_autorefd_method(
|
||||
AutoPtr, autoderefs, [m_const, m_imm, m_mutbl],
|
||||
|
@ -483,7 +483,7 @@ fn check_struct(ccx: @crate_ctxt, struct_def: @ast::struct_def,
|
||||
let tcx = ccx.tcx;
|
||||
let self_ty = ty::node_id_to_type(tcx, id);
|
||||
|
||||
do option::iter(&struct_def.dtor) |dtor| {
|
||||
do struct_def.dtor.iter() |dtor| {
|
||||
let class_t = {self_ty: self_ty,
|
||||
self_id: dtor.node.self_id,
|
||||
def_id: local_def(id),
|
||||
@ -495,10 +495,6 @@ fn check_struct(ccx: @crate_ctxt, struct_def: @ast::struct_def,
|
||||
Some(class_t));
|
||||
};
|
||||
|
||||
// typecheck the methods
|
||||
for struct_def.methods.each |m| {
|
||||
check_method(ccx, *m, self_ty, local_def(id));
|
||||
}
|
||||
// Check that the class is instantiable
|
||||
check_instantiable(ccx.tcx, span, id);
|
||||
}
|
||||
@ -539,7 +535,7 @@ fn check_item(ccx: @crate_ctxt, it: @ast::item) {
|
||||
}
|
||||
}
|
||||
}
|
||||
ast::item_class(struct_def, _) => {
|
||||
ast::item_struct(struct_def, _) => {
|
||||
check_struct(ccx, struct_def, it.id, it.span);
|
||||
}
|
||||
ast::item_ty(t, tps) => {
|
||||
@ -940,7 +936,7 @@ fn impl_self_ty(vcx: &VtableContext,
|
||||
region_param: region_param,
|
||||
raw_ty: vcx.ccx.to_ty(rscope::type_rscope(region_param), st)}
|
||||
}
|
||||
Some(ast_map::node_item(@{node: ast::item_class(_, ts),
|
||||
Some(ast_map::node_item(@{node: ast::item_struct(_, ts),
|
||||
id: class_id, _},_)) => {
|
||||
/* If the impl is a class, the self ty is just the class ty
|
||||
(doing a no-op subst for the ty params; in the next step,
|
||||
@ -948,7 +944,7 @@ fn impl_self_ty(vcx: &VtableContext,
|
||||
*/
|
||||
{n_tps: ts.len(),
|
||||
region_param: region_param,
|
||||
raw_ty: ty::mk_class(tcx, local_def(class_id),
|
||||
raw_ty: ty::mk_struct(tcx, local_def(class_id),
|
||||
{self_r: rscope::bound_self_region(region_param),
|
||||
self_ty: None,
|
||||
tps: ty::ty_params_to_tys(tcx, ts)})}
|
||||
@ -1538,14 +1534,14 @@ fn check_expr_with_unifier(fcx: @fn_ctxt,
|
||||
_ => ()
|
||||
}
|
||||
}
|
||||
ty::ty_class(base_id, ref substs) => {
|
||||
ty::ty_struct(base_id, ref substs) => {
|
||||
// This is just for fields -- the same code handles
|
||||
// methods in both classes and traits
|
||||
|
||||
// (1) verify that the class id actually has a field called
|
||||
// field
|
||||
debug!("class named %s", ty_to_str(tcx, base_t));
|
||||
let cls_items = ty::lookup_class_fields(tcx, base_id);
|
||||
let cls_items = ty::lookup_struct_fields(tcx, base_id);
|
||||
match lookup_field_ty(tcx, base_id, cls_items,
|
||||
field, &(*substs)) {
|
||||
Some(field_ty) => {
|
||||
@ -1685,7 +1681,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt,
|
||||
tcx.region_paramd_items.find(class_id.node);
|
||||
match tcx.items.find(class_id.node) {
|
||||
Some(ast_map::node_item(@{
|
||||
node: ast::item_class(_, type_parameters),
|
||||
node: ast::item_struct(_, type_parameters),
|
||||
_
|
||||
}, _)) => {
|
||||
|
||||
@ -1694,7 +1690,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt,
|
||||
let self_region =
|
||||
bound_self_region(region_parameterized);
|
||||
|
||||
raw_type = ty::mk_class(tcx, class_id, {
|
||||
raw_type = ty::mk_struct(tcx, class_id, {
|
||||
self_r: self_region,
|
||||
self_ty: None,
|
||||
tps: ty::ty_params_to_tys(tcx, type_parameters)
|
||||
@ -1727,7 +1723,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt,
|
||||
let struct_type = ty::subst(tcx, &substitutions, raw_type);
|
||||
|
||||
// Look up and check the fields.
|
||||
let class_fields = ty::lookup_class_fields(tcx, class_id);
|
||||
let class_fields = ty::lookup_struct_fields(tcx, class_id);
|
||||
bot = check_struct_or_variant_fields(fcx,
|
||||
span,
|
||||
class_id,
|
||||
@ -1808,7 +1804,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt,
|
||||
let enum_type = ty::subst(tcx, &substitutions, raw_type);
|
||||
|
||||
// Look up and check the enum variant fields.
|
||||
let variant_fields = ty::lookup_class_fields(tcx, variant_id);
|
||||
let variant_fields = ty::lookup_struct_fields(tcx, variant_id);
|
||||
bot = check_struct_or_variant_fields(fcx,
|
||||
span,
|
||||
variant_id,
|
||||
@ -1927,7 +1923,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt,
|
||||
with a single variant which has a \
|
||||
single argument");
|
||||
}
|
||||
ty::ty_class(*) => {
|
||||
ty::ty_struct(*) => {
|
||||
tcx.sess.span_err(
|
||||
expr.span,
|
||||
~"can only dereference structs with one anonymous \
|
||||
@ -2351,7 +2347,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt,
|
||||
ast::expr_struct(path, ref fields, base_expr) => {
|
||||
// Resolve the path.
|
||||
match tcx.def_map.find(id) {
|
||||
Some(ast::def_class(type_def_id)) => {
|
||||
Some(ast::def_struct(type_def_id)) => {
|
||||
check_struct_constructor(fcx, id, expr.span, type_def_id,
|
||||
(*fields), base_expr);
|
||||
}
|
||||
@ -2627,7 +2623,7 @@ fn check_enum_variants(ccx: @crate_ctxt,
|
||||
arg_tys = Some(~[]);
|
||||
}
|
||||
ast::struct_variant_kind(_) => {
|
||||
arg_tys = Some(ty::lookup_class_fields(
|
||||
arg_tys = Some(ty::lookup_struct_fields(
|
||||
ccx.tcx, local_def(v.node.id)).map(|cf|
|
||||
ty::node_id_to_type(ccx.tcx, cf.id.node)));
|
||||
}
|
||||
@ -2731,7 +2727,7 @@ fn ty_param_bounds_and_ty_for_def(fcx: @fn_ctxt, sp: span, defn: ast::def) ->
|
||||
|
||||
ast::def_fn(id, _) | ast::def_static_method(id, _, _) |
|
||||
ast::def_const(id) | ast::def_variant(_, id) |
|
||||
ast::def_class(id) => {
|
||||
ast::def_struct(id) => {
|
||||
return ty::lookup_item_type(fcx.ccx.tcx, id);
|
||||
}
|
||||
ast::def_upvar(_, inner, _, _) => {
|
||||
|
@ -21,7 +21,7 @@ use metadata::decoder::{dl_def, dl_field, dl_impl};
|
||||
use middle::resolve::{Impl, MethodInfo};
|
||||
use middle::ty::{DerivedMethodInfo, ProvidedMethodSource,
|
||||
ProvidedMethodInfo, get};
|
||||
use middle::ty::{lookup_item_type, subst, t, ty_bot, ty_box, ty_class};
|
||||
use middle::ty::{lookup_item_type, subst, t, ty_bot, ty_box, ty_struct};
|
||||
use middle::ty::{ty_bool, ty_enum, ty_int, ty_nil, ty_ptr, ty_rptr, ty_uint};
|
||||
use middle::ty::{ty_float, ty_estr, ty_evec, ty_rec, ty_uniq};
|
||||
use middle::ty::{ty_err, ty_fn, ty_trait, ty_tup, ty_infer};
|
||||
@ -30,7 +30,7 @@ use middle::ty::{ty_opaque_closure_ptr, ty_unboxed_vec, type_is_ty_var};
|
||||
use middle::typeck::infer::{infer_ctxt, can_mk_subty};
|
||||
use middle::typeck::infer::{new_infer_ctxt, resolve_ivar, resolve_type};
|
||||
use syntax::ast::{crate, def_id, def_mod, def_ty};
|
||||
use syntax::ast::{item, item_class, item_const, item_enum, item_fn};
|
||||
use syntax::ast::{item, item_struct, item_const, item_enum, item_fn};
|
||||
use syntax::ast::{item_foreign_mod, item_impl, item_mac, item_mod};
|
||||
use syntax::ast::{item_trait, item_ty, local_crate, method, node_id};
|
||||
use syntax::ast::{trait_ref};
|
||||
@ -78,7 +78,7 @@ fn get_base_type(inference_context: infer_ctxt, span: span, original_type: t)
|
||||
base_mutability_and_type.ty)
|
||||
}
|
||||
|
||||
ty_enum(*) | ty_trait(*) | ty_class(*) => {
|
||||
ty_enum(*) | ty_trait(*) | ty_struct(*) => {
|
||||
debug!("(getting base type) found base type");
|
||||
Some(resolved_type)
|
||||
}
|
||||
@ -108,7 +108,7 @@ fn get_base_type_def_id(inference_context: infer_ctxt,
|
||||
Some(base_type) => {
|
||||
match get(base_type).sty {
|
||||
ty_enum(def_id, _) |
|
||||
ty_class(def_id, _) |
|
||||
ty_struct(def_id, _) |
|
||||
ty_trait(def_id, _, _) => {
|
||||
return Some(def_id);
|
||||
}
|
||||
@ -188,9 +188,6 @@ impl CoherenceChecker {
|
||||
item_impl(_, opt_trait, _, _) => {
|
||||
self.check_implementation(item, opt_trait.to_vec());
|
||||
}
|
||||
item_class(struct_def, _) => {
|
||||
self.check_implementation(item, struct_def.traits);
|
||||
}
|
||||
_ => {
|
||||
// Nothing to do.
|
||||
}
|
||||
@ -772,10 +769,6 @@ impl CoherenceChecker {
|
||||
methods: methods
|
||||
};
|
||||
}
|
||||
item_class(struct_def, _) => {
|
||||
return self.create_impl_from_struct(struct_def, item.ident,
|
||||
item.id);
|
||||
}
|
||||
_ => {
|
||||
self.crate_context.tcx.sess.span_bug(item.span,
|
||||
~"can't convert a \
|
||||
@ -784,23 +777,6 @@ impl CoherenceChecker {
|
||||
}
|
||||
}
|
||||
|
||||
fn create_impl_from_struct(struct_def: @ast::struct_def,
|
||||
ident: ast::ident,
|
||||
id: node_id)
|
||||
-> @Impl {
|
||||
let mut methods = ~[];
|
||||
for struct_def.methods.each |ast_method| {
|
||||
methods.push(@{
|
||||
did: local_def(ast_method.id),
|
||||
n_tps: ast_method.tps.len(),
|
||||
ident: ast_method.ident,
|
||||
self_type: ast_method.self_ty.node
|
||||
});
|
||||
}
|
||||
|
||||
return @{ did: local_def(id), ident: ident, methods: methods };
|
||||
}
|
||||
|
||||
fn span_of_impl(implementation: @Impl) -> span {
|
||||
assert implementation.did.crate == local_crate;
|
||||
match self.crate_context.tcx.items.find(implementation.did.node) {
|
||||
@ -999,7 +975,7 @@ impl CoherenceChecker {
|
||||
|
||||
let self_type = self.get_self_type_for_implementation(*impl_info);
|
||||
match ty::get(self_type.ty).sty {
|
||||
ty::ty_class(type_def_id, _) => {
|
||||
ty::ty_struct(type_def_id, _) => {
|
||||
tcx.destructor_for_type.insert(type_def_id,
|
||||
method_def_id);
|
||||
tcx.destructors.insert(method_def_id, ());
|
||||
|
@ -259,14 +259,7 @@ fn ensure_trait_methods(ccx: @crate_ctxt, id: ast::node_id, trait_ty: ty::t) {
|
||||
method_ty
|
||||
});
|
||||
}
|
||||
ast_map::node_item(@{node: ast::item_class(struct_def, _), _}, _) => {
|
||||
// All methods need to be stored, since lookup_method
|
||||
// relies on the same method cache for self-calls
|
||||
store_methods::<@ast::method>(ccx, id, struct_def.methods, |m| {
|
||||
ty_of_method(ccx, *m, region_paramd)
|
||||
});
|
||||
}
|
||||
_ => { /* Ignore things that aren't traits or classes */ }
|
||||
_ => { /* Ignore things that aren't traits */ }
|
||||
}
|
||||
}
|
||||
|
||||
@ -595,7 +588,7 @@ fn convert(ccx: @crate_ctxt, it: @ast::item) {
|
||||
// check_methods_against_trait(ccx, tps, rp, selfty, *t, cms);
|
||||
// }
|
||||
}
|
||||
ast::item_class(struct_def, tps) => {
|
||||
ast::item_struct(struct_def, tps) => {
|
||||
// Write the class type
|
||||
let tpt = ty_of_item(ccx, it);
|
||||
write_ty_to_tcx(tcx, it.id, tpt.ty);
|
||||
@ -636,18 +629,13 @@ fn convert_struct(ccx: @crate_ctxt,
|
||||
region_param: rp,
|
||||
ty: t_dtor});
|
||||
};
|
||||
ensure_trait_methods(ccx, id, tpt.ty);
|
||||
|
||||
// Write the type of each of the members
|
||||
for struct_def.fields.each |f| {
|
||||
convert_field(ccx, rp, tpt.bounds, *f);
|
||||
}
|
||||
let {bounds: bounds, substs: substs} = mk_substs(ccx, tps, rp);
|
||||
let selfty = ty::mk_class(tcx, local_def(id), substs);
|
||||
let cms = convert_methods(ccx, struct_def.methods, rp, bounds);
|
||||
for struct_def.traits.each |trait_ref| {
|
||||
check_methods_against_trait(ccx, tps, rp, selfty, *trait_ref, cms);
|
||||
}
|
||||
let {bounds: _, substs: substs} = mk_substs(ccx, tps, rp);
|
||||
let selfty = ty::mk_struct(tcx, local_def(id), substs);
|
||||
|
||||
// If this struct is enum-like or tuple-like, create the type of its
|
||||
// constructor.
|
||||
@ -835,9 +823,9 @@ fn ty_of_item(ccx: @crate_ctxt, it: @ast::item)
|
||||
tcx.tcache.insert(local_def(it.id), tpt);
|
||||
return tpt;
|
||||
}
|
||||
ast::item_class(_, tps) => {
|
||||
ast::item_struct(_, tps) => {
|
||||
let {bounds: bounds, substs: substs} = mk_substs(ccx, tps, rp);
|
||||
let t = ty::mk_class(tcx, local_def(it.id), substs);
|
||||
let t = ty::mk_struct(tcx, local_def(it.id), substs);
|
||||
let tpt = {bounds: bounds,
|
||||
region_param: rp,
|
||||
ty: t};
|
||||
|
@ -28,7 +28,7 @@ use syntax::visit::{default_simple_visitor, mk_simple_visitor, visit_crate};
|
||||
use middle::resolve::{Impl, MethodInfo};
|
||||
use middle::ty;
|
||||
use middle::ty::{DerivedFieldInfo, ReVar, re_infer, re_static, substs};
|
||||
use middle::ty::{ty_class, ty_enum, ty_param_bounds_and_ty};
|
||||
use middle::ty::{ty_struct, ty_enum, ty_param_bounds_and_ty};
|
||||
use /*middle::typeck::*/check::method;
|
||||
use /*middle::typeck::*/check::vtable;
|
||||
use /*middle::typeck::*/infer::infer_ctxt;
|
||||
@ -182,7 +182,7 @@ impl DerivingChecker {
|
||||
impl_span: span) {
|
||||
let tcx = self.crate_context.tcx;
|
||||
let field_info = dvec::DVec();
|
||||
for ty::lookup_class_fields(tcx, struct_def_id).each |field| {
|
||||
for ty::lookup_struct_fields(tcx, struct_def_id).each |field| {
|
||||
let field_type = ty::lookup_field_type(
|
||||
tcx, struct_def_id, field.id, struct_substs);
|
||||
match self.check_deriving_for_substructure_type(field_type,
|
||||
@ -288,7 +288,7 @@ impl DerivingChecker {
|
||||
item.id,
|
||||
item.span);
|
||||
}
|
||||
ty_class(def_id, ref substs) => {
|
||||
ty_struct(def_id, ref substs) => {
|
||||
self.check_deriving_for_struct(
|
||||
def_id,
|
||||
substs,
|
||||
|
@ -452,10 +452,10 @@ fn super_tys<C:combine>(
|
||||
}
|
||||
}
|
||||
|
||||
(ty::ty_class(a_id, ref a_substs), ty::ty_class(b_id, ref b_substs))
|
||||
(ty::ty_struct(a_id, ref a_substs), ty::ty_struct(b_id, ref b_substs))
|
||||
if a_id == b_id => {
|
||||
do self.substs(a_id, a_substs, b_substs).chain |substs| {
|
||||
Ok(ty::mk_class(tcx, a_id, substs))
|
||||
Ok(ty::mk_struct(tcx, a_id, substs))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -122,7 +122,7 @@ impl Env {
|
||||
None
|
||||
}
|
||||
|
||||
ast::item_enum(*) | ast::item_class(*) |
|
||||
ast::item_enum(*) | ast::item_struct(*) |
|
||||
ast::item_trait(*) | ast::item_impl(*) |
|
||||
ast::item_mac(*) => {
|
||||
None
|
||||
|
@ -18,7 +18,7 @@ use middle::ty::{ctxt, field, method};
|
||||
use middle::ty::{mt, t, param_bound};
|
||||
use middle::ty::{re_bound, re_free, re_scope, re_infer, re_static, Region};
|
||||
use middle::ty::{ReSkolemized, ReVar};
|
||||
use middle::ty::{ty_bool, ty_bot, ty_box, ty_class, ty_enum};
|
||||
use middle::ty::{ty_bool, ty_bot, ty_box, ty_struct, ty_enum};
|
||||
use middle::ty::{ty_err, ty_estr, ty_evec, ty_float, ty_fn, ty_trait, ty_int};
|
||||
use middle::ty::{ty_nil, ty_opaque_box, ty_opaque_closure_ptr, ty_param};
|
||||
use middle::ty::{ty_ptr, ty_rec, ty_rptr, ty_self, ty_tup};
|
||||
@ -408,7 +408,7 @@ fn ty_to_str(cx: ctxt, typ: t) -> ~str {
|
||||
~"'" + str::from_bytes(~[('a' as u8) + (id as u8)])
|
||||
}
|
||||
ty_self => ~"self",
|
||||
ty_enum(did, ref substs) | ty_class(did, ref substs) => {
|
||||
ty_enum(did, ref substs) | ty_struct(did, ref substs) => {
|
||||
let path = ty::item_path(cx, did);
|
||||
let base = ast_map::path_to_str(path, cx.sess.intr());
|
||||
parameterized(cx, base, (*substs).self_r, (*substs).tps)
|
||||
|
@ -127,7 +127,7 @@ fn moddoc_from_mod(
|
||||
tydoc_from_ty(ItemDoc)
|
||||
))
|
||||
}
|
||||
ast::item_class(def, _) => {
|
||||
ast::item_struct(def, _) => {
|
||||
Some(doc::StructTag(
|
||||
structdoc_from_struct(ItemDoc, def)
|
||||
))
|
||||
|
@ -360,12 +360,12 @@ fn fold_struct(
|
||||
/// what I actually want
|
||||
fn strip_struct_extra_stuff(item: @ast::item) -> @ast::item {
|
||||
let node = match item.node {
|
||||
ast::item_class(def, tys) => {
|
||||
ast::item_struct(def, tys) => {
|
||||
let def = @{
|
||||
dtor: None, // Remove the drop { } block
|
||||
.. *def
|
||||
};
|
||||
ast::item_class(def, tys)
|
||||
ast::item_struct(def, tys)
|
||||
}
|
||||
_ => fail ~"not a struct"
|
||||
};
|
||||
|
@ -134,8 +134,8 @@ enum def {
|
||||
@def, // closed over def
|
||||
node_id, // expr node that creates the closure
|
||||
node_id), // id for the block/body of the closure expr
|
||||
def_class(def_id),
|
||||
def_typaram_binder(node_id), /* class, impl or trait that has ty params */
|
||||
def_struct(def_id),
|
||||
def_typaram_binder(node_id), /* struct, impl or trait with ty params */
|
||||
def_region(node_id),
|
||||
def_label(node_id)
|
||||
}
|
||||
@ -235,9 +235,9 @@ impl def : cmp::Eq {
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
def_class(e0a) => {
|
||||
def_struct(e0a) => {
|
||||
match (*other) {
|
||||
def_class(e0b) => e0a == e0b,
|
||||
def_struct(e0b) => e0a == e0b,
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
@ -1408,13 +1408,11 @@ impl attr_style : cmp::Eq {
|
||||
type attribute_ = {style: attr_style, value: meta_item, is_sugared_doc: bool};
|
||||
|
||||
/*
|
||||
trait_refs appear in both impls and in classes that implement traits.
|
||||
trait_refs appear in impls.
|
||||
resolve maps each trait_ref's ref_id to its defining trait; that's all
|
||||
that the ref_id is for. The impl_id maps to the "self type" of this impl.
|
||||
If this impl is an item_impl, the impl_id is redundant (it could be the
|
||||
same as the impl's node id). If this impl is actually an impl_class, then
|
||||
conceptually, the impl_id stands in for the pair of (this class, this
|
||||
trait)
|
||||
same as the impl's node id).
|
||||
*/
|
||||
#[auto_serialize]
|
||||
#[auto_deserialize]
|
||||
@ -1451,19 +1449,19 @@ type struct_field = spanned<struct_field_>;
|
||||
#[auto_serialize]
|
||||
#[auto_deserialize]
|
||||
enum struct_field_kind {
|
||||
named_field(ident, class_mutability, visibility),
|
||||
named_field(ident, struct_mutability, visibility),
|
||||
unnamed_field // element of a tuple-like struct
|
||||
}
|
||||
|
||||
impl struct_field_kind : cmp::Eq {
|
||||
pure fn eq(&self, other: &struct_field_kind) -> bool {
|
||||
match (*self) {
|
||||
named_field(ident_a, class_mutability_a, visibility_a) => {
|
||||
named_field(ident_a, struct_mutability_a, visibility_a) => {
|
||||
match *other {
|
||||
named_field(ident_b, class_mutability_b, visibility_b)
|
||||
named_field(ident_b, struct_mutability_b, visibility_b)
|
||||
=> {
|
||||
ident_a == ident_b &&
|
||||
class_mutability_a == class_mutability_b &&
|
||||
struct_mutability_a == struct_mutability_b &&
|
||||
visibility_a == visibility_b
|
||||
}
|
||||
unnamed_field => false
|
||||
@ -1485,12 +1483,10 @@ impl struct_field_kind : cmp::Eq {
|
||||
#[auto_serialize]
|
||||
#[auto_deserialize]
|
||||
type struct_def = {
|
||||
traits: ~[@trait_ref], /* traits this struct implements */
|
||||
fields: ~[@struct_field], /* fields */
|
||||
methods: ~[@method], /* methods */
|
||||
/* (not including ctor or dtor) */
|
||||
/* dtor is optional */
|
||||
dtor: Option<class_dtor>,
|
||||
dtor: Option<struct_dtor>,
|
||||
/* ID of the constructor. This is only used for tuple- or enum-like
|
||||
* structs. */
|
||||
ctor_id: Option<node_id>
|
||||
@ -1515,7 +1511,7 @@ enum item_ {
|
||||
item_foreign_mod(foreign_mod),
|
||||
item_ty(@Ty, ~[ty_param]),
|
||||
item_enum(enum_def, ~[ty_param]),
|
||||
item_class(@struct_def, ~[ty_param]),
|
||||
item_struct(@struct_def, ~[ty_param]),
|
||||
item_trait(~[ty_param], ~[@trait_ref], ~[trait_method]),
|
||||
item_impl(~[ty_param],
|
||||
Option<@trait_ref>, /* (optional) trait this impl implements */
|
||||
@ -1526,41 +1522,33 @@ enum item_ {
|
||||
|
||||
#[auto_serialize]
|
||||
#[auto_deserialize]
|
||||
enum class_mutability { class_mutable, class_immutable }
|
||||
enum struct_mutability { struct_mutable, struct_immutable }
|
||||
|
||||
impl class_mutability : to_bytes::IterBytes {
|
||||
impl struct_mutability : to_bytes::IterBytes {
|
||||
pure fn iter_bytes(&self, +lsb0: bool, f: to_bytes::Cb) {
|
||||
(*self as u8).iter_bytes(lsb0, f)
|
||||
}
|
||||
}
|
||||
|
||||
impl class_mutability : cmp::Eq {
|
||||
pure fn eq(&self, other: &class_mutability) -> bool {
|
||||
impl struct_mutability : cmp::Eq {
|
||||
pure fn eq(&self, other: &struct_mutability) -> bool {
|
||||
match ((*self), (*other)) {
|
||||
(class_mutable, class_mutable) => true,
|
||||
(class_immutable, class_immutable) => true,
|
||||
(class_mutable, _) => false,
|
||||
(class_immutable, _) => false,
|
||||
(struct_mutable, struct_mutable) => true,
|
||||
(struct_immutable, struct_immutable) => true,
|
||||
(struct_mutable, _) => false,
|
||||
(struct_immutable, _) => false,
|
||||
}
|
||||
}
|
||||
pure fn ne(&self, other: &class_mutability) -> bool { !(*self).eq(other) }
|
||||
pure fn ne(&self, other: &struct_mutability) -> bool {
|
||||
!(*self).eq(other)
|
||||
}
|
||||
}
|
||||
|
||||
type class_ctor = spanned<class_ctor_>;
|
||||
type struct_dtor = spanned<struct_dtor_>;
|
||||
|
||||
#[auto_serialize]
|
||||
#[auto_deserialize]
|
||||
type class_ctor_ = {id: node_id,
|
||||
attrs: ~[attribute],
|
||||
self_id: node_id,
|
||||
dec: fn_decl,
|
||||
body: blk};
|
||||
|
||||
type class_dtor = spanned<class_dtor_>;
|
||||
|
||||
#[auto_serialize]
|
||||
#[auto_deserialize]
|
||||
type class_dtor_ = {id: node_id,
|
||||
type struct_dtor_ = {id: node_id,
|
||||
attrs: ~[attribute],
|
||||
self_id: node_id,
|
||||
body: blk};
|
||||
@ -1591,7 +1579,7 @@ enum inlined_item {
|
||||
ii_item(@item),
|
||||
ii_method(def_id /* impl id */, @method),
|
||||
ii_foreign(@foreign_item),
|
||||
ii_dtor(class_dtor, ident, ~[ty_param], def_id /* parent id */)
|
||||
ii_dtor(struct_dtor, ident, ~[ty_param], def_id /* parent id */)
|
||||
}
|
||||
|
||||
|
||||
|
@ -81,8 +81,8 @@ enum ast_node {
|
||||
// order they are introduced.
|
||||
node_arg(arg, uint),
|
||||
node_local(uint),
|
||||
// Destructor for a class
|
||||
node_dtor(~[ty_param], @class_dtor, def_id, @path),
|
||||
// Destructor for a struct
|
||||
node_dtor(~[ty_param], @struct_dtor, def_id, @path),
|
||||
node_block(blk),
|
||||
node_struct_ctor(@struct_def, @item, @path),
|
||||
}
|
||||
@ -245,13 +245,11 @@ fn map_item(i: @item, cx: ctx, v: vt) {
|
||||
}));
|
||||
}
|
||||
}
|
||||
item_class(struct_def, _) => {
|
||||
map_struct_def(struct_def, node_item(i, item_path), i.ident, i.id, cx,
|
||||
item_struct(struct_def, _) => {
|
||||
map_struct_def(struct_def, node_item(i, item_path), i.ident, cx,
|
||||
v);
|
||||
}
|
||||
item_trait(_, traits, ref methods) => {
|
||||
// Map trait refs to their parent classes. This is
|
||||
// so we can find the self_ty
|
||||
for traits.each |p| {
|
||||
cx.map.insert(p.ref_id, node_item(i, item_path));
|
||||
}
|
||||
@ -274,18 +272,8 @@ fn map_item(i: @item, cx: ctx, v: vt) {
|
||||
}
|
||||
|
||||
fn map_struct_def(struct_def: @ast::struct_def, parent_node: ast_node,
|
||||
ident: ast::ident, id: ast::node_id, cx: ctx, _v: vt) {
|
||||
// Map trait refs to their parent classes. This is
|
||||
// so we can find the self_ty
|
||||
for struct_def.traits.each |p| {
|
||||
cx.map.insert(p.ref_id, parent_node);
|
||||
}
|
||||
let d_id = ast_util::local_def(id);
|
||||
ident: ast::ident, cx: ctx, _v: vt) {
|
||||
let p = extend(cx, ident);
|
||||
// only need to handle methods
|
||||
for vec::each(struct_def.methods) |m| {
|
||||
map_method(d_id, p, *m, cx);
|
||||
}
|
||||
// If this is a tuple-like struct, register the constructor.
|
||||
match struct_def.ctor_id {
|
||||
None => {}
|
||||
@ -342,7 +330,7 @@ fn node_id_to_str(map: map, id: node_id, itr: @ident_interner) -> ~str {
|
||||
item_foreign_mod(*) => ~"foreign mod",
|
||||
item_ty(*) => ~"ty",
|
||||
item_enum(*) => ~"enum",
|
||||
item_class(*) => ~"class",
|
||||
item_struct(*) => ~"struct",
|
||||
item_trait(*) => ~"trait",
|
||||
item_impl(*) => ~"impl",
|
||||
item_mac(*) => ~"macro"
|
||||
|
@ -68,7 +68,7 @@ pure fn def_id_of_def(d: def) -> def_id {
|
||||
def_fn(id, _) | def_static_method(id, _, _) | def_mod(id) |
|
||||
def_foreign_mod(id) | def_const(id) |
|
||||
def_variant(_, id) | def_ty(id) | def_ty_param(id, _) |
|
||||
def_use(id) | def_class(id) => {
|
||||
def_use(id) | def_struct(id) => {
|
||||
id
|
||||
}
|
||||
def_arg(id, _) | def_local(id, _) | def_self(id) |
|
||||
@ -374,7 +374,7 @@ impl inlined_item: inlined_item_utils {
|
||||
ii_foreign(i) => (v.visit_foreign_item)(i, e, v),
|
||||
ii_method(_, m) => visit::visit_method_helper(m, e, v),
|
||||
ii_dtor(ref dtor, _, tps, parent_id) => {
|
||||
visit::visit_class_dtor_helper((*dtor), tps, parent_id, e, v);
|
||||
visit::visit_struct_dtor_helper((*dtor), tps, parent_id, e, v);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -131,7 +131,7 @@ fn expand_auto_serialize(
|
||||
|
||||
~[filter_attrs(*item), ser_impl]
|
||||
},
|
||||
ast::item_class(@{ fields, _}, tps) => {
|
||||
ast::item_struct(@{ fields, _}, tps) => {
|
||||
let ser_impl = mk_struct_ser_impl(
|
||||
cx,
|
||||
item.span,
|
||||
@ -195,7 +195,7 @@ fn expand_auto_deserialize(
|
||||
|
||||
~[filter_attrs(*item), deser_impl]
|
||||
},
|
||||
ast::item_class(@{ fields, _}, tps) => {
|
||||
ast::item_struct(@{ fields, _}, tps) => {
|
||||
let deser_impl = mk_struct_deser_impl(
|
||||
cx,
|
||||
item.span,
|
||||
@ -755,8 +755,8 @@ fn mk_struct_fields(fields: ~[@ast::struct_field]) -> ~[field] {
|
||||
span: field.span,
|
||||
ident: ident,
|
||||
mutbl: match mutbl {
|
||||
ast::class_mutable => ast::m_mutbl,
|
||||
ast::class_immutable => ast::m_imm,
|
||||
ast::struct_mutable => ast::m_mutbl,
|
||||
ast::struct_immutable => ast::m_imm,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,7 @@
|
||||
/// #[deriving_iter_bytes] extensions.
|
||||
|
||||
use ast::{Ty, and, bind_by_ref, binop, deref, enum_def, enum_variant_kind};
|
||||
use ast::{expr, expr_match, ident, item, item_, item_class, item_enum};
|
||||
use ast::{expr, expr_match, ident, item, item_, item_struct, item_enum};
|
||||
use ast::{item_impl, m_imm, meta_item, method, named_field, or, pat};
|
||||
use ast::{pat_ident, pat_wild, public, pure_fn, re_anon, stmt, struct_def};
|
||||
use ast::{struct_variant_kind, sty_by_ref, sty_region, tuple_variant_kind};
|
||||
@ -83,7 +83,7 @@ fn expand_deriving(cx: ext_ctxt,
|
||||
for in_items.each |item| {
|
||||
result.push(copy *item);
|
||||
match item.node {
|
||||
item_class(struct_def, copy ty_params) => {
|
||||
item_struct(struct_def, copy ty_params) => {
|
||||
result.push(expand_deriving_struct_def(cx,
|
||||
span,
|
||||
struct_def,
|
||||
|
@ -234,9 +234,9 @@ fn noop_fold_item_underscore(i: item_, fld: ast_fold) -> item_ {
|
||||
|x| fold_struct_def(*x, fld))
|
||||
}), fold_ty_params(typms, fld))
|
||||
}
|
||||
item_class(struct_def, typms) => {
|
||||
item_struct(struct_def, typms) => {
|
||||
let struct_def = fold_struct_def(struct_def, fld);
|
||||
item_class(struct_def, /* FIXME (#2543) */ copy typms)
|
||||
item_struct(struct_def, /* FIXME (#2543) */ copy typms)
|
||||
}
|
||||
item_impl(tps, ifce, ty, ref methods) => {
|
||||
item_impl(fold_ty_params(tps, fld),
|
||||
@ -271,9 +271,7 @@ fn fold_struct_def(struct_def: @ast::struct_def, fld: ast_fold)
|
||||
id: dtor_id,.. dtor.node},
|
||||
.. *dtor}};
|
||||
return @{
|
||||
traits: vec::map(struct_def.traits, |p| fold_trait_ref(*p, fld)),
|
||||
fields: vec::map(struct_def.fields, |f| fold_struct_field(*f, fld)),
|
||||
methods: vec::map(struct_def.methods, |m| fld.fold_method(*m)),
|
||||
dtor: dtor,
|
||||
ctor_id: option::map(&struct_def.ctor_id, |cid| fld.new_id(*cid))
|
||||
};
|
||||
@ -569,11 +567,8 @@ fn noop_fold_variant(v: variant_, fld: ast_fold) -> variant_ {
|
||||
id: dtor_id,.. dtor.node},
|
||||
.. *dtor}};
|
||||
kind = struct_variant_kind(@{
|
||||
traits: ~[],
|
||||
fields: vec::map(struct_def.fields,
|
||||
|f| fld.fold_struct_field(*f)),
|
||||
methods: vec::map(struct_def.methods,
|
||||
|m| fld.fold_method(*m)),
|
||||
dtor: dtor,
|
||||
ctor_id: option::map(&struct_def.ctor_id, |c| fld.new_id(*c))
|
||||
})
|
||||
|
@ -36,7 +36,7 @@ use ast::{_mod, add, arg, arm, attribute,
|
||||
bind_by_ref, bind_infer, bind_by_value, bind_by_move,
|
||||
bitand, bitor, bitxor, blk, blk_check_mode, box, by_copy,
|
||||
by_move, by_ref, by_val, capture_clause,
|
||||
capture_item, class_immutable, class_mutable,
|
||||
capture_item, struct_immutable, struct_mutable,
|
||||
crate, crate_cfg, decl, decl_item, decl_local,
|
||||
default_blk, deref, div, enum_def, enum_variant_kind, expl, expr,
|
||||
expr_, expr_addr_of, expr_match, expr_again, expr_assert,
|
||||
@ -50,7 +50,7 @@ use ast::{_mod, add, arg, arm, attribute,
|
||||
expr_vstore_mut_slice, expr_while, extern_fn, field, fn_decl,
|
||||
foreign_item, foreign_item_const, foreign_item_fn, foreign_mod,
|
||||
ident, impure_fn, infer, inherited,
|
||||
item, item_, item_class, item_const, item_enum, item_fn,
|
||||
item, item_, item_struct, item_const, item_enum, item_fn,
|
||||
item_foreign_mod, item_impl, item_mac, item_mod, item_trait,
|
||||
item_ty, lit, lit_, lit_bool, lit_float, lit_float_unsuffixed,
|
||||
lit_int, lit_int_unsuffixed, lit_nil, lit_str, lit_uint, local,
|
||||
@ -98,17 +98,10 @@ enum restriction {
|
||||
RESTRICT_NO_BAR_OR_DOUBLEBAR_OP,
|
||||
}
|
||||
|
||||
enum class_member {
|
||||
field_member(@struct_field),
|
||||
method_member(@method)
|
||||
}
|
||||
// So that we can distinguish a class dtor from other class members
|
||||
|
||||
/*
|
||||
So that we can distinguish a class ctor or dtor
|
||||
from other class members
|
||||
*/
|
||||
enum class_contents { dtor_decl(blk, ~[attribute], codemap::span),
|
||||
members(~[@class_member]) }
|
||||
members(~[@struct_field]) }
|
||||
|
||||
type arg_or_capture_item = Either<arg, capture_item>;
|
||||
type item_info = (ident, item_, Option<~[attribute]>);
|
||||
@ -2192,11 +2185,11 @@ impl Parser {
|
||||
}
|
||||
|
||||
/* assumes "let" token has already been consumed */
|
||||
fn parse_instance_var(pr: visibility) -> @class_member {
|
||||
let mut is_mutbl = class_immutable;
|
||||
fn parse_instance_var(pr: visibility) -> @struct_field {
|
||||
let mut is_mutbl = struct_immutable;
|
||||
let lo = self.span.lo;
|
||||
if self.eat_keyword(~"mut") {
|
||||
is_mutbl = class_mutable;
|
||||
is_mutbl = struct_mutable;
|
||||
}
|
||||
if !is_plain_ident(self.token) {
|
||||
self.fatal(~"expected ident");
|
||||
@ -2204,11 +2197,11 @@ impl Parser {
|
||||
let name = self.parse_ident();
|
||||
self.expect(token::COLON);
|
||||
let ty = self.parse_ty(false);
|
||||
return @field_member(@spanned(lo, self.last_span.hi, {
|
||||
return @spanned(lo, self.last_span.hi, {
|
||||
kind: named_field(name, is_mutbl, pr),
|
||||
id: self.get_id(),
|
||||
ty: ty
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
fn parse_stmt(+first_item_attrs: ~[attribute]) -> @stmt {
|
||||
@ -2811,18 +2804,16 @@ impl Parser {
|
||||
|p| p.parse_trait_ref())
|
||||
}
|
||||
|
||||
fn parse_item_class() -> item_info {
|
||||
fn parse_item_struct() -> item_info {
|
||||
let class_name = self.parse_value_ident();
|
||||
self.parse_region_param();
|
||||
let ty_params = self.parse_ty_params();
|
||||
let traits : ~[@trait_ref] = if self.eat(token::COLON) {
|
||||
if self.eat(token::COLON) {
|
||||
self.obsolete(copy self.span, ObsoleteClassTraits);
|
||||
self.parse_trait_ref_list(token::LBRACE)
|
||||
let _ = self.parse_trait_ref_list(token::LBRACE);
|
||||
}
|
||||
else { ~[] };
|
||||
|
||||
let mut fields: ~[@struct_field];
|
||||
let mut methods: ~[@method] = ~[];
|
||||
let mut the_dtor: Option<(blk, ~[attribute], codemap::span)> = None;
|
||||
let is_tuple_like;
|
||||
|
||||
@ -2847,13 +2838,8 @@ impl Parser {
|
||||
}
|
||||
}
|
||||
members(mms) => {
|
||||
for mms.each |mm| {
|
||||
match *mm {
|
||||
@field_member(struct_field) =>
|
||||
fields.push(struct_field),
|
||||
@method_member(the_method_member) =>
|
||||
methods.push(the_method_member)
|
||||
}
|
||||
for mms.each |struct_field| {
|
||||
fields.push(*struct_field)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2894,10 +2880,8 @@ impl Parser {
|
||||
let _ = self.get_id(); // XXX: Workaround for crazy bug.
|
||||
let new_id = self.get_id();
|
||||
(class_name,
|
||||
item_class(@{
|
||||
traits: traits,
|
||||
item_struct(@{
|
||||
fields: move fields,
|
||||
methods: move methods,
|
||||
dtor: actual_dtor,
|
||||
ctor_id: if is_tuple_like { Some(new_id) } else { None }
|
||||
}, ty_params),
|
||||
@ -2911,7 +2895,7 @@ impl Parser {
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_single_class_item(vis: visibility) -> @class_member {
|
||||
fn parse_single_class_item(vis: visibility) -> @struct_field {
|
||||
let obsolete_let = self.eat_obsolete_ident("let");
|
||||
if obsolete_let { self.obsolete(copy self.last_span, ObsoleteLet) }
|
||||
|
||||
@ -2939,10 +2923,16 @@ impl Parser {
|
||||
self.token)));
|
||||
}
|
||||
}
|
||||
return a_var;
|
||||
a_var
|
||||
} else {
|
||||
self.obsolete(copy self.span, ObsoleteClassMethod);
|
||||
return @method_member(self.parse_method());
|
||||
self.parse_method();
|
||||
// bogus value
|
||||
@spanned(self.span.lo, self.span.hi,
|
||||
{ kind: unnamed_field, id: self.get_id(),
|
||||
ty: @{id: self.get_id(),
|
||||
node: ty_nil,
|
||||
span: copy self.span} })
|
||||
}
|
||||
}
|
||||
|
||||
@ -3328,7 +3318,6 @@ impl Parser {
|
||||
fn parse_struct_def() -> @struct_def {
|
||||
let mut the_dtor: Option<(blk, ~[attribute], codemap::span)> = None;
|
||||
let mut fields: ~[@struct_field] = ~[];
|
||||
let mut methods: ~[@method] = ~[];
|
||||
while self.token != token::RBRACE {
|
||||
match self.parse_class_item() {
|
||||
dtor_decl(ref blk, ref attrs, s) => {
|
||||
@ -3346,13 +3335,8 @@ impl Parser {
|
||||
}
|
||||
}
|
||||
members(mms) => {
|
||||
for mms.each |mm| {
|
||||
match *mm {
|
||||
@field_member(struct_field) =>
|
||||
fields.push(struct_field),
|
||||
@method_member(the_method_member) =>
|
||||
methods.push(the_method_member)
|
||||
}
|
||||
for mms.each |struct_field| {
|
||||
fields.push(*struct_field);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -3368,9 +3352,7 @@ impl Parser {
|
||||
};
|
||||
|
||||
return @{
|
||||
traits: ~[],
|
||||
fields: move fields,
|
||||
methods: move methods,
|
||||
dtor: actual_dtor,
|
||||
ctor_id: None
|
||||
};
|
||||
@ -3593,7 +3575,7 @@ impl Parser {
|
||||
visibility,
|
||||
maybe_append(attrs, extra_attrs)));
|
||||
} else if items_allowed && self.eat_keyword(~"struct") {
|
||||
let (ident, item_, extra_attrs) = self.parse_item_class();
|
||||
let (ident, item_, extra_attrs) = self.parse_item_struct();
|
||||
return iovi_item(self.mk_item(lo, self.last_span.hi, ident, item_,
|
||||
visibility,
|
||||
maybe_append(attrs, extra_attrs)));
|
||||
|
@ -527,7 +527,7 @@ fn print_item(s: ps, &&item: @ast::item) {
|
||||
print_enum_def(s, (*enum_definition), params, item.ident,
|
||||
item.span, item.vis);
|
||||
}
|
||||
ast::item_class(struct_def, tps) => {
|
||||
ast::item_struct(struct_def, tps) => {
|
||||
head(s, visibility_qualified(item.vis, ~"struct"));
|
||||
print_struct(s, struct_def, tps, item.ident, item.span);
|
||||
}
|
||||
@ -676,11 +676,6 @@ fn print_struct(s: ps, struct_def: @ast::struct_def, tps: ~[ast::ty_param],
|
||||
print_ident(s, ident);
|
||||
nbsp(s);
|
||||
print_type_params(s, tps);
|
||||
if vec::len(struct_def.traits) != 0u {
|
||||
word_space(s, ~":");
|
||||
commasep(s, inconsistent, struct_def.traits, |s, p|
|
||||
print_path(s, p.path, false));
|
||||
}
|
||||
if ast_util::struct_def_is_tuple_like(struct_def) {
|
||||
popen(s);
|
||||
let mut first = true;
|
||||
@ -720,7 +715,7 @@ fn print_struct(s: ps, struct_def: @ast::struct_def, tps: ~[ast::ty_param],
|
||||
hardbreak_if_not_bol(s);
|
||||
maybe_print_comment(s, field.span.lo);
|
||||
print_visibility(s, visibility);
|
||||
if mutability == ast::class_mutable {
|
||||
if mutability == ast::struct_mutable {
|
||||
word_nbsp(s, ~"mut");
|
||||
}
|
||||
print_ident(s, ident);
|
||||
@ -731,9 +726,6 @@ fn print_struct(s: ps, struct_def: @ast::struct_def, tps: ~[ast::ty_param],
|
||||
}
|
||||
}
|
||||
|
||||
for struct_def.methods.each |method| {
|
||||
print_method(s, *method);
|
||||
}
|
||||
bclose(s, span);
|
||||
}
|
||||
}
|
||||
|
@ -154,7 +154,7 @@ fn visit_item<E>(i: @item, e: E, v: vt<E>) {
|
||||
visit_method_helper(*m, e, v)
|
||||
}
|
||||
}
|
||||
item_class(struct_def, tps) => {
|
||||
item_struct(struct_def, tps) => {
|
||||
(v.visit_ty_params)(tps, e, v);
|
||||
(v.visit_struct_def)(struct_def, i.ident, tps, i.id, e, v);
|
||||
}
|
||||
@ -297,7 +297,7 @@ fn visit_method_helper<E>(m: @method, e: E, v: vt<E>) {
|
||||
m.decl, m.body, m.span, m.id, e, v);
|
||||
}
|
||||
|
||||
fn visit_class_dtor_helper<E>(dtor: class_dtor, tps: ~[ty_param],
|
||||
fn visit_struct_dtor_helper<E>(dtor: struct_dtor, tps: ~[ty_param],
|
||||
parent_id: def_id, e: E, v: vt<E>) {
|
||||
(v.visit_fn)(fk_dtor(/* FIXME (#2543) */ copy tps, dtor.node.attrs,
|
||||
dtor.node.self_id, parent_id), ast_util::dtor_dec(),
|
||||
@ -330,14 +330,8 @@ fn visit_struct_def<E>(sd: @struct_def, _nm: ast::ident, tps: ~[ty_param],
|
||||
for sd.fields.each |f| {
|
||||
(v.visit_struct_field)(*f, e, v);
|
||||
}
|
||||
for sd.methods.each |m| {
|
||||
(v.visit_struct_method)(*m, e, v);
|
||||
}
|
||||
for sd.traits.each |p| {
|
||||
visit_path(p.path, e, v);
|
||||
}
|
||||
do option::iter(&sd.dtor) |dtor| {
|
||||
visit_class_dtor_helper(*dtor, tps, ast_util::local_def(id), e, v)
|
||||
visit_struct_dtor_helper(*dtor, tps, ast_util::local_def(id), e, v)
|
||||
};
|
||||
}
|
||||
|
||||
|
15
src/test/run-pass/guards-not-exhaustive.rs
Normal file
15
src/test/run-pass/guards-not-exhaustive.rs
Normal file
@ -0,0 +1,15 @@
|
||||
use option::*;
|
||||
|
||||
enum Q { R(Option<uint>) }
|
||||
|
||||
fn xyzzy(q: Q) -> uint {
|
||||
match q {
|
||||
R(S) if S.is_some() => { 0 }
|
||||
_ => 1
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fn main() {
|
||||
assert xyzzy(R(Some(5))) == 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user