Skip to content

Commit b284419

Browse files
committed
Add feature gate macro_lifetime_matcher
1 parent e838cfc commit b284419

8 files changed

+56
-2
lines changed

src/libsyntax/ext/tt/macro_rules.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -886,8 +886,20 @@ fn is_legal_fragment_specifier(sess: &ParseSess,
886886
frag_name: &str,
887887
frag_span: Span) -> bool {
888888
match frag_name {
889-
"item" | "block" | "stmt" | "expr" | "pat" | "lifetime" |
889+
"item" | "block" | "stmt" | "expr" | "pat" |
890890
"path" | "ty" | "ident" | "meta" | "tt" | "" => true,
891+
"lifetime" => {
892+
if !features.borrow().macro_lifetime_matcher
893+
&& !attr::contains_name(attrs, "allow_internal_unstable") {
894+
let explain = feature_gate::EXPLAIN_LIFETIME_MATCHER;
895+
emit_feature_err(sess,
896+
"macro_lifetime_matcher",
897+
frag_span,
898+
GateIssue::Language,
899+
explain);
900+
}
901+
true
902+
},
891903
"vis" => {
892904
if !features.borrow().macro_vis_matcher
893905
&& !attr::contains_name(attrs, "allow_internal_unstable") {

src/libsyntax/feature_gate.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,9 @@ declare_features! (
447447

448448
// Termination trait in main (RFC 1937)
449449
(active, termination_trait, "1.24.0", Some(43301)),
450+
451+
// Allows use of the :lifetime macro fragment specifier
452+
(active, macro_lifetime_matcher, "1.24.0", Some(46895)),
450453
);
451454

452455
declare_features! (
@@ -520,7 +523,7 @@ declare_features! (
520523
(accepted, loop_break_value, "1.19.0", Some(37339)),
521524
// Permits numeric fields in struct expressions and patterns.
522525
(accepted, relaxed_adts, "1.19.0", Some(35626)),
523-
// Coerces non capturing closures to function pointers
526+
// Coerces non capturing closures to function pointers
524527
(accepted, closure_to_fn_coercion, "1.19.0", Some(39817)),
525528
// Allows attributes on struct literal fields.
526529
(accepted, struct_field_attributes, "1.20.0", Some(38814)),
@@ -1226,6 +1229,9 @@ pub const EXPLAIN_DERIVE_UNDERSCORE: &'static str =
12261229
pub const EXPLAIN_VIS_MATCHER: &'static str =
12271230
":vis fragment specifier is experimental and subject to change";
12281231

1232+
pub const EXPLAIN_LIFETIME_MATCHER: &'static str =
1233+
":lifetime fragment specifier is experimental and subject to change";
1234+
12291235
pub const EXPLAIN_PLACEMENT_IN: &'static str =
12301236
"placement-in expression syntax is experimental and subject to change.";
12311237

src/test/run-pass/macro-lifetime-used-with-bound.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
#![feature(macro_lifetime_matcher)]
12+
1113
macro_rules! foo {
1214
($l:lifetime, $l2:lifetime) => {
1315
fn f<$l: $l2, $l2>(arg: &$l str, arg2: &$l2 str) -> &$l str {

src/test/run-pass/macro-lifetime-used-with-labels.rs

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

1111
#![allow(unreachable_code)]
12+
#![feature(macro_lifetime_matcher)]
1213

1314
macro_rules! x {
1415
($a:lifetime) => {

src/test/run-pass/macro-lifetime-used-with-static.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
#![feature(macro_lifetime_matcher)]
12+
1113
macro_rules! foo {
1214
($l:lifetime) => {
1315
fn f(arg: &$l str) -> &$l str {

src/test/run-pass/macro-lifetime.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
#![feature(macro_lifetime_matcher)]
12+
1113
macro_rules! foo {
1214
($l:lifetime) => {
1315
fn f<$l>(arg: &$l str) -> &$l str {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
// Test that the :lifetime macro fragment cannot be used when macro_lifetime_matcher
12+
// feature gate is not used.
13+
14+
macro_rules! m { ($lt:lifetime) => {} }
15+
//~^ ERROR :lifetime fragment specifier is experimental and subject to change
16+
17+
fn main() {
18+
m!('a);
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: :lifetime fragment specifier is experimental and subject to change (see issue #46895)
2+
--> $DIR/feature-gate-macro-lifetime-matcher.rs:14:19
3+
|
4+
14 | macro_rules! m { ($lt:lifetime) => {} }
5+
| ^^^^^^^^^^^^
6+
|
7+
= help: add #![feature(macro_lifetime_matcher)] to the crate attributes to enable
8+
9+
error: aborting due to previous error
10+

0 commit comments

Comments
 (0)