Skip to content

Commit b6ac9c0

Browse files
committed
Avoid calling the column!() macro in panic
1 parent 7c4e1a5 commit b6ac9c0

File tree

4 files changed

+50
-4
lines changed

4 files changed

+50
-4
lines changed

src/libcore/macros.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
#[macro_export]
12+
// This stability attribute is totally useless.
13+
#[stable(feature = "rust1", since = "1.0.0")]
14+
#[cfg(stage0)]
15+
macro_rules! __rust_unstable_column {
16+
() => {
17+
column!()
18+
}
19+
}
20+
1121
/// Entry point of thread panic, for details, see std::macros
1222
#[macro_export]
1323
#[allow_internal_unstable]
@@ -18,7 +28,7 @@ macro_rules! panic {
1828
);
1929
($msg:expr) => ({
2030
static _MSG_FILE_LINE_COL: (&'static str, &'static str, u32, u32) =
21-
($msg, file!(), line!(), column!());
31+
($msg, file!(), line!(), __rust_unstable_column!());
2232
$crate::panicking::panic(&_MSG_FILE_LINE_COL)
2333
});
2434
($fmt:expr, $($arg:tt)*) => ({
@@ -27,7 +37,7 @@ macro_rules! panic {
2737
// insufficient, since the user may have
2838
// `#[forbid(dead_code)]` and which cannot be overridden.
2939
static _MSG_FILE_LINE_COL: (&'static str, u32, u32) =
30-
(file!(), line!(), column!());
40+
(file!(), line!(), __rust_unstable_column!());
3141
$crate::panicking::panic_fmt(format_args!($fmt, $($arg)*), &_MSG_FILE_LINE_COL)
3242
});
3343
}

src/libstd/macros.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@
1414
//! library. Each macro is available for use when linking against the standard
1515
//! library.
1616
17+
#[macro_export]
18+
// This stability attribute is totally useless.
19+
#[stable(feature = "rust1", since = "1.0.0")]
20+
#[cfg(stage0)]
21+
macro_rules! __rust_unstable_column {
22+
() => {
23+
column!()
24+
}
25+
}
26+
1727
/// The entry point for panic of Rust threads.
1828
///
1929
/// This macro is used to inject panic into a Rust thread, causing the thread to
@@ -48,7 +58,8 @@ macro_rules! panic {
4858
($msg:expr) => ({
4959
$crate::rt::begin_panic($msg, {
5060
// static requires less code at runtime, more constant data
51-
static _FILE_LINE_COL: (&'static str, u32, u32) = (file!(), line!(), column!());
61+
static _FILE_LINE_COL: (&'static str, u32, u32) = (file!(), line!(),
62+
__rust_unstable_column!());
5263
&_FILE_LINE_COL
5364
})
5465
});
@@ -58,7 +69,8 @@ macro_rules! panic {
5869
// used inside a dead function. Just `#[allow(dead_code)]` is
5970
// insufficient, since the user may have
6071
// `#[forbid(dead_code)]` and which cannot be overridden.
61-
static _FILE_LINE_COL: (&'static str, u32, u32) = (file!(), line!(), column!());
72+
static _FILE_LINE_COL: (&'static str, u32, u32) = (file!(), line!(),
73+
__rust_unstable_column!());
6274
&_FILE_LINE_COL
6375
})
6476
});

src/libsyntax_ext/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ pub fn register_builtins(resolver: &mut syntax::ext::base::Resolver,
8989
use syntax::ext::source_util::*;
9090
register! {
9191
line: expand_line,
92+
__rust_unstable_column: expand_column,
9293
column: expand_column,
9394
file: expand_file,
9495
stringify: expand_stringify,

src/test/run-pass/issue-43057.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![allow(unused)]
12+
13+
macro_rules! column {
14+
($i:ident) => {
15+
$i
16+
};
17+
}
18+
19+
fn foo() -> ! {
20+
panic!();
21+
}
22+
23+
fn main() {}

0 commit comments

Comments
 (0)