@@ -349,12 +349,14 @@ impl IgnoredDiagnosticOption {
349
349
option_name : & ' static str ,
350
350
) {
351
351
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
+ }
358
360
}
359
361
}
360
362
}
@@ -498,12 +500,14 @@ impl<'tcx> OnUnimplementedDirective {
498
500
}
499
501
500
502
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
+ }
507
511
} else {
508
512
// nothing found
509
513
tcx. dcx ( ) . emit_err ( NoValueInOnUnimplemented { span : item. span ( ) } ) ;
@@ -636,30 +640,38 @@ impl<'tcx> OnUnimplementedDirective {
636
640
AttrArgs :: Eq ( span, AttrArgsEq :: Hir ( expr) ) => span. to ( expr. span ) ,
637
641
} ;
638
642
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
+ }
645
651
Ok ( None )
646
652
}
647
653
} else if is_diagnostic_namespace_variant {
648
654
match & attr. kind {
649
655
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
+ }
656
674
}
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
- ) ,
663
675
} ;
664
676
665
677
Ok ( None )
@@ -788,12 +800,14 @@ impl<'tcx> OnUnimplementedFormatString {
788
800
|| format_spec. precision_span . is_some ( )
789
801
|| format_spec. fill_span . is_some ( ) )
790
802
{
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
+ }
797
811
}
798
812
match a. position {
799
813
Position :: ArgumentNamed ( s) => {
@@ -809,15 +823,17 @@ impl<'tcx> OnUnimplementedFormatString {
809
823
s if generics. params . iter ( ) . any ( |param| param. name == s) => ( ) ,
810
824
s => {
811
825
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
+ }
821
837
} else {
822
838
result = Err ( struct_span_code_err ! (
823
839
tcx. dcx( ) ,
@@ -839,12 +855,14 @@ impl<'tcx> OnUnimplementedFormatString {
839
855
// `{:1}` and `{}` are not to be used
840
856
Position :: ArgumentIs ( ..) | Position :: ArgumentImplicitlyIs ( _) => {
841
857
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
+ }
848
866
} else {
849
867
let reported = struct_span_code_err ! (
850
868
tcx. dcx( ) ,
@@ -867,12 +885,14 @@ impl<'tcx> OnUnimplementedFormatString {
867
885
// so that users are aware that something is not correct
868
886
for e in parser. errors {
869
887
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
+ }
876
896
} else {
877
897
let reported =
878
898
struct_span_code_err ! ( tcx. dcx( ) , self . span, E0231 , "{}" , e. description, ) . emit ( ) ;
0 commit comments