about summary refs log tree commit diff
path: root/compiler/rustc_ast/src/ast.rs
diff options
context:
space:
mode:
authorEll <ahunpochoevjamshed@gmail.com>2025-05-30 10:57:08 +0300
committerEll <ahunpochoevjamshed@gmail.com>2025-06-02 15:29:34 +0300
commita6a1c1b247aa0fa404983efa3c226c25cafdd704 (patch)
tree02fbcb8315df8ef7af779ee1b508d5843254ba3b /compiler/rustc_ast/src/ast.rs
parentebe9b0060240953d721508ceb4d02a745efda88f (diff)
downloadrust-a6a1c1b247aa0fa404983efa3c226c25cafdd704.tar.gz
rust-a6a1c1b247aa0fa404983efa3c226c25cafdd704.zip
Separately check equality of the scalar types and compound types in the order of declaration.
Diffstat (limited to 'compiler/rustc_ast/src/ast.rs')
-rw-r--r--compiler/rustc_ast/src/ast.rs33
1 files changed, 33 insertions, 0 deletions
diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs
index a16219361c0..1d4df97da58 100644
--- a/compiler/rustc_ast/src/ast.rs
+++ b/compiler/rustc_ast/src/ast.rs
@@ -2452,6 +2452,39 @@ impl TyKind {
             None
         }
     }
+
+    /// Returns `true` if this type is considered a scalar primitive (e.g.,
+    /// `i32`, `u8`, `bool`, etc).
+    ///
+    /// This check is based on **symbol equality** and does **not** remove any
+    /// path prefixes or references. If a type alias or shadowing is present
+    /// (e.g., `type i32 = CustomType;`), this method will still return `true`
+    /// for `i32`, even though it may not refer to the primitive type.
+    pub fn maybe_scalar(&self) -> bool {
+        let Some(ty_sym) = self.is_simple_path() else {
+            // unit type
+            return self.is_unit();
+        };
+        matches!(
+            ty_sym,
+            sym::i8
+                | sym::i16
+                | sym::i32
+                | sym::i64
+                | sym::i128
+                | sym::u8
+                | sym::u16
+                | sym::u32
+                | sym::u64
+                | sym::u128
+                | sym::f16
+                | sym::f32
+                | sym::f64
+                | sym::f128
+                | sym::char
+                | sym::bool
+        )
+    }
 }
 
 /// A pattern type pattern.