@@ -350,12 +350,14 @@ impl IgnoredDiagnosticOption {
350350 option_name : & ' static str ,
351351 ) {
352352 if let ( Some ( new_item) , Some ( old_item) ) = ( new, old) {
353- tcx. emit_node_span_lint (
354- UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES ,
355- tcx. local_def_id_to_hir_id ( item_def_id. expect_local ( ) ) ,
356- new_item,
357- IgnoredDiagnosticOption { span : new_item, prev_span : old_item, option_name } ,
358- ) ;
353+ if let Some ( item_def_id) = item_def_id. as_local ( ) {
354+ tcx. emit_node_span_lint (
355+ UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES ,
356+ tcx. local_def_id_to_hir_id ( item_def_id) ,
357+ new_item,
358+ IgnoredDiagnosticOption { span : new_item, prev_span : old_item, option_name } ,
359+ ) ;
360+ }
359361 }
360362 }
361363}
@@ -639,30 +641,38 @@ impl<'tcx> OnUnimplementedDirective {
639641 AttrArgs :: Eq ( span, AttrArgsEq :: Hir ( expr) ) => span. to ( expr. span ) ,
640642 } ;
641643
642- tcx. emit_node_span_lint (
643- UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES ,
644- tcx. local_def_id_to_hir_id ( item_def_id. expect_local ( ) ) ,
645- report_span,
646- MalformedOnUnimplementedAttrLint :: new ( report_span) ,
647- ) ;
644+ if let Some ( item_def_id) = item_def_id. as_local ( ) {
645+ tcx. emit_node_span_lint (
646+ UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES ,
647+ tcx. local_def_id_to_hir_id ( item_def_id) ,
648+ report_span,
649+ MalformedOnUnimplementedAttrLint :: new ( report_span) ,
650+ ) ;
651+ }
648652 Ok ( None )
649653 }
650654 } else if is_diagnostic_namespace_variant {
651655 match & attr. kind {
652656 AttrKind :: Normal ( p) if !matches ! ( p. item. args, AttrArgs :: Empty ) => {
653- tcx. emit_node_span_lint (
654- UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES ,
655- tcx. local_def_id_to_hir_id ( item_def_id. expect_local ( ) ) ,
656- attr. span ,
657- MalformedOnUnimplementedAttrLint :: new ( attr. span ) ,
658- ) ;
657+ if let Some ( item_def_id) = item_def_id. as_local ( ) {
658+ tcx. emit_node_span_lint (
659+ UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES ,
660+ tcx. local_def_id_to_hir_id ( item_def_id) ,
661+ attr. span ,
662+ MalformedOnUnimplementedAttrLint :: new ( attr. span ) ,
663+ ) ;
664+ }
665+ }
666+ _ => {
667+ if let Some ( item_def_id) = item_def_id. as_local ( ) {
668+ tcx. emit_node_span_lint (
669+ UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES ,
670+ tcx. local_def_id_to_hir_id ( item_def_id) ,
671+ attr. span ,
672+ MissingOptionsForOnUnimplementedAttr ,
673+ )
674+ }
659675 }
660- _ => tcx. emit_node_span_lint (
661- UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES ,
662- tcx. local_def_id_to_hir_id ( item_def_id. expect_local ( ) ) ,
663- attr. span ,
664- MissingOptionsForOnUnimplementedAttr ,
665- ) ,
666676 } ;
667677
668678 Ok ( None )
@@ -791,12 +801,14 @@ impl<'tcx> OnUnimplementedFormatString {
791801 || format_spec. precision_span . is_some ( )
792802 || format_spec. fill_span . is_some ( ) )
793803 {
794- tcx. emit_node_span_lint (
795- UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES ,
796- tcx. local_def_id_to_hir_id ( item_def_id. expect_local ( ) ) ,
797- self . span ,
798- InvalidFormatSpecifier ,
799- ) ;
804+ if let Some ( item_def_id) = item_def_id. as_local ( ) {
805+ tcx. emit_node_span_lint (
806+ UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES ,
807+ tcx. local_def_id_to_hir_id ( item_def_id) ,
808+ self . span ,
809+ InvalidFormatSpecifier ,
810+ ) ;
811+ }
800812 }
801813 match a. position {
802814 Position :: ArgumentNamed ( s) => {
@@ -812,15 +824,17 @@ impl<'tcx> OnUnimplementedFormatString {
812824 s if generics. params . iter ( ) . any ( |param| param. name == s) => ( ) ,
813825 s => {
814826 if self . is_diagnostic_namespace_variant {
815- tcx. emit_node_span_lint (
816- UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES ,
817- tcx. local_def_id_to_hir_id ( item_def_id. expect_local ( ) ) ,
818- self . span ,
819- UnknownFormatParameterForOnUnimplementedAttr {
820- argument_name : s,
821- trait_name,
822- } ,
823- ) ;
827+ if let Some ( item_def_id) = item_def_id. as_local ( ) {
828+ tcx. emit_node_span_lint (
829+ UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES ,
830+ tcx. local_def_id_to_hir_id ( item_def_id) ,
831+ self . span ,
832+ UnknownFormatParameterForOnUnimplementedAttr {
833+ argument_name : s,
834+ trait_name,
835+ } ,
836+ ) ;
837+ }
824838 } else {
825839 result = Err ( struct_span_code_err ! (
826840 tcx. dcx( ) ,
@@ -842,12 +856,14 @@ impl<'tcx> OnUnimplementedFormatString {
842856 // `{:1}` and `{}` are not to be used
843857 Position :: ArgumentIs ( ..) | Position :: ArgumentImplicitlyIs ( _) => {
844858 if self . is_diagnostic_namespace_variant {
845- tcx. emit_node_span_lint (
846- UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES ,
847- tcx. local_def_id_to_hir_id ( item_def_id. expect_local ( ) ) ,
848- self . span ,
849- DisallowedPositionalArgument ,
850- ) ;
859+ if let Some ( item_def_id) = item_def_id. as_local ( ) {
860+ tcx. emit_node_span_lint (
861+ UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES ,
862+ tcx. local_def_id_to_hir_id ( item_def_id) ,
863+ self . span ,
864+ DisallowedPositionalArgument ,
865+ ) ;
866+ }
851867 } else {
852868 let reported = struct_span_code_err ! (
853869 tcx. dcx( ) ,
@@ -870,12 +886,14 @@ impl<'tcx> OnUnimplementedFormatString {
870886 // so that users are aware that something is not correct
871887 for e in parser. errors {
872888 if self . is_diagnostic_namespace_variant {
873- tcx. emit_node_span_lint (
874- UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES ,
875- tcx. local_def_id_to_hir_id ( item_def_id. expect_local ( ) ) ,
876- self . span ,
877- WrappedParserError { description : e. description , label : e. label } ,
878- ) ;
889+ if let Some ( item_def_id) = item_def_id. as_local ( ) {
890+ tcx. emit_node_span_lint (
891+ UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES ,
892+ tcx. local_def_id_to_hir_id ( item_def_id) ,
893+ self . span ,
894+ WrappedParserError { description : e. description , label : e. label } ,
895+ ) ;
896+ }
879897 } else {
880898 let reported =
881899 struct_span_code_err ! ( tcx. dcx( ) , self . span, E0231 , "{}" , e. description, ) . emit ( ) ;
0 commit comments