Skip to content

Commit

Permalink
Add a feature gate
Browse files Browse the repository at this point in the history
@alexcrichton figured out a way how to do it :)
  • Loading branch information
est31 committed Aug 10, 2017
1 parent b6ac9c0 commit 5cf9f63
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/libsyntax/ext/source_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax_ext/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 14 additions & 0 deletions src/test/compile-fail/rust-unstable-column-gated.rs
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 5cf9f63

Please sign in to comment.