summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_type_ir/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/rustc_type_ir/src/lib.rs')
-rw-r--r--compiler/rustc_type_ir/src/lib.rs24
1 files changed, 23 insertions, 1 deletions
diff --git a/compiler/rustc_type_ir/src/lib.rs b/compiler/rustc_type_ir/src/lib.rs
index 5a991e03d..a3c98ae00 100644
--- a/compiler/rustc_type_ir/src/lib.rs
+++ b/compiler/rustc_type_ir/src/lib.rs
@@ -83,7 +83,7 @@ pub trait CollectAndApply<T, R>: Sized {
/// Produce a result of type `Self::Output` from `iter`. The result will
/// typically be produced by applying `f` on the elements produced by
/// `iter`, though this may not happen in some impls, e.g. if an error
- /// occured during iteration.
+ /// occurred during iteration.
fn collect_and_apply<I, F>(iter: I, f: F) -> Self::Output
where
I: Iterator<Item = Self>,
@@ -432,6 +432,17 @@ impl IntTy {
_ => *self,
}
}
+
+ pub fn to_unsigned(self) -> UintTy {
+ match self {
+ IntTy::Isize => UintTy::Usize,
+ IntTy::I8 => UintTy::U8,
+ IntTy::I16 => UintTy::U16,
+ IntTy::I32 => UintTy::U32,
+ IntTy::I64 => UintTy::U64,
+ IntTy::I128 => UintTy::U128,
+ }
+ }
}
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Copy, Debug)]
@@ -479,6 +490,17 @@ impl UintTy {
_ => *self,
}
}
+
+ pub fn to_signed(self) -> IntTy {
+ match self {
+ UintTy::Usize => IntTy::Isize,
+ UintTy::U8 => IntTy::I8,
+ UintTy::U16 => IntTy::I16,
+ UintTy::U32 => IntTy::I32,
+ UintTy::U64 => IntTy::I64,
+ UintTy::U128 => IntTy::I128,
+ }
+ }
}
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]