Skip to content

Commit 8fdc8f3

Browse files
committed
Support foreign 'static mut' variables as well
1 parent 1841b31 commit 8fdc8f3

File tree

16 files changed

+129
-40
lines changed

16 files changed

+129
-40
lines changed

src/librustc/metadata/encoder.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,9 +1111,13 @@ fn encode_info_for_foreign_item(ecx: &EncodeContext,
11111111
}
11121112
encode_path(ecx, ebml_w, path, ast_map::path_name(nitem.ident));
11131113
}
1114-
foreign_item_const(*) => {
1114+
foreign_item_static(_, mutbl) => {
11151115
encode_def_id(ebml_w, local_def(nitem.id));
1116-
encode_family(ebml_w, 'c');
1116+
if mutbl {
1117+
encode_family(ebml_w, 'b');
1118+
} else {
1119+
encode_family(ebml_w, 'c');
1120+
}
11171121
encode_type(ecx, ebml_w, node_id_to_type(ecx.tcx, nitem.id));
11181122
encode_symbol(ecx, ebml_w, nitem.id);
11191123
encode_path(ecx, ebml_w, path, ast_map::path_name(nitem.ident));

src/librustc/middle/lint.rs

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -709,40 +709,42 @@ fn check_item_default_methods(cx: &Context, item: @ast::item) {
709709
}
710710

711711
fn check_item_ctypes(cx: &Context, it: @ast::item) {
712+
fn check_ty(cx: &Context, ty: @ast::Ty) {
713+
match ty.node {
714+
ast::ty_path(_, _, id) => {
715+
match cx.tcx.def_map.get_copy(&id) {
716+
ast::def_prim_ty(ast::ty_int(ast::ty_i)) => {
717+
cx.span_lint(ctypes, ty.span,
718+
"found rust type `int` in foreign module, while \
719+
libc::c_int or libc::c_long should be used");
720+
}
721+
ast::def_prim_ty(ast::ty_uint(ast::ty_u)) => {
722+
cx.span_lint(ctypes, ty.span,
723+
"found rust type `uint` in foreign module, while \
724+
libc::c_uint or libc::c_ulong should be used");
725+
}
726+
_ => ()
727+
}
728+
}
729+
_ => ()
730+
}
731+
}
712732

713733
fn check_foreign_fn(cx: &Context, decl: &ast::fn_decl) {
714734
let tys = vec::map(decl.inputs, |a| a.ty );
715735
for vec::each(vec::append_one(tys, decl.output)) |ty| {
716-
match ty.node {
717-
ast::ty_path(_, _, id) => {
718-
match cx.tcx.def_map.get_copy(&id) {
719-
ast::def_prim_ty(ast::ty_int(ast::ty_i)) => {
720-
cx.span_lint(ctypes, ty.span,
721-
"found rust type `int` in foreign module, while \
722-
libc::c_int or libc::c_long should be used");
723-
}
724-
ast::def_prim_ty(ast::ty_uint(ast::ty_u)) => {
725-
cx.span_lint(ctypes, ty.span,
726-
"found rust type `uint` in foreign module, while \
727-
libc::c_uint or libc::c_ulong should be used");
728-
}
729-
_ => ()
730-
}
731-
}
732-
_ => ()
733-
}
736+
check_ty(cx, *ty);
734737
}
735738
}
736739

737740
match it.node {
738741
ast::item_foreign_mod(ref nmod) if !nmod.abis.is_intrinsic() => {
739742
for nmod.items.iter().advance |ni| {
740743
match ni.node {
741-
ast::foreign_item_fn(ref decl, _, _) => {
742-
check_foreign_fn(cx, decl);
743-
}
744-
// FIXME #4622: Not implemented.
745-
ast::foreign_item_const(*) => {}
744+
ast::foreign_item_fn(ref decl, _, _) => {
745+
check_foreign_fn(cx, decl);
746+
}
747+
ast::foreign_item_static(t, _) => { check_ty(cx, t); }
746748
}
747749
}
748750
}

src/librustc/middle/resolve.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1566,8 +1566,8 @@ impl Resolver {
15661566
visit_foreign_item(foreign_item, (new_parent, visitor));
15671567
}
15681568
}
1569-
foreign_item_const(*) => {
1570-
let def = def_static(local_def(foreign_item.id), false);
1569+
foreign_item_static(_, m) => {
1570+
let def = def_static(local_def(foreign_item.id), m);
15711571
name_bindings.define_value(Public, def, foreign_item.span);
15721572

15731573
visit_foreign_item(foreign_item, (new_parent, visitor));
@@ -3665,7 +3665,7 @@ impl Resolver {
36653665
|| visit_foreign_item(*foreign_item,
36663666
((), visitor)));
36673667
}
3668-
foreign_item_const(_) => {
3668+
foreign_item_static(*) => {
36693669
visit_foreign_item(*foreign_item,
36703670
((), visitor));
36713671
}

src/librustc/middle/trans/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2463,7 +2463,7 @@ pub fn get_item_val(ccx: @mut CrateContext, id: ast::node_id) -> ValueRef {
24632463
ni.id,
24642464
ni.attrs)
24652465
}
2466-
ast::foreign_item_const(*) => {
2466+
ast::foreign_item_static(*) => {
24672467
let typ = ty::node_id_to_type(ccx.tcx, ni.id);
24682468
let ident = token::ident_to_str(&ni.ident);
24692469
let g = do str::as_c_str(ident) |buf| {

src/librustc/middle/trans/foreign.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ pub fn trans_foreign_mod(ccx: @mut CrateContext,
332332
}
333333
}
334334
}
335-
ast::foreign_item_const(*) => {
335+
ast::foreign_item_static(*) => {
336336
let ident = token::ident_to_str(&foreign_item.ident);
337337
ccx.item_symbols.insert(foreign_item.id, /* bad */ident.to_owned());
338338
}

src/librustc/middle/typeck/collect.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1153,7 +1153,7 @@ pub fn ty_of_foreign_item(ccx: &CrateCtxt,
11531153
generics,
11541154
abis)
11551155
}
1156-
ast::foreign_item_const(t) => {
1156+
ast::foreign_item_static(t, _) => {
11571157
ty::ty_param_bounds_and_ty {
11581158
generics: ty::Generics {
11591159
type_param_defs: @~[],

src/librustdoc/extract.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ fn nmoddoc_from_mod(
150150
ast::foreign_item_fn(*) => {
151151
fns.push(fndoc_from_fn(ItemDoc));
152152
}
153-
ast::foreign_item_const(*) => {} // XXX: Not implemented.
153+
ast::foreign_item_static(*) => {} // XXX: Not implemented.
154154
}
155155
}
156156
doc::NmodDoc {

src/libsyntax/ast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1124,7 +1124,7 @@ pub struct foreign_item {
11241124
#[deriving(Eq, Encodable, Decodable)]
11251125
pub enum foreign_item_ {
11261126
foreign_item_fn(fn_decl, purity, Generics),
1127-
foreign_item_const(@Ty)
1127+
foreign_item_static(@Ty, /* is_mutbl */ bool),
11281128
}
11291129

11301130
// The data we save and restore about an inlined item or method. This is not

src/libsyntax/fold.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,8 @@ fn noop_fold_foreign_item(ni: @foreign_item, fld: @ast_fold)
236236
purity,
237237
fold_generics(generics, fld))
238238
}
239-
foreign_item_const(t) => {
240-
foreign_item_const(fld.fold_ty(t))
239+
foreign_item_static(t, m) => {
240+
foreign_item_static(fld.fold_ty(t), m)
241241
}
242242
},
243243
id: fld.new_id(ni.id),

src/libsyntax/parse/parser.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use ast::{expr_vec, expr_vstore, expr_vstore_mut_box};
3333
use ast::{expr_vstore_slice, expr_vstore_box};
3434
use ast::{expr_vstore_mut_slice, expr_while, extern_fn, field, fn_decl};
3535
use ast::{expr_vstore_uniq, Onceness, Once, Many};
36-
use ast::{foreign_item, foreign_item_const, foreign_item_fn, foreign_mod};
36+
use ast::{foreign_item, foreign_item_static, foreign_item_fn, foreign_mod};
3737
use ast::{ident, impure_fn, inherited, item, item_, item_static};
3838
use ast::{item_enum, item_fn, item_foreign_mod, item_impl};
3939
use ast::{item_mac, item_mod, item_struct, item_trait, item_ty, lit, lit_};
@@ -3684,6 +3684,7 @@ impl Parser {
36843684
} else {
36853685
self.expect_keyword(keywords::Static);
36863686
}
3687+
let mutbl = self.eat_keyword(keywords::Mut);
36873688

36883689
let ident = self.parse_ident();
36893690
self.expect(&token::COLON);
@@ -3692,7 +3693,7 @@ impl Parser {
36923693
self.expect(&token::SEMI);
36933694
@ast::foreign_item { ident: ident,
36943695
attrs: attrs,
3695-
node: foreign_item_const(ty),
3696+
node: foreign_item_static(ty, mutbl),
36963697
id: self.get_id(),
36973698
span: mk_sp(lo, hi),
36983699
vis: vis }

0 commit comments

Comments
 (0)