11use rustc_data_structures:: fx:: { FxHashMap , FxIndexSet } ;
22use rustc_data_structures:: vec_map:: VecMap ;
3+ use rustc_errors:: ErrorGuaranteed ;
34use rustc_hir:: def_id:: LocalDefId ;
45use rustc_hir:: OpaqueTyOrigin ;
56use rustc_infer:: infer:: TyCtxtInferExt as _;
@@ -149,13 +150,13 @@ impl<'tcx> RegionInferenceContext<'tcx> {
149150 // once we convert the generic parameters to those of the opaque type.
150151 if let Some ( prev) = result. get_mut ( & opaque_type_key. def_id ) {
151152 if prev. ty != ty {
152- if ! ty. references_error ( ) {
153+ let guar = ty. error_reported ( ) . err ( ) . unwrap_or_else ( || {
153154 prev. report_mismatch (
154155 & OpaqueHiddenType { ty, span : concrete_type. span } ,
155156 infcx. tcx ,
156- ) ;
157- }
158- prev. ty = infcx. tcx . ty_error ( ) ;
157+ )
158+ } ) ;
159+ prev. ty = infcx. tcx . ty_error_with_guaranteed ( guar ) ;
159160 }
160161 // Pick a better span if there is one.
161162 // FIXME(oli-obk): collect multiple spans for better diagnostics down the road.
@@ -254,13 +255,13 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
254255 . remap_generic_params_to_declaration_params ( opaque_type_key, self . tcx , false )
255256 . ty ;
256257
257- if ! check_opaque_type_parameter_valid (
258+ if let Err ( guar ) = check_opaque_type_parameter_valid (
258259 self . tcx ,
259260 opaque_type_key,
260261 origin,
261262 instantiated_ty. span ,
262263 ) {
263- return self . tcx . ty_error ( ) ;
264+ return self . tcx . ty_error_with_guaranteed ( guar ) ;
264265 }
265266
266267 // Only check this for TAIT. RPIT already supports `tests/ui/impl-trait/nested-return-type2.rs`
@@ -335,7 +336,7 @@ fn check_opaque_type_parameter_valid(
335336 opaque_type_key : OpaqueTypeKey < ' _ > ,
336337 origin : OpaqueTyOrigin ,
337338 span : Span ,
338- ) -> bool {
339+ ) -> Result < ( ) , ErrorGuaranteed > {
339340 match origin {
340341 // No need to check return position impl trait (RPIT)
341342 // because for type and const parameters they are correct
@@ -358,7 +359,7 @@ fn check_opaque_type_parameter_valid(
358359 // fn foo<l0..'ln>() -> foo::<'static..'static>::Foo<'l0..'lm>.
359360 //
360361 // which would error here on all of the `'static` args.
361- OpaqueTyOrigin :: FnReturn ( ..) | OpaqueTyOrigin :: AsyncFn ( ..) => return true ,
362+ OpaqueTyOrigin :: FnReturn ( ..) | OpaqueTyOrigin :: AsyncFn ( ..) => return Ok ( ( ) ) ,
362363 // Check these
363364 OpaqueTyOrigin :: TyAlias => { }
364365 }
@@ -379,13 +380,13 @@ fn check_opaque_type_parameter_valid(
379380 // Prevent `fn foo() -> Foo<u32>` from being defining.
380381 let opaque_param = opaque_generics. param_at ( i, tcx) ;
381382 let kind = opaque_param. kind . descr ( ) ;
382- tcx. sess . emit_err ( NonGenericOpaqueTypeParam {
383+
384+ return Err ( tcx. sess . emit_err ( NonGenericOpaqueTypeParam {
383385 ty : arg,
384386 kind,
385387 span,
386388 param_span : tcx. def_span ( opaque_param. def_id ) ,
387- } ) ;
388- return false ;
389+ } ) ) ;
389390 }
390391 }
391392
@@ -396,12 +397,13 @@ fn check_opaque_type_parameter_valid(
396397 . into_iter ( )
397398 . map ( |i| tcx. def_span ( opaque_generics. param_at ( i, tcx) . def_id ) )
398399 . collect ( ) ;
399- tcx. sess
400+ return Err ( tcx
401+ . sess
400402 . struct_span_err ( span, "non-defining opaque type use in defining scope" )
401403 . span_note ( spans, & format ! ( "{} used multiple times" , descr) )
402- . emit ( ) ;
403- return false ;
404+ . emit ( ) ) ;
404405 }
405406 }
406- true
407+
408+ Ok ( ( ) )
407409}
0 commit comments