@@ -14,6 +14,7 @@ use rustc_infer::traits::Normalized;
1414use rustc_middle:: ty:: fold:: { FallibleTypeFolder , TypeFoldable , TypeSuperFoldable } ;
1515use rustc_middle:: ty:: visit:: { TypeSuperVisitable , TypeVisitable } ;
1616use rustc_middle:: ty:: { self , Ty , TyCtxt , TypeVisitor } ;
17+ use rustc_span:: DUMMY_SP ;
1718
1819use std:: ops:: ControlFlow ;
1920
@@ -253,7 +254,15 @@ impl<'cx, 'tcx> FallibleTypeFolder<'tcx> for QueryNormalizer<'cx, 'tcx> {
253254 let result = tcx. normalize_projection_ty ( c_data) ?;
254255 // We don't expect ambiguity.
255256 if result. is_ambiguous ( ) {
256- bug ! ( "unexpected ambiguity: {:?} {:?}" , c_data, result) ;
257+ // Rustdoc normalizes possibly not well-formed types, so only
258+ // treat this as a bug if we're not in rustdoc.
259+ if !tcx. sess . opts . actually_rustdoc {
260+ tcx. sess . delay_span_bug (
261+ DUMMY_SP ,
262+ format ! ( "unexpected ambiguity: {:?} {:?}" , c_data, result) ,
263+ ) ;
264+ }
265+ return Err ( NoSolution ) ;
257266 }
258267 let InferOk { value : result, obligations } =
259268 self . infcx . instantiate_query_response_and_region_obligations (
@@ -296,7 +305,15 @@ impl<'cx, 'tcx> FallibleTypeFolder<'tcx> for QueryNormalizer<'cx, 'tcx> {
296305 let result = tcx. normalize_projection_ty ( c_data) ?;
297306 // We don't expect ambiguity.
298307 if result. is_ambiguous ( ) {
299- bug ! ( "unexpected ambiguity: {:?} {:?}" , c_data, result) ;
308+ // Rustdoc normalizes possibly not well-formed types, so only
309+ // treat this as a bug if we're not in rustdoc.
310+ if !tcx. sess . opts . actually_rustdoc {
311+ tcx. sess . delay_span_bug (
312+ DUMMY_SP ,
313+ format ! ( "unexpected ambiguity: {:?} {:?}" , c_data, result) ,
314+ ) ;
315+ }
316+ return Err ( NoSolution ) ;
300317 }
301318 let InferOk { value : result, obligations } =
302319 self . infcx . instantiate_query_response_and_region_obligations (
0 commit comments