auto merge of #7291 : alexcrichton/rust/static-mut, r=huonw
This adds both `static mut` items and `static mut` foreign items. This involved changing far less code than I thought it was going to, but the tests seem to pass and the variables seem functional. I'm more than willing to write more tests, so suggestions are welcome! Closes #553
This commit is contained in:
commit
b11346bb5d
40 changed files with 358 additions and 109 deletions
|
@ -33,8 +33,8 @@ use ast::{expr_vec, expr_vstore, expr_vstore_mut_box};
|
|||
use ast::{expr_vstore_slice, expr_vstore_box};
|
||||
use ast::{expr_vstore_mut_slice, expr_while, extern_fn, field, fn_decl};
|
||||
use ast::{expr_vstore_uniq, Onceness, Once, Many};
|
||||
use ast::{foreign_item, foreign_item_const, foreign_item_fn, foreign_mod};
|
||||
use ast::{ident, impure_fn, inherited, item, item_, item_const};
|
||||
use ast::{foreign_item, foreign_item_static, foreign_item_fn, foreign_mod};
|
||||
use ast::{ident, impure_fn, inherited, item, item_, item_static};
|
||||
use ast::{item_enum, item_fn, item_foreign_mod, item_impl};
|
||||
use ast::{item_mac, item_mod, item_struct, item_trait, item_ty, lit, lit_};
|
||||
use ast::{lit_bool, lit_float, lit_float_unsuffixed, lit_int};
|
||||
|
@ -3556,13 +3556,14 @@ impl Parser {
|
|||
}
|
||||
|
||||
fn parse_item_const(&self) -> item_info {
|
||||
let m = if self.eat_keyword(keywords::Mut) {m_mutbl} else {m_imm};
|
||||
let id = self.parse_ident();
|
||||
self.expect(&token::COLON);
|
||||
let ty = self.parse_ty(false);
|
||||
self.expect(&token::EQ);
|
||||
let e = self.parse_expr();
|
||||
self.expect(&token::SEMI);
|
||||
(id, item_const(ty, e), None)
|
||||
(id, item_static(ty, m, e), None)
|
||||
}
|
||||
|
||||
// parse a mod { ...} item
|
||||
|
@ -3683,6 +3684,7 @@ impl Parser {
|
|||
} else {
|
||||
self.expect_keyword(keywords::Static);
|
||||
}
|
||||
let mutbl = self.eat_keyword(keywords::Mut);
|
||||
|
||||
let ident = self.parse_ident();
|
||||
self.expect(&token::COLON);
|
||||
|
@ -3691,7 +3693,7 @@ impl Parser {
|
|||
self.expect(&token::SEMI);
|
||||
@ast::foreign_item { ident: ident,
|
||||
attrs: attrs,
|
||||
node: foreign_item_const(ty),
|
||||
node: foreign_item_static(ty, mutbl),
|
||||
id: self.get_id(),
|
||||
span: mk_sp(lo, hi),
|
||||
vis: vis }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue