@@ -8,7 +8,7 @@ use kani_metadata::{CbmcSolver, HarnessAttributes, HarnessKind, Stub};
88use quote:: ToTokens ;
99use rustc_ast:: { LitKind , MetaItem , MetaItemKind , attr} ;
1010use rustc_errors:: ErrorGuaranteed ;
11- use rustc_hir:: { AttrArgs , AttrKind , Attribute , def:: DefKind , def_id:: DefId } ;
11+ use rustc_hir:: { AttrArgs , Attribute , def:: DefKind , def_id:: DefId } ;
1212use rustc_middle:: ty:: { Instance , TyCtxt , TyKind } ;
1313use rustc_session:: Session ;
1414use rustc_smir:: rustc_internal;
@@ -214,7 +214,7 @@ impl<'tcx> KaniAttributes<'tcx> {
214214 . resolve_from_mod ( name. as_str ( ) )
215215 . map_err ( |e| {
216216 let mut err = self . tcx . dcx ( ) . struct_span_err (
217- attr. span ,
217+ attr. span ( ) ,
218218 format ! (
219219 "Failed to resolve replacement function {}: {e}" ,
220220 name. as_str( )
@@ -229,7 +229,7 @@ impl<'tcx> KaniAttributes<'tcx> {
229229 err. emit ( ) ;
230230 } )
231231 . ok ( ) ?;
232- Some ( ( name, def, attr. span ) )
232+ Some ( ( name, def, attr. span ( ) ) )
233233 } )
234234 . collect ( )
235235 }
@@ -247,10 +247,10 @@ impl<'tcx> KaniAttributes<'tcx> {
247247 self . expect_maybe_one ( KaniAttributeKind :: ProofForContract ) . and_then ( |target| {
248248 let name = expect_key_string_value ( self . tcx . sess , target) . ok ( ) ?;
249249 self . resolve_from_mod ( name. as_str ( ) )
250- . map ( |ok| ( name, ok, target. span ) )
250+ . map ( |ok| ( name, ok, target. span ( ) ) )
251251 . map_err ( |resolve_err| {
252252 let mut err = self . tcx . dcx ( ) . struct_span_err (
253- target. span ,
253+ target. span ( ) ,
254254 format ! (
255255 "Failed to resolve checking function {} because {resolve_err}" ,
256256 name. as_str( )
@@ -336,7 +336,7 @@ impl<'tcx> KaniAttributes<'tcx> {
336336 // Check that all attributes are correctly used and well formed.
337337 let is_harness = self . is_proof_harness ( ) ;
338338 for ( & kind, attrs) in self . map . iter ( ) {
339- let local_error = |msg| self . tcx . dcx ( ) . span_err ( attrs[ 0 ] . span , msg) ;
339+ let local_error = |msg| self . tcx . dcx ( ) . span_err ( attrs[ 0 ] . span ( ) , msg) ;
340340
341341 if !is_harness && kind. is_harness_only ( ) {
342342 local_error ( format ! (
@@ -451,7 +451,7 @@ impl<'tcx> KaniAttributes<'tcx> {
451451 kind. as_ref( )
452452 ) ;
453453 if let Some ( attr) = self . map . get ( & kind) . unwrap ( ) . first ( ) {
454- self . tcx . dcx ( ) . span_err ( attr. span , msg) ;
454+ self . tcx . dcx ( ) . span_err ( attr. span ( ) , msg) ;
455455 } else {
456456 self . tcx . dcx ( ) . err ( msg) ;
457457 }
@@ -646,7 +646,7 @@ impl<'tcx> KaniAttributes<'tcx> {
646646
647647 /// Check that if this item is tagged with a proof_attribute, it is a valid harness.
648648 fn check_proof_attribute ( & self , kind : KaniAttributeKind , proof_attribute : & Attribute ) {
649- let span = proof_attribute. span ;
649+ let span = proof_attribute. span ( ) ;
650650 let tcx = self . tcx ;
651651 if let KaniAttributeKind :: Proof = kind {
652652 expect_no_args ( tcx, kind, proof_attribute) ;
@@ -719,7 +719,7 @@ fn expect_key_string_value(
719719 sess : & Session ,
720720 attr : & Attribute ,
721721) -> Result < rustc_span:: Symbol , ErrorGuaranteed > {
722- let span = attr. span ;
722+ let span = attr. span ( ) ;
723723 let AttrArgs :: Eq { expr, .. } = & attr. get_normal_item ( ) . args else {
724724 return Err ( sess
725725 . dcx ( )
@@ -743,7 +743,7 @@ fn expect_single<'a>(
743743 . expect ( & format ! ( "expected at least one attribute {} in {attributes:?}" , kind. as_ref( ) ) ) ;
744744 if attributes. len ( ) > 1 {
745745 tcx. dcx ( ) . span_err (
746- attr. span ,
746+ attr. span ( ) ,
747747 format ! ( "only one '#[kani::{}]' attribute is allowed per harness" , kind. as_ref( ) ) ,
748748 ) ;
749749 }
@@ -774,7 +774,7 @@ impl UnstableAttrParseError<'_> {
774774 fn report ( & self , tcx : TyCtxt ) -> ErrorGuaranteed {
775775 tcx. dcx ( )
776776 . struct_span_err (
777- self . attr . span ,
777+ self . attr . span ( ) ,
778778 format ! ( "failed to parse `#[kani::unstable_feature]`: {}" , self . reason) ,
779779 )
780780 . with_note ( format ! (
@@ -817,7 +817,7 @@ impl<'a> TryFrom<&'a Attribute> for UnstableAttribute {
817817fn expect_no_args ( tcx : TyCtxt , kind : KaniAttributeKind , attr : & Attribute ) {
818818 if !attr. is_word ( ) {
819819 tcx. dcx ( )
820- . struct_span_err ( attr. span , format ! ( "unexpected argument for `{}`" , kind. as_ref( ) ) )
820+ . struct_span_err ( attr. span ( ) , format ! ( "unexpected argument for `{}`" , kind. as_ref( ) ) )
821821 . with_help ( "remove the extra argument" )
822822 . emit ( ) ;
823823 }
@@ -830,7 +830,7 @@ fn parse_unwind(tcx: TyCtxt, attr: &Attribute) -> Option<u32> {
830830 None => {
831831 // There are no integers or too many arguments given to the attribute
832832 tcx. dcx ( ) . span_err (
833- attr. span ,
833+ attr. span ( ) ,
834834 "invalid argument for `unwind` attribute, expected an integer" ,
835835 ) ;
836836 None
@@ -839,7 +839,7 @@ fn parse_unwind(tcx: TyCtxt, attr: &Attribute) -> Option<u32> {
839839 if let Ok ( val) = unwind_integer_value. try_into ( ) {
840840 Some ( val)
841841 } else {
842- tcx. dcx ( ) . span_err ( attr. span , "value above maximum permitted value - u32::MAX" ) ;
842+ tcx. dcx ( ) . span_err ( attr. span ( ) , "value above maximum permitted value - u32::MAX" ) ;
843843 None
844844 }
845845 }
@@ -854,13 +854,13 @@ fn parse_stubs(tcx: TyCtxt, harness: DefId, attributes: &[&Attribute]) -> Vec<St
854854 Ok ( FnResolution :: Fn ( _) ) => { /* no-op */ }
855855 Ok ( FnResolution :: FnImpl { .. } ) => {
856856 tcx. dcx ( ) . span_err (
857- attr. span ,
857+ attr. span ( ) ,
858858 "Kani currently does not support stubbing trait implementations." ,
859859 ) ;
860860 }
861861 Err ( err) => {
862862 tcx. dcx ( ) . span_err (
863- attr. span ,
863+ attr. span ( ) ,
864864 format ! ( "failed to resolve `{}`: {err}" , pretty_type_path( path) ) ,
865865 ) ;
866866 }
@@ -871,7 +871,7 @@ fn parse_stubs(tcx: TyCtxt, harness: DefId, attributes: &[&Attribute]) -> Vec<St
871871 . filter_map ( |attr| {
872872 let paths = parse_paths ( tcx, attr) . unwrap_or_else ( |_| {
873873 tcx. dcx ( ) . span_err (
874- attr. span ,
874+ attr. span ( ) ,
875875 format ! (
876876 "attribute `kani::{}` takes two path arguments; found argument that is not a path" ,
877877 KaniAttributeKind :: Stub . as_ref( ) )
@@ -893,7 +893,7 @@ fn parse_stubs(tcx: TyCtxt, harness: DefId, attributes: &[&Attribute]) -> Vec<St
893893 }
894894 _ => {
895895 tcx. dcx ( ) . span_err (
896- attr. span ,
896+ attr. span ( ) ,
897897 format ! (
898898 "attribute `kani::stub` takes two path arguments; found {}" ,
899899 paths. len( )
@@ -912,15 +912,15 @@ fn parse_solver(tcx: TyCtxt, attr: &Attribute) -> Option<CbmcSolver> {
912912 const ATTRIBUTE : & str = "#[kani::solver]" ;
913913 let invalid_arg_err = |attr : & Attribute | {
914914 tcx. dcx ( ) . span_err (
915- attr. span ,
915+ attr. span ( ) ,
916916 format ! ( "invalid argument for `{ATTRIBUTE}` attribute, expected one of the supported solvers (e.g. `kissat`) or a SAT solver binary (e.g. `bin=\" <SAT_SOLVER_BINARY>\" `)" ) ,
917917 )
918918 } ;
919919
920920 let attr_args = attr. meta_item_list ( ) . unwrap ( ) ;
921921 if attr_args. len ( ) != 1 {
922922 tcx. dcx ( ) . span_err (
923- attr. span ,
923+ attr. span ( ) ,
924924 format ! (
925925 "the `{ATTRIBUTE}` attribute expects a single argument. Got {} arguments." ,
926926 attr_args. len( )
@@ -943,7 +943,7 @@ fn parse_solver(tcx: TyCtxt, attr: &Attribute) -> Option<CbmcSolver> {
943943 match solver {
944944 Ok ( solver) => Some ( solver) ,
945945 Err ( _) => {
946- tcx. dcx ( ) . span_err ( attr. span , format ! ( "unknown solver `{ident_str}`" ) ) ;
946+ tcx. dcx ( ) . span_err ( attr. span ( ) , format ! ( "unknown solver `{ident_str}`" ) ) ;
947947 None
948948 }
949949 }
@@ -1016,27 +1016,47 @@ fn parse_str_value(attr: &Attribute) -> Option<String> {
10161016
10171017/// If the attribute is named `kanitool::name`, this extracts `name`
10181018fn attr_kind ( tcx : TyCtxt , attr : & Attribute ) -> Option < KaniAttributeKind > {
1019- match & attr. kind {
1020- AttrKind :: Normal ( normal) => {
1021- let segments = & normal. path . segments ;
1022- if ( !segments. is_empty ( ) ) && segments[ 0 ] . as_str ( ) == "kanitool" {
1023- let ident_str = segments[ 1 ..]
1024- . iter ( )
1025- . map ( |segment| segment. as_str ( ) )
1026- . intersperse ( "::" )
1027- . collect :: < String > ( ) ;
1028- KaniAttributeKind :: try_from ( ident_str. as_str ( ) )
1029- . inspect_err ( |& err| {
1030- debug ! ( ?err, "attr_kind_failed" ) ;
1031- tcx. dcx ( ) . span_err ( attr. span , format ! ( "unknown attribute `{ident_str}`" ) ) ;
1032- } )
1033- . ok ( )
1034- } else {
1035- None
1036- }
1019+ if let Attribute :: Unparsed ( normal) = attr {
1020+ let segments = & normal. path . segments ;
1021+ if ( !segments. is_empty ( ) ) && segments[ 0 ] . as_str ( ) == "kanitool" {
1022+ let ident_str = segments[ 1 ..]
1023+ . iter ( )
1024+ . map ( |segment| segment. as_str ( ) )
1025+ . intersperse ( "::" )
1026+ . collect :: < String > ( ) ;
1027+ KaniAttributeKind :: try_from ( ident_str. as_str ( ) )
1028+ . inspect_err ( |& err| {
1029+ debug ! ( ?err, "attr_kind_failed" ) ;
1030+ tcx. dcx ( ) . span_err ( attr. span ( ) , format ! ( "unknown attribute `{ident_str}`" ) ) ;
1031+ } )
1032+ . ok ( )
1033+ } else {
1034+ None
10371035 }
1038- _ => None ,
1036+ } else {
1037+ None
10391038 }
1039+ // match &attr.kind {
1040+ // AttrKind::Normal(normal) => {
1041+ // let segments = &normal.path.segments;
1042+ // if (!segments.is_empty()) && segments[0].as_str() == "kanitool" {
1043+ // let ident_str = segments[1..]
1044+ // .iter()
1045+ // .map(|segment| segment.as_str())
1046+ // .intersperse("::")
1047+ // .collect::<String>();
1048+ // KaniAttributeKind::try_from(ident_str.as_str())
1049+ // .inspect_err(|&err| {
1050+ // debug!(?err, "attr_kind_failed");
1051+ // tcx.dcx().span_err(attr.span(), format!("unknown attribute `{ident_str}`"));
1052+ // })
1053+ // .ok()
1054+ // } else {
1055+ // None
1056+ // }
1057+ // }
1058+ // _ => None,
1059+ // }
10401060}
10411061
10421062/// Parse an attribute using `syn`.
@@ -1099,7 +1119,7 @@ fn pretty_type_path(path: &TypePath) -> String {
10991119/// Retrieve the value of the `fn_marker` attribute for the given definition if it has one.
11001120pub ( crate ) fn fn_marker < T : CrateDef > ( def : T ) -> Option < String > {
11011121 let fn_marker: [ SymbolStable ; 2 ] = [ "kanitool" . into ( ) , "fn_marker" . into ( ) ] ;
1102- let marker = def. attrs_by_path ( & fn_marker) . pop ( ) ?;
1122+ let marker = def. tool_attrs ( & fn_marker) . pop ( ) ?;
11031123 let attribute = syn_attr_stable ( & marker) ;
11041124 let meta_name = attribute. meta . require_name_value ( ) . unwrap_or_else ( |_| {
11051125 panic ! ( "Expected name value attribute for `kanitool::fn_marker`, but found: `{:?}`" , marker)
0 commit comments