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:
parent
236ac911de
commit
bb3e09f144
3 changed files with 14 additions and 32 deletions
|
@ -3501,7 +3501,6 @@ dependencies = [
|
|||
"rustc_span",
|
||||
"rustc_target",
|
||||
"thin-vec",
|
||||
"tracing",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
|
@ -19,5 +19,4 @@ rustc_session = { path = "../rustc_session" }
|
|||
rustc_span = { path = "../rustc_span" }
|
||||
rustc_target = { path = "../rustc_target" }
|
||||
thin-vec = "0.2.12"
|
||||
tracing = "0.1"
|
||||
# tidy-alphabetical-end
|
||||
|
|
|
@ -10,51 +10,35 @@ use rustc_span::symbol::sym;
|
|||
use rustc_span::Span;
|
||||
use rustc_target::spec::abi;
|
||||
use thin_vec::ThinVec;
|
||||
use tracing::debug;
|
||||
|
||||
use crate::errors;
|
||||
|
||||
macro_rules! gate_feature_fn {
|
||||
($visitor: expr, $has_feature: expr, $span: expr, $name: expr, $explain: expr, $help: expr) => {{
|
||||
let (visitor, has_feature, span, name, explain, help) =
|
||||
(&*$visitor, $has_feature, $span, $name, $explain, $help);
|
||||
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, $help:expr) => {{
|
||||
if !$has_feature($visitor.features) && !$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) => {{
|
||||
let (visitor, has_feature, span, name, explain) =
|
||||
(&*$visitor, $has_feature, $span, $name, $explain);
|
||||
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();
|
||||
($visitor:expr, $has_feature:expr, $span:expr, $name:expr, $explain:expr) => {{
|
||||
if !$has_feature($visitor.features) && !$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) => {{
|
||||
let (visitor, has_feature, span, name, explain) =
|
||||
(&*$visitor, $has_feature, $span, $name, $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);
|
||||
(future_incompatible; $visitor:expr, $has_feature:expr, $span:expr, $name:expr, $explain:expr) => {{
|
||||
if !$has_feature($visitor.features) && !$span.allows_unstable($name) {
|
||||
feature_warn(&$visitor.sess.parse_sess, $name, $span, $explain);
|
||||
}
|
||||
}};
|
||||
}
|
||||
|
||||
macro_rules! gate_feature_post {
|
||||
($visitor: expr, $feature: ident, $span: expr, $explain: expr, $help: expr) => {
|
||||
gate_feature_fn!($visitor, |x: &Features| x.$feature, $span, sym::$feature, $explain, $help)
|
||||
($visitor:expr, $feature:ident, $span:expr, $explain:expr, $help:expr) => {
|
||||
gate_feature_fn!($visitor, |x:&Features| x.$feature, $span, sym::$feature, $explain, $help)
|
||||
};
|
||||
($visitor: expr, $feature: ident, $span: expr, $explain: expr) => {
|
||||
gate_feature_fn!($visitor, |x: &Features| x.$feature, $span, sym::$feature, $explain)
|
||||
($visitor:expr, $feature:ident, $span:expr, $explain:expr) => {
|
||||
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)
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue