diff --git a/src/librustc_incremental/calculate_svh/svh_visitor.rs b/src/librustc_incremental/calculate_svh/svh_visitor.rs index 91646aa7f5d..4bad264ac87 100644 --- a/src/librustc_incremental/calculate_svh/svh_visitor.rs +++ b/src/librustc_incremental/calculate_svh/svh_visitor.rs @@ -18,7 +18,7 @@ use syntax::abi::Abi; use syntax::ast::{self, Name, NodeId}; use syntax::attr; use syntax::parse::token; -use syntax::symbol::InternedString; +use syntax::symbol::{Symbol, InternedString}; use syntax_pos::{Span, NO_EXPANSION, COMMAND_LINE_EXPN, BytePos}; use syntax::tokenstream; use rustc::hir; @@ -247,6 +247,8 @@ enum SawExprComponent<'a> { SawExprBinary(hir::BinOp_), SawExprUnary(hir::UnOp), SawExprLit(ast::LitKind), + SawExprLitStr(InternedString, ast::StrStyle), + SawExprLitFloat(InternedString, Option), SawExprCast, SawExprType, SawExprIf, @@ -315,7 +317,7 @@ fn saw_expr<'a>(node: &'a Expr_, ExprUnary(op, _) => { (SawExprUnary(op), unop_can_panic_at_runtime(op)) } - ExprLit(ref lit) => (SawExprLit(lit.node.clone()), false), + ExprLit(ref lit) => (saw_lit(lit), false), ExprCast(..) => (SawExprCast, false), ExprType(..) => (SawExprType, false), ExprIf(..) => (SawExprIf, false), @@ -342,6 +344,15 @@ fn saw_expr<'a>(node: &'a Expr_, } } +fn saw_lit(lit: &ast::Lit) -> SawExprComponent<'static> { + match lit.node { + ast::LitKind::Str(s, style) => SawExprLitStr(s.as_str(), style), + ast::LitKind::Float(s, ty) => SawExprLitFloat(s.as_str(), Some(ty)), + ast::LitKind::FloatUnsuffixed(s) => SawExprLitFloat(s.as_str(), None), + ref node @ _ => SawExprLit(node.clone()), + } +} + #[derive(Hash)] enum SawItemComponent { SawItemExternCrate, @@ -875,23 +886,16 @@ impl<'a, 'hash, 'tcx> StrictVersionHashVisitor<'a, 'hash, 'tcx> { // ignoring span information, it doesn't matter here self.hash_discriminant(&meta_item.node); - let name = &*meta_item.name.as_str(); + meta_item.name.as_str().len().hash(self.st); + meta_item.name.as_str().hash(self.st); + match meta_item.node { - ast::MetaItemKind::Word => { - name.len().hash(self.st); - name.hash(self.st); - } - ast::MetaItemKind::NameValue(ref lit) => { - name.len().hash(self.st); - name.hash(self.st); - lit.node.hash(self.st); - } + ast::MetaItemKind::Word => {} + ast::MetaItemKind::NameValue(ref lit) => saw_lit(lit).hash(self.st), ast::MetaItemKind::List(ref items) => { - name.len().hash(self.st); - name.hash(self.st); // Sort subitems so the hash does not depend on their order let indices = self.indices_sorted_by(&items, |p| { - (p.name(), fnv::hash(&p.literal().map(|i| &i.node))) + (p.name().map(Symbol::as_str), fnv::hash(&p.literal().map(saw_lit))) }); items.len().hash(self.st); for (index, &item_index) in indices.iter().enumerate() { @@ -903,7 +907,7 @@ impl<'a, 'hash, 'tcx> StrictVersionHashVisitor<'a, 'hash, 'tcx> { self.hash_meta_item(meta_item); } ast::NestedMetaItemKind::Literal(ref lit) => { - lit.node.hash(self.st); + saw_lit(lit).hash(self.st); } } }