Change the format! statics to be all-caps
This lets them get past the non_uppercase_statics lint mode (if it's turned on) Closes #9631
This commit is contained in:
parent
12404aaadd
commit
eafbcfb73c
@ -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`
|
||||
fn trans_piece(&mut self, piece: &parse::Piece) -> @ast::Expr {
|
||||
let sp = self.fmtsp;
|
||||
@ -444,14 +455,9 @@ impl Context {
|
||||
~[]
|
||||
), None);
|
||||
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()));
|
||||
// Flag these 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);
|
||||
let item = self.ecx.item(sp, static_name, ~[unnamed], st);
|
||||
let item = self.ecx.item(sp, static_name, self.static_attrs(), st);
|
||||
self.method_statics.push(item);
|
||||
self.ecx.expr_ident(sp, static_name)
|
||||
};
|
||||
@ -572,11 +578,9 @@ impl Context {
|
||||
);
|
||||
let ty = self.ecx.ty(self.fmtsp, ty);
|
||||
let st = ast::item_static(ty, ast::MutImmutable, fmt);
|
||||
let static_name = self.ecx.ident_of("__static_fmtstr");
|
||||
// see above comment for `address_insignificant` and why we do it
|
||||
let unnamed = self.ecx.meta_word(self.fmtsp, @"address_insignificant");
|
||||
let unnamed = self.ecx.attribute(self.fmtsp, unnamed);
|
||||
let item = self.ecx.item(self.fmtsp, static_name, ~[unnamed], st);
|
||||
let static_name = self.ecx.ident_of("__STATIC_FMTSTR");
|
||||
let item = self.ecx.item(self.fmtsp, static_name,
|
||||
self.static_attrs(), st);
|
||||
let decl = respan(self.fmtsp, ast::DeclItem(item));
|
||||
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