Skip to content

Commit 6968754

Browse files
authored
Rollup merge of rust-lang#61688 - RalfJung:is-floating-point, r=cramertj
is_fp and is_floating_point do the same thing, remove the former also consistently mark all these `is_*` methods for inlining
2 parents 2bb4820 + 5b54a78 commit 6968754

File tree

3 files changed

+34
-11
lines changed

3 files changed

+34
-11
lines changed

src/librustc/ty/sty.rs

+31-8
Original file line numberDiff line numberDiff line change
@@ -1665,13 +1665,15 @@ impl RegionKind {
16651665

16661666
/// Type utilities
16671667
impl<'a, 'gcx, 'tcx> TyS<'tcx> {
1668+
#[inline]
16681669
pub fn is_unit(&self) -> bool {
16691670
match self.sty {
16701671
Tuple(ref tys) => tys.is_empty(),
16711672
_ => false,
16721673
}
16731674
}
16741675

1676+
#[inline]
16751677
pub fn is_never(&self) -> bool {
16761678
match self.sty {
16771679
Never => true,
@@ -1726,6 +1728,7 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> {
17261728
}
17271729
}
17281730

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

1747+
#[inline]
17441748
pub fn is_ty_infer(&self) -> bool {
17451749
match self.sty {
17461750
Infer(_) => true,
17471751
_ => false,
17481752
}
17491753
}
17501754

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

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

1767+
#[inline]
17611768
pub fn is_param(&self, index: u32) -> bool {
17621769
match self.sty {
17631770
ty::Param(ref data) => data.index == index,
17641771
_ => false,
17651772
}
17661773
}
17671774

1775+
#[inline]
17681776
pub fn is_self(&self) -> bool {
17691777
match self.sty {
17701778
Param(ref p) => p.is_self(),
17711779
_ => false,
17721780
}
17731781
}
17741782

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

1826+
#[inline]
18171827
pub fn is_region_ptr(&self) -> bool {
18181828
match self.sty {
18191829
Ref(..) => true,
18201830
_ => false,
18211831
}
18221832
}
18231833

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

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

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

18471860
/// Returns `true` if this type is an `Rc<T>`.
1861+
#[inline]
18481862
pub fn is_rc(&self) -> bool {
18491863
match self.sty {
18501864
Adt(def, _) => def.is_rc(),
18511865
_ => false,
18521866
}
18531867
}
18541868

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

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

1908+
#[inline]
18911909
pub fn is_trait(&self) -> bool {
18921910
match self.sty {
18931911
Dynamic(..) => true,
18941912
_ => false,
18951913
}
18961914
}
18971915

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

1926+
#[inline]
19071927
pub fn is_closure(&self) -> bool {
19081928
match self.sty {
19091929
Closure(..) => true,
19101930
_ => false,
19111931
}
19121932
}
19131933

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

1950+
#[inline]
19291951
pub fn is_fresh_ty(&self) -> bool {
19301952
match self.sty {
19311953
Infer(FreshTy(_)) => true,
19321954
_ => false,
19331955
}
19341956
}
19351957

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

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

19521976
#[inline]
1953-
pub fn is_fp(&self) -> bool {
1954-
match self.sty {
1955-
Infer(FloatVar(_)) | Float(_) => true,
1956-
_ => false
1957-
}
1958-
}
1959-
19601977
pub fn is_numeric(&self) -> bool {
1961-
self.is_integral() || self.is_fp()
1978+
self.is_integral() || self.is_floating_point()
19621979
}
19631980

1981+
#[inline]
19641982
pub fn is_signed(&self) -> bool {
19651983
match self.sty {
19661984
Int(_) => true,
19671985
_ => false,
19681986
}
19691987
}
19701988

1989+
#[inline]
19711990
pub fn is_pointer_sized(&self) -> bool {
19721991
match self.sty {
19731992
Int(ast::IntTy::Isize) | Uint(ast::UintTy::Usize) => true,
19741993
_ => false,
19751994
}
19761995
}
19771996

1997+
#[inline]
19781998
pub fn is_machine(&self) -> bool {
19791999
match self.sty {
19802000
Int(..) | Uint(..) | Float(..) => true,
19812001
_ => false,
19822002
}
19832003
}
19842004

2005+
#[inline]
19852006
pub fn has_concrete_skeleton(&self) -> bool {
19862007
match self.sty {
19872008
Param(_) | Infer(_) | Error => false,
@@ -2028,13 +2049,15 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> {
20282049
}
20292050
}
20302051

2052+
#[inline]
20312053
pub fn is_fn(&self) -> bool {
20322054
match self.sty {
20332055
FnDef(..) | FnPtr(_) => true,
20342056
_ => false,
20352057
}
20362058
}
20372059

2060+
#[inline]
20382061
pub fn is_impl_trait(&self) -> bool {
20392062
match self.sty {
20402063
Opaque(..) => true,

src/librustc_codegen_ssa/mir/rvalue.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
429429
mir::Rvalue::UnaryOp(op, ref operand) => {
430430
let operand = self.codegen_operand(&mut bx, operand);
431431
let lloperand = operand.immediate();
432-
let is_float = operand.layout.ty.is_fp();
432+
let is_float = operand.layout.ty.is_floating_point();
433433
let llval = match op {
434434
mir::UnOp::Not => bx.not(lloperand),
435435
mir::UnOp::Neg => if is_float {
@@ -536,7 +536,7 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
536536
rhs: Bx::Value,
537537
input_ty: Ty<'tcx>,
538538
) -> Bx::Value {
539-
let is_float = input_ty.is_fp();
539+
let is_float = input_ty.is_floating_point();
540540
let is_signed = input_ty.is_signed();
541541
let is_unit = input_ty.is_unit();
542542
match op {

src/librustc_typeck/check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4045,7 +4045,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
40454045
hir::UnNeg => {
40464046
let result = self.check_user_unop(expr, oprnd_t, unop);
40474047
// If it's builtin, we can reuse the type, this helps inference.
4048-
if !(oprnd_t.is_integral() || oprnd_t.is_fp()) {
4048+
if !oprnd_t.is_numeric() {
40494049
oprnd_t = result;
40504050
}
40514051
}

0 commit comments

Comments
 (0)