Add a feature gate
@alexcrichton figured out a way how to do it :)
This commit is contained in:
parent
b6ac9c0d30
commit
5cf9f6330a
3 changed files with 25 additions and 1 deletions
|
@ -52,6 +52,16 @@ pub fn expand_column(cx: &mut ExtCtxt, sp: Span, tts: &[tokenstream::TokenTree])
|
||||||
base::MacEager::expr(cx.expr_u32(topmost, loc.col.to_usize() as u32))
|
base::MacEager::expr(cx.expr_u32(topmost, loc.col.to_usize() as u32))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* __rust_unstable_column!(): expands to the current column number */
|
||||||
|
pub fn expand_column_gated(cx: &mut ExtCtxt, sp: Span, tts: &[tokenstream::TokenTree])
|
||||||
|
-> Box<base::MacResult+'static> {
|
||||||
|
if sp.allows_unstable() {
|
||||||
|
expand_column(cx, sp, tts)
|
||||||
|
} else {
|
||||||
|
cx.span_fatal(sp, "the __rust_unstable_column macro is unstable");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// file!(): expands to the current filename */
|
/// file!(): expands to the current filename */
|
||||||
/// The filemap (`loc.file`) contains a bunch more information we could spit
|
/// The filemap (`loc.file`) contains a bunch more information we could spit
|
||||||
/// out if we wanted.
|
/// out if we wanted.
|
||||||
|
|
|
@ -89,7 +89,7 @@ pub fn register_builtins(resolver: &mut syntax::ext::base::Resolver,
|
||||||
use syntax::ext::source_util::*;
|
use syntax::ext::source_util::*;
|
||||||
register! {
|
register! {
|
||||||
line: expand_line,
|
line: expand_line,
|
||||||
__rust_unstable_column: expand_column,
|
__rust_unstable_column: expand_column_gated,
|
||||||
column: expand_column,
|
column: expand_column,
|
||||||
file: expand_file,
|
file: expand_file,
|
||||||
stringify: expand_stringify,
|
stringify: expand_stringify,
|
||||||
|
|
14
src/test/compile-fail/rust-unstable-column-gated.rs
Normal file
14
src/test/compile-fail/rust-unstable-column-gated.rs
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
|
||||||
|
// file at the top-level directory of this distribution and at
|
||||||
|
// http://rust-lang.org/COPYRIGHT.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||||
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||||
|
// option. This file may not be copied, modified, or distributed
|
||||||
|
// except according to those terms.
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
println!("{}", __rust_unstable_column!());
|
||||||
|
//~^ERROR the __rust_unstable_column macro is unstable
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue