diff options
| author | Celina G. Val <celinval@amazon.com> | 2023-12-15 13:18:41 -0800 |
|---|---|---|
| committer | Celina G. Val <celinval@amazon.com> | 2023-12-15 13:18:41 -0800 |
| commit | 86451badf1113c6b6de99043e3abb87d7021d7e7 (patch) | |
| tree | 5b5bfc6ee0009738c000938c238a5da7fdf07ce2 /compiler | |
| parent | 3f39cae1199a2a0217c3646a16d1ae7fa599130b (diff) | |
| download | rust-86451badf1113c6b6de99043e3abb87d7021d7e7.tar.gz rust-86451badf1113c6b6de99043e3abb87d7021d7e7.zip | |
Add a method to check if type is a CStr
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_smir/src/rustc_smir/context.rs | 6 | ||||
| -rw-r--r-- | compiler/stable_mir/src/compiler_interface.rs | 3 | ||||
| -rw-r--r-- | compiler/stable_mir/src/ty.rs | 6 |
3 files changed, 15 insertions, 0 deletions
diff --git a/compiler/rustc_smir/src/rustc_smir/context.rs b/compiler/rustc_smir/src/rustc_smir/context.rs index 70313cc021e..ae47f767f93 100644 --- a/compiler/rustc_smir/src/rustc_smir/context.rs +++ b/compiler/rustc_smir/src/rustc_smir/context.rs @@ -220,6 +220,12 @@ impl<'tcx> Context for TablesWrapper<'tcx> { def.internal(&mut *tables).repr().simd() } + fn adt_is_cstr(&self, def: AdtDef) -> bool { + let mut tables = self.0.borrow_mut(); + let def_id = def.0.internal(&mut *tables); + tables.tcx.lang_items().c_str() == Some(def_id) + } + fn fn_sig(&self, def: FnDef, args: &GenericArgs) -> PolyFnSig { let mut tables = self.0.borrow_mut(); let def_id = def.0.internal(&mut *tables); diff --git a/compiler/stable_mir/src/compiler_interface.rs b/compiler/stable_mir/src/compiler_interface.rs index 2fac59e71fd..57c60b70d8a 100644 --- a/compiler/stable_mir/src/compiler_interface.rs +++ b/compiler/stable_mir/src/compiler_interface.rs @@ -72,6 +72,9 @@ pub trait Context { /// Returns whether this ADT is simd. fn adt_is_simd(&self, def: AdtDef) -> bool; + /// Returns whether this definition is a C string. + fn adt_is_cstr(&self, def: AdtDef) -> bool; + /// Retrieve the function signature for the given generic arguments. fn fn_sig(&self, def: FnDef, args: &GenericArgs) -> PolyFnSig; diff --git a/compiler/stable_mir/src/ty.rs b/compiler/stable_mir/src/ty.rs index 3d5e264104b..4807a9028eb 100644 --- a/compiler/stable_mir/src/ty.rs +++ b/compiler/stable_mir/src/ty.rs @@ -317,6 +317,12 @@ impl TyKind { } #[inline] + pub fn is_cstr(&self) -> bool { + let TyKind::RigidTy(RigidTy::Adt(def, _)) = self else { return false }; + with(|cx| cx.adt_is_cstr(*def)) + } + + #[inline] pub fn is_slice(&self) -> bool { matches!(self, TyKind::RigidTy(RigidTy::Slice(_))) } |
