From fc284c1eee0180903fe11463dcee06e414202cf7 Mon Sep 17 00:00:00 2001 From: Dan Aloni Date: Mon, 19 Nov 2018 16:32:18 +0200 Subject: [PATCH 1/2] Stabilize macro_literal_matcher --- .../macro-literal-matcher.md | 17 ---------- src/libsyntax/ext/tt/macro_rules.rs | 31 ++++++++----------- src/libsyntax/feature_gate.rs | 8 ++--- src/test/run-pass/issues/issue-52169.rs | 2 +- src/test/run-pass/macros/macro-literal.rs | 2 +- .../feature-gate-macro-literal-matcher.rs | 19 ------------ .../feature-gate-macro-literal-matcher.stderr | 11 ------- 7 files changed, 17 insertions(+), 73 deletions(-) delete mode 100644 src/doc/unstable-book/src/language-features/macro-literal-matcher.md delete mode 100644 src/test/ui/feature-gates/feature-gate-macro-literal-matcher.rs delete mode 100644 src/test/ui/feature-gates/feature-gate-macro-literal-matcher.stderr diff --git a/src/doc/unstable-book/src/language-features/macro-literal-matcher.md b/src/doc/unstable-book/src/language-features/macro-literal-matcher.md deleted file mode 100644 index 870158200dee9..0000000000000 --- a/src/doc/unstable-book/src/language-features/macro-literal-matcher.md +++ /dev/null @@ -1,17 +0,0 @@ -# `macro_literal_matcher` - -The tracking issue for this feature is: [#35625] - -The RFC is: [rfc#1576]. - -With this feature gate enabled, the [list of designators] gains one more entry: - -* `literal`: a literal. Examples: 2, "string", 'c' - -A `literal` may be followed by anything, similarly to the `ident` specifier. - -[rfc#1576]: http://rust-lang.github.io/rfcs/1576-macros-literal-matcher.html -[#35625]: https://github.com/rust-lang/rust/issues/35625 -[list of designators]: ../reference/macros-by-example.html - ------------------------- diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs index 6bba891278aca..55c1904bd274a 100644 --- a/src/libsyntax/ext/tt/macro_rules.rs +++ b/src/libsyntax/ext/tt/macro_rules.rs @@ -19,7 +19,7 @@ use ext::tt::macro_parser::{MatchedSeq, MatchedNonterminal}; use ext::tt::macro_parser::{parse, parse_failure_msg}; use ext::tt::quoted; use ext::tt::transcribe::transcribe; -use feature_gate::{self, emit_feature_err, Features, GateIssue}; +use feature_gate::Features; use parse::{Directory, ParseSess}; use parse::parser::Parser; use parse::token::{self, NtTT}; @@ -1027,26 +1027,21 @@ fn has_legal_fragment_specifier(sess: &ParseSess, Ok(()) } -fn is_legal_fragment_specifier(sess: &ParseSess, - features: &Features, - attrs: &[ast::Attribute], +fn is_legal_fragment_specifier(_sess: &ParseSess, + _features: &Features, + _attrs: &[ast::Attribute], frag_name: &str, - frag_span: Span) -> bool { + _frag_span: Span) -> bool { + /* + * If new fragmnet specifiers are invented in nightly, `_sess`, + * `_features`, `_attrs`, and `_frag_span` will be useful for + * here for checking against feature gates. See past versions of + * this function. + */ match frag_name { "item" | "block" | "stmt" | "expr" | "pat" | "lifetime" | - "path" | "ty" | "ident" | "meta" | "tt" | "vis" | "" => true, - "literal" => { - if !features.macro_literal_matcher && - !attr::contains_name(attrs, "allow_internal_unstable") { - let explain = feature_gate::EXPLAIN_LITERAL_MATCHER; - emit_feature_err(sess, - "macro_literal_matcher", - frag_span, - GateIssue::Language, - explain); - } - true - }, + "path" | "ty" | "ident" | "meta" | "tt" | "vis" | "literal" | + "" => true, _ => false, } } diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index 2f5db9bd08155..73567765a04c4 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -436,9 +436,6 @@ declare_features! ( // Allows irrefutable patterns in if-let and while-let statements (RFC 2086) (active, irrefutable_let_patterns, "1.27.0", Some(44495), None), - // Allows use of the :literal macro fragment specifier (RFC 1576) - (active, macro_literal_matcher, "1.27.0", Some(35625), None), - // inconsistent bounds in where clauses (active, trivial_bounds, "1.28.0", Some(48214), None), @@ -690,6 +687,8 @@ declare_features! ( (accepted, impl_header_lifetime_elision, "1.31.0", Some(15872), None), // `extern crate foo as bar;` puts `bar` into extern prelude. (accepted, extern_crate_item_prelude, "1.31.0", Some(55599), None), + // Allows use of the :literal macro fragment specifier (RFC 1576) + (accepted, macro_literal_matcher, "1.31.0", Some(35625), None), ); // If you change this, please modify src/doc/unstable-book as well. You must @@ -1425,9 +1424,6 @@ pub const EXPLAIN_DEPR_CUSTOM_DERIVE: &'static str = pub const EXPLAIN_DERIVE_UNDERSCORE: &'static str = "attributes of the form `#[derive_*]` are reserved for the compiler"; -pub const EXPLAIN_LITERAL_MATCHER: &'static str = - ":literal fragment specifier is experimental and subject to change"; - pub const EXPLAIN_UNSIZED_TUPLE_COERCION: &'static str = "unsized tuple coercion is not stable enough for use and is subject to change"; diff --git a/src/test/run-pass/issues/issue-52169.rs b/src/test/run-pass/issues/issue-52169.rs index 19c0f51d235bc..9421dfc7897d0 100644 --- a/src/test/run-pass/issues/issue-52169.rs +++ b/src/test/run-pass/issues/issue-52169.rs @@ -9,7 +9,7 @@ // except according to those terms. // run-pass -#![feature(macro_literal_matcher)] +#![cfg_attr(stage0, feature(macro_literal_matcher))] macro_rules! a { ($i:literal) => { "right" }; diff --git a/src/test/run-pass/macros/macro-literal.rs b/src/test/run-pass/macros/macro-literal.rs index ecbb47757d11e..07e27d9f516cb 100644 --- a/src/test/run-pass/macros/macro-literal.rs +++ b/src/test/run-pass/macros/macro-literal.rs @@ -9,7 +9,7 @@ // except according to those terms. // run-pass -#![feature(macro_literal_matcher)] +#![cfg_attr(stage0, feature(macro_literal_matcher))] macro_rules! mtester { ($l:literal) => { diff --git a/src/test/ui/feature-gates/feature-gate-macro-literal-matcher.rs b/src/test/ui/feature-gates/feature-gate-macro-literal-matcher.rs deleted file mode 100644 index db5cca193ab4e..0000000000000 --- a/src/test/ui/feature-gates/feature-gate-macro-literal-matcher.rs +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2018 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 or the MIT license -// , 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:literal) => {} } -//~^ ERROR :literal fragment specifier is experimental and subject to change - -fn main() { - m!("some string literal"); -} diff --git a/src/test/ui/feature-gates/feature-gate-macro-literal-matcher.stderr b/src/test/ui/feature-gates/feature-gate-macro-literal-matcher.stderr deleted file mode 100644 index f714b916966a1..0000000000000 --- a/src/test/ui/feature-gates/feature-gate-macro-literal-matcher.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error[E0658]: :literal fragment specifier is experimental and subject to change (see issue #35625) - --> $DIR/feature-gate-macro-literal-matcher.rs:14:19 - | -LL | macro_rules! m { ($lt:literal) => {} } - | ^^^^^^^^^^^ - | - = help: add #![feature(macro_literal_matcher)] to the crate attributes to enable - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0658`. From b8ae7b801bf1f3d298493b2e7e1328a1a7ecace7 Mon Sep 17 00:00:00 2001 From: Dan Aloni Date: Tue, 20 Nov 2018 09:11:12 +0200 Subject: [PATCH 2/2] macro_literal_matcher: fixes per petrochenkov's review --- src/libsyntax/ext/tt/macro_rules.rs | 6 +++--- src/test/run-pass/issues/issue-52169.rs | 1 - src/test/run-pass/macros/macro-literal.rs | 1 - 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs index 55c1904bd274a..d526e464ba4f5 100644 --- a/src/libsyntax/ext/tt/macro_rules.rs +++ b/src/libsyntax/ext/tt/macro_rules.rs @@ -1033,9 +1033,9 @@ fn is_legal_fragment_specifier(_sess: &ParseSess, frag_name: &str, _frag_span: Span) -> bool { /* - * If new fragmnet specifiers are invented in nightly, `_sess`, - * `_features`, `_attrs`, and `_frag_span` will be useful for - * here for checking against feature gates. See past versions of + * If new fragment specifiers are invented in nightly, `_sess`, + * `_features`, `_attrs`, and `_frag_span` will be useful here + * for checking against feature gates. See past versions of * this function. */ match frag_name { diff --git a/src/test/run-pass/issues/issue-52169.rs b/src/test/run-pass/issues/issue-52169.rs index 9421dfc7897d0..c4ed534cc20ec 100644 --- a/src/test/run-pass/issues/issue-52169.rs +++ b/src/test/run-pass/issues/issue-52169.rs @@ -9,7 +9,6 @@ // except according to those terms. // run-pass -#![cfg_attr(stage0, feature(macro_literal_matcher))] macro_rules! a { ($i:literal) => { "right" }; diff --git a/src/test/run-pass/macros/macro-literal.rs b/src/test/run-pass/macros/macro-literal.rs index 07e27d9f516cb..de268e3388a5e 100644 --- a/src/test/run-pass/macros/macro-literal.rs +++ b/src/test/run-pass/macros/macro-literal.rs @@ -9,7 +9,6 @@ // except according to those terms. // run-pass -#![cfg_attr(stage0, feature(macro_literal_matcher))] macro_rules! mtester { ($l:literal) => {