@@ -5,6 +5,7 @@ use std::{fmt, iter};
55
66use arrayvec:: ArrayVec ;
77use rustc_abi:: { ExternAbi , VariantIdx } ;
8+ use rustc_ast:: AttrStyle ;
89use rustc_attr_parsing:: { AttributeKind , ConstStability , Deprecation , Stability , StableSince } ;
910use rustc_data_structures:: fx:: { FxHashSet , FxIndexMap , FxIndexSet } ;
1011use rustc_hir:: def:: { CtorKind , DefKind , Res } ;
@@ -759,13 +760,20 @@ impl Item {
759760 Some ( tcx. visibility ( def_id) )
760761 }
761762
762- pub ( crate ) fn attributes ( & self , tcx : TyCtxt < ' _ > , cache : & Cache , is_json : bool ) -> Vec < String > {
763+ /// Returns a Vec of stringified attributes with a boolean set to `true` if it's an inner
764+ /// attribute.
765+ pub ( crate ) fn attributes (
766+ & self ,
767+ tcx : TyCtxt < ' _ > ,
768+ cache : & Cache ,
769+ is_json : bool ,
770+ ) -> Vec < ( bool , String ) > {
763771 const ALLOWED_ATTRIBUTES : & [ Symbol ] =
764772 & [ sym:: export_name, sym:: link_section, sym:: no_mangle, sym:: non_exhaustive] ;
765773
766774 use rustc_abi:: IntegerType ;
767775
768- let mut attrs: Vec < String > = self
776+ let mut attrs: Vec < ( bool , String ) > = self
769777 . attrs
770778 . other_attrs
771779 . iter ( )
@@ -786,15 +794,19 @@ impl Item {
786794 // because it isn't public API.
787795 None
788796 }
789- _ => Some ( rustc_hir_pretty:: attribute_to_string ( & tcx, attr) ) ,
797+ _ => Some ( (
798+ attr. opt_style ( ) == Some ( AttrStyle :: Inner ) ,
799+ rustc_hir_pretty:: attribute_to_string ( & tcx, attr) ,
800+ ) ) ,
790801 }
791802 } else if attr. has_any_name ( ALLOWED_ATTRIBUTES ) {
792- Some (
803+ Some ( (
804+ attr. opt_style ( ) == Some ( AttrStyle :: Inner ) ,
793805 rustc_hir_pretty:: attribute_to_string ( & tcx, attr)
794806 . replace ( "\\ \n " , "" )
795807 . replace ( '\n' , "" )
796808 . replace ( " " , " " ) ,
797- )
809+ ) )
798810 } else {
799811 None
800812 }
@@ -860,7 +872,7 @@ impl Item {
860872 out. push ( & int_s) ;
861873 }
862874 if !out. is_empty ( ) {
863- attrs. push ( format ! ( "#[repr({})]" , out. join( ", " ) ) ) ;
875+ attrs. push ( ( false , format ! ( "#[repr({})]" , out. join( ", " ) ) ) ) ;
864876 }
865877 }
866878 attrs
0 commit comments