@@ -5,6 +5,7 @@ use rustc_middle::thir::visit::{self, Visitor};
5
5
use rustc_hir as hir;
6
6
use rustc_middle:: mir:: BorrowKind ;
7
7
use rustc_middle:: thir:: * ;
8
+ use rustc_middle:: ty:: print:: with_no_trimmed_paths;
8
9
use rustc_middle:: ty:: { self , ParamEnv , Ty , TyCtxt } ;
9
10
use rustc_session:: lint:: builtin:: { UNSAFE_OP_IN_UNSAFE_FN , UNUSED_UNSAFE } ;
10
11
use rustc_session:: lint:: Level ;
@@ -524,17 +525,19 @@ impl UnsafeOpKind {
524
525
hir_id : hir:: HirId ,
525
526
span : Span ,
526
527
) {
528
+ // FIXME: ideally we would want to trim the def paths, but this is not
529
+ // feasible with the current lint emission API (see issue #106126).
527
530
match self {
528
- CallToUnsafeFunction ( did) if did . is_some ( ) => tcx. emit_spanned_lint (
531
+ CallToUnsafeFunction ( Some ( did) ) => tcx. emit_spanned_lint (
529
532
UNSAFE_OP_IN_UNSAFE_FN ,
530
533
hir_id,
531
534
span,
532
535
UnsafeOpInUnsafeFnCallToUnsafeFunctionRequiresUnsafe {
533
536
span,
534
- function : & tcx. def_path_str ( did. unwrap ( ) ) ,
537
+ function : & with_no_trimmed_paths ! ( tcx. def_path_str( * did) ) ,
535
538
} ,
536
539
) ,
537
- CallToUnsafeFunction ( .. ) => tcx. emit_spanned_lint (
540
+ CallToUnsafeFunction ( None ) => tcx. emit_spanned_lint (
538
541
UNSAFE_OP_IN_UNSAFE_FN ,
539
542
hir_id,
540
543
span,
@@ -594,7 +597,7 @@ impl UnsafeOpKind {
594
597
span,
595
598
UnsafeOpInUnsafeFnCallToFunctionWithRequiresUnsafe {
596
599
span,
597
- function : & tcx. def_path_str ( * did) ,
600
+ function : & with_no_trimmed_paths ! ( tcx. def_path_str( * did) ) ,
598
601
} ,
599
602
) ,
600
603
}
@@ -607,24 +610,24 @@ impl UnsafeOpKind {
607
610
unsafe_op_in_unsafe_fn_allowed : bool ,
608
611
) {
609
612
match self {
610
- CallToUnsafeFunction ( did) if did . is_some ( ) && unsafe_op_in_unsafe_fn_allowed => {
613
+ CallToUnsafeFunction ( Some ( did) ) if unsafe_op_in_unsafe_fn_allowed => {
611
614
tcx. sess . emit_err ( CallToUnsafeFunctionRequiresUnsafeUnsafeOpInUnsafeFnAllowed {
612
615
span,
613
- function : & tcx. def_path_str ( did. unwrap ( ) ) ,
616
+ function : & tcx. def_path_str ( * did) ,
614
617
} ) ;
615
618
}
616
- CallToUnsafeFunction ( did) if did . is_some ( ) => {
619
+ CallToUnsafeFunction ( Some ( did) ) => {
617
620
tcx. sess . emit_err ( CallToUnsafeFunctionRequiresUnsafe {
618
621
span,
619
- function : & tcx. def_path_str ( did. unwrap ( ) ) ,
622
+ function : & tcx. def_path_str ( * did) ,
620
623
} ) ;
621
624
}
622
- CallToUnsafeFunction ( .. ) if unsafe_op_in_unsafe_fn_allowed => {
625
+ CallToUnsafeFunction ( None ) if unsafe_op_in_unsafe_fn_allowed => {
623
626
tcx. sess . emit_err (
624
627
CallToUnsafeFunctionRequiresUnsafeNamelessUnsafeOpInUnsafeFnAllowed { span } ,
625
628
) ;
626
629
}
627
- CallToUnsafeFunction ( .. ) => {
630
+ CallToUnsafeFunction ( None ) => {
628
631
tcx. sess . emit_err ( CallToUnsafeFunctionRequiresUnsafeNameless { span } ) ;
629
632
}
630
633
UseOfInlineAssembly if unsafe_op_in_unsafe_fn_allowed => {
0 commit comments