@@ -843,12 +843,28 @@ pub(crate) fn get_publish(
843
843
}
844
844
}
845
845
846
+ // Only those relevant to classifying an item as external / not external
847
+ // (external_body is relevant because it means anything on the inside of the item should
848
+ // be external)
849
+ #[ derive( Debug ) ]
850
+ pub ( crate ) struct ExternalAttrs {
851
+ pub ( crate ) external : bool ,
852
+ pub ( crate ) external_body : bool ,
853
+ pub ( crate ) external_fn_specification : bool ,
854
+ pub ( crate ) external_type_specification : bool ,
855
+ pub ( crate ) external_trait_specification : bool ,
856
+ pub ( crate ) sets_mode : bool ,
857
+ pub ( crate ) verify : bool ,
858
+ pub ( crate ) verus_macro : bool ,
859
+ pub ( crate ) size_of_global : bool ,
860
+ pub ( crate ) any_other_verus_specific_attribute : bool ,
861
+ pub ( crate ) internal_get_field_many_variants : bool ,
862
+ }
863
+
846
864
#[ derive( Debug ) ]
847
865
pub ( crate ) struct VerifierAttrs {
848
866
pub ( crate ) verus_macro : bool ,
849
867
pub ( crate ) external_body : bool ,
850
- pub ( crate ) external : bool ,
851
- pub ( crate ) verify : bool ,
852
868
pub ( crate ) opaque : bool ,
853
869
pub ( crate ) publish : Option < bool > ,
854
870
pub ( crate ) opaque_outside_module : bool ,
@@ -896,20 +912,6 @@ pub(crate) struct VerifierAttrs {
896
912
pub ( crate ) type_invariant_fn : bool ,
897
913
}
898
914
899
- impl VerifierAttrs {
900
- pub ( crate ) fn is_external ( & self , cmd_line_args : & crate :: config:: Args ) -> bool {
901
- self . external
902
- || !( cmd_line_args. no_external_by_default
903
- || self . verus_macro
904
- || self . external_body
905
- || self . external_fn_specification
906
- || self . external_type_specification
907
- || self . external_trait_specification . is_some ( )
908
- || self . verify
909
- || self . sets_mode )
910
- }
911
- }
912
-
913
915
// Check for the `get_field_many_variants` attribute
914
916
// Skips additional checks that are meant to be applied only during the 'main' processing
915
917
// of an item.
@@ -946,16 +948,55 @@ pub(crate) fn is_sealed(
946
948
Ok ( false )
947
949
}
948
950
951
+ /// Get the attributes needed to determine if the item is external.
952
+ pub ( crate ) fn get_external_attrs (
953
+ attrs : & [ Attribute ] ,
954
+ diagnostics : Option < & mut Vec < VirErrAs > > ,
955
+ ) -> Result < ExternalAttrs , VirErr > {
956
+ let mut es = ExternalAttrs {
957
+ external_body : false ,
958
+ external_fn_specification : false ,
959
+ external_type_specification : false ,
960
+ external_trait_specification : false ,
961
+ external : false ,
962
+ verify : false ,
963
+ sets_mode : false ,
964
+ verus_macro : false ,
965
+ size_of_global : false ,
966
+ any_other_verus_specific_attribute : false ,
967
+ internal_get_field_many_variants : false ,
968
+ } ;
969
+
970
+ for attr in parse_attrs ( attrs, diagnostics) ? {
971
+ match attr {
972
+ Attr :: ExternalBody => es. external_body = true ,
973
+ Attr :: ExternalFnSpecification => es. external_fn_specification = true ,
974
+ Attr :: ExternalTypeSpecification => es. external_type_specification = true ,
975
+ Attr :: ExternalTraitSpecification ( _) => es. external_trait_specification = true ,
976
+ Attr :: External => es. external = true ,
977
+ Attr :: Verify => es. verify = true ,
978
+ Attr :: Mode ( _) => es. sets_mode = true ,
979
+ Attr :: VerusMacro => es. verus_macro = true ,
980
+ Attr :: SizeOfGlobal => es. size_of_global = true ,
981
+ Attr :: InternalGetFieldManyVariants => es. internal_get_field_many_variants = true ,
982
+ Attr :: Trusted => { }
983
+ Attr :: UnsupportedRustcAttr ( ..) => { }
984
+ _ => {
985
+ es. any_other_verus_specific_attribute = true ;
986
+ }
987
+ }
988
+ }
989
+
990
+ return Ok ( es) ;
991
+ }
992
+
949
993
pub ( crate ) fn get_verifier_attrs (
950
994
attrs : & [ Attribute ] ,
951
995
diagnostics : Option < & mut Vec < VirErrAs > > ,
952
- cmd_line_args : Option < & crate :: config:: Args > ,
953
996
) -> Result < VerifierAttrs , VirErr > {
954
997
let mut vs = VerifierAttrs {
955
998
verus_macro : false ,
956
999
external_body : false ,
957
- external : false ,
958
- verify : false ,
959
1000
opaque : false ,
960
1001
publish : None ,
961
1002
opaque_outside_module : false ,
@@ -1006,8 +1047,6 @@ pub(crate) fn get_verifier_attrs(
1006
1047
match attr {
1007
1048
Attr :: VerusMacro => vs. verus_macro = true ,
1008
1049
Attr :: ExternalBody => vs. external_body = true ,
1009
- Attr :: External => vs. external = true ,
1010
- Attr :: Verify => vs. verify = true ,
1011
1050
Attr :: ExternalFnSpecification => vs. external_fn_specification = true ,
1012
1051
Attr :: ExternalTypeSpecification => vs. external_type_specification = true ,
1013
1052
Attr :: ExternalTraitSpecification ( assoc) => {
@@ -1072,24 +1111,8 @@ pub(crate) fn get_verifier_attrs(
1072
1111
_ => { }
1073
1112
}
1074
1113
}
1075
- if attrs. len ( ) > 0 {
1076
- let span = attrs[ 0 ] . span ;
1077
- let mismatches = vec ! [
1078
- ( "inside verus macro" , "`verify`" , vs. verus_macro, vs. verify) ,
1079
- ( "`external`" , "`verify`" , vs. external, vs. verify) ,
1080
- ( "`external_body`" , "`verify`" , vs. external_body, vs. verify) ,
1081
- ( "`external_body`" , "`external`" , vs. external_body, vs. external) ,
1082
- ] ;
1083
- for ( msg1, msg2, flag1, flag2) in mismatches {
1084
- if flag1 && flag2 {
1085
- return err_span ( span, format ! ( "item cannot be both {msg1} and {msg2}" , ) ) ;
1086
- }
1087
- }
1088
- }
1089
1114
if let Some ( ( rustc_attr, span) ) = unsupported_rustc_attr {
1090
- if cmd_line_args. is_none ( ) || !vs. is_external ( cmd_line_args. unwrap ( ) ) {
1091
- return err_span ( span, format ! ( "The attribute `{rustc_attr:}` is not supported" ) ) ;
1092
- }
1115
+ return err_span ( span, format ! ( "The attribute `{rustc_attr:}` is not supported" ) ) ;
1093
1116
}
1094
1117
Ok ( vs)
1095
1118
}
0 commit comments