1
Fork 0

Remove MacDelimiter.

It's the same as `Delimiter`, minus the `Invisible` variant. I'm
generally in favour of using types to make impossible states
unrepresentable, but this one feels very low-value, and the conversions
between the two types are annoying and confusing.

Look at the change in `src/tools/rustfmt/src/expr.rs` for an example:
the old code converted from `MacDelimiter` to `Delimiter` and back
again, for no good reason. This suggests the author was confused about
the types.
This commit is contained in:
Nicholas Nethercote 2023-08-02 09:56:26 +10:00
parent ba294a816b
commit d75ee2a6bc
13 changed files with 37 additions and 67 deletions

View file

@ -25,7 +25,7 @@ use rustc_ast::util::case::Case;
use rustc_ast::AttrId;
use rustc_ast::DUMMY_NODE_ID;
use rustc_ast::{self as ast, AnonConst, Const, DelimArgs, Extern};
use rustc_ast::{Async, AttrArgs, AttrArgsEq, Expr, ExprKind, MacDelimiter, Mutability, StrLit};
use rustc_ast::{Async, AttrArgs, AttrArgsEq, Expr, ExprKind, Mutability, StrLit};
use rustc_ast::{HasAttrs, HasTokens, Unsafe, Visibility, VisibilityKind};
use rustc_ast_pretty::pprust;
use rustc_data_structures::fx::FxHashMap;
@ -1216,12 +1216,10 @@ impl<'a> Parser<'a> {
|| self.check(&token::OpenDelim(Delimiter::Brace));
delimited.then(|| {
// We've confirmed above that there is a delimiter so unwrapping is OK.
let TokenTree::Delimited(dspan, delim, tokens) = self.parse_token_tree() else {
unreachable!()
};
DelimArgs { dspan, delim: MacDelimiter::from_token(delim).unwrap(), tokens }
DelimArgs { dspan, delim, tokens }
})
}