Auto merge of #119000 - celinval:smir-cstr, r=ouz-a
Add a method to StableMIR to check if a type is a CStr Also add a check that StableMIR works properly with C string literal.
This commit is contained in:
commit
9f13b9d9ca
4 changed files with 37 additions and 0 deletions
|
@ -219,6 +219,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);
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -316,6 +316,12 @@ impl TyKind {
|
|||
*self == TyKind::RigidTy(RigidTy::Str)
|
||||
}
|
||||
|
||||
#[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(_)))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue