Skip to content

Commit 499b309

Browse files
committed
Fix a FIXME, by adding a gate_multi macro.
Note that this adds the `span.allows_unstable` checking that this case previously lacked.
1 parent de17ec9 commit 499b309

File tree

1 file changed

+24
-18
lines changed

1 file changed

+24
-18
lines changed

compiler/rustc_ast_passes/src/feature_gate.rs

+24-18
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,27 @@ macro_rules! gate {
3030
}
3131

3232
/// The unusual case, where the `has_feature` condition is non-standard.
33-
macro_rules! gate_alt {
33+
macro_rules! gate_complex {
3434
($visitor:expr, $has_feature:expr, $name:expr, $span:expr, $explain:expr) => {{
3535
if !$has_feature && !$span.allows_unstable($name) {
3636
feature_err(&$visitor.sess.parse_sess, $name, $span, $explain).emit();
3737
}
3838
}};
3939
}
4040

41+
/// The case involving a multispan.
42+
macro_rules! gate_multi {
43+
($visitor:expr, $feature:ident, $spans:expr, $explain:expr) => {{
44+
if !$visitor.features.$feature {
45+
let spans: Vec<_> =
46+
$spans.filter(|span| !span.allows_unstable(sym::$feature)).collect();
47+
if !spans.is_empty() {
48+
feature_err(&$visitor.sess.parse_sess, sym::$feature, spans, $explain).emit();
49+
}
50+
}
51+
}};
52+
}
53+
4154
/// The legacy case.
4255
macro_rules! gate_legacy {
4356
($visitor:expr, $feature:ident, $span:expr, $explain:expr) => {{
@@ -141,23 +154,16 @@ impl<'a> PostExpansionVisitor<'a> {
141154
fn check_late_bound_lifetime_defs(&self, params: &[ast::GenericParam]) {
142155
// Check only lifetime parameters are present and that the lifetime
143156
// parameters that are present have no bounds.
144-
let non_lt_param_spans: Vec<_> = params
145-
.iter()
146-
.filter_map(|param| match param.kind {
147-
ast::GenericParamKind::Lifetime { .. } => None,
148-
_ => Some(param.ident.span),
149-
})
150-
.collect();
151-
// FIXME: gate_feature_post doesn't really handle multispans...
152-
if !non_lt_param_spans.is_empty() && !self.features.non_lifetime_binders {
153-
feature_err(
154-
&self.sess.parse_sess,
155-
sym::non_lifetime_binders,
156-
non_lt_param_spans,
157-
crate::fluent_generated::ast_passes_forbidden_non_lifetime_param,
158-
)
159-
.emit();
160-
}
157+
let non_lt_param_spans = params.iter().filter_map(|param| match param.kind {
158+
ast::GenericParamKind::Lifetime { .. } => None,
159+
_ => Some(param.ident.span),
160+
});
161+
gate_multi!(
162+
&self,
163+
non_lifetime_binders,
164+
non_lt_param_spans,
165+
crate::fluent_generated::ast_passes_forbidden_non_lifetime_param
166+
);
161167
for param in params {
162168
if !param.bounds.is_empty() {
163169
let spans: Vec<_> = param.bounds.iter().map(|b| b.span()).collect();

0 commit comments

Comments
 (0)