Skip to content

Commit f0f7ca2

Browse files
committed
Auto merge of #21769 - brooksbp:column-line-macro, r=nick29581
Please see discussion in #19284 .
2 parents 67eb38e + fc9fa1a commit f0f7ca2

File tree

11 files changed

+66
-15
lines changed

11 files changed

+66
-15
lines changed

src/libcore/macros.rs

+6
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,21 @@ macro_rules! panic {
1515
panic!("explicit panic")
1616
);
1717
($msg:expr) => ({
18+
#[cfg(stage0)]
1819
static _MSG_FILE_LINE: (&'static str, &'static str, usize) = ($msg, file!(), line!());
20+
#[cfg(not(stage0))]
21+
static _MSG_FILE_LINE: (&'static str, &'static str, u32) = ($msg, file!(), line!());
1922
::core::panicking::panic(&_MSG_FILE_LINE)
2023
});
2124
($fmt:expr, $($arg:tt)*) => ({
2225
// The leading _'s are to avoid dead code warnings if this is
2326
// used inside a dead function. Just `#[allow(dead_code)]` is
2427
// insufficient, since the user may have
2528
// `#[forbid(dead_code)]` and which cannot be overridden.
29+
#[cfg(stage0)]
2630
static _FILE_LINE: (&'static str, usize) = (file!(), line!());
31+
#[cfg(not(stage0))]
32+
static _FILE_LINE: (&'static str, u32) = (file!(), line!());
2733
::core::panicking::panic_fmt(format_args!($fmt, $($arg)*), &_FILE_LINE)
2834
});
2935
}

src/libcore/panicking.rs

+34-5
Original file line numberDiff line numberDiff line change
@@ -34,26 +34,55 @@ use fmt;
3434

3535
#[cold] #[inline(never)] // this is the slow path, always
3636
#[lang="panic"]
37-
pub fn panic(expr_file_line: &(&'static str, &'static str, uint)) -> ! {
37+
#[cfg(stage0)]
38+
pub fn panic(expr_file_line: &(&'static str, &'static str, usize)) -> ! {
39+
let (expr, file, line) = *expr_file_line;
40+
panic_fmt(format_args!("{}", expr), &(file, line))
41+
}
42+
#[cold] #[inline(never)] // this is the slow path, always
43+
#[lang="panic"]
44+
#[cfg(not(stage0))]
45+
pub fn panic(expr_file_line: &(&'static str, &'static str, u32)) -> ! {
3846
let (expr, file, line) = *expr_file_line;
3947
panic_fmt(format_args!("{}", expr), &(file, line))
4048
}
4149

4250
#[cold] #[inline(never)]
4351
#[lang="panic_bounds_check"]
44-
fn panic_bounds_check(file_line: &(&'static str, uint),
45-
index: uint, len: uint) -> ! {
52+
#[cfg(stage0)]
53+
fn panic_bounds_check(file_line: &(&'static str, usize),
54+
index: usize, len: usize) -> ! {
55+
panic_fmt(format_args!("index out of bounds: the len is {} but the index is {}",
56+
len, index), file_line)
57+
}
58+
#[cold] #[inline(never)]
59+
#[lang="panic_bounds_check"]
60+
#[cfg(not(stage0))]
61+
fn panic_bounds_check(file_line: &(&'static str, u32),
62+
index: usize, len: usize) -> ! {
4663
panic_fmt(format_args!("index out of bounds: the len is {} but the index is {}",
4764
len, index), file_line)
4865
}
4966

5067
#[cold] #[inline(never)]
51-
pub fn panic_fmt(fmt: fmt::Arguments, file_line: &(&'static str, uint)) -> ! {
68+
#[cfg(stage0)]
69+
pub fn panic_fmt(fmt: fmt::Arguments, file_line: &(&'static str, usize)) -> ! {
70+
#[allow(improper_ctypes)]
71+
extern {
72+
#[lang = "panic_fmt"]
73+
fn panic_impl(fmt: fmt::Arguments, file: &'static str, line: uint) -> !;
74+
}
75+
let (file, line) = *file_line;
76+
unsafe { panic_impl(fmt, file, line as uint) }
77+
}
78+
#[cold] #[inline(never)]
79+
#[cfg(not(stage0))]
80+
pub fn panic_fmt(fmt: fmt::Arguments, file_line: &(&'static str, u32)) -> ! {
5281
#[allow(improper_ctypes)]
5382
extern {
5483
#[lang = "panic_fmt"]
5584
fn panic_impl(fmt: fmt::Arguments, file: &'static str, line: uint) -> !;
5685
}
5786
let (file, line) = *file_line;
58-
unsafe { panic_impl(fmt, file, line) }
87+
unsafe { panic_impl(fmt, file, line as uint) }
5988
}

src/liblog/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -342,15 +342,15 @@ pub struct LogRecord<'a> {
342342
pub file: &'a str,
343343

344344
/// The line number of where the LogRecord originated.
345-
pub line: uint,
345+
pub line: u32,
346346
}
347347

348348
#[doc(hidden)]
349349
#[derive(Copy)]
350350
pub struct LogLocation {
351351
pub module_path: &'static str,
352352
pub file: &'static str,
353-
pub line: uint,
353+
pub line: u32,
354354
}
355355

356356
/// Tests whether a given module's name is enabled for a particular level of

src/liblog/macros.rs

+7
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@
5050
#[macro_export]
5151
macro_rules! log {
5252
($lvl:expr, $($arg:tt)+) => ({
53+
#[cfg(stage0)]
54+
static LOC: ::log::LogLocation = ::log::LogLocation {
55+
line: line!() as u32,
56+
file: file!(),
57+
module_path: module_path!(),
58+
};
59+
#[cfg(not(stage0))]
5360
static LOC: ::log::LogLocation = ::log::LogLocation {
5461
line: line!(),
5562
file: file!(),

src/librustc_trans/trans/common.rs

+4
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,10 @@ pub fn C_i32(ccx: &CrateContext, i: i32) -> ValueRef {
774774
C_integral(Type::i32(ccx), i as u64, true)
775775
}
776776

777+
pub fn C_u32(ccx: &CrateContext, i: u32) -> ValueRef {
778+
C_integral(Type::i32(ccx), i as u64, false)
779+
}
780+
777781
pub fn C_u64(ccx: &CrateContext, i: u64) -> ValueRef {
778782
C_integral(Type::i64(ccx), i, false)
779783
}

src/librustc_trans/trans/controlflow.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ pub fn trans_fail<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
377377
let loc = bcx.sess().codemap().lookup_char_pos(call_info.span.lo);
378378
let filename = token::intern_and_get_ident(&loc.file.name);
379379
let filename = C_str_slice(ccx, filename);
380-
let line = C_uint(ccx, loc.line);
380+
let line = C_u32(ccx, loc.line as u32);
381381
let expr_file_line_const = C_struct(ccx, &[v_str, filename, line], false);
382382
let expr_file_line = consts::addr_of(ccx, expr_file_line_const,
383383
"panic_loc", call_info.id);
@@ -406,7 +406,7 @@ pub fn trans_fail_bounds_check<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
406406

407407
// Invoke the lang item
408408
let filename = C_str_slice(ccx, filename);
409-
let line = C_uint(ccx, loc.line);
409+
let line = C_u32(ccx, loc.line as u32);
410410
let file_line_const = C_struct(ccx, &[filename, line], false);
411411
let file_line = consts::addr_of(ccx, file_line_const,
412412
"panic_bounds_check_loc", call_info.id);

src/libstd/macros.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ macro_rules! panic {
4444
($msg:expr) => ({
4545
$crate::rt::begin_unwind($msg, {
4646
// static requires less code at runtime, more constant data
47-
static _FILE_LINE: (&'static str, usize) = (file!(), line!());
47+
static _FILE_LINE: (&'static str, usize) = (file!(), line!() as usize);
4848
&_FILE_LINE
4949
})
5050
});
@@ -54,7 +54,7 @@ macro_rules! panic {
5454
// used inside a dead function. Just `#[allow(dead_code)]` is
5555
// insufficient, since the user may have
5656
// `#[forbid(dead_code)]` and which cannot be overridden.
57-
static _FILE_LINE: (&'static str, usize) = (file!(), line!());
57+
static _FILE_LINE: (&'static str, usize) = (file!(), line!() as usize);
5858
&_FILE_LINE
5959
})
6060
});

src/libsyntax/ext/build.rs

+4
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ pub trait AstBuilder {
148148
fn expr_usize(&self, span: Span, i: usize) -> P<ast::Expr>;
149149
fn expr_int(&self, sp: Span, i: isize) -> P<ast::Expr>;
150150
fn expr_u8(&self, sp: Span, u: u8) -> P<ast::Expr>;
151+
fn expr_u32(&self, sp: Span, u: u32) -> P<ast::Expr>;
151152
fn expr_bool(&self, sp: Span, value: bool) -> P<ast::Expr>;
152153

153154
fn expr_vec(&self, sp: Span, exprs: Vec<P<ast::Expr>>) -> P<ast::Expr>;
@@ -704,6 +705,9 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
704705
fn expr_u8(&self, sp: Span, u: u8) -> P<ast::Expr> {
705706
self.expr_lit(sp, ast::LitInt(u as u64, ast::UnsignedIntLit(ast::TyU8)))
706707
}
708+
fn expr_u32(&self, sp: Span, u: u32) -> P<ast::Expr> {
709+
self.expr_lit(sp, ast::LitInt(u as u64, ast::UnsignedIntLit(ast::TyU32)))
710+
}
707711
fn expr_bool(&self, sp: Span, value: bool) -> P<ast::Expr> {
708712
self.expr_lit(sp, ast::LitBool(value))
709713
}

src/libsyntax/ext/source_util.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub fn expand_line(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
3535
let topmost = cx.original_span_in_file();
3636
let loc = cx.codemap().lookup_char_pos(topmost.lo);
3737

38-
base::MacExpr::new(cx.expr_usize(topmost, loc.line))
38+
base::MacExpr::new(cx.expr_u32(topmost, loc.line as u32))
3939
}
4040

4141
/* column!(): expands to the current column number */
@@ -45,7 +45,8 @@ pub fn expand_column(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
4545

4646
let topmost = cx.original_span_in_file();
4747
let loc = cx.codemap().lookup_char_pos(topmost.lo);
48-
base::MacExpr::new(cx.expr_usize(topmost, loc.col.to_usize()))
48+
49+
base::MacExpr::new(cx.expr_u32(topmost, loc.col.to_usize() as u32))
4950
}
5051

5152
/// file!(): expands to the current filename */

src/test/run-pass/syntax-extension-source-utils-files/includeme.fragment

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
{
44
assert!(file!().ends_with("includeme.fragment"));
5-
assert!(line!() == 5_usize);
5+
assert!(line!() == 5u32);
66
format!("victory robot {}", line!())
77
}

src/test/run-pass/syntax-extension-source-utils.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ macro_rules! indirect_line { () => ( line!() ) }
2323

2424
pub fn main() {
2525
assert_eq!(line!(), 25);
26-
//assert!((column!() == 11));
26+
assert!((column!() == 4u32));
2727
assert_eq!(indirect_line!(), 27);
2828
assert!((file!().ends_with("syntax-extension-source-utils.rs")));
2929
assert_eq!(stringify!((2*3) + 5).to_string(), "( 2 * 3 ) + 5".to_string());

0 commit comments

Comments
 (0)