Skip to content

Commit 7e0b79d

Browse files
committed
Use rvalue promotion to 'static instead of static items.
1 parent a3beb8f commit 7e0b79d

File tree

5 files changed

+10
-63
lines changed

5 files changed

+10
-63
lines changed

src/libcore/macros.rs

+3-10
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,11 @@ macro_rules! panic {
1717
panic!("explicit panic")
1818
);
1919
($msg:expr) => ({
20-
static _MSG_FILE_LINE_COL: (&'static str, &'static str, u32, u32) =
21-
($msg, file!(), line!(), __rust_unstable_column!());
22-
$crate::panicking::panic(&_MSG_FILE_LINE_COL)
20+
$crate::panicking::panic(&($msg, file!(), line!(), __rust_unstable_column!()))
2321
});
2422
($fmt:expr, $($arg:tt)*) => ({
25-
// The leading _'s are to avoid dead code warnings if this is
26-
// used inside a dead function. Just `#[allow(dead_code)]` is
27-
// insufficient, since the user may have
28-
// `#[forbid(dead_code)]` and which cannot be overridden.
29-
static _MSG_FILE_LINE_COL: (&'static str, u32, u32) =
30-
(file!(), line!(), __rust_unstable_column!());
31-
$crate::panicking::panic_fmt(format_args!($fmt, $($arg)*), &_MSG_FILE_LINE_COL)
23+
$crate::panicking::panic_fmt(format_args!($fmt, $($arg)*),
24+
&(file!(), line!(), __rust_unstable_column!()))
3225
});
3326
}
3427

src/librustc_mir/transform/elaborate_drops.rs

-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ use syntax::ast;
2929
use syntax_pos::Span;
3030

3131
use std::fmt;
32-
use std::u32;
3332

3433
pub struct ElaborateDrops;
3534

src/libstd/ffi/c_str.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ impl fmt::Debug for CStr {
545545
#[stable(feature = "cstr_default", since = "1.10.0")]
546546
impl<'a> Default for &'a CStr {
547547
fn default() -> &'a CStr {
548-
static SLICE: &'static [c_char] = &[0];
548+
const SLICE: &'static [c_char] = &[0];
549549
unsafe { CStr::from_ptr(SLICE.as_ptr()) }
550550
}
551551
}

src/libstd/macros.rs

+3-15
Original file line numberDiff line numberDiff line change
@@ -66,23 +66,11 @@ macro_rules! panic {
6666
panic!("explicit panic")
6767
});
6868
($msg:expr) => ({
69-
$crate::rt::begin_panic($msg, {
70-
// static requires less code at runtime, more constant data
71-
static _FILE_LINE_COL: (&'static str, u32, u32) = (file!(), line!(),
72-
__rust_unstable_column!());
73-
&_FILE_LINE_COL
74-
})
69+
$crate::rt::begin_panic($msg, &(file!(), line!(), __rust_unstable_column!()))
7570
});
7671
($fmt:expr, $($arg:tt)+) => ({
77-
$crate::rt::begin_panic_fmt(&format_args!($fmt, $($arg)+), {
78-
// The leading _'s are to avoid dead code warnings if this is
79-
// used inside a dead function. Just `#[allow(dead_code)]` is
80-
// insufficient, since the user may have
81-
// `#[forbid(dead_code)]` and which cannot be overridden.
82-
static _FILE_LINE_COL: (&'static str, u32, u32) = (file!(), line!(),
83-
__rust_unstable_column!());
84-
&_FILE_LINE_COL
85-
})
72+
$crate::rt::begin_panic_fmt(&format_args!($fmt, $($arg)+),
73+
&(file!(), line!(), __rust_unstable_column!()))
8674
});
8775
}
8876

src/libsyntax_ext/format.rs

+3-36
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use syntax::ext::base;
1919
use syntax::ext::build::AstBuilder;
2020
use syntax::parse::token;
2121
use syntax::ptr::P;
22-
use syntax::symbol::{Symbol, keywords};
22+
use syntax::symbol::Symbol;
2323
use syntax_pos::{Span, DUMMY_SP};
2424
use syntax::tokenstream;
2525

@@ -501,32 +501,6 @@ impl<'a, 'b> Context<'a, 'b> {
501501
}
502502
}
503503

504-
fn static_array(ecx: &mut ExtCtxt,
505-
name: &str,
506-
piece_ty: P<ast::Ty>,
507-
pieces: Vec<P<ast::Expr>>)
508-
-> P<ast::Expr> {
509-
let sp = piece_ty.span;
510-
let ty = ecx.ty_rptr(sp,
511-
ecx.ty(sp, ast::TyKind::Slice(piece_ty)),
512-
Some(ecx.lifetime(sp, keywords::StaticLifetime.ident())),
513-
ast::Mutability::Immutable);
514-
let slice = ecx.expr_vec_slice(sp, pieces);
515-
// static instead of const to speed up codegen by not requiring this to be inlined
516-
let st = ast::ItemKind::Static(ty, ast::Mutability::Immutable, slice);
517-
518-
let name = ecx.ident_of(name);
519-
let item = ecx.item(sp, name, vec![], st);
520-
let stmt = ast::Stmt {
521-
id: ast::DUMMY_NODE_ID,
522-
node: ast::StmtKind::Item(item),
523-
span: sp,
524-
};
525-
526-
// Wrap the declaration in a block so that it forms a single expression.
527-
ecx.expr_block(ecx.block(sp, vec![stmt, ecx.stmt_expr(ecx.expr_ident(sp, name))]))
528-
}
529-
530504
/// Actually builds the expression which the format_args! block will be
531505
/// expanded to
532506
fn into_expr(self) -> P<ast::Expr> {
@@ -537,12 +511,7 @@ impl<'a, 'b> Context<'a, 'b> {
537511

538512
// First, build up the static array which will become our precompiled
539513
// format "string"
540-
let static_lifetime = self.ecx.lifetime(self.fmtsp, keywords::StaticLifetime.ident());
541-
let piece_ty = self.ecx.ty_rptr(self.fmtsp,
542-
self.ecx.ty_ident(self.fmtsp, self.ecx.ident_of("str")),
543-
Some(static_lifetime),
544-
ast::Mutability::Immutable);
545-
let pieces = Context::static_array(self.ecx, "__STATIC_FMTSTR", piece_ty, self.str_pieces);
514+
let pieces = self.ecx.expr_vec_slice(self.fmtsp, self.str_pieces);
546515

547516
// Before consuming the expressions, we have to remember spans for
548517
// count arguments as they are now generated separate from other
@@ -623,9 +592,7 @@ impl<'a, 'b> Context<'a, 'b> {
623592
} else {
624593
// Build up the static array which will store our precompiled
625594
// nonstandard placeholders, if there are any.
626-
let piece_ty = self.ecx
627-
.ty_path(self.ecx.path_global(self.macsp, Context::rtpath(self.ecx, "Argument")));
628-
let fmt = Context::static_array(self.ecx, "__STATIC_FMTARGS", piece_ty, self.pieces);
595+
let fmt = self.ecx.expr_vec_slice(self.macsp, self.pieces);
629596

630597
("new_v1_formatted", vec![pieces, args_slice, fmt])
631598
};

0 commit comments

Comments
 (0)