@@ -856,8 +856,15 @@ pub struct UnknownLangItem {
856
856
857
857
pub struct InvalidAttrAtCrateLevel {
858
858
pub span : Span ,
859
- pub snippet : Option < String > ,
859
+ pub sugg_span : Option < Span > ,
860
860
pub name : Symbol ,
861
+ pub item : Option < ItemFollowingInnerAttr > ,
862
+ }
863
+
864
+ #[ derive( Clone , Copy ) ]
865
+ pub struct ItemFollowingInnerAttr {
866
+ pub span : Span ,
867
+ pub kind : & ' static str ,
861
868
}
862
869
863
870
impl IntoDiagnostic < ' _ > for InvalidAttrAtCrateLevel {
@@ -871,15 +878,18 @@ impl IntoDiagnostic<'_> for InvalidAttrAtCrateLevel {
871
878
diag. set_arg ( "name" , self . name ) ;
872
879
// Only emit an error with a suggestion if we can create a string out
873
880
// of the attribute span
874
- if let Some ( src) = self . snippet {
875
- let replacement = src. replace ( "#!" , "#" ) ;
881
+ if let Some ( span) = self . sugg_span {
876
882
diag. span_suggestion_verbose (
877
- self . span ,
883
+ span,
878
884
fluent:: passes_suggestion,
879
- replacement ,
885
+ String :: new ( ) ,
880
886
rustc_errors:: Applicability :: MachineApplicable ,
881
887
) ;
882
888
}
889
+ if let Some ( item) = self . item {
890
+ diag. set_arg ( "kind" , item. kind ) ;
891
+ diag. span_label ( item. span , fluent:: passes_invalid_attr_at_crate_level_item) ;
892
+ }
883
893
diag
884
894
}
885
895
}
0 commit comments