Skip to content

Commit c7f158b

Browse files
author
Alexander Regueiro
committed
Added feature gate (macro_hygiene_optout).
1 parent 61c2a4d commit c7f158b

11 files changed

+40
-7
lines changed

src/libsyntax/ext/tt/macro_rules.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ pub fn compile(sess: &ParseSess, features: &Features, def: &ast::Item) -> Syntax
261261
if let MatchedNonterminal(ref nt) = *m {
262262
if let NtTT(ref tt) = **nt {
263263
return quoted::parse(tt.clone().into(),
264-
!body.legacy,
264+
!body.legacy && features.macro_hygiene_optout,
265265
false,
266266
sess,
267267
features,

src/libsyntax/feature_gate.rs

+3
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,9 @@ declare_features! (
305305
// Declarative macros 2.0 (`macro`).
306306
(active, decl_macro, "1.17.0", Some(39412), None),
307307

308+
// Hygiene opt-out (escaping) for macros 2.0 using `#ident` syntax.
309+
(active, macro_hygiene_optout, "1.27.0", None, None),
310+
308311
// Allows #[link(kind="static-nobundle"...]
309312
(active, static_nobundle, "1.16.0", Some(37403), None),
310313

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2018 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+
#![feature(decl_macro)]
12+
13+
macro m() {
14+
pub mod #foo {
15+
//~^ ERROR expected identifier, found `#`
16+
pub const #BAR: u32 = 123;
17+
}
18+
}
19+
20+
fn main() {
21+
m!();
22+
}

src/test/compile-fail/hygiene-optout-1.rs

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// except according to those terms.
1010

1111
#![feature(decl_macro)]
12+
#![feature(macro_hygiene_optout)]
1213

1314
macro m($mod_name:ident) {
1415
pub mod $mod_name {

src/test/compile-fail/hygiene-optout-2.rs

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// except according to those terms.
1010

1111
#![feature(decl_macro)]
12+
#![feature(macro_hygiene_optout)]
1213

1314
macro m() {
1415
pub mod #foo {

src/test/compile-fail/hygiene-optout-3.rs

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// except according to those terms.
1010

1111
#![feature(decl_macro)]
12+
#![feature(macro_hygiene_optout)]
1213

1314
macro m_helper() {
1415
struct #S;

src/test/compile-fail/hygiene-optout-4.rs

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// except according to those terms.
1010

1111
#![feature(decl_macro)]
12+
#![feature(macro_hygiene_optout)]
1213

1314
macro m() {
1415
struct #S;

src/test/compile-fail/hygiene-optout-5.rs

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// except according to those terms.
1010

1111
#![feature(decl_macro)]
12+
#![feature(macro_hygiene_optout)]
1213

1314
macro m($mod_name:ident) {
1415
pub mod $#mod_name {

src/test/run-pass/hygiene-optout-1.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@
99
// except according to those terms.
1010

1111
#![feature(decl_macro)]
12+
#![feature(macro_hygiene_optout)]
1213

13-
macro m($mod_name:ident) {
14-
pub mod #$mod_name {
14+
macro m() {
15+
pub mod #foo {
1516
pub const #BAR: u32 = 123;
1617
}
1718
}
1819

1920
fn main() {
20-
m!(foo);
21+
m!();
2122
assert_eq!(123, foo::BAR);
2223
}

src/test/run-pass/hygiene-optout-2.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@
99
// except according to those terms.
1010

1111
#![feature(decl_macro)]
12+
#![feature(macro_hygiene_optout)]
1213

13-
macro m() {
14-
pub mod #foo {
14+
macro m($mod_name:ident) {
15+
pub mod #$mod_name {
1516
pub const #BAR: u32 = 123;
1617
}
1718
}
1819

1920
fn main() {
20-
m!();
21+
m!(foo);
2122
assert_eq!(123, foo::BAR);
2223
}

src/test/run-pass/hygiene-optout-lifetimes.rs

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// except according to those terms.
1010

1111
#![feature(decl_macro)]
12+
#![feature(macro_hygiene_optout)]
1213

1314
use std::marker::PhantomData;
1415

0 commit comments

Comments
 (0)