@@ -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
}
@@ -638,30 +640,38 @@ impl<'tcx> OnUnimplementedDirective {
638
640
AttrArgs :: Eq ( span, AttrArgsEq :: Hir ( expr) ) => span. to ( expr. span ) ,
639
641
} ;
640
642
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
+ }
647
651
Ok ( None )
648
652
}
649
653
} else if is_diagnostic_namespace_variant {
650
654
match & attr. kind {
651
655
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
+ }
658
674
}
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
- ) ,
665
675
} ;
666
676
667
677
Ok ( None )
@@ -790,12 +800,14 @@ impl<'tcx> OnUnimplementedFormatString {
790
800
|| format_spec. precision_span . is_some ( )
791
801
|| format_spec. fill_span . is_some ( ) )
792
802
{
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
+ }
799
811
}
800
812
match a. position {
801
813
Position :: ArgumentNamed ( s) => {
@@ -811,15 +823,17 @@ impl<'tcx> OnUnimplementedFormatString {
811
823
s if generics. params . iter ( ) . any ( |param| param. name == s) => ( ) ,
812
824
s => {
813
825
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
+ }
823
837
} else {
824
838
result = Err ( struct_span_code_err ! (
825
839
tcx. dcx( ) ,
@@ -841,12 +855,14 @@ impl<'tcx> OnUnimplementedFormatString {
841
855
// `{:1}` and `{}` are not to be used
842
856
Position :: ArgumentIs ( ..) | Position :: ArgumentImplicitlyIs ( _) => {
843
857
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
+ }
850
866
} else {
851
867
let reported = struct_span_code_err ! (
852
868
tcx. dcx( ) ,
@@ -869,12 +885,14 @@ impl<'tcx> OnUnimplementedFormatString {
869
885
// so that users are aware that something is not correct
870
886
for e in parser. errors {
871
887
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
+ }
878
896
} else {
879
897
let reported =
880
898
struct_span_code_err ! ( tcx. dcx( ) , self . span, E0231 , "{}" , e. description, ) . emit ( ) ;
0 commit comments