Skip to content

Commit b496d7b

Browse files
pcwaltonhuonw
authored andcommitted
libsyntax: Make float literals not use @str
1 parent 8d6ef2e commit b496d7b

File tree

7 files changed

+24
-20
lines changed

7 files changed

+24
-20
lines changed

src/librustc/middle/const_eval.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -515,9 +515,9 @@ pub fn lit_to_const(lit: &Lit) -> const_val {
515515
LitInt(n, _) => const_int(n),
516516
LitUint(n, _) => const_uint(n),
517517
LitIntUnsuffixed(n) => const_int(n),
518-
LitFloat(n, _) => const_float(from_str::<f64>(n).unwrap() as f64),
519-
LitFloatUnsuffixed(n) =>
520-
const_float(from_str::<f64>(n).unwrap() as f64),
518+
LitFloat(ref n, _) | LitFloatUnsuffixed(ref n) => {
519+
const_float(from_str::<f64>(n.get()).unwrap() as f64)
520+
}
521521
LitNil => const_int(0i64),
522522
LitBool(b) => const_bool(b)
523523
}

src/librustc/middle/trans/consts.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,14 @@ pub fn const_lit(cx: &CrateContext, e: &ast::Expr, lit: ast::Lit)
5757
ty_to_str(cx.tcx, lit_int_ty)))
5858
}
5959
}
60-
ast::LitFloat(fs, t) => C_floating(fs, Type::float_from_ty(t)),
61-
ast::LitFloatUnsuffixed(fs) => {
60+
ast::LitFloat(ref fs, t) => {
61+
C_floating(fs.get(), Type::float_from_ty(t))
62+
}
63+
ast::LitFloatUnsuffixed(ref fs) => {
6264
let lit_float_ty = ty::node_id_to_type(cx.tcx, e.id);
6365
match ty::get(lit_float_ty).sty {
6466
ty::ty_float(t) => {
65-
C_floating(fs, Type::float_from_ty(t))
67+
C_floating(fs.get(), Type::float_from_ty(t))
6668
}
6769
_ => {
6870
cx.sess.span_bug(lit.span,

src/librustdoc/clean.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,8 +1152,8 @@ fn lit_to_str(lit: &ast::Lit) -> ~str {
11521152
ast::LitInt(i, _t) => i.to_str(),
11531153
ast::LitUint(u, _t) => u.to_str(),
11541154
ast::LitIntUnsuffixed(i) => i.to_str(),
1155-
ast::LitFloat(f, _t) => f.to_str(),
1156-
ast::LitFloatUnsuffixed(f) => f.to_str(),
1155+
ast::LitFloat(ref f, _t) => f.get().to_str(),
1156+
ast::LitFloatUnsuffixed(ref f) => f.get().to_str(),
11571157
ast::LitBool(b) => b.to_str(),
11581158
ast::LitNil => ~"",
11591159
}

src/libsyntax/ast.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -728,8 +728,8 @@ pub enum Lit_ {
728728
LitInt(i64, IntTy),
729729
LitUint(u64, UintTy),
730730
LitIntUnsuffixed(i64),
731-
LitFloat(@str, FloatTy),
732-
LitFloatUnsuffixed(@str),
731+
LitFloat(InternedString, FloatTy),
732+
LitFloatUnsuffixed(InternedString),
733733
LitNil,
734734
LitBool(bool),
735735
}

src/libsyntax/ext/concat.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,11 @@ pub fn expand_syntax_ext(cx: &mut base::ExtCtxt,
2929
match e.node {
3030
ast::ExprLit(lit) => {
3131
match lit.node {
32-
ast::LitStr(ref s, _) => {
32+
ast::LitStr(ref s, _) |
33+
ast::LitFloat(ref s, _) |
34+
ast::LitFloatUnsuffixed(ref s) => {
3335
accumulator.push_str(s.get());
3436
}
35-
ast::LitFloat(s, _) | ast::LitFloatUnsuffixed(s) => {
36-
accumulator.push_str(s);
37-
}
3837
ast::LitChar(c) => {
3938
accumulator.push_char(char::from_u32(c).unwrap());
4039
}

src/libsyntax/parse/parser.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1405,9 +1405,12 @@ impl Parser {
14051405
token::LIT_INT(i, it) => LitInt(i, it),
14061406
token::LIT_UINT(u, ut) => LitUint(u, ut),
14071407
token::LIT_INT_UNSUFFIXED(i) => LitIntUnsuffixed(i),
1408-
token::LIT_FLOAT(s, ft) => LitFloat(self.id_to_str(s), ft),
1409-
token::LIT_FLOAT_UNSUFFIXED(s) =>
1410-
LitFloatUnsuffixed(self.id_to_str(s)),
1408+
token::LIT_FLOAT(s, ft) => {
1409+
LitFloat(self.id_to_interned_str(s), ft)
1410+
}
1411+
token::LIT_FLOAT_UNSUFFIXED(s) => {
1412+
LitFloatUnsuffixed(self.id_to_interned_str(s))
1413+
}
14111414
token::LIT_STR(s) => {
14121415
LitStr(self.id_to_interned_str(s), ast::CookedStr)
14131416
}

src/libsyntax/print/pprust.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2202,10 +2202,10 @@ pub fn print_literal(s: &mut State, lit: &ast::Lit) {
22022202
word(&mut s.s, (i as u64).to_str_radix(10u));
22032203
}
22042204
}
2205-
ast::LitFloat(f, t) => {
2206-
word(&mut s.s, f.to_owned() + ast_util::float_ty_to_str(t));
2205+
ast::LitFloat(ref f, t) => {
2206+
word(&mut s.s, f.get() + ast_util::float_ty_to_str(t));
22072207
}
2208-
ast::LitFloatUnsuffixed(f) => word(&mut s.s, f),
2208+
ast::LitFloatUnsuffixed(ref f) => word(&mut s.s, f.get()),
22092209
ast::LitNil => word(&mut s.s, "()"),
22102210
ast::LitBool(val) => {
22112211
if val { word(&mut s.s, "true"); } else { word(&mut s.s, "false"); }

0 commit comments

Comments
 (0)