1
1
use rustc_data_structures:: fx:: { FxHashMap , FxIndexSet } ;
2
2
use rustc_data_structures:: vec_map:: VecMap ;
3
+ use rustc_errors:: ErrorGuaranteed ;
3
4
use rustc_hir:: def_id:: LocalDefId ;
4
5
use rustc_hir:: OpaqueTyOrigin ;
5
6
use rustc_infer:: infer:: TyCtxtInferExt as _;
@@ -149,13 +150,13 @@ impl<'tcx> RegionInferenceContext<'tcx> {
149
150
// once we convert the generic parameters to those of the opaque type.
150
151
if let Some ( prev) = result. get_mut ( & opaque_type_key. def_id ) {
151
152
if prev. ty != ty {
152
- if ! ty. references_error ( ) {
153
+ let guar = ty. error_reported ( ) . err ( ) . unwrap_or_else ( || {
153
154
prev. report_mismatch (
154
155
& OpaqueHiddenType { ty, span : concrete_type. span } ,
155
156
infcx. tcx ,
156
- ) ;
157
- }
158
- prev. ty = infcx. tcx . ty_error ( ) ;
157
+ )
158
+ } ) ;
159
+ prev. ty = infcx. tcx . ty_error_with_guaranteed ( guar ) ;
159
160
}
160
161
// Pick a better span if there is one.
161
162
// FIXME(oli-obk): collect multiple spans for better diagnostics down the road.
@@ -254,13 +255,13 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
254
255
. remap_generic_params_to_declaration_params ( opaque_type_key, self . tcx , false )
255
256
. ty ;
256
257
257
- if ! check_opaque_type_parameter_valid (
258
+ if let Err ( guar ) = check_opaque_type_parameter_valid (
258
259
self . tcx ,
259
260
opaque_type_key,
260
261
origin,
261
262
instantiated_ty. span ,
262
263
) {
263
- return self . tcx . ty_error ( ) ;
264
+ return self . tcx . ty_error_with_guaranteed ( guar ) ;
264
265
}
265
266
266
267
// 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(
335
336
opaque_type_key : OpaqueTypeKey < ' _ > ,
336
337
origin : OpaqueTyOrigin ,
337
338
span : Span ,
338
- ) -> bool {
339
+ ) -> Result < ( ) , ErrorGuaranteed > {
339
340
match origin {
340
341
// No need to check return position impl trait (RPIT)
341
342
// because for type and const parameters they are correct
@@ -358,7 +359,7 @@ fn check_opaque_type_parameter_valid(
358
359
// fn foo<l0..'ln>() -> foo::<'static..'static>::Foo<'l0..'lm>.
359
360
//
360
361
// which would error here on all of the `'static` args.
361
- OpaqueTyOrigin :: FnReturn ( ..) | OpaqueTyOrigin :: AsyncFn ( ..) => return true ,
362
+ OpaqueTyOrigin :: FnReturn ( ..) | OpaqueTyOrigin :: AsyncFn ( ..) => return Ok ( ( ) ) ,
362
363
// Check these
363
364
OpaqueTyOrigin :: TyAlias => { }
364
365
}
@@ -379,13 +380,13 @@ fn check_opaque_type_parameter_valid(
379
380
// Prevent `fn foo() -> Foo<u32>` from being defining.
380
381
let opaque_param = opaque_generics. param_at ( i, tcx) ;
381
382
let kind = opaque_param. kind . descr ( ) ;
382
- tcx. sess . emit_err ( NonGenericOpaqueTypeParam {
383
+
384
+ return Err ( tcx. sess . emit_err ( NonGenericOpaqueTypeParam {
383
385
ty : arg,
384
386
kind,
385
387
span,
386
388
param_span : tcx. def_span ( opaque_param. def_id ) ,
387
- } ) ;
388
- return false ;
389
+ } ) ) ;
389
390
}
390
391
}
391
392
@@ -396,12 +397,13 @@ fn check_opaque_type_parameter_valid(
396
397
. into_iter ( )
397
398
. map ( |i| tcx. def_span ( opaque_generics. param_at ( i, tcx) . def_id ) )
398
399
. collect ( ) ;
399
- tcx. sess
400
+ return Err ( tcx
401
+ . sess
400
402
. struct_span_err ( span, "non-defining opaque type use in defining scope" )
401
403
. span_note ( spans, & format ! ( "{} used multiple times" , descr) )
402
- . emit ( ) ;
403
- return false ;
404
+ . emit ( ) ) ;
404
405
}
405
406
}
406
- true
407
+
408
+ Ok ( ( ) )
407
409
}
0 commit comments