diff options
| author | bors <bors@rust-lang.org> | 2023-12-12 07:09:19 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-12-12 07:09:19 +0000 |
| commit | fda521a988749458326ecef2e92e979077727a4e (patch) | |
| tree | 73ec9f26b38eb86b5676735f79e577c12fe0024a /compiler/rustc_parse/src/parser | |
| parent | aaeb4dd3a93a6be4cba5eb173f35453803994773 (diff) | |
| parent | 03b7ed06c88ae869daa4f2a30ef341918cc76ac7 (diff) | |
| download | rust-fda521a988749458326ecef2e92e979077727a4e.tar.gz rust-fda521a988749458326ecef2e92e979077727a4e.zip | |
Auto merge of #3223 - rust-lang:rustup-2023-12-12, r=RalfJung
Automatic Rustup
Diffstat (limited to 'compiler/rustc_parse/src/parser')
| -rw-r--r-- | compiler/rustc_parse/src/parser/attr.rs | 1 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/attr_wrapper.rs | 14 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/expr.rs | 12 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/item.rs | 8 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/mod.rs | 44 |
5 files changed, 45 insertions, 34 deletions
diff --git a/compiler/rustc_parse/src/parser/attr.rs b/compiler/rustc_parse/src/parser/attr.rs index 422bb79308d..c9ce896b868 100644 --- a/compiler/rustc_parse/src/parser/attr.rs +++ b/compiler/rustc_parse/src/parser/attr.rs @@ -7,7 +7,6 @@ use rustc_ast::attr; use rustc_ast::token::{self, Delimiter, Nonterminal}; use rustc_errors::{error_code, Diagnostic, IntoDiagnostic, PResult}; use rustc_span::{sym, BytePos, Span}; -use std::convert::TryInto; use thin_vec::ThinVec; use tracing::debug; diff --git a/compiler/rustc_parse/src/parser/attr_wrapper.rs b/compiler/rustc_parse/src/parser/attr_wrapper.rs index c66a7176aab..5e8447030f1 100644 --- a/compiler/rustc_parse/src/parser/attr_wrapper.rs +++ b/compiler/rustc_parse/src/parser/attr_wrapper.rs @@ -1,7 +1,7 @@ use super::{Capturing, FlatToken, ForceCollect, Parser, ReplaceRange, TokenCursor, TrailingToken}; use rustc_ast::token::{self, Delimiter, Token, TokenKind}; -use rustc_ast::tokenstream::{AttrTokenStream, AttributesData, ToAttrTokenStream}; -use rustc_ast::tokenstream::{AttrTokenTree, DelimSpan, LazyAttrTokenStream, Spacing}; +use rustc_ast::tokenstream::{AttrTokenStream, AttrTokenTree, AttributesData, DelimSpacing}; +use rustc_ast::tokenstream::{DelimSpan, LazyAttrTokenStream, Spacing, ToAttrTokenStream}; use rustc_ast::{self as ast}; use rustc_ast::{AttrVec, Attribute, HasAttrs, HasTokens}; use rustc_errors::PResult; @@ -389,7 +389,7 @@ fn make_token_stream( #[derive(Debug)] struct FrameData { // This is `None` for the first frame, `Some` for all others. - open_delim_sp: Option<(Delimiter, Span)>, + open_delim_sp: Option<(Delimiter, Span, Spacing)>, inner: Vec<AttrTokenTree>, } let mut stack = vec![FrameData { open_delim_sp: None, inner: vec![] }]; @@ -397,21 +397,23 @@ fn make_token_stream( while let Some((token, spacing)) = token_and_spacing { match token { FlatToken::Token(Token { kind: TokenKind::OpenDelim(delim), span }) => { - stack.push(FrameData { open_delim_sp: Some((delim, span)), inner: vec![] }); + stack + .push(FrameData { open_delim_sp: Some((delim, span, spacing)), inner: vec![] }); } FlatToken::Token(Token { kind: TokenKind::CloseDelim(delim), span }) => { let frame_data = stack .pop() .unwrap_or_else(|| panic!("Token stack was empty for token: {token:?}")); - let (open_delim, open_sp) = frame_data.open_delim_sp.unwrap(); + let (open_delim, open_sp, open_spacing) = frame_data.open_delim_sp.unwrap(); assert_eq!( open_delim, delim, "Mismatched open/close delims: open={open_delim:?} close={span:?}" ); let dspan = DelimSpan::from_pair(open_sp, span); + let dspacing = DelimSpacing::new(open_spacing, spacing); let stream = AttrTokenStream::new(frame_data.inner); - let delimited = AttrTokenTree::Delimited(dspan, delim, stream); + let delimited = AttrTokenTree::Delimited(dspan, dspacing, delim, stream); stack .last_mut() .unwrap_or_else(|| panic!("Bottom token frame is missing for token: {token:?}")) diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index 406a6def019..5b0011e9f70 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -2276,7 +2276,7 @@ impl<'a> Parser<'a> { } if self.token.kind == TokenKind::Semi - && matches!(self.token_cursor.stack.last(), Some((_, Delimiter::Parenthesis, _))) + && matches!(self.token_cursor.stack.last(), Some((.., Delimiter::Parenthesis))) && self.may_recover() { // It is likely that the closure body is a block but where the @@ -2918,7 +2918,15 @@ impl<'a> Parser<'a> { let mut result = if !is_fat_arrow && !is_almost_fat_arrow { // A pattern without a body, allowed for never patterns. arm_body = None; - this.expect_one_of(&[token::Comma], &[token::CloseDelim(Delimiter::Brace)]) + this.expect_one_of(&[token::Comma], &[token::CloseDelim(Delimiter::Brace)]).map( + |x| { + // Don't gate twice + if !pat.contains_never_pattern() { + this.sess.gated_spans.gate(sym::never_patterns, pat.span); + } + x + }, + ) } else { if let Err(mut err) = this.expect(&token::FatArrow) { // We might have a `=>` -> `=` or `->` typo (issue #89396). diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs index d22cc04d182..89919247e82 100644 --- a/compiler/rustc_parse/src/parser/item.rs +++ b/compiler/rustc_parse/src/parser/item.rs @@ -3,18 +3,12 @@ use super::ty::{AllowPlus, RecoverQPath, RecoverReturnSign}; use super::{AttrWrapper, FollowedByType, ForceCollect, Parser, PathStyle, TrailingToken}; use crate::errors::{self, MacroExpandsToAdtField}; use crate::fluent_generated as fluent; -use ast::StaticItem; use rustc_ast::ast::*; use rustc_ast::ptr::P; use rustc_ast::token::{self, Delimiter, TokenKind}; use rustc_ast::tokenstream::{DelimSpan, TokenStream, TokenTree}; use rustc_ast::util::case::Case; -use rustc_ast::MacCall; -use rustc_ast::{self as ast, AttrVec, Attribute, DUMMY_NODE_ID}; -use rustc_ast::{BindingAnnotation, Block, FnDecl, FnSig, Param, SelfKind}; -use rustc_ast::{Const, Defaultness, IsAuto, Mutability, Unsafe, UseTree, UseTreeKind}; -use rustc_ast::{EnumDef, FieldDef, Generics, TraitRef, Ty, TyKind, Variant, VariantData}; -use rustc_ast::{FnHeader, ForeignItem, Path, PathSegment, Visibility, VisibilityKind}; +use rustc_ast::{self as ast}; use rustc_ast_pretty::pprust; use rustc_errors::{ struct_span_err, Applicability, DiagnosticBuilder, ErrorGuaranteed, IntoDiagnostic, PResult, diff --git a/compiler/rustc_parse/src/parser/mod.rs b/compiler/rustc_parse/src/parser/mod.rs index 7a306823ed4..2baedb2766f 100644 --- a/compiler/rustc_parse/src/parser/mod.rs +++ b/compiler/rustc_parse/src/parser/mod.rs @@ -20,7 +20,7 @@ pub use path::PathStyle; use rustc_ast::ptr::P; use rustc_ast::token::{self, Delimiter, Nonterminal, Token, TokenKind}; -use rustc_ast::tokenstream::{AttributesData, DelimSpan, Spacing}; +use rustc_ast::tokenstream::{AttributesData, DelimSpacing, DelimSpan, Spacing}; use rustc_ast::tokenstream::{TokenStream, TokenTree, TokenTreeCursor}; use rustc_ast::util::case::Case; use rustc_ast::AttrId; @@ -130,7 +130,7 @@ pub struct Parser<'a> { pub sess: &'a ParseSess, /// The current token. pub token: Token, - /// The spacing for the current token + /// The spacing for the current token. pub token_spacing: Spacing, /// The previous token. pub prev_token: Token, @@ -240,7 +240,7 @@ struct TokenCursor { // Token streams surrounding the current one. The delimiters for stack[n]'s // tokens are in `stack[n-1]`. `stack[0]` (when present) has no delimiters // because it's the outermost token stream which never has delimiters. - stack: Vec<(TokenTreeCursor, Delimiter, DelimSpan)>, + stack: Vec<(TokenTreeCursor, DelimSpan, DelimSpacing, Delimiter)>, } impl TokenCursor { @@ -264,24 +264,31 @@ impl TokenCursor { )); return (token.clone(), spacing); } - &TokenTree::Delimited(sp, delim, ref tts) => { + &TokenTree::Delimited(sp, spacing, delim, ref tts) => { let trees = tts.clone().into_trees(); - self.stack.push((mem::replace(&mut self.tree_cursor, trees), delim, sp)); + self.stack.push(( + mem::replace(&mut self.tree_cursor, trees), + sp, + spacing, + delim, + )); if delim != Delimiter::Invisible { - return (Token::new(token::OpenDelim(delim), sp.open), Spacing::Alone); + return (Token::new(token::OpenDelim(delim), sp.open), spacing.open); } // No open delimiter to return; continue on to the next iteration. } }; - } else if let Some((tree_cursor, delim, span)) = self.stack.pop() { + } else if let Some((tree_cursor, span, spacing, delim)) = self.stack.pop() { // We have exhausted this token stream. Move back to its parent token stream. self.tree_cursor = tree_cursor; if delim != Delimiter::Invisible { - return (Token::new(token::CloseDelim(delim), span.close), Spacing::Alone); + return (Token::new(token::CloseDelim(delim), span.close), spacing.close); } // No close delimiter to return; continue on to the next iteration. } else { - // We have exhausted the outermost token stream. + // We have exhausted the outermost token stream. The use of + // `Spacing::Alone` is arbitrary and immaterial, because the + // `Eof` token's spacing is never used. return (Token::new(token::Eof, DUMMY_SP), Spacing::Alone); } } @@ -699,8 +706,8 @@ impl<'a> Parser<'a> { // is not needed (we'll capture the entire 'glued' token), // and `bump` will set this field to `None` self.break_last_token = true; - // Use the spacing of the glued token as the spacing - // of the unglued second token. + // Use the spacing of the glued token as the spacing of the + // unglued second token. self.bump_with((Token::new(second, second_span), self.token_spacing)); true } @@ -1068,7 +1075,7 @@ impl<'a> Parser<'a> { return looker(&self.token); } - if let Some(&(_, delim, span)) = self.token_cursor.stack.last() + if let Some(&(_, span, _, delim)) = self.token_cursor.stack.last() && delim != Delimiter::Invisible { // We are not in the outermost token stream, and the token stream @@ -1077,7 +1084,7 @@ impl<'a> Parser<'a> { let tree_cursor = &self.token_cursor.tree_cursor; let all_normal = (0..dist).all(|i| { let token = tree_cursor.look_ahead(i); - !matches!(token, Some(TokenTree::Delimited(_, Delimiter::Invisible, _))) + !matches!(token, Some(TokenTree::Delimited(.., Delimiter::Invisible, _))) }); if all_normal { // There were no skipped delimiters. Do lookahead by plain indexing. @@ -1086,7 +1093,7 @@ impl<'a> Parser<'a> { // Indexing stayed within the current token stream. match tree { TokenTree::Token(token, _) => looker(token), - TokenTree::Delimited(dspan, delim, _) => { + TokenTree::Delimited(dspan, _, delim, _) => { looker(&Token::new(token::OpenDelim(*delim), dspan.open)) } } @@ -1264,7 +1271,7 @@ impl<'a> Parser<'a> { || self.check(&token::OpenDelim(Delimiter::Brace)); delimited.then(|| { - let TokenTree::Delimited(dspan, delim, tokens) = self.parse_token_tree() else { + let TokenTree::Delimited(dspan, _, delim, tokens) = self.parse_token_tree() else { unreachable!() }; DelimArgs { dspan, delim, tokens } @@ -1288,7 +1295,7 @@ impl<'a> Parser<'a> { token::OpenDelim(..) => { // Grab the tokens within the delimiters. let stream = self.token_cursor.tree_cursor.stream.clone(); - let (_, delim, span) = *self.token_cursor.stack.last().unwrap(); + let (_, span, spacing, delim) = *self.token_cursor.stack.last().unwrap(); // Advance the token cursor through the entire delimited // sequence. After getting the `OpenDelim` we are *within* the @@ -1308,12 +1315,13 @@ impl<'a> Parser<'a> { // Consume close delimiter self.bump(); - TokenTree::Delimited(span, delim, stream) + TokenTree::Delimited(span, spacing, delim, stream) } token::CloseDelim(_) | token::Eof => unreachable!(), _ => { + let prev_spacing = self.token_spacing; self.bump(); - TokenTree::Token(self.prev_token.clone(), Spacing::Alone) + TokenTree::Token(self.prev_token.clone(), prev_spacing) } } } |
