rapx 0.7.55

A static analysis platform for Rust program analysis and verification
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use rustc_middle::ty::{self, Ty, TyCtxt};
use rustc_span::sym;

pub fn std_vec<'tcx>(element_ty: Ty<'tcx>, tcx: TyCtxt<'tcx>) -> Option<Ty<'tcx>> {
    let vec_def_id = tcx.get_diagnostic_item(sym::Vec)?;
    let alloc_def_id = tcx.lang_items().global_alloc_ty()?;
    let alloc_ty = tcx.type_of(alloc_def_id).skip_binder();
    let args = tcx.mk_args(&[
        ty::GenericArg::from(element_ty),
        ty::GenericArg::from(alloc_ty),
    ]);
    Some(Ty::new_adt(tcx, tcx.adt_def(vec_def_id), args))
}

pub fn std_string<'tcx>(tcx: TyCtxt<'tcx>) -> Option<Ty<'tcx>> {
    let string_def_id = tcx.lang_items().string()?;
    Some(tcx.type_of(string_def_id).skip_binder())
}