Skip to content
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

is_fp and is_floating_point do the same thing, remove the former #61688

Merged
merged 1 commit into from
Jun 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 31 additions & 8 deletions src/librustc/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1665,13 +1665,15 @@ impl RegionKind {

/// Type utilities
impl<'a, 'gcx, 'tcx> TyS<'tcx> {
#[inline]
pub fn is_unit(&self) -> bool {
match self.sty {
Tuple(ref tys) => tys.is_empty(),
_ => false,
}
}

#[inline]
pub fn is_never(&self) -> bool {
match self.sty {
Never => true,
Expand Down Expand Up @@ -1726,6 +1728,7 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> {
}
}

#[inline]
pub fn is_primitive(&self) -> bool {
match self.sty {
Bool | Char | Int(_) | Uint(_) | Float(_) => true,
Expand All @@ -1741,13 +1744,15 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> {
}
}

#[inline]
pub fn is_ty_infer(&self) -> bool {
match self.sty {
Infer(_) => true,
_ => false,
}
}

#[inline]
pub fn is_phantom_data(&self) -> bool {
if let Adt(def, _) = self.sty {
def.is_phantom_data()
Expand All @@ -1756,22 +1761,26 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> {
}
}

#[inline]
pub fn is_bool(&self) -> bool { self.sty == Bool }

#[inline]
pub fn is_param(&self, index: u32) -> bool {
match self.sty {
ty::Param(ref data) => data.index == index,
_ => false,
}
}

#[inline]
pub fn is_self(&self) -> bool {
match self.sty {
Param(ref p) => p.is_self(),
_ => false,
}
}

#[inline]
pub fn is_slice(&self) -> bool {
match self.sty {
RawPtr(TypeAndMut { ty, .. }) | Ref(_, ty, _) => match ty.sty {
Expand Down Expand Up @@ -1814,13 +1823,15 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> {
}
}

#[inline]
pub fn is_region_ptr(&self) -> bool {
match self.sty {
Ref(..) => true,
_ => false,
}
}

#[inline]
pub fn is_mutable_pointer(&self) -> bool {
match self.sty {
RawPtr(TypeAndMut { mutbl: hir::Mutability::MutMutable, .. }) |
Expand All @@ -1829,6 +1840,7 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> {
}
}

#[inline]
pub fn is_unsafe_ptr(&self) -> bool {
match self.sty {
RawPtr(_) => return true,
Expand All @@ -1837,6 +1849,7 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> {
}

/// Returns `true` if this type is an `Arc<T>`.
#[inline]
pub fn is_arc(&self) -> bool {
match self.sty {
Adt(def, _) => def.is_arc(),
Expand All @@ -1845,13 +1858,15 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> {
}

/// Returns `true` if this type is an `Rc<T>`.
#[inline]
pub fn is_rc(&self) -> bool {
match self.sty {
Adt(def, _) => def.is_rc(),
_ => false,
}
}

#[inline]
pub fn is_box(&self) -> bool {
match self.sty {
Adt(def, _) => def.is_box(),
Expand All @@ -1870,6 +1885,7 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> {
/// A scalar type is one that denotes an atomic datum, with no sub-components.
/// (A RawPtr is scalar because it represents a non-managed pointer, so its
/// contents are abstract to rustc.)
#[inline]
pub fn is_scalar(&self) -> bool {
match self.sty {
Bool | Char | Int(_) | Float(_) | Uint(_) |
Expand All @@ -1880,6 +1896,7 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> {
}

/// Returns `true` if this type is a floating point type.
#[inline]
pub fn is_floating_point(&self) -> bool {
match self.sty {
Float(_) |
Expand All @@ -1888,13 +1905,15 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> {
}
}

#[inline]
pub fn is_trait(&self) -> bool {
match self.sty {
Dynamic(..) => true,
_ => false,
}
}

#[inline]
pub fn is_enum(&self) -> bool {
match self.sty {
Adt(adt_def, _) => {
Expand All @@ -1904,13 +1923,15 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> {
}
}

#[inline]
pub fn is_closure(&self) -> bool {
match self.sty {
Closure(..) => true,
_ => false,
}
}

#[inline]
pub fn is_generator(&self) -> bool {
match self.sty {
Generator(..) => true,
Expand All @@ -1926,13 +1947,15 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> {
}
}

#[inline]
pub fn is_fresh_ty(&self) -> bool {
match self.sty {
Infer(FreshTy(_)) => true,
_ => false,
}
}

#[inline]
pub fn is_fresh(&self) -> bool {
match self.sty {
Infer(FreshTy(_)) => true,
Expand All @@ -1942,6 +1965,7 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> {
}
}

#[inline]
pub fn is_char(&self) -> bool {
match self.sty {
Char => true,
Expand All @@ -1950,38 +1974,35 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> {
}

#[inline]
pub fn is_fp(&self) -> bool {
match self.sty {
Infer(FloatVar(_)) | Float(_) => true,
_ => false
}
}

pub fn is_numeric(&self) -> bool {
self.is_integral() || self.is_fp()
self.is_integral() || self.is_floating_point()
}

#[inline]
pub fn is_signed(&self) -> bool {
match self.sty {
Int(_) => true,
_ => false,
}
}

#[inline]
pub fn is_pointer_sized(&self) -> bool {
match self.sty {
Int(ast::IntTy::Isize) | Uint(ast::UintTy::Usize) => true,
_ => false,
}
}

#[inline]
pub fn is_machine(&self) -> bool {
match self.sty {
Int(..) | Uint(..) | Float(..) => true,
_ => false,
}
}

#[inline]
pub fn has_concrete_skeleton(&self) -> bool {
match self.sty {
Param(_) | Infer(_) | Error => false,
Expand Down Expand Up @@ -2028,6 +2049,7 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> {
}
}

#[inline]
pub fn is_fn(&self) -> bool {
match self.sty {
FnDef(..) | FnPtr(_) => true,
Expand All @@ -2043,6 +2065,7 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> {
}
}

#[inline]
pub fn is_impl_trait(&self) -> bool {
match self.sty {
Opaque(..) => true,
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_codegen_ssa/mir/rvalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
mir::Rvalue::UnaryOp(op, ref operand) => {
let operand = self.codegen_operand(&mut bx, operand);
let lloperand = operand.immediate();
let is_float = operand.layout.ty.is_fp();
let is_float = operand.layout.ty.is_floating_point();
let llval = match op {
mir::UnOp::Not => bx.not(lloperand),
mir::UnOp::Neg => if is_float {
Expand Down Expand Up @@ -536,7 +536,7 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
rhs: Bx::Value,
input_ty: Ty<'tcx>,
) -> Bx::Value {
let is_float = input_ty.is_fp();
let is_float = input_ty.is_floating_point();
let is_signed = input_ty.is_signed();
let is_unit = input_ty.is_unit();
match op {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4089,7 +4089,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
hir::UnNeg => {
let result = self.check_user_unop(expr, oprnd_t, unop);
// If it's builtin, we can reuse the type, this helps inference.
if !(oprnd_t.is_integral() || oprnd_t.is_fp()) {
if !oprnd_t.is_numeric() {
oprnd_t = result;
}
}
Expand Down