Skip to content

Commit 4f76632

Browse files
committed
Turn ast::Lit into a struct
1 parent ef01f29 commit 4f76632

File tree

5 files changed

+24
-17
lines changed

5 files changed

+24
-17
lines changed

src/librustc/ich/impls_syntax.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,11 @@ impl_stable_hash_for!(enum ::syntax::ast::LitIntType {
162162
Unsuffixed
163163
});
164164

165-
impl_stable_hash_for_spanned!(::syntax::ast::LitKind);
165+
impl_stable_hash_for!(struct ::syntax::ast::Lit {
166+
node,
167+
span
168+
});
169+
166170
impl_stable_hash_for!(enum ::syntax::ast::LitKind {
167171
Str(value, style),
168172
Err(value),

src/libsyntax/ast.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1351,7 +1351,11 @@ pub enum StrStyle {
13511351
}
13521352

13531353
/// A literal.
1354-
pub type Lit = Spanned<LitKind>;
1354+
#[derive(Clone, RustcEncodable, RustcDecodable, Debug, Hash, PartialEq)]
1355+
pub struct Lit {
1356+
pub node: LitKind,
1357+
pub span: Span,
1358+
}
13551359

13561360
#[derive(Clone, RustcEncodable, RustcDecodable, Debug, Copy, Hash, PartialEq)]
13571361
pub enum LitIntType {

src/libsyntax/attr/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::ast::{AttrId, Attribute, AttrStyle, Name, Ident, Path, PathSegment};
1616
use crate::ast::{MetaItem, MetaItemKind, NestedMetaItem};
1717
use crate::ast::{Lit, LitKind, Expr, ExprKind, Item, Local, Stmt, StmtKind, GenericParam};
1818
use crate::mut_visit::visit_clobber;
19-
use crate::source_map::{BytePos, Spanned, respan, dummy_spanned};
19+
use crate::source_map::{BytePos, Spanned, dummy_spanned};
2020
use crate::parse::lexer::comments::{doc_comment_style, strip_doc_comment_decoration};
2121
use crate::parse::parser::Parser;
2222
use crate::parse::{self, ParseSess, PResult};
@@ -350,11 +350,11 @@ impl Attribute {
350350
/* Constructors */
351351

352352
pub fn mk_name_value_item_str(ident: Ident, value: Spanned<Symbol>) -> MetaItem {
353-
let value = respan(value.span, LitKind::Str(value.node, ast::StrStyle::Cooked));
353+
let value = Lit { node: LitKind::Str(value.node, ast::StrStyle::Cooked), span: value.span };
354354
mk_name_value_item(ident.span.to(value.span), ident, value)
355355
}
356356

357-
pub fn mk_name_value_item(span: Span, ident: Ident, value: ast::Lit) -> MetaItem {
357+
pub fn mk_name_value_item(span: Span, ident: Ident, value: Lit) -> MetaItem {
358358
MetaItem { path: Path::from_ident(ident), span, node: MetaItemKind::NameValue(value) }
359359
}
360360

@@ -417,7 +417,7 @@ pub fn mk_spanned_attr_outer(sp: Span, id: AttrId, item: MetaItem) -> Attribute
417417

418418
pub fn mk_sugared_doc_attr(id: AttrId, text: Symbol, span: Span) -> Attribute {
419419
let style = doc_comment_style(&text.as_str());
420-
let lit = respan(span, LitKind::Str(text, ast::StrStyle::Cooked));
420+
let lit = Lit { node: LitKind::Str(text, ast::StrStyle::Cooked), span };
421421
Attribute {
422422
id,
423423
style,
@@ -562,7 +562,7 @@ impl MetaItemKind {
562562
tokens.next();
563563
return if let Some(TokenTree::Token(span, token)) = tokens.next() {
564564
LitKind::from_token(token)
565-
.map(|lit| MetaItemKind::NameValue(Spanned { node: lit, span: span }))
565+
.map(|node| MetaItemKind::NameValue(Lit { node, span }))
566566
} else {
567567
None
568568
};
@@ -609,7 +609,7 @@ impl NestedMetaItem {
609609
if let Some(TokenTree::Token(span, token)) = tokens.peek().cloned() {
610610
if let Some(node) = LitKind::from_token(token) {
611611
tokens.next();
612-
return Some(NestedMetaItem::Literal(respan(span, node)));
612+
return Some(NestedMetaItem::Literal(Lit { node, span }));
613613
}
614614
}
615615

src/libsyntax/ext/build.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -697,8 +697,8 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
697697
self.expr_struct(span, self.path_ident(span, id), fields)
698698
}
699699

700-
fn expr_lit(&self, sp: Span, lit: ast::LitKind) -> P<ast::Expr> {
701-
self.expr(sp, ast::ExprKind::Lit(respan(sp, lit)))
700+
fn expr_lit(&self, span: Span, node: ast::LitKind) -> P<ast::Expr> {
701+
self.expr(span, ast::ExprKind::Lit(ast::Lit { node, span }))
702702
}
703703
fn expr_usize(&self, span: Span, i: usize) -> P<ast::Expr> {
704704
self.expr_lit(span, ast::LitKind::Int(i as u128,
@@ -1164,10 +1164,10 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
11641164
attr::mk_list_item(sp, Ident::with_empty_ctxt(name).with_span_pos(sp), mis)
11651165
}
11661166

1167-
fn meta_name_value(&self, sp: Span, name: ast::Name, value: ast::LitKind)
1167+
fn meta_name_value(&self, span: Span, name: ast::Name, node: ast::LitKind)
11681168
-> ast::MetaItem {
1169-
attr::mk_name_value_item(sp, Ident::with_empty_ctxt(name).with_span_pos(sp),
1170-
respan(sp, value))
1169+
attr::mk_name_value_item(span, Ident::with_empty_ctxt(name).with_span_pos(span),
1170+
ast::Lit { node, span })
11711171
}
11721172

11731173
fn item_use(&self, sp: Span,

src/libsyntax/parse/parser.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2135,15 +2135,14 @@ impl<'a> Parser<'a> {
21352135
/// Matches `lit = true | false | token_lit`.
21362136
crate fn parse_lit(&mut self) -> PResult<'a, Lit> {
21372137
let lo = self.span;
2138-
let lit = if self.eat_keyword(keywords::True) {
2138+
let node = if self.eat_keyword(keywords::True) {
21392139
LitKind::Bool(true)
21402140
} else if self.eat_keyword(keywords::False) {
21412141
LitKind::Bool(false)
21422142
} else {
2143-
let lit = self.parse_lit_token()?;
2144-
lit
2143+
self.parse_lit_token()?
21452144
};
2146-
Ok(source_map::Spanned { node: lit, span: lo.to(self.prev_span) })
2145+
Ok(Lit { node, span: lo.to(self.prev_span) })
21472146
}
21482147

21492148
/// Matches `'-' lit | lit` (cf. `ast_validation::AstValidator::check_expr_within_pat`).

0 commit comments

Comments
 (0)