@@ -14,6 +14,7 @@ use rustc_infer::traits::Normalized;
14
14
use rustc_middle:: ty:: fold:: { FallibleTypeFolder , TypeFoldable , TypeSuperFoldable } ;
15
15
use rustc_middle:: ty:: visit:: { TypeSuperVisitable , TypeVisitable } ;
16
16
use rustc_middle:: ty:: { self , Ty , TyCtxt , TypeVisitor } ;
17
+ use rustc_span:: DUMMY_SP ;
17
18
18
19
use std:: ops:: ControlFlow ;
19
20
@@ -253,7 +254,15 @@ impl<'cx, 'tcx> FallibleTypeFolder<'tcx> for QueryNormalizer<'cx, 'tcx> {
253
254
let result = tcx. normalize_projection_ty ( c_data) ?;
254
255
// We don't expect ambiguity.
255
256
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 ) ;
257
266
}
258
267
let InferOk { value : result, obligations } =
259
268
self . infcx . instantiate_query_response_and_region_obligations (
@@ -296,7 +305,15 @@ impl<'cx, 'tcx> FallibleTypeFolder<'tcx> for QueryNormalizer<'cx, 'tcx> {
296
305
let result = tcx. normalize_projection_ty ( c_data) ?;
297
306
// We don't expect ambiguity.
298
307
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 ) ;
300
317
}
301
318
let InferOk { value : result, obligations } =
302
319
self . infcx . instantiate_query_response_and_region_obligations (
0 commit comments