Skip to content

Commit 5cf9f63

Browse files
committed
Add a feature gate
@alexcrichton figured out a way how to do it :)
1 parent b6ac9c0 commit 5cf9f63

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

src/libsyntax/ext/source_util.rs

+10
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,16 @@ pub fn expand_column(cx: &mut ExtCtxt, sp: Span, tts: &[tokenstream::TokenTree])
5252
base::MacEager::expr(cx.expr_u32(topmost, loc.col.to_usize() as u32))
5353
}
5454

55+
/* __rust_unstable_column!(): expands to the current column number */
56+
pub fn expand_column_gated(cx: &mut ExtCtxt, sp: Span, tts: &[tokenstream::TokenTree])
57+
-> Box<base::MacResult+'static> {
58+
if sp.allows_unstable() {
59+
expand_column(cx, sp, tts)
60+
} else {
61+
cx.span_fatal(sp, "the __rust_unstable_column macro is unstable");
62+
}
63+
}
64+
5565
/// file!(): expands to the current filename */
5666
/// The filemap (`loc.file`) contains a bunch more information we could spit
5767
/// out if we wanted.

src/libsyntax_ext/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +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,
92+
__rust_unstable_column: expand_column_gated,
9393
column: expand_column,
9494
file: expand_file,
9595
stringify: expand_stringify,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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+
fn main() {
12+
println!("{}", __rust_unstable_column!());
13+
//~^ERROR the __rust_unstable_column macro is unstable
14+
}

0 commit comments

Comments
 (0)