auto merge of #9633 : alexcrichton/rust/issue-9631, r=huonw
Closes #9631
This commit is contained in:
commit
c8cdabc32f
@ -319,6 +319,17 @@ impl Context {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// These attributes are applied to all statics that this syntax extension
|
||||||
|
/// will generate.
|
||||||
|
fn static_attrs(&self) -> ~[ast::Attribute] {
|
||||||
|
// Flag statics as `address_insignificant` so LLVM can merge duplicate
|
||||||
|
// globals as much as possible (which we're generating a whole lot of).
|
||||||
|
let unnamed = self.ecx.meta_word(self.fmtsp, @"address_insignificant");
|
||||||
|
let unnamed = self.ecx.attribute(self.fmtsp, unnamed);
|
||||||
|
|
||||||
|
return ~[unnamed];
|
||||||
|
}
|
||||||
|
|
||||||
/// Translate a `parse::Piece` to a static `rt::Piece`
|
/// Translate a `parse::Piece` to a static `rt::Piece`
|
||||||
fn trans_piece(&mut self, piece: &parse::Piece) -> @ast::Expr {
|
fn trans_piece(&mut self, piece: &parse::Piece) -> @ast::Expr {
|
||||||
let sp = self.fmtsp;
|
let sp = self.fmtsp;
|
||||||
@ -444,14 +455,9 @@ impl Context {
|
|||||||
~[]
|
~[]
|
||||||
), None);
|
), None);
|
||||||
let st = ast::item_static(ty, ast::MutImmutable, method);
|
let st = ast::item_static(ty, ast::MutImmutable, method);
|
||||||
let static_name = self.ecx.ident_of(format!("__static_method_{}",
|
let static_name = self.ecx.ident_of(format!("__STATIC_METHOD_{}",
|
||||||
self.method_statics.len()));
|
self.method_statics.len()));
|
||||||
// Flag these statics as `address_insignificant` so LLVM can
|
let item = self.ecx.item(sp, static_name, self.static_attrs(), st);
|
||||||
// merge duplicate globals as much as possible (which we're
|
|
||||||
// generating a whole lot of).
|
|
||||||
let unnamed = self.ecx.meta_word(self.fmtsp, @"address_insignificant");
|
|
||||||
let unnamed = self.ecx.attribute(self.fmtsp, unnamed);
|
|
||||||
let item = self.ecx.item(sp, static_name, ~[unnamed], st);
|
|
||||||
self.method_statics.push(item);
|
self.method_statics.push(item);
|
||||||
self.ecx.expr_ident(sp, static_name)
|
self.ecx.expr_ident(sp, static_name)
|
||||||
};
|
};
|
||||||
@ -572,11 +578,9 @@ impl Context {
|
|||||||
);
|
);
|
||||||
let ty = self.ecx.ty(self.fmtsp, ty);
|
let ty = self.ecx.ty(self.fmtsp, ty);
|
||||||
let st = ast::item_static(ty, ast::MutImmutable, fmt);
|
let st = ast::item_static(ty, ast::MutImmutable, fmt);
|
||||||
let static_name = self.ecx.ident_of("__static_fmtstr");
|
let static_name = self.ecx.ident_of("__STATIC_FMTSTR");
|
||||||
// see above comment for `address_insignificant` and why we do it
|
let item = self.ecx.item(self.fmtsp, static_name,
|
||||||
let unnamed = self.ecx.meta_word(self.fmtsp, @"address_insignificant");
|
self.static_attrs(), st);
|
||||||
let unnamed = self.ecx.attribute(self.fmtsp, unnamed);
|
|
||||||
let item = self.ecx.item(self.fmtsp, static_name, ~[unnamed], st);
|
|
||||||
let decl = respan(self.fmtsp, ast::DeclItem(item));
|
let decl = respan(self.fmtsp, ast::DeclItem(item));
|
||||||
lets.push(@respan(self.fmtsp, ast::StmtDecl(@decl, ast::DUMMY_NODE_ID)));
|
lets.push(@respan(self.fmtsp, ast::StmtDecl(@decl, ast::DUMMY_NODE_ID)));
|
||||||
|
|
||||||
|
15
src/test/run-pass/format-no-uppercase-statics.rs
Normal file
15
src/test/run-pass/format-no-uppercase-statics.rs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
|
||||||
|
// file at the top-level directory of this distribution and at
|
||||||
|
// http://rust-lang.org/COPYRIGHT.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||||
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||||
|
// option. This file may not be copied, modified, or distributed
|
||||||
|
// except according to those terms.
|
||||||
|
|
||||||
|
#[deny(non_uppercase_statics)];
|
||||||
|
|
||||||
|
pub fn main() {
|
||||||
|
println!("I generate statics with {0, select, other{#}}", "weird names");
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user