diff options
| author | Nicholas Nethercote <n.nethercote@gmail.com> | 2022-11-29 13:36:00 +1100 |
|---|---|---|
| committer | Nicholas Nethercote <n.nethercote@gmail.com> | 2022-12-02 13:49:19 +1100 |
| commit | 2fd364acff5f962b0ce4f4dffb5ae085d5f2b67a (patch) | |
| tree | 041c2e45d4449c44f874c737a3dcdbcaa8895c9f /compiler/rustc_parse/src | |
| parent | a7f35c42d474f893c56b6e0f7df3f8bb965f2650 (diff) | |
| download | rust-2fd364acff5f962b0ce4f4dffb5ae085d5f2b67a.tar.gz rust-2fd364acff5f962b0ce4f4dffb5ae085d5f2b67a.zip | |
Remove `token::Lit` from `ast::MetaItemLit`.
`token::Lit` contains a `kind` field that indicates what kind of literal it is. `ast::MetaItemLit` currently wraps a `token::Lit` but also has its own `kind` field. This means that `ast::MetaItemLit` encodes the literal kind in two different ways. This commit changes `ast::MetaItemLit` so it no longer wraps `token::Lit`. It now contains the `symbol` and `suffix` fields from `token::Lit`, but not the `kind` field, eliminating the redundancy.
Diffstat (limited to 'compiler/rustc_parse/src')
| -rw-r--r-- | compiler/rustc_parse/src/parser/expr.rs | 11 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/pat.rs | 2 |
2 files changed, 7 insertions, 6 deletions
diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index e0443a697b5..1c773bea000 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -1551,7 +1551,7 @@ impl<'a> Parser<'a> { }) }); consume_colon = false; - Ok(self.mk_expr(lo, ExprKind::Lit(lit.token_lit))) + Ok(self.mk_expr(lo, ExprKind::Lit(lit.as_token_lit()))) } else if !ate_colon && (self.check_noexpect(&TokenKind::Comma) || self.check_noexpect(&TokenKind::Gt)) { @@ -1654,7 +1654,8 @@ impl<'a> Parser<'a> { } let name = lifetime.without_first_quote().name; ast::MetaItemLit { - token_lit: token::Lit::new(token::LitKind::Char, name, None), + symbol: name, + suffix: None, kind: ast::LitKind::Char(name.as_str().chars().next().unwrap_or('_')), span: lifetime.span, } @@ -1773,8 +1774,8 @@ impl<'a> Parser<'a> { Some(lit) => match lit.kind { ast::LitKind::Str(symbol_unescaped, style) => Ok(ast::StrLit { style, - symbol: lit.token_lit.symbol, - suffix: lit.token_lit.suffix, + symbol: lit.symbol, + suffix: lit.suffix, span: lit.span, symbol_unescaped, }), @@ -1817,7 +1818,7 @@ impl<'a> Parser<'a> { pub(super) fn parse_token_lit(&mut self) -> PResult<'a, (token::Lit, Span)> { self.parse_opt_token_lit() .ok_or(()) - .or_else(|()| self.handle_missing_lit().map(|lit| (lit.token_lit, lit.span))) + .or_else(|()| self.handle_missing_lit().map(|lit| (lit.as_token_lit(), lit.span))) } pub(super) fn parse_meta_item_lit(&mut self) -> PResult<'a, MetaItemLit> { diff --git a/compiler/rustc_parse/src/parser/pat.rs b/compiler/rustc_parse/src/parser/pat.rs index cbeec951e2d..b5147158f70 100644 --- a/compiler/rustc_parse/src/parser/pat.rs +++ b/compiler/rustc_parse/src/parser/pat.rs @@ -420,7 +420,7 @@ impl<'a> Parser<'a> { err.span_label(self_.token.span, format!("expected {}", expected)); err }); - PatKind::Lit(self.mk_expr(lo, ExprKind::Lit(lit.token_lit))) + PatKind::Lit(self.mk_expr(lo, ExprKind::Lit(lit.as_token_lit()))) } else { // Try to parse everything else as literal with optional minus match self.parse_literal_maybe_minus() { |
