Skip to content

Commit dfff733

Browse files
Allow type op to delay ambiguity
1 parent 3dbc9ed commit dfff733

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

compiler/rustc_middle/src/traits/query.rs

+12
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,24 @@ pub enum NoSolutionOrAmbiguous {
116116
}
117117

118118
impl NoSolutionOrAmbiguous {
119+
// Expect unambiguous errors only
119120
pub fn expect_unambiguous(self) -> NoSolution {
120121
match self {
121122
NoSolutionOrAmbiguous::NoSolution => NoSolution,
122123
NoSolutionOrAmbiguous::Ambiguous => bug!("unexpected ambiguity"),
123124
}
124125
}
126+
127+
/// Delay an ambiguity as a `delay_span_bug`.
128+
pub fn delay_ambiguous(self, tcx: TyCtxt<'_>, span: Span) -> NoSolution {
129+
match self {
130+
NoSolutionOrAmbiguous::NoSolution => NoSolution,
131+
NoSolutionOrAmbiguous::Ambiguous => {
132+
tcx.sess.delay_span_bug(span, "unexpected ambiguity");
133+
NoSolution
134+
}
135+
}
136+
}
125137
}
126138

127139
impl From<NoSolution> for NoSolutionOrAmbiguous {

compiler/rustc_traits/src/type_op.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ where
221221
let Normalized { value, obligations } = infcx
222222
.at(&ObligationCause::dummy(), param_env)
223223
.normalize(value)
224-
.map_err(|err| err.expect_unambiguous())?;
224+
.map_err(|err| err.delay_ambiguous(infcx.tcx, DUMMY_SP))?;
225225
fulfill_cx.register_predicate_obligations(infcx, obligations);
226226
Ok(value)
227227
}

0 commit comments

Comments
 (0)