Skip to content

Instantly share code, notes, and snippets.

@brooksbp
Created February 14, 2015 06:41
Show Gist options
  • Save brooksbp/babc8303ce5982311ef4 to your computer and use it in GitHub Desktop.
Save brooksbp/babc8303ce5982311ef4 to your computer and use it in GitHub Desktop.
diff --git a/src/libcore/macros.rs b/src/libcore/macros.rs
index d02ed7c..11af436 100644
--- a/src/libcore/macros.rs
+++ b/src/libcore/macros.rs
@@ -15,8 +15,10 @@ macro_rules! panic {
panic!("explicit panic")
);
($msg:expr) => ({
- static _MSG_FILE_LINE: (&'static str, &'static str, usize) =
- ($msg, file!(), line!() as usize);
+ #[cfg(stage0)]
+ static _MSG_FILE_LINE: (&'static str, &'static str, u32) = ($msg, file!(), line!() as u32);
+ #[cfg(not(stage0))]
+ static _MSG_FILE_LINE: (&'static str, &'static str, u32) = ($msg, file!(), line!());
::core::panicking::panic(&_MSG_FILE_LINE)
});
($fmt:expr, $($arg:tt)*) => ({
@@ -24,7 +26,10 @@ macro_rules! panic {
// used inside a dead function. Just `#[allow(dead_code)]` is
// insufficient, since the user may have
// `#[forbid(dead_code)]` and which cannot be overridden.
- static _FILE_LINE: (&'static str, usize) = (file!(), line!() as usize);
+ #[cfg(stage0)]
+ static _FILE_LINE: (&'static str, u32) = (file!(), line!() as u32);
+ #[cfg(not(stage0))]
+ static _FILE_LINE: (&'static str, u32) = (file!(), line!());
::core::panicking::panic_fmt(format_args!($fmt, $($arg)*), &_FILE_LINE)
});
}
diff --git a/src/libcore/panicking.rs b/src/libcore/panicking.rs
index 61b4284..5164bce 100644
--- a/src/libcore/panicking.rs
+++ b/src/libcore/panicking.rs
@@ -34,26 +34,26 @@ use fmt;
#[cold] #[inline(never)] // this is the slow path, always
#[lang="panic"]
-pub fn panic(expr_file_line: &(&'static str, &'static str, uint)) -> ! {
+pub fn panic(expr_file_line: &(&'static str, &'static str, u32)) -> ! {
let (expr, file, line) = *expr_file_line;
panic_fmt(format_args!("{}", expr), &(file, line))
}
#[cold] #[inline(never)]
#[lang="panic_bounds_check"]
-fn panic_bounds_check(file_line: &(&'static str, uint),
+fn panic_bounds_check(file_line: &(&'static str, u32),
index: uint, len: uint) -> ! {
panic_fmt(format_args!("index out of bounds: the len is {} but the index is {}",
len, index), file_line)
}
#[cold] #[inline(never)]
-pub fn panic_fmt(fmt: fmt::Arguments, file_line: &(&'static str, uint)) -> ! {
+pub fn panic_fmt(fmt: fmt::Arguments, file_line: &(&'static str, u32)) -> ! {
#[allow(improper_ctypes)]
extern {
#[lang = "panic_fmt"]
- fn panic_impl(fmt: fmt::Arguments, file: &'static str, line: uint) -> !;
+ fn panic_impl(fmt: fmt::Arguments, file: &'static str, line: usize) -> !;
}
let (file, line) = *file_line;
- unsafe { panic_impl(fmt, file, line) }
+ unsafe { panic_impl(fmt, file, line as usize) }
}
diff --git a/src/liblog/lib.rs b/src/liblog/lib.rs
index 1fedf49..68246f3 100644
--- a/src/liblog/lib.rs
+++ b/src/liblog/lib.rs
@@ -343,7 +343,7 @@ pub struct LogRecord<'a> {
pub file: &'a str,
/// The line number of where the LogRecord originated.
- pub line: uint,
+ pub line: u32,
}
#[doc(hidden)]
@@ -351,7 +351,7 @@ pub struct LogRecord<'a> {
pub struct LogLocation {
pub module_path: &'static str,
pub file: &'static str,
- pub line: uint,
+ pub line: u32,
}
/// Tests whether a given module's name is enabled for a particular level of
diff --git a/src/liblog/macros.rs b/src/liblog/macros.rs
index 787d9c4..b1d292e 100644
--- a/src/liblog/macros.rs
+++ b/src/liblog/macros.rs
@@ -50,8 +50,15 @@
#[macro_export]
macro_rules! log {
($lvl:expr, $($arg:tt)+) => ({
+ #[cfg(stage0)]
static LOC: ::log::LogLocation = ::log::LogLocation {
- line: line!() as usize,
+ line: line!() as u32,
+ file: file!(),
+ module_path: module_path!(),
+ };
+ #[cfg(not(stage0))]
+ static LOC: ::log::LogLocation = ::log::LogLocation {
+ line: line!(),
file: file!(),
module_path: module_path!(),
};
diff --git a/src/libstd/macros.rs b/src/libstd/macros.rs
index 7132cd6..748a1b0 100644
--- a/src/libstd/macros.rs
+++ b/src/libstd/macros.rs
@@ -44,7 +44,10 @@ macro_rules! panic {
($msg:expr) => ({
$crate::rt::begin_unwind($msg, {
// static requires less code at runtime, more constant data
- static _FILE_LINE: (&'static str, usize) = (file!(), line!() as usize);
+ #[cfg(stage0)]
+ static _FILE_LINE: (&'static str, u32) = (file!(), line!() as u32);
+ #[cfg(not(stage0))]
+ static _FILE_LINE: (&'static str, u32) = (file!(), line!());
&_FILE_LINE
})
});
@@ -54,7 +57,10 @@ macro_rules! panic {
// used inside a dead function. Just `#[allow(dead_code)]` is
// insufficient, since the user may have
// `#[forbid(dead_code)]` and which cannot be overridden.
- static _FILE_LINE: (&'static str, usize) = (file!(), line!() as usize);
+ #[cfg(stage0)]
+ static _FILE_LINE: (&'static str, u32) = (file!(), line!() as u32);
+ #[cfg(not(stage0))]
+ static _FILE_LINE: (&'static str, u32) = (file!(), line!());
&_FILE_LINE
})
});
diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs
index 454c21f..7ba045f 100644
--- a/src/libsyntax/ext/build.rs
+++ b/src/libsyntax/ext/build.rs
@@ -147,6 +147,7 @@ pub trait AstBuilder {
fn expr_usize(&self, span: Span, i: usize) -> P<ast::Expr>;
fn expr_int(&self, sp: Span, i: isize) -> P<ast::Expr>;
+ fn expr_u8(&self, sp: Span, u: u8) -> P<ast::Expr>;
fn expr_u32(&self, sp: Span, u: u32) -> P<ast::Expr>;
fn expr_bool(&self, sp: Span, value: bool) -> P<ast::Expr>;
@@ -701,6 +702,9 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
self.expr_lit(sp, ast::LitInt(i as u64, ast::SignedIntLit(ast::TyIs(false),
ast::Sign::new(i))))
}
+ fn expr_u8(&self, sp: Span, u: u8) -> P<ast::Expr> {
+ self.expr_lit(sp, ast::LitInt(u as u64, ast::UnsignedIntLit(ast::TyU8)))
+ }
fn expr_u32(&self, sp: Span, u: u32) -> P<ast::Expr> {
self.expr_lit(sp, ast::LitInt(u as u64, ast::UnsignedIntLit(ast::TyU32)))
}
diff --git a/src/test/run-pass/syntax-extension-source-utils-files/includeme.fragment b/src/test/run-pass/s\
yntax-extension-source-utils-files/includeme.fragment
index 70cd7b7..61d6d3f 100644
--- a/src/test/run-pass/syntax-extension-source-utils-files/includeme.fragment
+++ b/src/test/run-pass/syntax-extension-source-utils-files/includeme.fragment
@@ -2,6 +2,6 @@
{
assert!(file!().ends_with("includeme.fragment"));
- assert!(line!() == 5_u32);
+ assert!(line!() == 5u32);
format!("victory robot {}", line!())
}
diff --git a/src/test/run-pass/syntax-extension-source-utils.rs b/src/test/run-pass/syntax-extension-source\
-utils.rs
index d1dc02b..ddd8cd8 100644
--- a/src/test/run-pass/syntax-extension-source-utils.rs
+++ b/src/test/run-pass/syntax-extension-source-utils.rs
@@ -23,7 +23,7 @@ macro_rules! indirect_line { () => ( line!() ) }
pub fn main() {
assert_eq!(line!(), 25);
- assert!((column!() == 4_u32));
+ assert!((column!() == 4u32));
assert_eq!(indirect_line!(), 27);
assert!((file!().ends_with("syntax-extension-source-utils.rs")));
assert_eq!(stringify!((2*3) + 5).to_string(), "( 2 * 3 ) + 5".to_string());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment