Skip to content

Commit

Permalink
Allow type op to delay ambiguity
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Oct 20, 2022
1 parent 3dbc9ed commit dfff733
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions compiler/rustc_middle/src/traits/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,24 @@ pub enum NoSolutionOrAmbiguous {
}

impl NoSolutionOrAmbiguous {
// Expect unambiguous errors only
pub fn expect_unambiguous(self) -> NoSolution {
match self {
NoSolutionOrAmbiguous::NoSolution => NoSolution,
NoSolutionOrAmbiguous::Ambiguous => bug!("unexpected ambiguity"),
}
}

/// Delay an ambiguity as a `delay_span_bug`.
pub fn delay_ambiguous(self, tcx: TyCtxt<'_>, span: Span) -> NoSolution {
match self {
NoSolutionOrAmbiguous::NoSolution => NoSolution,
NoSolutionOrAmbiguous::Ambiguous => {
tcx.sess.delay_span_bug(span, "unexpected ambiguity");
NoSolution
}
}
}
}

impl From<NoSolution> for NoSolutionOrAmbiguous {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_traits/src/type_op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ where
let Normalized { value, obligations } = infcx
.at(&ObligationCause::dummy(), param_env)
.normalize(value)
.map_err(|err| err.expect_unambiguous())?;
.map_err(|err| err.delay_ambiguous(infcx.tcx, DUMMY_SP))?;
fulfill_cx.register_predicate_obligations(infcx, obligations);
Ok(value)
}
Expand Down

0 comments on commit dfff733

Please sign in to comment.