@@ -5,6 +5,7 @@ use rustc_middle::thir::visit::{self, Visitor};
55use rustc_hir as hir;
66use rustc_middle:: mir:: BorrowKind ;
77use rustc_middle:: thir:: * ;
8+ use rustc_middle:: ty:: print:: with_no_trimmed_paths;
89use rustc_middle:: ty:: { self , ParamEnv , Ty , TyCtxt } ;
910use rustc_session:: lint:: builtin:: { UNSAFE_OP_IN_UNSAFE_FN , UNUSED_UNSAFE } ;
1011use rustc_session:: lint:: Level ;
@@ -524,17 +525,19 @@ impl UnsafeOpKind {
524525 hir_id : hir:: HirId ,
525526 span : Span ,
526527 ) {
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).
527530 match self {
528- CallToUnsafeFunction ( did) if did . is_some ( ) => tcx. emit_spanned_lint (
531+ CallToUnsafeFunction ( Some ( did) ) => tcx. emit_spanned_lint (
529532 UNSAFE_OP_IN_UNSAFE_FN ,
530533 hir_id,
531534 span,
532535 UnsafeOpInUnsafeFnCallToUnsafeFunctionRequiresUnsafe {
533536 span,
534- function : & tcx. def_path_str ( did. unwrap ( ) ) ,
537+ function : & with_no_trimmed_paths ! ( tcx. def_path_str( * did) ) ,
535538 } ,
536539 ) ,
537- CallToUnsafeFunction ( .. ) => tcx. emit_spanned_lint (
540+ CallToUnsafeFunction ( None ) => tcx. emit_spanned_lint (
538541 UNSAFE_OP_IN_UNSAFE_FN ,
539542 hir_id,
540543 span,
@@ -594,7 +597,7 @@ impl UnsafeOpKind {
594597 span,
595598 UnsafeOpInUnsafeFnCallToFunctionWithRequiresUnsafe {
596599 span,
597- function : & tcx. def_path_str ( * did) ,
600+ function : & with_no_trimmed_paths ! ( tcx. def_path_str( * did) ) ,
598601 } ,
599602 ) ,
600603 }
@@ -607,24 +610,24 @@ impl UnsafeOpKind {
607610 unsafe_op_in_unsafe_fn_allowed : bool ,
608611 ) {
609612 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 => {
611614 tcx. sess . emit_err ( CallToUnsafeFunctionRequiresUnsafeUnsafeOpInUnsafeFnAllowed {
612615 span,
613- function : & tcx. def_path_str ( did. unwrap ( ) ) ,
616+ function : & tcx. def_path_str ( * did) ,
614617 } ) ;
615618 }
616- CallToUnsafeFunction ( did) if did . is_some ( ) => {
619+ CallToUnsafeFunction ( Some ( did) ) => {
617620 tcx. sess . emit_err ( CallToUnsafeFunctionRequiresUnsafe {
618621 span,
619- function : & tcx. def_path_str ( did. unwrap ( ) ) ,
622+ function : & tcx. def_path_str ( * did) ,
620623 } ) ;
621624 }
622- CallToUnsafeFunction ( .. ) if unsafe_op_in_unsafe_fn_allowed => {
625+ CallToUnsafeFunction ( None ) if unsafe_op_in_unsafe_fn_allowed => {
623626 tcx. sess . emit_err (
624627 CallToUnsafeFunctionRequiresUnsafeNamelessUnsafeOpInUnsafeFnAllowed { span } ,
625628 ) ;
626629 }
627- CallToUnsafeFunction ( .. ) => {
630+ CallToUnsafeFunction ( None ) => {
628631 tcx. sess . emit_err ( CallToUnsafeFunctionRequiresUnsafeNameless { span } ) ;
629632 }
630633 UseOfInlineAssembly if unsafe_op_in_unsafe_fn_allowed => {
0 commit comments