Skip to content

Commit

Permalink
rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
b-naber committed Dec 1, 2021
1 parent 4d9a0bf commit 6952470
Showing 1 changed file with 19 additions and 31 deletions.
50 changes: 19 additions & 31 deletions compiler/rustc_middle/src/ty/normalize_erasing_regions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,7 @@ impl<'tcx> TyCtxt<'tcx> {
Ok(value)
} else {
let mut folder = TryNormalizeAfterErasingRegionsFolder::new(self, param_env);
let result = value.fold_with(&mut folder);

match folder.found_normalization_error() {
Some(e) => Err(e),
None => Ok(result),
}
value.fold_with(&mut folder)
}
}

Expand Down Expand Up @@ -191,12 +186,11 @@ impl TypeFolder<'tcx> for NormalizeAfterErasingRegionsFolder<'tcx> {
struct TryNormalizeAfterErasingRegionsFolder<'tcx> {
tcx: TyCtxt<'tcx>,
param_env: ty::ParamEnv<'tcx>,
normalization_error: Option<NormalizationError<'tcx>>,
}

impl<'tcx> TryNormalizeAfterErasingRegionsFolder<'tcx> {
fn new(tcx: TyCtxt<'tcx>, param_env: ty::ParamEnv<'tcx>) -> Self {
TryNormalizeAfterErasingRegionsFolder { tcx, param_env, normalization_error: None }
TryNormalizeAfterErasingRegionsFolder { tcx, param_env }
}

#[instrument(skip(self), level = "debug")]
Expand All @@ -209,47 +203,41 @@ impl<'tcx> TryNormalizeAfterErasingRegionsFolder<'tcx> {

self.tcx.try_normalize_generic_arg_after_erasing_regions(arg)
}

pub fn found_normalization_error(&self) -> Option<NormalizationError<'tcx>> {
self.normalization_error
}
}

impl TypeFolder<'tcx> for TryNormalizeAfterErasingRegionsFolder<'tcx> {
type Error = NormalizationError<'tcx>;

fn tcx(&self) -> TyCtxt<'tcx> {
self.tcx
}

fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
fn fold_ty(&mut self, ty: Ty<'tcx>) -> Result<Ty<'tcx>, Self::Error> {
match self.try_normalize_generic_arg_after_erasing_regions(ty.into()) {
Ok(t) => t.expect_ty(),
Err(_) => {
self.normalization_error = Some(NormalizationError::Type(ty));
ty
}
Ok(t) => Ok(t.expect_ty()),
Err(_) => Err(NormalizationError::Type(ty)),
}
}

fn fold_const(&mut self, c: &'tcx ty::Const<'tcx>) -> &'tcx ty::Const<'tcx> {
fn fold_const(
&mut self,
c: &'tcx ty::Const<'tcx>,
) -> Result<&'tcx ty::Const<'tcx>, Self::Error> {
match self.try_normalize_generic_arg_after_erasing_regions(c.into()) {
Ok(t) => t.expect_const(),
Err(_) => {
self.normalization_error = Some(NormalizationError::Const(*c));
c
}
Ok(t) => Ok(t.expect_const()),
Err(_) => Err(NormalizationError::Const(*c)),
}
}

#[inline]
fn fold_mir_const(&mut self, c: mir::ConstantKind<'tcx>) -> mir::ConstantKind<'tcx> {
fn fold_mir_const(
&mut self,
c: mir::ConstantKind<'tcx>,
) -> Result<mir::ConstantKind<'tcx>, Self::Error> {
// FIXME: This *probably* needs canonicalization too!
let arg = self.param_env.and(c);
match self.tcx.try_normalize_mir_const_after_erasing_regions(arg) {
Ok(c) => c,
Err(_) => {
self.normalization_error = Some(NormalizationError::ConstantKind(c));
c
}
Ok(c) => Ok(c),
Err(_) => Err(NormalizationError::ConstantKind(c)),
}
}
}

0 comments on commit 6952470

Please sign in to comment.