Skip to content

Commit

Permalink
syntax: Turn token::Lit into a struct
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed May 23, 2019
1 parent 558559e commit ca2a50f
Show file tree
Hide file tree
Showing 12 changed files with 275 additions and 286 deletions.
3 changes: 1 addition & 2 deletions src/librustc/hir/print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1249,8 +1249,7 @@ impl<'a> State<'a> {

fn print_literal(&mut self, lit: &hir::Lit) -> io::Result<()> {
self.maybe_print_comment(lit.span.lo())?;
let (token, suffix) = lit.node.to_lit_token();
self.writer().word(pprust::literal_to_string(token, suffix))
self.writer().word(pprust::literal_to_string(lit.node.to_lit_token()))
}

pub fn print_expr(&mut self, expr: &hir::Expr) -> io::Result<()> {
Expand Down
34 changes: 18 additions & 16 deletions src/librustc/ich/impls_syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ impl_stable_hash_for!(enum ::syntax::ast::LitIntType {
impl_stable_hash_for!(struct ::syntax::ast::Lit {
node,
token,
suffix,
span
});

Expand Down Expand Up @@ -288,17 +287,23 @@ for tokenstream::TokenStream {
}
}

impl_stable_hash_for!(enum token::Lit {
Bool(val),
Byte(val),
Char(val),
Err(val),
Integer(val),
Float(val),
Str_(val),
ByteStr(val),
StrRaw(val, n),
ByteStrRaw(val, n)
impl_stable_hash_for!(enum token::LitKind {
Bool,
Byte,
Char,
Integer,
Float,
Str,
ByteStr,
StrRaw(n),
ByteStrRaw(n),
Err
});

impl_stable_hash_for!(struct token::Lit {
kind,
symbol,
suffix
});

fn hash_token<'a, 'gcx, W: StableHasherResult>(
Expand Down Expand Up @@ -348,10 +353,7 @@ fn hash_token<'a, 'gcx, W: StableHasherResult>(
token::Token::CloseDelim(delim_token) => {
std_hash::Hash::hash(&delim_token, hasher);
}
token::Token::Literal(lit, opt_name) => {
lit.hash_stable(hcx, hasher);
opt_name.hash_stable(hcx, hasher);
}
token::Token::Literal(lit) => lit.hash_stable(hcx, hasher),

token::Token::Ident(ident, is_raw) => {
ident.name.hash_stable(hcx, hasher);
Expand Down
14 changes: 7 additions & 7 deletions src/librustdoc/html/highlight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,17 +310,17 @@ impl<'a> Classifier<'a> {
}
}

token::Literal(lit, _suf) => {
match lit {
token::Literal(lit) => {
match lit.kind {
// Text literals.
token::Byte(..) | token::Char(..) | token::Err(..) |
token::ByteStr(..) | token::ByteStrRaw(..) |
token::Str_(..) | token::StrRaw(..) => Class::String,
token::Byte | token::Char | token::Err |
token::ByteStr | token::ByteStrRaw(..) |
token::Str | token::StrRaw(..) => Class::String,

// Number literals.
token::Integer(..) | token::Float(..) => Class::Number,
token::Integer | token::Float => Class::Number,

token::Bool(..) => panic!("literal token contains `Lit::Bool`"),
token::Bool => panic!("literal token contains `Lit::Bool`"),
}
}

Expand Down
2 changes: 0 additions & 2 deletions src/libsyntax/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1347,8 +1347,6 @@ pub enum StrStyle {
pub struct Lit {
/// The original literal token as written in source code.
pub token: token::Lit,
/// The original literal suffix as written in source code.
pub suffix: Option<Symbol>,
/// The "semantic" representation of the literal lowered from the original tokens.
/// Strings are unescaped, hexadecimal forms are eliminated, etc.
/// FIXME: Remove this and only create the semantic representation during lowering to HIR.
Expand Down
4 changes: 2 additions & 2 deletions src/libsyntax/diagnostics/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ pub fn expand_register_diagnostic<'cx>(ecx: &'cx mut ExtCtxt<'_>,
},
(3, Some(&TokenTree::Token(_, token::Ident(ref code, _))),
Some(&TokenTree::Token(_, token::Comma)),
Some(&TokenTree::Token(_, token::Literal(token::StrRaw(description, _), None)))) => {
(code, Some(description))
Some(&TokenTree::Token(_, token::Literal(token::Lit { symbol, .. })))) => {
(code, Some(symbol))
}
_ => unreachable!()
};
Expand Down
Loading

0 comments on commit ca2a50f

Please sign in to comment.