Rollup merge of #109029 - compiler-errors:parse-gating, r=jackh726

Gate usages of `dyn*` and const closures in macros

We silently accepted `dyn*` and const closures in macros as long as they didn't expand to anything containing these experimental features, unlike other gated features such as `for<'a>` binders on closures, etc. Let's not do that, to make sure nobody begins relying on this.
This commit is contained in:
Matthias Krüger 2023-03-12 20:44:51 +01:00 committed by GitHub
commit 98fea68470
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 61 additions and 27 deletions

View file

@ -2105,7 +2105,7 @@ impl<'a> Parser<'a> {
ClosureBinder::NotPresent
};
let constness = self.parse_closure_constness(Case::Sensitive);
let constness = self.parse_closure_constness();
let movability =
if self.eat_keyword(kw::Static) { Movability::Static } else { Movability::Movable };

View file

@ -1196,9 +1196,13 @@ impl<'a> Parser<'a> {
self.parse_constness_(case, false)
}
/// Parses constness for closures
fn parse_closure_constness(&mut self, case: Case) -> Const {
self.parse_constness_(case, true)
/// Parses constness for closures (case sensitive, feature-gated)
fn parse_closure_constness(&mut self) -> Const {
let constness = self.parse_constness_(Case::Sensitive, true);
if let Const::Yes(span) = constness {
self.sess.gated_spans.gate(sym::const_closures, span);
}
constness
}
fn parse_constness_(&mut self, case: Case, is_closure: bool) -> Const {

View file

@ -624,10 +624,12 @@ impl<'a> Parser<'a> {
///
/// Note that this does *not* parse bare trait objects.
fn parse_dyn_ty(&mut self, impl_dyn_multi: &mut bool) -> PResult<'a, TyKind> {
let lo = self.token.span;
self.bump(); // `dyn`
// parse dyn* types
let syntax = if self.eat(&TokenKind::BinOp(token::Star)) {
self.sess.gated_spans.gate(sym::dyn_star, lo.to(self.prev_token.span));
TraitObjectSyntax::DynStar
} else {
TraitObjectSyntax::Dyn