Skip to content

Commit 55f76cd

Browse files
committedNov 7, 2019
syntax: use distinct FloatTy from rustc_target.
We also sever syntax's dependency on rustc_target as a result. This should slightly improve pipe-lining. Moreover, some cleanup is done in related code.
·
1.88.01.41.0
1 parent bffc3d8 commit 55f76cd

File tree

19 files changed

+123
-158
lines changed

19 files changed

+123
-158
lines changed
 

‎Cargo.lock

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3762,7 +3762,6 @@ dependencies = [
37623762
"rustc",
37633763
"rustc_codegen_utils",
37643764
"rustc_data_structures",
3765-
"rustc_target",
37663765
"serde_json",
37673766
"syntax",
37683767
"syntax_pos",
@@ -4362,7 +4361,6 @@ dependencies = [
43624361
"rustc_errors",
43634362
"rustc_index",
43644363
"rustc_lexer",
4365-
"rustc_target",
43664364
"scoped-tls",
43674365
"serialize",
43684366
"smallvec 1.0.0",
@@ -4380,7 +4378,6 @@ dependencies = [
43804378
"rustc_errors",
43814379
"rustc_index",
43824380
"rustc_lexer",
4383-
"rustc_target",
43844381
"scoped-tls",
43854382
"serialize",
43864383
"smallvec 1.0.0",

‎src/librustc/ich/impls_syntax.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ for ::syntax::attr::StabilityLevel {
124124

125125
impl_stable_hash_for!(struct ::syntax::attr::RustcDeprecation { since, reason, suggestion });
126126

127-
128127
impl_stable_hash_for!(enum ::syntax::attr::IntType {
129128
SignedInt(int_ty),
130129
UnsignedInt(uint_ty)
@@ -136,6 +135,11 @@ impl_stable_hash_for!(enum ::syntax::ast::LitIntType {
136135
Unsuffixed
137136
});
138137

138+
impl_stable_hash_for!(enum ::syntax::ast::LitFloatType {
139+
Suffixed(float_ty),
140+
Unsuffixed
141+
});
142+
139143
impl_stable_hash_for!(struct ::syntax::ast::Lit {
140144
kind,
141145
token,
@@ -148,8 +152,7 @@ impl_stable_hash_for!(enum ::syntax::ast::LitKind {
148152
Byte(value),
149153
Char(value),
150154
Int(value, lit_int_type),
151-
Float(value, float_ty),
152-
FloatUnsuffixed(value),
155+
Float(value, lit_float_type),
153156
Bool(value),
154157
Err(value)
155158
});
@@ -159,6 +162,7 @@ impl_stable_hash_for_spanned!(::syntax::ast::LitKind);
159162
impl_stable_hash_for!(enum ::syntax::ast::IntTy { Isize, I8, I16, I32, I64, I128 });
160163
impl_stable_hash_for!(enum ::syntax::ast::UintTy { Usize, U8, U16, U32, U64, U128 });
161164
impl_stable_hash_for!(enum ::syntax::ast::FloatTy { F32, F64 });
165+
impl_stable_hash_for!(enum ::rustc_target::abi::FloatTy { F32, F64 });
162166
impl_stable_hash_for!(enum ::syntax::ast::Unsafety { Unsafe, Normal });
163167
impl_stable_hash_for!(enum ::syntax::ast::Constness { Const, NotConst });
164168
impl_stable_hash_for!(enum ::syntax::ast::Defaultness { Default, Final });

‎src/librustc/ty/layout.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,10 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
538538
ty::Uint(ity) => {
539539
scalar(Int(Integer::from_attr(dl, attr::UnsignedInt(ity)), false))
540540
}
541-
ty::Float(fty) => scalar(Float(fty)),
541+
ty::Float(fty) => scalar(Float(match fty {
542+
ast::FloatTy::F32 => FloatTy::F32,
543+
ast::FloatTy::F64 => FloatTy::F64,
544+
})),
542545
ty::FnPtr(_) => {
543546
let mut ptr = scalar_unit(Pointer);
544547
ptr.valid_range = 1..=*ptr.valid_range.end();

‎src/librustc/ty/print/obsolete.rs

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use rustc::ty::{self, Const, Instance, Ty, TyCtxt};
1212
use rustc::{bug, hir};
1313
use std::fmt::Write;
1414
use std::iter;
15-
use syntax::ast;
1615

1716
/// Same as `unique_type_name()` but with the result pushed onto the given
1817
/// `output` parameter.
@@ -39,20 +38,9 @@ impl DefPathBasedNames<'tcx> {
3938
ty::Char => output.push_str("char"),
4039
ty::Str => output.push_str("str"),
4140
ty::Never => output.push_str("!"),
42-
ty::Int(ast::IntTy::Isize) => output.push_str("isize"),
43-
ty::Int(ast::IntTy::I8) => output.push_str("i8"),
44-
ty::Int(ast::IntTy::I16) => output.push_str("i16"),
45-
ty::Int(ast::IntTy::I32) => output.push_str("i32"),
46-
ty::Int(ast::IntTy::I64) => output.push_str("i64"),
47-
ty::Int(ast::IntTy::I128) => output.push_str("i128"),
48-
ty::Uint(ast::UintTy::Usize) => output.push_str("usize"),
49-
ty::Uint(ast::UintTy::U8) => output.push_str("u8"),
50-
ty::Uint(ast::UintTy::U16) => output.push_str("u16"),
51-
ty::Uint(ast::UintTy::U32) => output.push_str("u32"),
52-
ty::Uint(ast::UintTy::U64) => output.push_str("u64"),
53-
ty::Uint(ast::UintTy::U128) => output.push_str("u128"),
54-
ty::Float(ast::FloatTy::F32) => output.push_str("f32"),
55-
ty::Float(ast::FloatTy::F64) => output.push_str("f64"),
41+
ty::Int(ty) => output.push_str(ty.name_str()),
42+
ty::Uint(ty) => output.push_str(ty.name_str()),
43+
ty::Float(ty) => output.push_str(ty.name_str()),
5644
ty::Adt(adt_def, substs) => {
5745
self.push_def_path(adt_def.did, output);
5846
self.push_generic_params(substs, iter::empty(), output, debug);

‎src/librustc/ty/print/pretty.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -466,9 +466,9 @@ pub trait PrettyPrinter<'tcx>:
466466
match ty.kind {
467467
ty::Bool => p!(write("bool")),
468468
ty::Char => p!(write("char")),
469-
ty::Int(t) => p!(write("{}", t.ty_to_string())),
470-
ty::Uint(t) => p!(write("{}", t.ty_to_string())),
471-
ty::Float(t) => p!(write("{}", t.ty_to_string())),
469+
ty::Int(t) => p!(write("{}", t.name_str())),
470+
ty::Uint(t) => p!(write("{}", t.name_str())),
471+
ty::Float(t) => p!(write("{}", t.name_str())),
472472
ty::RawPtr(ref tm) => {
473473
p!(write("*{} ", match tm.mutbl {
474474
hir::MutMutable => "mut",
@@ -895,10 +895,11 @@ pub trait PrettyPrinter<'tcx>:
895895
let bit_size = Integer::from_attr(&self.tcx(), UnsignedInt(*ui)).size();
896896
let max = truncate(u128::max_value(), bit_size);
897897

898+
let ui_str = ui.name_str();
898899
if data == max {
899-
p!(write("std::{}::MAX", ui))
900+
p!(write("std::{}::MAX", ui_str))
900901
} else {
901-
p!(write("{}{}", data, ui))
902+
p!(write("{}{}", data, ui_str))
902903
};
903904
},
904905
(ConstValue::Scalar(Scalar::Raw { data, .. }), ty::Int(i)) => {
@@ -911,10 +912,11 @@ pub trait PrettyPrinter<'tcx>:
911912
let size = self.tcx().layout_of(ty::ParamEnv::empty().and(ty))
912913
.unwrap()
913914
.size;
915+
let i_str = i.name_str();
914916
match data {
915-
d if d == min => p!(write("std::{}::MIN", i)),
916-
d if d == max => p!(write("std::{}::MAX", i)),
917-
_ => p!(write("{}{}", sign_extend(data, size) as i128, i))
917+
d if d == min => p!(write("std::{}::MIN", i_str)),
918+
d if d == max => p!(write("std::{}::MAX", i_str)),
919+
_ => p!(write("{}{}", sign_extend(data, size) as i128, i_str))
918920
}
919921
},
920922
(ConstValue::Scalar(Scalar::Raw { data, .. }), ty::Char) =>

‎src/librustc_codegen_llvm/debuginfo/metadata.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -843,13 +843,13 @@ fn basic_type_metadata(cx: &CodegenCx<'ll, 'tcx>, t: Ty<'tcx>) -> &'ll DIType {
843843
ty::Bool => ("bool", DW_ATE_boolean),
844844
ty::Char => ("char", DW_ATE_unsigned_char),
845845
ty::Int(int_ty) => {
846-
(int_ty.ty_to_string(), DW_ATE_signed)
846+
(int_ty.name_str(), DW_ATE_signed)
847847
},
848848
ty::Uint(uint_ty) => {
849-
(uint_ty.ty_to_string(), DW_ATE_unsigned)
849+
(uint_ty.name_str(), DW_ATE_unsigned)
850850
},
851851
ty::Float(float_ty) => {
852-
(float_ty.ty_to_string(), DW_ATE_float)
852+
(float_ty.name_str(), DW_ATE_float)
853853
},
854854
_ => bug!("debuginfo::basic_type_metadata - t is invalid type")
855855
};

‎src/librustc_codegen_llvm/intrinsic.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ use rustc::ty::layout::{self, LayoutOf, HasTyCtxt, Primitive};
1818
use rustc::mir::interpret::GlobalId;
1919
use rustc_codegen_ssa::common::{IntPredicate, TypeKind};
2020
use rustc::hir;
21-
use syntax::ast::{self, FloatTy};
22-
use rustc_target::abi::HasDataLayout;
21+
use rustc_target::abi::{FloatTy, HasDataLayout};
22+
use syntax::ast;
2323

2424
use rustc_codegen_ssa::common::span_invalid_monomorphization_error;
2525
use rustc_codegen_ssa::traits::*;
@@ -1335,7 +1335,7 @@ fn generic_simd_intrinsic(
13351335
},
13361336
ty::Float(f) => {
13371337
return_error!("unsupported element type `{}` of floating-point vector `{}`",
1338-
f, in_ty);
1338+
f.name_str(), in_ty);
13391339
},
13401340
_ => {
13411341
return_error!("`{}` is not a floating-point type", in_ty);

‎src/librustc_codegen_ssa/debuginfo/type_names.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ pub fn push_debuginfo_type_name<'tcx>(
3737
ty::Char => output.push_str("char"),
3838
ty::Str => output.push_str("str"),
3939
ty::Never => output.push_str("!"),
40-
ty::Int(int_ty) => output.push_str(int_ty.ty_to_string()),
41-
ty::Uint(uint_ty) => output.push_str(uint_ty.ty_to_string()),
42-
ty::Float(float_ty) => output.push_str(float_ty.ty_to_string()),
40+
ty::Int(int_ty) => output.push_str(int_ty.name_str()),
41+
ty::Uint(uint_ty) => output.push_str(uint_ty.name_str()),
42+
ty::Float(float_ty) => output.push_str(float_ty.name_str()),
4343
ty::Foreign(def_id) => push_item_name(tcx, def_id, qualified, output),
4444
ty::Adt(def, substs) => {
4545
push_item_name(tcx, def.did, qualified, output);

‎src/librustc_interface/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ rustc_codegen_utils = { path = "../librustc_codegen_utils" }
2727
rustc_metadata = { path = "../librustc_metadata" }
2828
rustc_mir = { path = "../librustc_mir" }
2929
rustc_passes = { path = "../librustc_passes" }
30-
rustc_target = { path = "../librustc_target" }
3130
rustc_typeck = { path = "../librustc_typeck" }
3231
rustc_lint = { path = "../librustc_lint" }
3332
rustc_errors = { path = "../librustc_errors" }
@@ -36,3 +35,6 @@ rustc_privacy = { path = "../librustc_privacy" }
3635
rustc_resolve = { path = "../librustc_resolve" }
3736
tempfile = "3.0.5"
3837
once_cell = "1"
38+
39+
[dev-dependencies]
40+
rustc_target = { path = "../librustc_target" }

‎src/librustc_lint/types.rs

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ fn lint_overflowing_range_endpoint<'a, 'tcx>(
6868
max: u128,
6969
expr: &'tcx hir::Expr,
7070
parent_expr: &'tcx hir::Expr,
71-
ty: impl std::fmt::Debug,
71+
ty: &str,
7272
) -> bool {
7373
// We only want to handle exclusive (`..`) ranges,
7474
// which are represented as `ExprKind::Struct`.
@@ -83,15 +83,15 @@ fn lint_overflowing_range_endpoint<'a, 'tcx>(
8383
let mut err = cx.struct_span_lint(
8484
OVERFLOWING_LITERALS,
8585
parent_expr.span,
86-
&format!("range endpoint is out of range for `{:?}`", ty),
86+
&format!("range endpoint is out of range for `{}`", ty),
8787
);
8888
if let Ok(start) = cx.sess().source_map().span_to_snippet(eps[0].span) {
8989
use ast::{LitKind, LitIntType};
9090
// We need to preserve the literal's suffix,
9191
// as it may determine typing information.
9292
let suffix = match lit.node {
93-
LitKind::Int(_, LitIntType::Signed(s)) => format!("{}", s),
94-
LitKind::Int(_, LitIntType::Unsigned(s)) => format!("{}", s),
93+
LitKind::Int(_, LitIntType::Signed(s)) => format!("{}", s.name_str()),
94+
LitKind::Int(_, LitIntType::Unsigned(s)) => format!("{}", s.name_str()),
9595
LitKind::Int(_, LitIntType::Unsuffixed) => "".to_owned(),
9696
_ => bug!(),
9797
};
@@ -161,11 +161,11 @@ fn report_bin_hex_error(
161161
let (t, actually) = match ty {
162162
attr::IntType::SignedInt(t) => {
163163
let actually = sign_extend(val, size) as i128;
164-
(format!("{:?}", t), actually.to_string())
164+
(t.name_str(), actually.to_string())
165165
}
166166
attr::IntType::UnsignedInt(t) => {
167167
let actually = truncate(val, size);
168-
(format!("{:?}", t), actually.to_string())
168+
(t.name_str(), actually.to_string())
169169
}
170170
};
171171
let mut err = cx.struct_span_lint(
@@ -204,7 +204,7 @@ fn report_bin_hex_error(
204204
// - `uX` => `uY`
205205
//
206206
// No suggestion for: `isize`, `usize`.
207-
fn get_type_suggestion(t: Ty<'_>, val: u128, negative: bool) -> Option<String> {
207+
fn get_type_suggestion(t: Ty<'_>, val: u128, negative: bool) -> Option<&'static str> {
208208
use syntax::ast::IntTy::*;
209209
use syntax::ast::UintTy::*;
210210
macro_rules! find_fit {
@@ -215,10 +215,10 @@ fn get_type_suggestion(t: Ty<'_>, val: u128, negative: bool) -> Option<String> {
215215
match $ty {
216216
$($type => {
217217
$(if !negative && val <= uint_ty_range($utypes).1 {
218-
return Some(format!("{:?}", $utypes))
218+
return Some($utypes.name_str())
219219
})*
220220
$(if val <= int_ty_range($itypes).1 as u128 + _neg {
221-
return Some(format!("{:?}", $itypes))
221+
return Some($itypes.name_str())
222222
})*
223223
None
224224
},)+
@@ -281,7 +281,7 @@ fn lint_int_literal<'a, 'tcx>(
281281
if let Node::Expr(par_e) = cx.tcx.hir().get(par_id) {
282282
if let hir::ExprKind::Struct(..) = par_e.kind {
283283
if is_range_literal(cx.sess(), par_e)
284-
&& lint_overflowing_range_endpoint(cx, lit, v, max, e, par_e, t)
284+
&& lint_overflowing_range_endpoint(cx, lit, v, max, e, par_e, t.name_str())
285285
{
286286
// The overflowing literal lint was overridden.
287287
return;
@@ -292,7 +292,7 @@ fn lint_int_literal<'a, 'tcx>(
292292
cx.span_lint(
293293
OVERFLOWING_LITERALS,
294294
e.span,
295-
&format!("literal out of range for `{:?}`", t),
295+
&format!("literal out of range for `{}`", t.name_str()),
296296
);
297297
}
298298
}
@@ -338,6 +338,7 @@ fn lint_uint_literal<'a, 'tcx>(
338338
}
339339
hir::ExprKind::Struct(..)
340340
if is_range_literal(cx.sess(), par_e) => {
341+
let t = t.name_str();
341342
if lint_overflowing_range_endpoint(cx, lit, lit_val, max, e, par_e, t) {
342343
// The overflowing literal lint was overridden.
343344
return;
@@ -353,7 +354,7 @@ fn lint_uint_literal<'a, 'tcx>(
353354
cx.span_lint(
354355
OVERFLOWING_LITERALS,
355356
e.span,
356-
&format!("literal out of range for `{:?}`", t),
357+
&format!("literal out of range for `{}`", t.name_str()),
357358
);
358359
}
359360
}
@@ -379,8 +380,7 @@ fn lint_literal<'a, 'tcx>(
379380
}
380381
ty::Float(t) => {
381382
let is_infinite = match lit.node {
382-
ast::LitKind::Float(v, _) |
383-
ast::LitKind::FloatUnsuffixed(v) => {
383+
ast::LitKind::Float(v, _) => {
384384
match t {
385385
ast::FloatTy::F32 => v.as_str().parse().map(f32::is_infinite),
386386
ast::FloatTy::F64 => v.as_str().parse().map(f64::is_infinite),
@@ -389,9 +389,11 @@ fn lint_literal<'a, 'tcx>(
389389
_ => bug!(),
390390
};
391391
if is_infinite == Ok(true) {
392-
cx.span_lint(OVERFLOWING_LITERALS,
393-
e.span,
394-
&format!("literal out of range for `{:?}`", t));
392+
cx.span_lint(
393+
OVERFLOWING_LITERALS,
394+
e.span,
395+
&format!("literal out of range for `{}`", t.name_str()),
396+
);
395397
}
396398
}
397399
_ => {}

‎src/librustc_mir/hair/constant.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,7 @@ crate fn lit_to_const<'tcx>(
4545
trunc(n as u128)?
4646
},
4747
LitKind::Int(n, _) => trunc(n)?,
48-
LitKind::Float(n, fty) => {
49-
parse_float(n, fty, neg).map_err(|_| LitToConstError::UnparseableFloat)?
50-
}
51-
LitKind::FloatUnsuffixed(n) => {
48+
LitKind::Float(n, _) => {
5249
let fty = match ty.kind {
5350
ty::Float(fty) => fty,
5451
_ => bug!()

‎src/librustc_save_analysis/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ log = "0.4"
1313
rustc = { path = "../librustc" }
1414
rustc_data_structures = { path = "../librustc_data_structures" }
1515
rustc_codegen_utils = { path = "../librustc_codegen_utils" }
16-
rustc_target = { path = "../librustc_target" }
1716
serde_json = "1"
1817
syntax = { path = "../libsyntax" }
1918
syntax_pos = { path = "../libsyntax_pos" }

‎src/librustc_target/abi/mod.rs

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@ pub use Primitive::*;
33

44
use crate::spec::Target;
55

6-
use std::fmt;
76
use std::ops::{Add, Deref, Sub, Mul, AddAssign, Range, RangeInclusive};
87

98
use rustc_index::vec::{Idx, IndexVec};
10-
use syntax_pos::symbol::{sym, Symbol};
119
use syntax_pos::Span;
1210

1311
pub mod call;
@@ -534,49 +532,13 @@ impl Integer {
534532
}
535533
}
536534

537-
538535
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Copy,
539-
PartialOrd, Ord)]
536+
PartialOrd, Ord, Debug)]
540537
pub enum FloatTy {
541538
F32,
542539
F64,
543540
}
544541

545-
impl fmt::Debug for FloatTy {
546-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
547-
fmt::Display::fmt(self, f)
548-
}
549-
}
550-
551-
impl fmt::Display for FloatTy {
552-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
553-
write!(f, "{}", self.ty_to_string())
554-
}
555-
}
556-
557-
impl FloatTy {
558-
pub fn ty_to_string(self) -> &'static str {
559-
match self {
560-
FloatTy::F32 => "f32",
561-
FloatTy::F64 => "f64",
562-
}
563-
}
564-
565-
pub fn to_symbol(self) -> Symbol {
566-
match self {
567-
FloatTy::F32 => sym::f32,
568-
FloatTy::F64 => sym::f64,
569-
}
570-
}
571-
572-
pub fn bit_width(self) -> usize {
573-
match self {
574-
FloatTy::F32 => 32,
575-
FloatTy::F64 => 64,
576-
}
577-
}
578-
}
579-
580542
/// Fundamental unit of memory access and layout.
581543
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
582544
pub enum Primitive {

‎src/librustc_typeck/check/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3660,8 +3660,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
36603660
});
36613661
opt_ty.unwrap_or_else(|| self.next_int_var())
36623662
}
3663-
ast::LitKind::Float(_, t) => tcx.mk_mach_float(t),
3664-
ast::LitKind::FloatUnsuffixed(_) => {
3663+
ast::LitKind::Float(_, ast::LitFloatType::Suffixed(t)) => tcx.mk_mach_float(t),
3664+
ast::LitKind::Float(_, ast::LitFloatType::Unsuffixed) => {
36653665
let opt_ty = expected.to_option(self).and_then(|ty| {
36663666
match ty.kind {
36673667
ty::Float(_) => Some(ty),

‎src/libsyntax/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,4 @@ errors = { path = "../librustc_errors", package = "rustc_errors" }
2020
rustc_data_structures = { path = "../librustc_data_structures" }
2121
rustc_index = { path = "../librustc_index" }
2222
rustc_lexer = { path = "../librustc_lexer" }
23-
rustc_target = { path = "../librustc_target" }
2423
smallvec = { version = "1.0", features = ["union", "may_dangle"] }

‎src/libsyntax/ast.rs

Lines changed: 51 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ pub use GenericArgs::*;
2222
pub use UnsafeSource::*;
2323
pub use crate::util::parser::ExprPrecedence;
2424

25-
pub use rustc_target::abi::FloatTy;
2625
pub use syntax_pos::symbol::{Ident, Symbol as Name};
2726

2827
use crate::parse::token::{self, DelimToken};
@@ -1400,7 +1399,7 @@ pub struct Lit {
14001399

14011400
// Clippy uses Hash and PartialEq
14021401
/// Type of the integer literal based on provided suffix.
1403-
#[derive(Clone, RustcEncodable, RustcDecodable, Debug, Copy, Hash, PartialEq)]
1402+
#[derive(Clone, Copy, RustcEncodable, RustcDecodable, Debug, Hash, PartialEq)]
14041403
pub enum LitIntType {
14051404
/// e.g. `42_i32`.
14061405
Signed(IntTy),
@@ -1410,6 +1409,15 @@ pub enum LitIntType {
14101409
Unsuffixed,
14111410
}
14121411

1412+
/// Type of the float literal based on provided suffix.
1413+
#[derive(Clone, Copy, RustcEncodable, RustcDecodable, Debug, Hash, PartialEq)]
1414+
pub enum LitFloatType {
1415+
/// A float literal with a suffix (`1f32` or `1E10f32`).
1416+
Suffixed(FloatTy),
1417+
/// A float literal without a suffix (`1.0 or 1.0E10`).
1418+
Unsuffixed,
1419+
}
1420+
14131421
/// Literal kind.
14141422
///
14151423
/// E.g., `"foo"`, `42`, `12.34`, or `bool`.
@@ -1427,9 +1435,7 @@ pub enum LitKind {
14271435
/// An integer literal (`1`).
14281436
Int(u128, LitIntType),
14291437
/// A float literal (`1f64` or `1E10f64`).
1430-
Float(Symbol, FloatTy),
1431-
/// A float literal without a suffix (`1.0 or 1.0E10`).
1432-
FloatUnsuffixed(Symbol),
1438+
Float(Symbol, LitFloatType),
14331439
/// A boolean literal.
14341440
Bool(bool),
14351441
/// Placeholder for a literal that wasn't well-formed in some way.
@@ -1456,7 +1462,7 @@ impl LitKind {
14561462
/// Returns `true` if this is a numeric literal.
14571463
pub fn is_numeric(&self) -> bool {
14581464
match *self {
1459-
LitKind::Int(..) | LitKind::Float(..) | LitKind::FloatUnsuffixed(..) => true,
1465+
LitKind::Int(..) | LitKind::Float(..) => true,
14601466
_ => false,
14611467
}
14621468
}
@@ -1473,14 +1479,14 @@ impl LitKind {
14731479
// suffixed variants
14741480
LitKind::Int(_, LitIntType::Signed(..))
14751481
| LitKind::Int(_, LitIntType::Unsigned(..))
1476-
| LitKind::Float(..) => true,
1482+
| LitKind::Float(_, LitFloatType::Suffixed(..)) => true,
14771483
// unsuffixed variants
14781484
LitKind::Str(..)
14791485
| LitKind::ByteStr(..)
14801486
| LitKind::Byte(..)
14811487
| LitKind::Char(..)
14821488
| LitKind::Int(_, LitIntType::Unsuffixed)
1483-
| LitKind::FloatUnsuffixed(..)
1489+
| LitKind::Float(_, LitFloatType::Unsuffixed)
14841490
| LitKind::Bool(..)
14851491
| LitKind::Err(..) => false,
14861492
}
@@ -1552,7 +1558,36 @@ pub enum ImplItemKind {
15521558
Macro(Mac),
15531559
}
15541560

1555-
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable, Copy)]
1561+
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable, Debug)]
1562+
pub enum FloatTy {
1563+
F32,
1564+
F64,
1565+
}
1566+
1567+
impl FloatTy {
1568+
pub fn name_str(self) -> &'static str {
1569+
match self {
1570+
FloatTy::F32 => "f32",
1571+
FloatTy::F64 => "f64",
1572+
}
1573+
}
1574+
1575+
pub fn name(self) -> Symbol {
1576+
match self {
1577+
FloatTy::F32 => sym::f32,
1578+
FloatTy::F64 => sym::f64,
1579+
}
1580+
}
1581+
1582+
pub fn bit_width(self) -> usize {
1583+
match self {
1584+
FloatTy::F32 => 32,
1585+
FloatTy::F64 => 64,
1586+
}
1587+
}
1588+
}
1589+
1590+
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable, Debug)]
15561591
pub enum IntTy {
15571592
Isize,
15581593
I8,
@@ -1562,20 +1597,8 @@ pub enum IntTy {
15621597
I128,
15631598
}
15641599

1565-
impl fmt::Debug for IntTy {
1566-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1567-
fmt::Display::fmt(self, f)
1568-
}
1569-
}
1570-
1571-
impl fmt::Display for IntTy {
1572-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1573-
write!(f, "{}", self.ty_to_string())
1574-
}
1575-
}
1576-
15771600
impl IntTy {
1578-
pub fn ty_to_string(&self) -> &'static str {
1601+
pub fn name_str(&self) -> &'static str {
15791602
match *self {
15801603
IntTy::Isize => "isize",
15811604
IntTy::I8 => "i8",
@@ -1586,7 +1609,7 @@ impl IntTy {
15861609
}
15871610
}
15881611

1589-
pub fn to_symbol(&self) -> Symbol {
1612+
pub fn name(&self) -> Symbol {
15901613
match *self {
15911614
IntTy::Isize => sym::isize,
15921615
IntTy::I8 => sym::i8,
@@ -1601,7 +1624,7 @@ impl IntTy {
16011624
// Cast to a `u128` so we can correctly print `INT128_MIN`. All integral types
16021625
// are parsed as `u128`, so we wouldn't want to print an extra negative
16031626
// sign.
1604-
format!("{}{}", val as u128, self.ty_to_string())
1627+
format!("{}{}", val as u128, self.name_str())
16051628
}
16061629

16071630
pub fn bit_width(&self) -> Option<usize> {
@@ -1616,7 +1639,7 @@ impl IntTy {
16161639
}
16171640
}
16181641

1619-
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable, Copy)]
1642+
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable, Copy, Debug)]
16201643
pub enum UintTy {
16211644
Usize,
16221645
U8,
@@ -1627,7 +1650,7 @@ pub enum UintTy {
16271650
}
16281651

16291652
impl UintTy {
1630-
pub fn ty_to_string(&self) -> &'static str {
1653+
pub fn name_str(&self) -> &'static str {
16311654
match *self {
16321655
UintTy::Usize => "usize",
16331656
UintTy::U8 => "u8",
@@ -1638,7 +1661,7 @@ impl UintTy {
16381661
}
16391662
}
16401663

1641-
pub fn to_symbol(&self) -> Symbol {
1664+
pub fn name(&self) -> Symbol {
16421665
match *self {
16431666
UintTy::Usize => sym::usize,
16441667
UintTy::U8 => sym::u8,
@@ -1650,7 +1673,7 @@ impl UintTy {
16501673
}
16511674

16521675
pub fn val_to_string(&self, val: u128) -> String {
1653-
format!("{}{}", val, self.ty_to_string())
1676+
format!("{}{}", val, self.name_str())
16541677
}
16551678

16561679
pub fn bit_width(&self) -> Option<usize> {
@@ -1665,18 +1688,6 @@ impl UintTy {
16651688
}
16661689
}
16671690

1668-
impl fmt::Debug for UintTy {
1669-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1670-
fmt::Display::fmt(self, f)
1671-
}
1672-
}
1673-
1674-
impl fmt::Display for UintTy {
1675-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1676-
write!(f, "{}", self.ty_to_string())
1677-
}
1678-
}
1679-
16801691
/// A constraint on an associated type (e.g., `A = Bar` in `Foo<A = Bar>` or
16811692
/// `A: TraitA + TraitB` in `Foo<A: TraitA + TraitB>`).
16821693
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]

‎src/libsyntax/parse/literal.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -157,17 +157,18 @@ impl LitKind {
157157
}
158158
LitKind::Int(n, ty) => {
159159
let suffix = match ty {
160-
ast::LitIntType::Unsigned(ty) => Some(ty.to_symbol()),
161-
ast::LitIntType::Signed(ty) => Some(ty.to_symbol()),
160+
ast::LitIntType::Unsigned(ty) => Some(ty.name()),
161+
ast::LitIntType::Signed(ty) => Some(ty.name()),
162162
ast::LitIntType::Unsuffixed => None,
163163
};
164164
(token::Integer, sym::integer(n), suffix)
165165
}
166166
LitKind::Float(symbol, ty) => {
167-
(token::Float, symbol, Some(ty.to_symbol()))
168-
}
169-
LitKind::FloatUnsuffixed(symbol) => {
170-
(token::Float, symbol, None)
167+
let suffix = match ty {
168+
ast::LitFloatType::Suffixed(ty) => Some(ty.name()),
169+
ast::LitFloatType::Unsuffixed => None,
170+
};
171+
(token::Float, symbol, suffix)
171172
}
172173
LitKind::Bool(value) => {
173174
let symbol = if value { kw::True } else { kw::False };
@@ -244,12 +245,12 @@ fn filtered_float_lit(symbol: Symbol, suffix: Option<Symbol>, base: u32)
244245
return Err(LitError::NonDecimalFloat(base));
245246
}
246247
Ok(match suffix {
247-
Some(suf) => match suf {
248-
sym::f32 => LitKind::Float(symbol, ast::FloatTy::F32),
249-
sym::f64 => LitKind::Float(symbol, ast::FloatTy::F64),
248+
Some(suf) => LitKind::Float(symbol, ast::LitFloatType::Suffixed(match suf {
249+
sym::f32 => ast::FloatTy::F32,
250+
sym::f64 => ast::FloatTy::F64,
250251
_ => return Err(LitError::InvalidFloatSuffix),
251-
}
252-
None => LitKind::FloatUnsuffixed(symbol)
252+
})),
253+
None => LitKind::Float(symbol, ast::LitFloatType::Unsuffixed)
253254
})
254255
}
255256

‎src/libsyntax_expand/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,5 @@ errors = { path = "../librustc_errors", package = "rustc_errors" }
2121
rustc_data_structures = { path = "../librustc_data_structures" }
2222
rustc_index = { path = "../librustc_index" }
2323
rustc_lexer = { path = "../librustc_lexer" }
24-
rustc_target = { path = "../librustc_target" }
2524
smallvec = { version = "1.0", features = ["union", "may_dangle"] }
2625
syntax = { path = "../libsyntax" }

‎src/libsyntax_ext/concat.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ pub fn expand_concat(
2121
match e.kind {
2222
ast::ExprKind::Lit(ref lit) => match lit.kind {
2323
ast::LitKind::Str(ref s, _)
24-
| ast::LitKind::Float(ref s, _)
25-
| ast::LitKind::FloatUnsuffixed(ref s) => {
24+
| ast::LitKind::Float(ref s, _) => {
2625
accumulator.push_str(&s.as_str());
2726
}
2827
ast::LitKind::Char(c) => {

0 commit comments

Comments
 (0)
Please sign in to comment.