Avoid producing NoDelim
values in MacArgs::delim()
.
This commit is contained in:
parent
f0bbc782ac
commit
6b367a0532
4 changed files with 44 additions and 38 deletions
|
@ -1542,10 +1542,10 @@ pub enum MacArgs {
|
|||
}
|
||||
|
||||
impl MacArgs {
|
||||
pub fn delim(&self) -> DelimToken {
|
||||
pub fn delim(&self) -> Option<DelimToken> {
|
||||
match self {
|
||||
MacArgs::Delimited(_, delim, _) => delim.to_token(),
|
||||
MacArgs::Empty | MacArgs::Eq(..) => token::NoDelim,
|
||||
MacArgs::Delimited(_, delim, _) => Some(delim.to_token()),
|
||||
MacArgs::Empty | MacArgs::Eq(..) => None,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -464,7 +464,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
|
|||
Some(MacHeader::Path(&item.path)),
|
||||
false,
|
||||
None,
|
||||
delim.to_token(),
|
||||
Some(delim.to_token()),
|
||||
tokens,
|
||||
true,
|
||||
span,
|
||||
|
@ -530,7 +530,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
|
|||
None,
|
||||
false,
|
||||
None,
|
||||
*delim,
|
||||
Some(*delim),
|
||||
tts,
|
||||
convert_dollar_crate,
|
||||
dspan.entire(),
|
||||
|
@ -556,12 +556,12 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
|
|||
header: Option<MacHeader<'_>>,
|
||||
has_bang: bool,
|
||||
ident: Option<Ident>,
|
||||
delim: DelimToken,
|
||||
delim: Option<DelimToken>,
|
||||
tts: &TokenStream,
|
||||
convert_dollar_crate: bool,
|
||||
span: Span,
|
||||
) {
|
||||
if delim == DelimToken::Brace {
|
||||
if delim == Some(DelimToken::Brace) {
|
||||
self.cbox(INDENT_UNIT);
|
||||
}
|
||||
match header {
|
||||
|
@ -577,7 +577,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
|
|||
self.print_ident(ident);
|
||||
}
|
||||
match delim {
|
||||
DelimToken::Brace => {
|
||||
Some(DelimToken::Brace) => {
|
||||
if header.is_some() || has_bang || ident.is_some() {
|
||||
self.nbsp();
|
||||
}
|
||||
|
@ -585,23 +585,25 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
|
|||
if !tts.is_empty() {
|
||||
self.space();
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
let token_str = self.token_kind_to_string(&token::OpenDelim(delim));
|
||||
self.word(token_str)
|
||||
}
|
||||
}
|
||||
self.ibox(0);
|
||||
self.print_tts(tts, convert_dollar_crate);
|
||||
self.end();
|
||||
match delim {
|
||||
DelimToken::Brace => {
|
||||
self.ibox(0);
|
||||
self.print_tts(tts, convert_dollar_crate);
|
||||
self.end();
|
||||
let empty = tts.is_empty();
|
||||
self.bclose(span, empty);
|
||||
}
|
||||
_ => {
|
||||
Some(delim) => {
|
||||
let token_str = self.token_kind_to_string(&token::OpenDelim(delim));
|
||||
self.word(token_str);
|
||||
self.ibox(0);
|
||||
self.print_tts(tts, convert_dollar_crate);
|
||||
self.end();
|
||||
let token_str = self.token_kind_to_string(&token::CloseDelim(delim));
|
||||
self.word(token_str)
|
||||
self.word(token_str);
|
||||
}
|
||||
None => {
|
||||
self.ibox(0);
|
||||
self.print_tts(tts, convert_dollar_crate);
|
||||
self.end();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -164,25 +164,29 @@ impl<'a> Parser<'a> {
|
|||
let delim = args.delim();
|
||||
let hi = self.prev_token.span;
|
||||
|
||||
let style =
|
||||
if delim == token::Brace { MacStmtStyle::Braces } else { MacStmtStyle::NoBraces };
|
||||
let style = match delim {
|
||||
Some(token::Brace) => MacStmtStyle::Braces,
|
||||
Some(_) => MacStmtStyle::NoBraces,
|
||||
None => unreachable!(),
|
||||
};
|
||||
|
||||
let mac = MacCall { path, args, prior_type_ascription: self.last_type_ascription };
|
||||
|
||||
let kind =
|
||||
if (delim == token::Brace && self.token != token::Dot && self.token != token::Question)
|
||||
|| self.token == token::Semi
|
||||
|| self.token == token::Eof
|
||||
{
|
||||
StmtKind::MacCall(P(MacCallStmt { mac, style, attrs, tokens: None }))
|
||||
} else {
|
||||
// Since none of the above applied, this is an expression statement macro.
|
||||
let e = self.mk_expr(lo.to(hi), ExprKind::MacCall(mac), AttrVec::new());
|
||||
let e = self.maybe_recover_from_bad_qpath(e, true)?;
|
||||
let e = self.parse_dot_or_call_expr_with(e, lo, attrs.into())?;
|
||||
let e = self.parse_assoc_expr_with(0, LhsExpr::AlreadyParsed(e))?;
|
||||
StmtKind::Expr(e)
|
||||
};
|
||||
let kind = if (style == MacStmtStyle::Braces
|
||||
&& self.token != token::Dot
|
||||
&& self.token != token::Question)
|
||||
|| self.token == token::Semi
|
||||
|| self.token == token::Eof
|
||||
{
|
||||
StmtKind::MacCall(P(MacCallStmt { mac, style, attrs, tokens: None }))
|
||||
} else {
|
||||
// Since none of the above applied, this is an expression statement macro.
|
||||
let e = self.mk_expr(lo.to(hi), ExprKind::MacCall(mac), AttrVec::new());
|
||||
let e = self.maybe_recover_from_bad_qpath(e, true)?;
|
||||
let e = self.parse_dot_or_call_expr_with(e, lo, attrs.into())?;
|
||||
let e = self.parse_assoc_expr_with(0, LhsExpr::AlreadyParsed(e))?;
|
||||
StmtKind::Expr(e)
|
||||
};
|
||||
Ok(self.mk_stmt(lo.to(hi), kind))
|
||||
}
|
||||
|
||||
|
|
|
@ -1325,7 +1325,7 @@ pub(crate) fn can_be_overflowed_expr(
|
|||
}
|
||||
ast::ExprKind::MacCall(ref mac) => {
|
||||
match (
|
||||
rustc_ast::ast::MacDelimiter::from_token(mac.args.delim()),
|
||||
rustc_ast::ast::MacDelimiter::from_token(mac.args.delim().unwrap()),
|
||||
context.config.overflow_delimited_expr(),
|
||||
) {
|
||||
(Some(ast::MacDelimiter::Bracket), true)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue