Skip to content

Commit

Permalink
Add feature gate macro_lifetime_matcher
Browse files Browse the repository at this point in the history
  • Loading branch information
ricochet1k committed Dec 28, 2017
1 parent e838cfc commit b284419
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 2 deletions.
14 changes: 13 additions & 1 deletion src/libsyntax/ext/tt/macro_rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -886,8 +886,20 @@ fn is_legal_fragment_specifier(sess: &ParseSess,
frag_name: &str,
frag_span: Span) -> bool {
match frag_name {
"item" | "block" | "stmt" | "expr" | "pat" | "lifetime" |
"item" | "block" | "stmt" | "expr" | "pat" |
"path" | "ty" | "ident" | "meta" | "tt" | "" => true,
"lifetime" => {
if !features.borrow().macro_lifetime_matcher
&& !attr::contains_name(attrs, "allow_internal_unstable") {
let explain = feature_gate::EXPLAIN_LIFETIME_MATCHER;
emit_feature_err(sess,
"macro_lifetime_matcher",
frag_span,
GateIssue::Language,
explain);
}
true
},
"vis" => {
if !features.borrow().macro_vis_matcher
&& !attr::contains_name(attrs, "allow_internal_unstable") {
Expand Down
8 changes: 7 additions & 1 deletion src/libsyntax/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,9 @@ declare_features! (

// Termination trait in main (RFC 1937)
(active, termination_trait, "1.24.0", Some(43301)),

// Allows use of the :lifetime macro fragment specifier
(active, macro_lifetime_matcher, "1.24.0", Some(46895)),
);

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

pub const EXPLAIN_LIFETIME_MATCHER: &'static str =
":lifetime fragment specifier is experimental and subject to change";

pub const EXPLAIN_PLACEMENT_IN: &'static str =
"placement-in expression syntax is experimental and subject to change.";

Expand Down
2 changes: 2 additions & 0 deletions src/test/run-pass/macro-lifetime-used-with-bound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(macro_lifetime_matcher)]

macro_rules! foo {
($l:lifetime, $l2:lifetime) => {
fn f<$l: $l2, $l2>(arg: &$l str, arg2: &$l2 str) -> &$l str {
Expand Down
1 change: 1 addition & 0 deletions src/test/run-pass/macro-lifetime-used-with-labels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// except according to those terms.

#![allow(unreachable_code)]
#![feature(macro_lifetime_matcher)]

macro_rules! x {
($a:lifetime) => {
Expand Down
2 changes: 2 additions & 0 deletions src/test/run-pass/macro-lifetime-used-with-static.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(macro_lifetime_matcher)]

macro_rules! foo {
($l:lifetime) => {
fn f(arg: &$l str) -> &$l str {
Expand Down
2 changes: 2 additions & 0 deletions src/test/run-pass/macro-lifetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(macro_lifetime_matcher)]

macro_rules! foo {
($l:lifetime) => {
fn f<$l>(arg: &$l str) -> &$l str {
Expand Down
19 changes: 19 additions & 0 deletions src/test/ui/feature-gate-macro-lifetime-matcher.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// 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.

// Test that the :lifetime macro fragment cannot be used when macro_lifetime_matcher
// feature gate is not used.

macro_rules! m { ($lt:lifetime) => {} }
//~^ ERROR :lifetime fragment specifier is experimental and subject to change

fn main() {
m!('a);
}
10 changes: 10 additions & 0 deletions src/test/ui/feature-gate-macro-lifetime-matcher.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
error: :lifetime fragment specifier is experimental and subject to change (see issue #46895)
--> $DIR/feature-gate-macro-lifetime-matcher.rs:14:19
|
14 | macro_rules! m { ($lt:lifetime) => {} }
| ^^^^^^^^^^^^
|
= help: add #![feature(macro_lifetime_matcher)] to the crate attributes to enable

error: aborting due to previous error

0 comments on commit b284419

Please sign in to comment.