about summary refs log tree commit diff
path: root/compiler/rustc_middle/src/ty/sty.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2025-01-09 05:21:43 +0000
committerbors <bors@rust-lang.org>2025-01-09 05:21:43 +0000
commit65d7296fc9868af121adb5e07358a3815a80a7a1 (patch)
tree8f8d05107e4da71372ddb2a8af2bca9a3591e562 /compiler/rustc_middle/src/ty/sty.rs
parente26ff2f9086fc449b963df578f8641c31846abe6 (diff)
parentafbd73559ff5505fbb349b2845eb1b823b44c049 (diff)
downloadrust-65d7296fc9868af121adb5e07358a3815a80a7a1.tar.gz
rust-65d7296fc9868af121adb5e07358a3815a80a7a1.zip
Auto merge of #135277 - matthiaskrgr:rollup-0k61sf8, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #128110 (Suggest Replacing Comma with Semicolon in Incorrect Repeat Expressions)
 - #134609 (Add new `{x86_64,i686}-win7-windows-gnu` targets)
 - #134875 (Implement `const Destruct` in old solver)
 - #135221 (Include rustc and rustdoc book in replace-version-placeholder)
 - #135231 (bootstrap: Add more comments to some of the test steps)
 - #135256 (Move `mod cargo`  below the import statements)

Failed merges:

 - #135195 (Make `lit_to_mir_constant` and `lit_to_const` infallible)

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_middle/src/ty/sty.rs')
-rw-r--r--compiler/rustc_middle/src/ty/sty.rs14
1 files changed, 13 insertions, 1 deletions
diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs
index 92b3632c8ac..2980964898c 100644
--- a/compiler/rustc_middle/src/ty/sty.rs
+++ b/compiler/rustc_middle/src/ty/sty.rs
@@ -27,7 +27,7 @@ use crate::infer::canonical::Canonical;
 use crate::ty::InferTy::*;
 use crate::ty::{
     self, AdtDef, BoundRegionKind, Discr, GenericArg, GenericArgs, GenericArgsRef, List, ParamEnv,
-    Region, Ty, TyCtxt, TypeFlags, TypeSuperVisitable, TypeVisitable, TypeVisitor,
+    Region, Ty, TyCtxt, TypeFlags, TypeSuperVisitable, TypeVisitable, TypeVisitor, UintTy,
 };
 
 // Re-export and re-parameterize some `I = TyCtxt<'tcx>` types here
@@ -1017,6 +1017,18 @@ impl<'tcx> Ty<'tcx> {
         }
     }
 
+    /// Check if type is an `usize`.
+    #[inline]
+    pub fn is_usize(self) -> bool {
+        matches!(self.kind(), Uint(UintTy::Usize))
+    }
+
+    /// Check if type is an `usize` or an integral type variable.
+    #[inline]
+    pub fn is_usize_like(self) -> bool {
+        matches!(self.kind(), Uint(UintTy::Usize) | Infer(IntVar(_)))
+    }
+
     #[inline]
     pub fn is_never(self) -> bool {
         matches!(self.kind(), Never)