mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-22 02:00:00 +03:00
Rollup merge of #63755 - Centril:simplify-prexp-gating, r=petrochenkov
Use dedicated type for spans in pre-expansion gating. - Simplify the overall pre-expansion gating "experience".
This commit is contained in:
@@ -2423,16 +2423,19 @@ pub fn check_crate(krate: &ast::Crate,
|
||||
};
|
||||
|
||||
macro_rules! gate_all {
|
||||
($gate:ident, $msg:literal) => { gate_all!($gate, $gate, $msg); };
|
||||
($spans:ident, $gate:ident, $msg:literal) => {
|
||||
for span in &*sess.$spans.borrow() { gate_feature!(&ctx, $gate, *span, $msg); }
|
||||
for span in &*sess.gated_spans.$spans.borrow() {
|
||||
gate_feature!(&ctx, $gate, *span, $msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
gate_all!(param_attr_spans, param_attrs, "attributes on function parameters are unstable");
|
||||
gate_all!(let_chains_spans, let_chains, "`let` expressions in this position are experimental");
|
||||
gate_all!(async_closure_spans, async_closure, "async closures are unstable");
|
||||
gate_all!(yield_spans, generators, "yield syntax is experimental");
|
||||
gate_all!(or_pattern_spans, or_patterns, "or-patterns syntax is experimental");
|
||||
gate_all!(param_attrs, "attributes on function parameters are unstable");
|
||||
gate_all!(let_chains, "`let` expressions in this position are experimental");
|
||||
gate_all!(async_closure, "async closures are unstable");
|
||||
gate_all!(yields, generators, "yield syntax is experimental");
|
||||
gate_all!(or_patterns, "or-patterns syntax is experimental");
|
||||
|
||||
let visitor = &mut PostExpansionVisitor {
|
||||
context: &ctx,
|
||||
|
||||
@@ -21,9 +21,8 @@ enum InnerAttributeParsePolicy<'a> {
|
||||
impl<'a> Parser<'a> {
|
||||
crate fn parse_arg_attributes(&mut self) -> PResult<'a, Vec<ast::Attribute>> {
|
||||
let attrs = self.parse_outer_attributes()?;
|
||||
attrs.iter().for_each(|a|
|
||||
self.sess.param_attr_spans.borrow_mut().push(a.span)
|
||||
);
|
||||
self.sess.gated_spans.param_attrs.borrow_mut()
|
||||
.extend(attrs.iter().map(|a| a.span));
|
||||
Ok(attrs)
|
||||
}
|
||||
|
||||
|
||||
+18
-14
@@ -39,6 +39,22 @@
|
||||
|
||||
pub type PResult<'a, T> = Result<T, DiagnosticBuilder<'a>>;
|
||||
|
||||
/// Collected spans during parsing for places where a certain feature was
|
||||
/// used and should be feature gated accordingly in `check_crate`.
|
||||
#[derive(Default)]
|
||||
pub struct GatedSpans {
|
||||
/// Spans collected for gating `param_attrs`, e.g. `fn foo(#[attr] x: u8) {}`.
|
||||
pub param_attrs: Lock<Vec<Span>>,
|
||||
/// Spans collected for gating `let_chains`, e.g. `if a && let b = c {}`.
|
||||
pub let_chains: Lock<Vec<Span>>,
|
||||
/// Spans collected for gating `async_closure`, e.g. `async || ..`.
|
||||
pub async_closure: Lock<Vec<Span>>,
|
||||
/// Spans collected for gating `yield e?` expressions (`generators` gate).
|
||||
pub yields: Lock<Vec<Span>>,
|
||||
/// Spans collected for gating `or_patterns`, e.g. `Some(Foo | Bar)`.
|
||||
pub or_patterns: Lock<Vec<Span>>,
|
||||
}
|
||||
|
||||
/// Info about a parsing session.
|
||||
pub struct ParseSess {
|
||||
pub span_diagnostic: Handler,
|
||||
@@ -58,16 +74,8 @@ pub struct ParseSess {
|
||||
/// operation token that followed it, but that the parser cannot identify without further
|
||||
/// analysis.
|
||||
pub ambiguous_block_expr_parse: Lock<FxHashMap<Span, Span>>,
|
||||
pub param_attr_spans: Lock<Vec<Span>>,
|
||||
// Places where `let` exprs were used and should be feature gated according to `let_chains`.
|
||||
pub let_chains_spans: Lock<Vec<Span>>,
|
||||
// Places where `async || ..` exprs were used and should be feature gated.
|
||||
pub async_closure_spans: Lock<Vec<Span>>,
|
||||
// Places where `yield e?` exprs were used and should be feature gated.
|
||||
pub yield_spans: Lock<Vec<Span>>,
|
||||
pub injected_crate_name: Once<Symbol>,
|
||||
// Places where or-patterns e.g. `Some(Foo | Bar)` were used and should be feature gated.
|
||||
pub or_pattern_spans: Lock<Vec<Span>>,
|
||||
pub gated_spans: GatedSpans,
|
||||
}
|
||||
|
||||
impl ParseSess {
|
||||
@@ -93,12 +101,8 @@ pub fn with_span_handler(handler: Handler, source_map: Lrc<SourceMap>) -> ParseS
|
||||
buffered_lints: Lock::new(vec![]),
|
||||
edition: ExpnId::root().expn_data().edition,
|
||||
ambiguous_block_expr_parse: Lock::new(FxHashMap::default()),
|
||||
param_attr_spans: Lock::new(Vec::new()),
|
||||
let_chains_spans: Lock::new(Vec::new()),
|
||||
async_closure_spans: Lock::new(Vec::new()),
|
||||
yield_spans: Lock::new(Vec::new()),
|
||||
injected_crate_name: Once::new(),
|
||||
or_pattern_spans: Lock::new(Vec::new()),
|
||||
gated_spans: GatedSpans::default(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -999,7 +999,7 @@ macro_rules! parse_lit {
|
||||
}
|
||||
|
||||
let span = lo.to(hi);
|
||||
self.sess.yield_spans.borrow_mut().push(span);
|
||||
self.sess.gated_spans.yields.borrow_mut().push(span);
|
||||
} else if self.eat_keyword(kw::Let) {
|
||||
return self.parse_let_expr(attrs);
|
||||
} else if is_span_rust_2018 && self.eat_keyword(kw::Await) {
|
||||
@@ -1111,7 +1111,7 @@ fn parse_lambda_expr(&mut self, attrs: ThinVec<Attribute>) -> PResult<'a, P<Expr
|
||||
};
|
||||
if asyncness.is_async() {
|
||||
// Feature gate `async ||` closures.
|
||||
self.sess.async_closure_spans.borrow_mut().push(self.prev_span);
|
||||
self.sess.gated_spans.async_closure.borrow_mut().push(self.prev_span);
|
||||
}
|
||||
|
||||
let capture_clause = self.parse_capture_clause();
|
||||
@@ -1234,7 +1234,7 @@ fn parse_cond_expr(&mut self) -> PResult<'a, P<Expr>> {
|
||||
|
||||
if let ExprKind::Let(..) = cond.node {
|
||||
// Remove the last feature gating of a `let` expression since it's stable.
|
||||
let last = self.sess.let_chains_spans.borrow_mut().pop();
|
||||
let last = self.sess.gated_spans.let_chains.borrow_mut().pop();
|
||||
debug_assert_eq!(cond.span, last.unwrap());
|
||||
}
|
||||
|
||||
@@ -1252,7 +1252,7 @@ fn parse_let_expr(&mut self, attrs: ThinVec<Attribute>) -> PResult<'a, P<Expr>>
|
||||
|this| this.parse_assoc_expr_with(1 + prec_let_scrutinee_needs_par(), None.into())
|
||||
)?;
|
||||
let span = lo.to(expr.span);
|
||||
self.sess.let_chains_spans.borrow_mut().push(span);
|
||||
self.sess.gated_spans.let_chains.borrow_mut().push(span);
|
||||
Ok(self.mk_expr(span, ExprKind::Let(pats, expr), attrs))
|
||||
}
|
||||
|
||||
|
||||
@@ -123,7 +123,7 @@ fn parse_pat_with_or(&mut self, expected: Option<&'static str>) -> PResult<'a, P
|
||||
|
||||
let or_pattern_span = lo.to(self.prev_span);
|
||||
|
||||
self.sess.or_pattern_spans.borrow_mut().push(or_pattern_span);
|
||||
self.sess.gated_spans.or_patterns.borrow_mut().push(or_pattern_span);
|
||||
|
||||
Ok(self.mk_pat(or_pattern_span, PatKind::Or(pats)))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user