提交 5cf9f633 编写于 作者: E est31

Add a feature gate

@alexcrichton figured out a way how to do it :)
上级 b6ac9c0d
......@@ -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))
}
/* __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 */
/// The filemap (`loc.file`) contains a bunch more information we could spit
/// out if we wanted.
......
......@@ -89,7 +89,7 @@ pub fn register_builtins(resolver: &mut syntax::ext::base::Resolver,
use syntax::ext::source_util::*;
register! {
line: expand_line,
__rust_unstable_column: expand_column,
__rust_unstable_column: expand_column_gated,
column: expand_column,
file: expand_file,
stringify: expand_stringify,
......
// 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
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册