@@ -364,41 +364,11 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
364
364
} ;
365
365
366
366
let mut fallback_to = |ty| {
367
- let unsafe_infer_vars = unsafe_infer_vars. get_or_init ( || {
368
- let unsafe_infer_vars = compute_unsafe_infer_vars ( self . root_ctxt , self . body_id ) ;
369
- debug ! ( ?unsafe_infer_vars) ;
370
- unsafe_infer_vars
371
- } ) ;
372
-
373
- let affected_unsafe_infer_vars =
374
- graph:: depth_first_search_as_undirected ( & coercion_graph, root_vid)
375
- . filter_map ( |x| unsafe_infer_vars. get ( & x) . copied ( ) )
376
- . collect :: < Vec < _ > > ( ) ;
377
-
378
- for ( hir_id, span, reason) in affected_unsafe_infer_vars {
379
- self . tcx . emit_node_span_lint (
380
- lint:: builtin:: NEVER_TYPE_FALLBACK_FLOWING_INTO_UNSAFE ,
381
- hir_id,
382
- span,
383
- match reason {
384
- UnsafeUseReason :: Call => {
385
- errors:: NeverTypeFallbackFlowingIntoUnsafe :: Call
386
- }
387
- UnsafeUseReason :: Method => {
388
- errors:: NeverTypeFallbackFlowingIntoUnsafe :: Method
389
- }
390
- UnsafeUseReason :: Path => {
391
- errors:: NeverTypeFallbackFlowingIntoUnsafe :: Path
392
- }
393
- UnsafeUseReason :: UnionField => {
394
- errors:: NeverTypeFallbackFlowingIntoUnsafe :: UnionField
395
- }
396
- UnsafeUseReason :: Deref => {
397
- errors:: NeverTypeFallbackFlowingIntoUnsafe :: Deref
398
- }
399
- } ,
400
- ) ;
401
- }
367
+ self . lint_never_type_fallback_flowing_into_unsafe_code (
368
+ & unsafe_infer_vars,
369
+ & coercion_graph,
370
+ root_vid,
371
+ ) ;
402
372
403
373
diverging_fallback. insert ( diverging_ty, ty) ;
404
374
} ;
@@ -464,6 +434,41 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
464
434
diverging_fallback
465
435
}
466
436
437
+ fn lint_never_type_fallback_flowing_into_unsafe_code (
438
+ & self ,
439
+ unsafe_infer_vars : & OnceCell < UnordMap < ty:: TyVid , ( HirId , Span , UnsafeUseReason ) > > ,
440
+ coercion_graph : & VecGraph < ty:: TyVid , true > ,
441
+ root_vid : ty:: TyVid ,
442
+ ) {
443
+ let unsafe_infer_vars = unsafe_infer_vars. get_or_init ( || {
444
+ let unsafe_infer_vars = compute_unsafe_infer_vars ( self . root_ctxt , self . body_id ) ;
445
+ debug ! ( ?unsafe_infer_vars) ;
446
+ unsafe_infer_vars
447
+ } ) ;
448
+
449
+ let affected_unsafe_infer_vars =
450
+ graph:: depth_first_search_as_undirected ( & coercion_graph, root_vid)
451
+ . filter_map ( |x| unsafe_infer_vars. get ( & x) . copied ( ) )
452
+ . collect :: < Vec < _ > > ( ) ;
453
+
454
+ for ( hir_id, span, reason) in affected_unsafe_infer_vars {
455
+ self . tcx . emit_node_span_lint (
456
+ lint:: builtin:: NEVER_TYPE_FALLBACK_FLOWING_INTO_UNSAFE ,
457
+ hir_id,
458
+ span,
459
+ match reason {
460
+ UnsafeUseReason :: Call => errors:: NeverTypeFallbackFlowingIntoUnsafe :: Call ,
461
+ UnsafeUseReason :: Method => errors:: NeverTypeFallbackFlowingIntoUnsafe :: Method ,
462
+ UnsafeUseReason :: Path => errors:: NeverTypeFallbackFlowingIntoUnsafe :: Path ,
463
+ UnsafeUseReason :: UnionField => {
464
+ errors:: NeverTypeFallbackFlowingIntoUnsafe :: UnionField
465
+ }
466
+ UnsafeUseReason :: Deref => errors:: NeverTypeFallbackFlowingIntoUnsafe :: Deref ,
467
+ } ,
468
+ ) ;
469
+ }
470
+ }
471
+
467
472
/// Returns a graph whose nodes are (unresolved) inference variables and where
468
473
/// an edge `?A -> ?B` indicates that the variable `?A` is coerced to `?B`.
469
474
fn create_coercion_graph ( & self ) -> VecGraph < ty:: TyVid , true > {
0 commit comments