Skip to main content

rapx/analysis/api_dependency/graph/
std_tys.rs

1#[cfg(not(rapx_ge_100))]
2use rustc_hir::LangItem;
3#[cfg(rapx_ge_100)]
4use rustc_hir::attrs::lang_items::LangItem;
5use rustc_middle::ty::{self, Ty, TyCtxt};
6use rustc_span::sym;
7
8pub fn std_vec<'tcx>(element_ty: Ty<'tcx>, tcx: TyCtxt<'tcx>) -> Ty<'tcx> {
9    let vec_def_id = tcx
10        .get_diagnostic_item(sym::Vec)
11        .expect("Vec should be defined in std");
12    let alloc_def_id = tcx
13        .lang_items()
14        .global_alloc_ty()
15        .expect("Global should be defined in std");
16    let alloc_ty = tcx.type_of(alloc_def_id).skip_binder();
17    let args = tcx.mk_args(&[
18        ty::GenericArg::from(element_ty),
19        ty::GenericArg::from(alloc_ty),
20    ]);
21    Ty::new_adt(tcx, tcx.adt_def(vec_def_id), args)
22}