Streamline gate_feature_* macros.

The debug probably isn't useful, and assigning all the `$foo`
metavariables to `foo` variables is verbose and weird. Also, `$x:expr`
usually doesn't have a space after the `:`.
This commit is contained in:
Nicholas Nethercote 2023-10-26 13:38:38 +11:00
parent 236ac911de
commit bb3e09f144
3 changed files with 14 additions and 32 deletions

View File

@ -3501,7 +3501,6 @@ dependencies = [
"rustc_span", "rustc_span",
"rustc_target", "rustc_target",
"thin-vec", "thin-vec",
"tracing",
] ]
[[package]] [[package]]

View File

@ -19,5 +19,4 @@ rustc_session = { path = "../rustc_session" }
rustc_span = { path = "../rustc_span" } rustc_span = { path = "../rustc_span" }
rustc_target = { path = "../rustc_target" } rustc_target = { path = "../rustc_target" }
thin-vec = "0.2.12" thin-vec = "0.2.12"
tracing = "0.1"
# tidy-alphabetical-end # tidy-alphabetical-end

View File

@ -10,51 +10,35 @@ use rustc_span::symbol::sym;
use rustc_span::Span; use rustc_span::Span;
use rustc_target::spec::abi; use rustc_target::spec::abi;
use thin_vec::ThinVec; use thin_vec::ThinVec;
use tracing::debug;
use crate::errors; use crate::errors;
macro_rules! gate_feature_fn { macro_rules! gate_feature_fn {
($visitor: expr, $has_feature: expr, $span: expr, $name: expr, $explain: expr, $help: expr) => {{ ($visitor:expr, $has_feature:expr, $span:expr, $name:expr, $explain:expr, $help:expr) => {{
let (visitor, has_feature, span, name, explain, help) = if !$has_feature($visitor.features) && !$span.allows_unstable($name) {
(&*$visitor, $has_feature, $span, $name, $explain, $help); feature_err(&$visitor.sess.parse_sess, $name, $span, $explain).help($help).emit();
let has_feature: bool = has_feature(visitor.features);
debug!("gate_feature(feature = {:?}, span = {:?}); has? {}", name, span, has_feature);
if !has_feature && !span.allows_unstable($name) {
feature_err(&visitor.sess.parse_sess, name, span, explain).help(help).emit();
} }
}}; }};
($visitor: expr, $has_feature: expr, $span: expr, $name: expr, $explain: expr) => {{ ($visitor:expr, $has_feature:expr, $span:expr, $name:expr, $explain:expr) => {{
let (visitor, has_feature, span, name, explain) = if !$has_feature($visitor.features) && !$span.allows_unstable($name) {
(&*$visitor, $has_feature, $span, $name, $explain); feature_err(&$visitor.sess.parse_sess, $name, $span, $explain).emit();
let has_feature: bool = has_feature(visitor.features);
debug!("gate_feature(feature = {:?}, span = {:?}); has? {}", name, span, has_feature);
if !has_feature && !span.allows_unstable($name) {
feature_err(&visitor.sess.parse_sess, name, span, explain).emit();
} }
}}; }};
(future_incompatible; $visitor: expr, $has_feature: expr, $span: expr, $name: expr, $explain: expr) => {{ (future_incompatible; $visitor:expr, $has_feature:expr, $span:expr, $name:expr, $explain:expr) => {{
let (visitor, has_feature, span, name, explain) = if !$has_feature($visitor.features) && !$span.allows_unstable($name) {
(&*$visitor, $has_feature, $span, $name, $explain); feature_warn(&$visitor.sess.parse_sess, $name, $span, $explain);
let has_feature: bool = has_feature(visitor.features);
debug!(
"gate_feature(feature = {:?}, span = {:?}); has? {} (future_incompatible)",
name, span, has_feature
);
if !has_feature && !span.allows_unstable($name) {
feature_warn(&visitor.sess.parse_sess, name, span, explain);
} }
}}; }};
} }
macro_rules! gate_feature_post { macro_rules! gate_feature_post {
($visitor: expr, $feature: ident, $span: expr, $explain: expr, $help: expr) => { ($visitor:expr, $feature:ident, $span:expr, $explain:expr, $help:expr) => {
gate_feature_fn!($visitor, |x: &Features| x.$feature, $span, sym::$feature, $explain, $help) gate_feature_fn!($visitor, |x:&Features| x.$feature, $span, sym::$feature, $explain, $help)
}; };
($visitor: expr, $feature: ident, $span: expr, $explain: expr) => { ($visitor:expr, $feature:ident, $span:expr, $explain:expr) => {
gate_feature_fn!($visitor, |x: &Features| x.$feature, $span, sym::$feature, $explain) gate_feature_fn!($visitor, |x:&Features| x.$feature, $span, sym::$feature, $explain)
}; };
(future_incompatible; $visitor: expr, $feature: ident, $span: expr, $explain: expr) => { (future_incompatible; $visitor:expr, $feature:ident, $span:expr, $explain:expr) => {
gate_feature_fn!(future_incompatible; $visitor, |x: &Features| x.$feature, $span, sym::$feature, $explain) gate_feature_fn!(future_incompatible; $visitor, |x: &Features| x.$feature, $span, sym::$feature, $explain)
}; };
} }