Skip to content

Commit bb3e09f

Browse files
committed
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 `:`.
1 parent 236ac91 commit bb3e09f

File tree

3 files changed

+14
-32
lines changed

3 files changed

+14
-32
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3501,7 +3501,6 @@ dependencies = [
35013501
"rustc_span",
35023502
"rustc_target",
35033503
"thin-vec",
3504-
"tracing",
35053504
]
35063505

35073506
[[package]]

compiler/rustc_ast_passes/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,4 @@ rustc_session = { path = "../rustc_session" }
1919
rustc_span = { path = "../rustc_span" }
2020
rustc_target = { path = "../rustc_target" }
2121
thin-vec = "0.2.12"
22-
tracing = "0.1"
2322
# tidy-alphabetical-end

compiler/rustc_ast_passes/src/feature_gate.rs

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,51 +10,35 @@ use rustc_span::symbol::sym;
1010
use rustc_span::Span;
1111
use rustc_target::spec::abi;
1212
use thin_vec::ThinVec;
13-
use tracing::debug;
1413

1514
use crate::errors;
1615

1716
macro_rules! gate_feature_fn {
18-
($visitor: expr, $has_feature: expr, $span: expr, $name: expr, $explain: expr, $help: expr) => {{
19-
let (visitor, has_feature, span, name, explain, help) =
20-
(&*$visitor, $has_feature, $span, $name, $explain, $help);
21-
let has_feature: bool = has_feature(visitor.features);
22-
debug!("gate_feature(feature = {:?}, span = {:?}); has? {}", name, span, has_feature);
23-
if !has_feature && !span.allows_unstable($name) {
24-
feature_err(&visitor.sess.parse_sess, name, span, explain).help(help).emit();
17+
($visitor:expr, $has_feature:expr, $span:expr, $name:expr, $explain:expr, $help:expr) => {{
18+
if !$has_feature($visitor.features) && !$span.allows_unstable($name) {
19+
feature_err(&$visitor.sess.parse_sess, $name, $span, $explain).help($help).emit();
2520
}
2621
}};
27-
($visitor: expr, $has_feature: expr, $span: expr, $name: expr, $explain: expr) => {{
28-
let (visitor, has_feature, span, name, explain) =
29-
(&*$visitor, $has_feature, $span, $name, $explain);
30-
let has_feature: bool = has_feature(visitor.features);
31-
debug!("gate_feature(feature = {:?}, span = {:?}); has? {}", name, span, has_feature);
32-
if !has_feature && !span.allows_unstable($name) {
33-
feature_err(&visitor.sess.parse_sess, name, span, explain).emit();
22+
($visitor:expr, $has_feature:expr, $span:expr, $name:expr, $explain:expr) => {{
23+
if !$has_feature($visitor.features) && !$span.allows_unstable($name) {
24+
feature_err(&$visitor.sess.parse_sess, $name, $span, $explain).emit();
3425
}
3526
}};
36-
(future_incompatible; $visitor: expr, $has_feature: expr, $span: expr, $name: expr, $explain: expr) => {{
37-
let (visitor, has_feature, span, name, explain) =
38-
(&*$visitor, $has_feature, $span, $name, $explain);
39-
let has_feature: bool = has_feature(visitor.features);
40-
debug!(
41-
"gate_feature(feature = {:?}, span = {:?}); has? {} (future_incompatible)",
42-
name, span, has_feature
43-
);
44-
if !has_feature && !span.allows_unstable($name) {
45-
feature_warn(&visitor.sess.parse_sess, name, span, explain);
27+
(future_incompatible; $visitor:expr, $has_feature:expr, $span:expr, $name:expr, $explain:expr) => {{
28+
if !$has_feature($visitor.features) && !$span.allows_unstable($name) {
29+
feature_warn(&$visitor.sess.parse_sess, $name, $span, $explain);
4630
}
4731
}};
4832
}
4933

5034
macro_rules! gate_feature_post {
51-
($visitor: expr, $feature: ident, $span: expr, $explain: expr, $help: expr) => {
52-
gate_feature_fn!($visitor, |x: &Features| x.$feature, $span, sym::$feature, $explain, $help)
35+
($visitor:expr, $feature:ident, $span:expr, $explain:expr, $help:expr) => {
36+
gate_feature_fn!($visitor, |x:&Features| x.$feature, $span, sym::$feature, $explain, $help)
5337
};
54-
($visitor: expr, $feature: ident, $span: expr, $explain: expr) => {
55-
gate_feature_fn!($visitor, |x: &Features| x.$feature, $span, sym::$feature, $explain)
38+
($visitor:expr, $feature:ident, $span:expr, $explain:expr) => {
39+
gate_feature_fn!($visitor, |x:&Features| x.$feature, $span, sym::$feature, $explain)
5640
};
57-
(future_incompatible; $visitor: expr, $feature: ident, $span: expr, $explain: expr) => {
41+
(future_incompatible; $visitor:expr, $feature:ident, $span:expr, $explain:expr) => {
5842
gate_feature_fn!(future_incompatible; $visitor, |x: &Features| x.$feature, $span, sym::$feature, $explain)
5943
};
6044
}

0 commit comments

Comments
 (0)