diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2025-01-09 06:02:39 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-01-09 06:02:39 +0100 |
| commit | e4e2d9ceb8f3ea9130e5597fa789bb6d8fe89cdc (patch) | |
| tree | 42407771dcd7e2500013d64937ea414ccc9598ba /compiler/rustc_middle/src/ty | |
| parent | e26ff2f9086fc449b963df578f8641c31846abe6 (diff) | |
| parent | 98cc3457af5655f289dd7a9de0ff8433697ea105 (diff) | |
| download | rust-e4e2d9ceb8f3ea9130e5597fa789bb6d8fe89cdc.tar.gz rust-e4e2d9ceb8f3ea9130e5597fa789bb6d8fe89cdc.zip | |
Rollup merge of #128110 - veera-sivarajan:bugfix-80173, r=cjgillot
Suggest Replacing Comma with Semicolon in Incorrect Repeat Expressions Fixes #80173 This PR detects typos in repeat expressions like `["_", 10]` and `vec![String::new(), 10]` and suggests replacing comma with semicolon. Also, improves code in other place by adding doc comments and making use of a helper function to check if a type implements `Clone`. References: 1. For `vec![T; N]`: https://doc.rust-lang.org/std/macro.vec.html 2. For `[T; N]`: https://doc.rust-lang.org/std/primitive.array.html
Diffstat (limited to 'compiler/rustc_middle/src/ty')
| -rw-r--r-- | compiler/rustc_middle/src/ty/sty.rs | 14 |
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) |
