check if const is ADT or not
This commit is contained in:
@@ -115,7 +115,7 @@ mod rustc {
|
||||
tcx: TyCtxt<'tcx>,
|
||||
param_env: ParamEnv<'tcx>,
|
||||
c: Const<'tcx>,
|
||||
) -> Self {
|
||||
) -> Option<Self> {
|
||||
use rustc_middle::ty::ScalarInt;
|
||||
use rustc_middle::ty::TypeVisitable;
|
||||
use rustc_span::symbol::sym;
|
||||
@@ -123,10 +123,15 @@ mod rustc {
|
||||
let c = c.eval(tcx, param_env);
|
||||
|
||||
if let Some(err) = c.error_reported() {
|
||||
return Self { alignment: true, lifetimes: true, safety: true, validity: true };
|
||||
return Some(Self {
|
||||
alignment: true,
|
||||
lifetimes: true,
|
||||
safety: true,
|
||||
validity: true,
|
||||
});
|
||||
}
|
||||
|
||||
let adt_def = c.ty().ty_adt_def().expect("The given `Const` must be an ADT.");
|
||||
let adt_def = c.ty().ty_adt_def()?;
|
||||
|
||||
assert_eq!(
|
||||
tcx.require_lang_item(LangItem::TransmuteOpts, None),
|
||||
@@ -148,12 +153,12 @@ mod rustc {
|
||||
fields[field_idx].unwrap_leaf() == ScalarInt::TRUE
|
||||
};
|
||||
|
||||
Self {
|
||||
Some(Self {
|
||||
alignment: get_field(sym::alignment),
|
||||
lifetimes: get_field(sym::lifetimes),
|
||||
safety: get_field(sym::safety),
|
||||
validity: get_field(sym::validity),
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user