Skip to content

Commit fc9fa1a

Browse files
committed
Resolve barriers to changing column!() / line!() return type to u32 in #19284 . Address review comments in #21769 .
1 parent 1212fd8 commit fc9fa1a

File tree

9 files changed

+64
-15
lines changed

9 files changed

+64
-15
lines changed

Diff for: src/libcore/macros.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,21 @@ macro_rules! panic {
1515
panic!("explicit panic")
1616
);
1717
($msg:expr) => ({
18-
static _MSG_FILE_LINE: (&'static str, &'static str, usize) =
19-
($msg, file!(), line!() as usize);
18+
#[cfg(stage0)]
19+
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!());
2022
::core::panicking::panic(&_MSG_FILE_LINE)
2123
});
2224
($fmt:expr, $($arg:tt)*) => ({
2325
// The leading _'s are to avoid dead code warnings if this is
2426
// used inside a dead function. Just `#[allow(dead_code)]` is
2527
// insufficient, since the user may have
2628
// `#[forbid(dead_code)]` and which cannot be overridden.
27-
static _FILE_LINE: (&'static str, usize) = (file!(), line!() as usize);
29+
#[cfg(stage0)]
30+
static _FILE_LINE: (&'static str, usize) = (file!(), line!());
31+
#[cfg(not(stage0))]
32+
static _FILE_LINE: (&'static str, u32) = (file!(), line!());
2833
::core::panicking::panic_fmt(format_args!($fmt, $($arg)*), &_FILE_LINE)
2934
});
3035
}

Diff for: 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
}

Diff for: 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

Diff for: src/liblog/macros.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,15 @@
5050
#[macro_export]
5151
macro_rules! log {
5252
($lvl:expr, $($arg:tt)+) => ({
53+
#[cfg(stage0)]
5354
static LOC: ::log::LogLocation = ::log::LogLocation {
54-
line: line!() as usize,
55+
line: line!() as u32,
56+
file: file!(),
57+
module_path: module_path!(),
58+
};
59+
#[cfg(not(stage0))]
60+
static LOC: ::log::LogLocation = ::log::LogLocation {
61+
line: line!(),
5562
file: file!(),
5663
module_path: module_path!(),
5764
};

Diff for: 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
}

Diff for: 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::addr_of(ccx, expr_file_line_const,
376376
"panic_loc", call_info.id);
@@ -399,7 +399,7 @@ pub fn trans_fail_bounds_check<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
399399

400400
// Invoke the lang item
401401
let filename = C_str_slice(ccx, filename);
402-
let line = C_uint(ccx, loc.line);
402+
let line = C_u32(ccx, loc.line as u32);
403403
let file_line_const = C_struct(ccx, &[filename, line], false);
404404
let file_line = consts::addr_of(ccx, file_line_const,
405405
"panic_bounds_check_loc", call_info.id);

Diff for: src/libsyntax/ext/build.rs

+4
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ pub trait AstBuilder {
147147

148148
fn expr_usize(&self, span: Span, i: usize) -> P<ast::Expr>;
149149
fn expr_int(&self, sp: Span, i: isize) -> P<ast::Expr>;
150+
fn expr_u8(&self, sp: Span, u: u8) -> P<ast::Expr>;
150151
fn expr_u32(&self, sp: Span, u: u32) -> P<ast::Expr>;
151152
fn expr_bool(&self, sp: Span, value: bool) -> P<ast::Expr>;
152153

@@ -701,6 +702,9 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
701702
self.expr_lit(sp, ast::LitInt(i as u64, ast::SignedIntLit(ast::TyIs(false),
702703
ast::Sign::new(i))))
703704
}
705+
fn expr_u8(&self, sp: Span, u: u8) -> P<ast::Expr> {
706+
self.expr_lit(sp, ast::LitInt(u as u64, ast::UnsignedIntLit(ast::TyU8)))
707+
}
704708
fn expr_u32(&self, sp: Span, u: u32) -> P<ast::Expr> {
705709
self.expr_lit(sp, ast::LitInt(u as u64, ast::UnsignedIntLit(ast::TyU32)))
706710
}

Diff for: 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_u32);
5+
assert!(line!() == 5u32);
66
format!("victory robot {}", line!())
77
}

Diff for: 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!() == 4_u32));
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)