Improve safe transmute error reporting
This patch updates the error reporting when Safe Transmute is not possible between 2 types by including the reason. Also, fix some small bugs that occur when computing the `Answer` for transmutability.
This commit is contained in:
parent
59a05ad118
commit
36febe1f4d
29 changed files with 495 additions and 593 deletions
|
@ -167,31 +167,31 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub(crate) enum Err {
|
||||
/// The layout of the type is unspecified.
|
||||
Unspecified,
|
||||
/// This error will be surfaced elsewhere by rustc, so don't surface it.
|
||||
Unknown,
|
||||
}
|
||||
|
||||
#[cfg(feature = "rustc")]
|
||||
pub(crate) mod rustc {
|
||||
use super::{Err, Tree};
|
||||
use super::Tree;
|
||||
use crate::layout::rustc::{Def, Ref};
|
||||
|
||||
use rustc_middle::ty;
|
||||
use rustc_middle::ty::layout::LayoutError;
|
||||
use rustc_middle::ty::util::Discr;
|
||||
use rustc_middle::ty::AdtDef;
|
||||
use rustc_middle::ty::ParamEnv;
|
||||
use rustc_middle::ty::SubstsRef;
|
||||
use rustc_middle::ty::Ty;
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
use rustc_middle::ty::VariantDef;
|
||||
use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitableExt};
|
||||
use rustc_span::ErrorGuaranteed;
|
||||
use rustc_target::abi::Align;
|
||||
use std::alloc;
|
||||
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub(crate) enum Err {
|
||||
/// The layout of the type is unspecified.
|
||||
Unspecified,
|
||||
/// This error will be surfaced elsewhere by rustc, so don't surface it.
|
||||
Unknown,
|
||||
TypeError(ErrorGuaranteed),
|
||||
}
|
||||
|
||||
impl<'tcx> From<LayoutError<'tcx>> for Err {
|
||||
fn from(err: LayoutError<'tcx>) -> Self {
|
||||
match err {
|
||||
|
@ -261,6 +261,10 @@ pub(crate) mod rustc {
|
|||
use rustc_middle::ty::UintTy::*;
|
||||
use rustc_target::abi::HasDataLayout;
|
||||
|
||||
if let Err(e) = ty.error_reported() {
|
||||
return Err(Err::TypeError(e));
|
||||
}
|
||||
|
||||
let target = tcx.data_layout();
|
||||
|
||||
match ty.kind() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue