Skip to content

Commit c8cdabc

Browse files
committed
auto merge of #9633 : alexcrichton/rust/issue-9631, r=huonw
Closes #9631
2 parents 24a2537 + eafbcfb commit c8cdabc

File tree

2 files changed

+31
-12
lines changed

2 files changed

+31
-12
lines changed

src/libsyntax/ext/format.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,17 @@ impl Context {
319319
}
320320
}
321321

322+
/// These attributes are applied to all statics that this syntax extension
323+
/// will generate.
324+
fn static_attrs(&self) -> ~[ast::Attribute] {
325+
// Flag statics as `address_insignificant` so LLVM can merge duplicate
326+
// globals as much as possible (which we're generating a whole lot of).
327+
let unnamed = self.ecx.meta_word(self.fmtsp, @"address_insignificant");
328+
let unnamed = self.ecx.attribute(self.fmtsp, unnamed);
329+
330+
return ~[unnamed];
331+
}
332+
322333
/// Translate a `parse::Piece` to a static `rt::Piece`
323334
fn trans_piece(&mut self, piece: &parse::Piece) -> @ast::Expr {
324335
let sp = self.fmtsp;
@@ -444,14 +455,9 @@ impl Context {
444455
~[]
445456
), None);
446457
let st = ast::item_static(ty, ast::MutImmutable, method);
447-
let static_name = self.ecx.ident_of(format!("__static_method_{}",
458+
let static_name = self.ecx.ident_of(format!("__STATIC_METHOD_{}",
448459
self.method_statics.len()));
449-
// Flag these statics as `address_insignificant` so LLVM can
450-
// merge duplicate globals as much as possible (which we're
451-
// generating a whole lot of).
452-
let unnamed = self.ecx.meta_word(self.fmtsp, @"address_insignificant");
453-
let unnamed = self.ecx.attribute(self.fmtsp, unnamed);
454-
let item = self.ecx.item(sp, static_name, ~[unnamed], st);
460+
let item = self.ecx.item(sp, static_name, self.static_attrs(), st);
455461
self.method_statics.push(item);
456462
self.ecx.expr_ident(sp, static_name)
457463
};
@@ -572,11 +578,9 @@ impl Context {
572578
);
573579
let ty = self.ecx.ty(self.fmtsp, ty);
574580
let st = ast::item_static(ty, ast::MutImmutable, fmt);
575-
let static_name = self.ecx.ident_of("__static_fmtstr");
576-
// see above comment for `address_insignificant` and why we do it
577-
let unnamed = self.ecx.meta_word(self.fmtsp, @"address_insignificant");
578-
let unnamed = self.ecx.attribute(self.fmtsp, unnamed);
579-
let item = self.ecx.item(self.fmtsp, static_name, ~[unnamed], st);
581+
let static_name = self.ecx.ident_of("__STATIC_FMTSTR");
582+
let item = self.ecx.item(self.fmtsp, static_name,
583+
self.static_attrs(), st);
580584
let decl = respan(self.fmtsp, ast::DeclItem(item));
581585
lets.push(@respan(self.fmtsp, ast::StmtDecl(@decl, ast::DUMMY_NODE_ID)));
582586

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#[deny(non_uppercase_statics)];
12+
13+
pub fn main() {
14+
println!("I generate statics with {0, select, other{#}}", "weird names");
15+
}

0 commit comments

Comments
 (0)