Skip to content

Commit b38fcde

Browse files
committed
Auto merge of rust-lang#14213 - swarnimarun:raw-ptr-ty, r=Veykril
add: clean api to get `raw_ptr` type There doesn't seem to be an API to fetch the type of `raw_ptr`, which is helpful for a project I work on. Notes: - I am unsure about the function name, do let me know if I should use something else. - Also unsure about where to add tests, for hir changes. Will fix it as needed.
2 parents 2e47915 + 832f8bf commit b38fcde

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

crates/hir/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3190,6 +3190,14 @@ impl Type {
31903190
matches!(self.ty.kind(Interner), TyKind::Raw(..))
31913191
}
31923192

3193+
pub fn remove_raw_ptr(&self) -> Option<Type> {
3194+
if let TyKind::Raw(_, ty) = self.ty.kind(Interner) {
3195+
Some(self.derived(ty.clone()))
3196+
} else {
3197+
None
3198+
}
3199+
}
3200+
31933201
pub fn contains_unknown(&self) -> bool {
31943202
// FIXME: When we get rid of `ConstScalar::Unknown`, we can just look at precomputed
31953203
// `TypeFlags` in `TyData`.

0 commit comments

Comments
 (0)