-
Notifications
You must be signed in to change notification settings - Fork 1.8k
fix f16/f128 lints #14956
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix f16/f128 lints #14956
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,55 @@ | ||
| use clippy_utils::ty::{EnumValue, read_explicit_enum_value}; | ||
| use rustc_middle::ty::{self, AdtDef, IntTy, Ty, TyCtxt, UintTy, VariantDiscr}; | ||
| use rustc_middle::ty::{self, AdtDef, FloatTy, IntTy, Ty, TyCtxt, UintTy, VariantDiscr}; | ||
|
|
||
| /// Returns the size in bits of an integral type, or `None` if `ty` is not an | ||
| /// integral type. | ||
| pub(super) fn int_ty_to_nbits(tcx: TyCtxt<'_>, ty: Ty<'_>) -> Option<u64> { | ||
| match ty.kind() { | ||
| ty::Int(IntTy::Isize) | ty::Uint(UintTy::Usize) => Some(tcx.data_layout.pointer_size.bits()), | ||
| ty::Int(i) => i.bit_width(), | ||
| ty::Uint(i) => i.bit_width(), | ||
| _ => None, | ||
| /// Returns the size in bits of an integral type. | ||
| /// Panics if the type is not an int or uint variant | ||
| pub(super) fn int_ty_to_nbits(typ: Ty<'_>, tcx: TyCtxt<'_>) -> u64 { | ||
| match typ.kind() { | ||
| ty::Int(i) => match i { | ||
| IntTy::Isize => tcx.data_layout.pointer_size.bits(), | ||
| IntTy::I8 => 8, | ||
| IntTy::I16 => 16, | ||
| IntTy::I32 => 32, | ||
| IntTy::I64 => 64, | ||
| IntTy::I128 => 128, | ||
| }, | ||
| ty::Uint(i) => match i { | ||
| UintTy::Usize => tcx.data_layout.pointer_size.bits(), | ||
| UintTy::U8 => 8, | ||
| UintTy::U16 => 16, | ||
| UintTy::U32 => 32, | ||
| UintTy::U64 => 64, | ||
| UintTy::U128 => 128, | ||
| }, | ||
| _ => unreachable!(), | ||
| } | ||
| } | ||
|
Comment on lines
+6
to
+26
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are reverting (here and at other places) changes that were committed yesterday. Please don't do that. And please explain what your PR is doing, what it fixes, why it is necessary, and when you change existing things why your solution is better than the one in place. For example, why would panicking (through There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to your approach, how can we make use of int_ty_to_nbits, float_ty_to_nbits, and float_ty_to_mantissa_nbits at the same time? Should all three return Option, and then handle the None cases externally? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know what you're trying to achieve, so this is a difficult question to answer. |
||
|
|
||
| /// Returns the size in bits of an floating type. | ||
| /// Panics if the type is not an float variant | ||
| pub(super) fn float_ty_to_nbits(typ: Ty<'_>) -> u64 { | ||
| match typ.kind() { | ||
| ty::Float(i) => match i { | ||
| FloatTy::F16 => 16, | ||
| FloatTy::F32 => 32, | ||
| FloatTy::F64 => 64, | ||
| FloatTy::F128 => 128, | ||
| }, | ||
| _ => unreachable!(), | ||
| } | ||
| } | ||
|
|
||
| /// Returns the mantissa size in bits of an floating type. | ||
| /// Panics if the type is not an float variant | ||
| pub(super) fn float_ty_to_mantissa_nbits(typ: Ty<'_>) -> u64 { | ||
| match typ.kind() { | ||
| ty::Float(i) => match i { | ||
| FloatTy::F16 => 10, | ||
| FloatTy::F32 => 23, | ||
| FloatTy::F64 => 52, | ||
| FloatTy::F128 => 112, | ||
| }, | ||
| _ => unreachable!(), | ||
| } | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ty::Infer(InferTy::FloatVar(_)) => 52should be unnecessary, is that right?