@@ -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}
@@ -638,30 +640,38 @@ impl<'tcx> OnUnimplementedDirective {
638640 AttrArgs :: Eq ( span, AttrArgsEq :: Hir ( expr) ) => span. to ( expr. span ) ,
639641 } ;
640642
641- tcx. emit_node_span_lint (
642- UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES ,
643- tcx. local_def_id_to_hir_id ( item_def_id. expect_local ( ) ) ,
644- report_span,
645- MalformedOnUnimplementedAttrLint :: new ( report_span) ,
646- ) ;
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+ }
647651 Ok ( None )
648652 }
649653 } else if is_diagnostic_namespace_variant {
650654 match & attr. kind {
651655 AttrKind :: Normal ( p) if !matches ! ( p. item. args, AttrArgs :: Empty ) => {
652- tcx. emit_node_span_lint (
653- UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES ,
654- tcx. local_def_id_to_hir_id ( item_def_id. expect_local ( ) ) ,
655- attr. span ,
656- MalformedOnUnimplementedAttrLint :: new ( attr. span ) ,
657- ) ;
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+ }
658674 }
659- _ => tcx. emit_node_span_lint (
660- UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES ,
661- tcx. local_def_id_to_hir_id ( item_def_id. expect_local ( ) ) ,
662- attr. span ,
663- MissingOptionsForOnUnimplementedAttr ,
664- ) ,
665675 } ;
666676
667677 Ok ( None )
@@ -790,12 +800,14 @@ impl<'tcx> OnUnimplementedFormatString {
790800 || format_spec. precision_span . is_some ( )
791801 || format_spec. fill_span . is_some ( ) )
792802 {
793- tcx. emit_node_span_lint (
794- UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES ,
795- tcx. local_def_id_to_hir_id ( item_def_id. expect_local ( ) ) ,
796- self . span ,
797- InvalidFormatSpecifier ,
798- ) ;
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+ }
799811 }
800812 match a. position {
801813 Position :: ArgumentNamed ( s) => {
@@ -811,15 +823,17 @@ impl<'tcx> OnUnimplementedFormatString {
811823 s if generics. params . iter ( ) . any ( |param| param. name == s) => ( ) ,
812824 s => {
813825 if self . is_diagnostic_namespace_variant {
814- tcx. emit_node_span_lint (
815- UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES ,
816- tcx. local_def_id_to_hir_id ( item_def_id. expect_local ( ) ) ,
817- self . span ,
818- UnknownFormatParameterForOnUnimplementedAttr {
819- argument_name : s,
820- trait_name,
821- } ,
822- ) ;
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+ }
823837 } else {
824838 result = Err ( struct_span_code_err ! (
825839 tcx. dcx( ) ,
@@ -841,12 +855,14 @@ impl<'tcx> OnUnimplementedFormatString {
841855 // `{:1}` and `{}` are not to be used
842856 Position :: ArgumentIs ( ..) | Position :: ArgumentImplicitlyIs ( _) => {
843857 if self . is_diagnostic_namespace_variant {
844- tcx. emit_node_span_lint (
845- UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES ,
846- tcx. local_def_id_to_hir_id ( item_def_id. expect_local ( ) ) ,
847- self . span ,
848- DisallowedPositionalArgument ,
849- ) ;
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+ }
850866 } else {
851867 let reported = struct_span_code_err ! (
852868 tcx. dcx( ) ,
@@ -869,12 +885,14 @@ impl<'tcx> OnUnimplementedFormatString {
869885 // so that users are aware that something is not correct
870886 for e in parser. errors {
871887 if self . is_diagnostic_namespace_variant {
872- tcx. emit_node_span_lint (
873- UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES ,
874- tcx. local_def_id_to_hir_id ( item_def_id. expect_local ( ) ) ,
875- self . span ,
876- WrappedParserError { description : e. description , label : e. label } ,
877- ) ;
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+ }
878896 } else {
879897 let reported =
880898 struct_span_code_err ! ( tcx. dcx( ) , self . span, E0231 , "{}" , e. description, ) . emit ( ) ;
0 commit comments