@@ -349,12 +349,14 @@ impl IgnoredDiagnosticOption {
349349 option_name : & ' static str ,
350350 ) {
351351 if let ( Some ( new_item) , Some ( old_item) ) = ( new, old) {
352- tcx. emit_node_span_lint (
353- UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES ,
354- tcx. local_def_id_to_hir_id ( item_def_id. expect_local ( ) ) ,
355- new_item,
356- IgnoredDiagnosticOption { span : new_item, prev_span : old_item, option_name } ,
357- ) ;
352+ if let Some ( item_def_id) = item_def_id. as_local ( ) {
353+ tcx. emit_node_span_lint (
354+ UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES ,
355+ tcx. local_def_id_to_hir_id ( item_def_id) ,
356+ new_item,
357+ IgnoredDiagnosticOption { span : new_item, prev_span : old_item, option_name } ,
358+ ) ;
359+ }
358360 }
359361 }
360362}
@@ -498,12 +500,14 @@ impl<'tcx> OnUnimplementedDirective {
498500 }
499501
500502 if is_diagnostic_namespace_variant {
501- tcx. emit_node_span_lint (
502- UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES ,
503- tcx. local_def_id_to_hir_id ( item_def_id. expect_local ( ) ) ,
504- vec ! [ item. span( ) ] ,
505- MalformedOnUnimplementedAttrLint :: new ( item. span ( ) ) ,
506- ) ;
503+ if let Some ( def_id) = item_def_id. as_local ( ) {
504+ tcx. emit_node_span_lint (
505+ UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES ,
506+ tcx. local_def_id_to_hir_id ( def_id) ,
507+ vec ! [ item. span( ) ] ,
508+ MalformedOnUnimplementedAttrLint :: new ( item. span ( ) ) ,
509+ ) ;
510+ }
507511 } else {
508512 // nothing found
509513 tcx. dcx ( ) . emit_err ( NoValueInOnUnimplemented { span : item. span ( ) } ) ;
@@ -636,30 +640,38 @@ impl<'tcx> OnUnimplementedDirective {
636640 AttrArgs :: Eq ( span, AttrArgsEq :: Hir ( expr) ) => span. to ( expr. span ) ,
637641 } ;
638642
639- tcx. emit_node_span_lint (
640- UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES ,
641- tcx. local_def_id_to_hir_id ( item_def_id. expect_local ( ) ) ,
642- report_span,
643- MalformedOnUnimplementedAttrLint :: new ( report_span) ,
644- ) ;
643+ if let Some ( item_def_id) = item_def_id. as_local ( ) {
644+ tcx. emit_node_span_lint (
645+ UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES ,
646+ tcx. local_def_id_to_hir_id ( item_def_id) ,
647+ report_span,
648+ MalformedOnUnimplementedAttrLint :: new ( report_span) ,
649+ ) ;
650+ }
645651 Ok ( None )
646652 }
647653 } else if is_diagnostic_namespace_variant {
648654 match & attr. kind {
649655 AttrKind :: Normal ( p) if !matches ! ( p. item. args, AttrArgs :: Empty ) => {
650- tcx. emit_node_span_lint (
651- UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES ,
652- tcx. local_def_id_to_hir_id ( item_def_id. expect_local ( ) ) ,
653- attr. span ,
654- MalformedOnUnimplementedAttrLint :: new ( attr. span ) ,
655- ) ;
656+ if let Some ( item_def_id) = item_def_id. as_local ( ) {
657+ tcx. emit_node_span_lint (
658+ UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES ,
659+ tcx. local_def_id_to_hir_id ( item_def_id) ,
660+ attr. span ,
661+ MalformedOnUnimplementedAttrLint :: new ( attr. span ) ,
662+ ) ;
663+ }
664+ }
665+ _ => {
666+ if let Some ( item_def_id) = item_def_id. as_local ( ) {
667+ tcx. emit_node_span_lint (
668+ UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES ,
669+ tcx. local_def_id_to_hir_id ( item_def_id) ,
670+ attr. span ,
671+ MissingOptionsForOnUnimplementedAttr ,
672+ )
673+ }
656674 }
657- _ => tcx. emit_node_span_lint (
658- UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES ,
659- tcx. local_def_id_to_hir_id ( item_def_id. expect_local ( ) ) ,
660- attr. span ,
661- MissingOptionsForOnUnimplementedAttr ,
662- ) ,
663675 } ;
664676
665677 Ok ( None )
@@ -788,12 +800,14 @@ impl<'tcx> OnUnimplementedFormatString {
788800 || format_spec. precision_span . is_some ( )
789801 || format_spec. fill_span . is_some ( ) )
790802 {
791- tcx. emit_node_span_lint (
792- UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES ,
793- tcx. local_def_id_to_hir_id ( item_def_id. expect_local ( ) ) ,
794- self . span ,
795- InvalidFormatSpecifier ,
796- ) ;
803+ if let Some ( item_def_id) = item_def_id. as_local ( ) {
804+ tcx. emit_node_span_lint (
805+ UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES ,
806+ tcx. local_def_id_to_hir_id ( item_def_id) ,
807+ self . span ,
808+ InvalidFormatSpecifier ,
809+ ) ;
810+ }
797811 }
798812 match a. position {
799813 Position :: ArgumentNamed ( s) => {
@@ -809,15 +823,17 @@ impl<'tcx> OnUnimplementedFormatString {
809823 s if generics. params . iter ( ) . any ( |param| param. name == s) => ( ) ,
810824 s => {
811825 if self . is_diagnostic_namespace_variant {
812- tcx. emit_node_span_lint (
813- UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES ,
814- tcx. local_def_id_to_hir_id ( item_def_id. expect_local ( ) ) ,
815- self . span ,
816- UnknownFormatParameterForOnUnimplementedAttr {
817- argument_name : s,
818- trait_name,
819- } ,
820- ) ;
826+ if let Some ( item_def_id) = item_def_id. as_local ( ) {
827+ tcx. emit_node_span_lint (
828+ UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES ,
829+ tcx. local_def_id_to_hir_id ( item_def_id) ,
830+ self . span ,
831+ UnknownFormatParameterForOnUnimplementedAttr {
832+ argument_name : s,
833+ trait_name,
834+ } ,
835+ ) ;
836+ }
821837 } else {
822838 result = Err ( struct_span_code_err ! (
823839 tcx. dcx( ) ,
@@ -839,12 +855,14 @@ impl<'tcx> OnUnimplementedFormatString {
839855 // `{:1}` and `{}` are not to be used
840856 Position :: ArgumentIs ( ..) | Position :: ArgumentImplicitlyIs ( _) => {
841857 if self . is_diagnostic_namespace_variant {
842- tcx. emit_node_span_lint (
843- UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES ,
844- tcx. local_def_id_to_hir_id ( item_def_id. expect_local ( ) ) ,
845- self . span ,
846- DisallowedPositionalArgument ,
847- ) ;
858+ if let Some ( item_def_id) = item_def_id. as_local ( ) {
859+ tcx. emit_node_span_lint (
860+ UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES ,
861+ tcx. local_def_id_to_hir_id ( item_def_id) ,
862+ self . span ,
863+ DisallowedPositionalArgument ,
864+ ) ;
865+ }
848866 } else {
849867 let reported = struct_span_code_err ! (
850868 tcx. dcx( ) ,
@@ -867,12 +885,14 @@ impl<'tcx> OnUnimplementedFormatString {
867885 // so that users are aware that something is not correct
868886 for e in parser. errors {
869887 if self . is_diagnostic_namespace_variant {
870- tcx. emit_node_span_lint (
871- UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES ,
872- tcx. local_def_id_to_hir_id ( item_def_id. expect_local ( ) ) ,
873- self . span ,
874- WrappedParserError { description : e. description , label : e. label } ,
875- ) ;
888+ if let Some ( item_def_id) = item_def_id. as_local ( ) {
889+ tcx. emit_node_span_lint (
890+ UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES ,
891+ tcx. local_def_id_to_hir_id ( item_def_id) ,
892+ self . span ,
893+ WrappedParserError { description : e. description , label : e. label } ,
894+ ) ;
895+ }
876896 } else {
877897 let reported =
878898 struct_span_code_err ! ( tcx. dcx( ) , self . span, E0231 , "{}" , e. description, ) . emit ( ) ;
0 commit comments