diff options
Diffstat (limited to 'compiler/rustc_parse/src')
| -rw-r--r-- | compiler/rustc_parse/src/parser/item.rs | 31 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/nonterminal.rs | 12 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/path.rs | 7 |
3 files changed, 38 insertions, 12 deletions
diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs index 29957bd2f71..5a3bfb83725 100644 --- a/compiler/rustc_parse/src/parser/item.rs +++ b/compiler/rustc_parse/src/parser/item.rs @@ -685,20 +685,35 @@ impl<'a> Parser<'a> { (None, self.parse_path(PathStyle::Expr)?) }; - let rename = if self.eat_keyword(kw::As) { Some(self.parse_ident()?) } else { None }; + let rename = |this: &mut Self| { + Ok(if this.eat_keyword(kw::As) { Some(this.parse_ident()?) } else { None }) + }; + let body = |this: &mut Self| { + Ok(if this.check(&token::OpenDelim(Delimiter::Brace)) { + Some(this.parse_block()?) + } else { + this.expect(&token::Semi)?; + None + }) + }; - let body = if self.check(&token::OpenDelim(Delimiter::Brace)) { - Some(self.parse_block()?) + let (ident, item_kind) = if self.eat(&token::PathSep) { + let (suffixes, _) = self.parse_delim_comma_seq(Delimiter::Brace, |p| { + Ok((p.parse_path_segment_ident()?, rename(p)?)) + })?; + let deleg = DelegationMac { qself, prefix: path, suffixes, body: body(self)? }; + (Ident::empty(), ItemKind::DelegationMac(Box::new(deleg))) } else { - self.expect(&token::Semi)?; - None + let rename = rename(self)?; + let ident = rename.unwrap_or_else(|| path.segments.last().unwrap().ident); + let deleg = Delegation { id: DUMMY_NODE_ID, qself, path, rename, body: body(self)? }; + (ident, ItemKind::Delegation(Box::new(deleg))) }; + let span = span.to(self.prev_token.span); self.psess.gated_spans.gate(sym::fn_delegation, span); - let ident = rename.unwrap_or_else(|| path.segments.last().unwrap().ident); - let deleg = Delegation { id: DUMMY_NODE_ID, qself, path, rename, body }; - Ok((ident, ItemKind::Delegation(Box::new(deleg)))) + Ok((ident, item_kind)) } fn parse_item_list<T>( diff --git a/compiler/rustc_parse/src/parser/nonterminal.rs b/compiler/rustc_parse/src/parser/nonterminal.rs index a6f0ab78b5c..619c4c63e51 100644 --- a/compiler/rustc_parse/src/parser/nonterminal.rs +++ b/compiler/rustc_parse/src/parser/nonterminal.rs @@ -36,13 +36,19 @@ impl<'a> Parser<'a> { } match kind { - NonterminalKind::Expr => { + NonterminalKind::Expr2021 => { token.can_begin_expr() // This exception is here for backwards compatibility. && !token.is_keyword(kw::Let) // This exception is here for backwards compatibility. && !token.is_keyword(kw::Const) } + NonterminalKind::Expr => { + token.can_begin_expr() + // This exception is here for backwards compatibility. + && !token.is_keyword(kw::Let) + && (token.span.edition().at_least_rust_2024() || !token.is_keyword(kw::Const)) + } NonterminalKind::Ty => token.can_begin_type(), NonterminalKind::Ident => get_macro_ident(token).is_some(), NonterminalKind::Literal => token.can_begin_literal_maybe_minus(), @@ -143,7 +149,9 @@ impl<'a> Parser<'a> { })?) } - NonterminalKind::Expr => NtExpr(self.parse_expr_force_collect()?), + NonterminalKind::Expr | NonterminalKind::Expr2021 => { + NtExpr(self.parse_expr_force_collect()?) + } NonterminalKind::Literal => { // The `:literal` matcher does not support attributes NtLiteral(self.collect_tokens_no_attrs(|this| this.parse_literal_maybe_minus())?) diff --git a/compiler/rustc_parse/src/parser/path.rs b/compiler/rustc_parse/src/parser/path.rs index c37d3f0441d..d845e8ab90d 100644 --- a/compiler/rustc_parse/src/parser/path.rs +++ b/compiler/rustc_parse/src/parser/path.rs @@ -95,12 +95,15 @@ impl<'a> Parser<'a> { debug!("parse_qpath: (decrement) count={:?}", self.unmatched_angle_bracket_count); } - if !self.recover_colon_before_qpath_proj() { + let is_import_coupler = self.is_import_coupler(); + if !is_import_coupler && !self.recover_colon_before_qpath_proj() { self.expect(&token::PathSep)?; } let qself = P(QSelf { ty, path_span, position: path.segments.len() }); - self.parse_path_segments(&mut path.segments, style, None)?; + if !is_import_coupler { + self.parse_path_segments(&mut path.segments, style, None)?; + } Ok(( qself, |
