Skip to content

Commit 1e3528a

Browse files
committed
Change column! / line! return type from usize to u32 rust-lang#19284
1 parent c5db290 commit 1e3528a

File tree

10 files changed

+54
-9
lines changed

10 files changed

+54
-9
lines changed

src/libcore/macros.rs

+7
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,22 @@ 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!());
22+
1923
::core::panicking::panic(&_MSG_FILE_LINE)
2024
});
2125
($fmt:expr, $($arg:tt)*) => ({
2226
// The leading _'s are to avoid dead code warnings if this is
2327
// used inside a dead function. Just `#[allow(dead_code)]` is
2428
// insufficient, since the user may have
2529
// `#[forbid(dead_code)]` and which cannot be overridden.
30+
#[cfg(stage0)]
2631
static _FILE_LINE: (&'static str, usize) = (file!(), line!());
32+
#[cfg(not(stage0))]
33+
static _FILE_LINE: (&'static str, u32) = (file!(), line!());
2734
::core::panicking::panic_fmt(format_args!($fmt, $($arg)*), &_FILE_LINE)
2835
});
2936
}

src/libcore/panicking.rs

+29
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,38 @@ use fmt;
3434

3535
#[cold] #[inline(never)] // this is the slow path, always
3636
#[lang="panic"]
37+
#[cfg(stage0)]
3738
pub fn panic(expr_file_line: &(&'static str, &'static str, uint)) -> ! {
3839
let (expr, file, line) = *expr_file_line;
3940
panic_fmt(format_args!("{}", expr), &(file, line))
4041
}
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)) -> ! {
46+
let (expr, file, line) = *expr_file_line;
47+
panic_fmt(format_args!("{}", expr), &(file, line))
48+
}
4149

4250
#[cold] #[inline(never)]
4351
#[lang="panic_bounds_check"]
52+
#[cfg(stage0)]
4453
fn panic_bounds_check(file_line: &(&'static str, uint),
4554
index: uint, len: uint) -> ! {
4655
panic_fmt(format_args!("index out of bounds: the len is {} but the index is {}",
4756
len, index), file_line)
4857
}
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: uint, len: uint) -> ! {
63+
panic_fmt(format_args!("index out of bounds: the len is {} but the index is {}",
64+
len, index), file_line)
65+
}
4966

5067
#[cold] #[inline(never)]
68+
#[cfg(stage0)]
5169
pub fn panic_fmt(fmt: fmt::Arguments, file_line: &(&'static str, uint)) -> ! {
5270
#[allow(improper_ctypes)]
5371
extern {
@@ -57,3 +75,14 @@ pub fn panic_fmt(fmt: fmt::Arguments, file_line: &(&'static str, uint)) -> ! {
5775
let (file, line) = *file_line;
5876
unsafe { panic_impl(fmt, file, line) }
5977
}
78+
#[cold] #[inline(never)]
79+
#[cfg(not(stage0))]
80+
pub fn panic_fmt(fmt: fmt::Arguments, file_line: &(&'static str, u32)) -> ! {
81+
#[allow(improper_ctypes)]
82+
extern {
83+
#[lang = "panic_fmt"]
84+
fn panic_impl(fmt: fmt::Arguments, file: &'static str, line: uint) -> !;
85+
}
86+
let (file, line) = *file_line;
87+
unsafe { panic_impl(fmt, file, line as uint) }
88+
}

src/liblog/macros.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
macro_rules! log {
5252
($lvl:expr, $($arg:tt)+) => ({
5353
static LOC: ::log::LogLocation = ::log::LogLocation {
54-
line: line!(),
54+
line: line!() as uint,
5555
file: file!(),
5656
module_path: module_path!(),
5757
};

src/librustc_trans/trans/common.rs

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

781+
pub fn C_u32(ccx: &CrateContext, i: u32) -> ValueRef {
782+
C_integral(Type::i32(ccx), i as u64, false)
783+
}
784+
781785
pub fn C_u64(ccx: &CrateContext, i: u64) -> ValueRef {
782786
C_integral(Type::i64(ccx), i, false)
783787
}

src/librustc_trans/trans/controlflow.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ pub fn trans_fail<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
370370
let loc = bcx.sess().codemap().lookup_char_pos(call_info.span.lo);
371371
let filename = token::intern_and_get_ident(&loc.file.name[]);
372372
let filename = C_str_slice(ccx, filename);
373-
let line = C_uint(ccx, loc.line);
373+
let line = C_u32(ccx, loc.line as u32);
374374
let expr_file_line_const = C_struct(ccx, &[v_str, filename, line], false);
375375
let expr_file_line = consts::const_addr_of(ccx, expr_file_line_const, ast::MutImmutable);
376376
let args = vec!(expr_file_line);
@@ -398,7 +398,7 @@ pub fn trans_fail_bounds_check<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
398398

399399
// Invoke the lang item
400400
let filename = C_str_slice(ccx, filename);
401-
let line = C_uint(ccx, loc.line);
401+
let line = C_u32(ccx, loc.line as u32);
402402
let file_line_const = C_struct(ccx, &[filename, line], false);
403403
let file_line = consts::const_addr_of(ccx, file_line_const, ast::MutImmutable);
404404
let args = vec!(file_line, index, len);

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!() == 5u);
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)