2023-01-09 12:36:22 -06:00
|
|
|
//! Functions to detect special lang items
|
|
|
|
|
2023-02-13 05:55:14 -06:00
|
|
|
use hir_def::{lang_item::LangItem, AdtId, HasModule};
|
2023-01-09 12:36:22 -06:00
|
|
|
|
|
|
|
use crate::db::HirDatabase;
|
|
|
|
|
|
|
|
pub fn is_box(adt: AdtId, db: &dyn HirDatabase) -> bool {
|
|
|
|
let krate = adt.module(db.upcast()).krate();
|
2023-02-13 05:55:14 -06:00
|
|
|
let box_adt =
|
|
|
|
db.lang_item(krate, LangItem::OwnedBox).and_then(|it| it.as_struct()).map(AdtId::from);
|
2023-01-09 12:36:22 -06:00
|
|
|
Some(adt) == box_adt
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn is_unsafe_cell(adt: AdtId, db: &dyn HirDatabase) -> bool {
|
|
|
|
let krate = adt.module(db.upcast()).krate();
|
2023-02-13 05:55:14 -06:00
|
|
|
let box_adt =
|
|
|
|
db.lang_item(krate, LangItem::UnsafeCell).and_then(|it| it.as_struct()).map(AdtId::from);
|
2023-01-09 12:36:22 -06:00
|
|
|
Some(adt) == box_adt
|
|
|
|
}
|