@@ -8,7 +8,7 @@ use kani_metadata::{CbmcSolver, HarnessAttributes, HarnessKind, Stub};
8
8
use quote:: ToTokens ;
9
9
use rustc_ast:: { LitKind , MetaItem , MetaItemKind , attr} ;
10
10
use 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 } ;
12
12
use rustc_middle:: ty:: { Instance , TyCtxt , TyKind } ;
13
13
use rustc_session:: Session ;
14
14
use rustc_smir:: rustc_internal;
@@ -214,7 +214,7 @@ impl<'tcx> KaniAttributes<'tcx> {
214
214
. resolve_from_mod ( name. as_str ( ) )
215
215
. map_err ( |e| {
216
216
let mut err = self . tcx . dcx ( ) . struct_span_err (
217
- attr. span ,
217
+ attr. span ( ) ,
218
218
format ! (
219
219
"Failed to resolve replacement function {}: {e}" ,
220
220
name. as_str( )
@@ -229,7 +229,7 @@ impl<'tcx> KaniAttributes<'tcx> {
229
229
err. emit ( ) ;
230
230
} )
231
231
. ok ( ) ?;
232
- Some ( ( name, def, attr. span ) )
232
+ Some ( ( name, def, attr. span ( ) ) )
233
233
} )
234
234
. collect ( )
235
235
}
@@ -247,10 +247,10 @@ impl<'tcx> KaniAttributes<'tcx> {
247
247
self . expect_maybe_one ( KaniAttributeKind :: ProofForContract ) . and_then ( |target| {
248
248
let name = expect_key_string_value ( self . tcx . sess , target) . ok ( ) ?;
249
249
self . resolve_from_mod ( name. as_str ( ) )
250
- . map ( |ok| ( name, ok, target. span ) )
250
+ . map ( |ok| ( name, ok, target. span ( ) ) )
251
251
. map_err ( |resolve_err| {
252
252
let mut err = self . tcx . dcx ( ) . struct_span_err (
253
- target. span ,
253
+ target. span ( ) ,
254
254
format ! (
255
255
"Failed to resolve checking function {} because {resolve_err}" ,
256
256
name. as_str( )
@@ -336,7 +336,7 @@ impl<'tcx> KaniAttributes<'tcx> {
336
336
// Check that all attributes are correctly used and well formed.
337
337
let is_harness = self . is_proof_harness ( ) ;
338
338
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) ;
340
340
341
341
if !is_harness && kind. is_harness_only ( ) {
342
342
local_error ( format ! (
@@ -451,7 +451,7 @@ impl<'tcx> KaniAttributes<'tcx> {
451
451
kind. as_ref( )
452
452
) ;
453
453
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) ;
455
455
} else {
456
456
self . tcx . dcx ( ) . err ( msg) ;
457
457
}
@@ -646,7 +646,7 @@ impl<'tcx> KaniAttributes<'tcx> {
646
646
647
647
/// Check that if this item is tagged with a proof_attribute, it is a valid harness.
648
648
fn check_proof_attribute ( & self , kind : KaniAttributeKind , proof_attribute : & Attribute ) {
649
- let span = proof_attribute. span ;
649
+ let span = proof_attribute. span ( ) ;
650
650
let tcx = self . tcx ;
651
651
if let KaniAttributeKind :: Proof = kind {
652
652
expect_no_args ( tcx, kind, proof_attribute) ;
@@ -719,7 +719,7 @@ fn expect_key_string_value(
719
719
sess : & Session ,
720
720
attr : & Attribute ,
721
721
) -> Result < rustc_span:: Symbol , ErrorGuaranteed > {
722
- let span = attr. span ;
722
+ let span = attr. span ( ) ;
723
723
let AttrArgs :: Eq { expr, .. } = & attr. get_normal_item ( ) . args else {
724
724
return Err ( sess
725
725
. dcx ( )
@@ -743,7 +743,7 @@ fn expect_single<'a>(
743
743
. expect ( & format ! ( "expected at least one attribute {} in {attributes:?}" , kind. as_ref( ) ) ) ;
744
744
if attributes. len ( ) > 1 {
745
745
tcx. dcx ( ) . span_err (
746
- attr. span ,
746
+ attr. span ( ) ,
747
747
format ! ( "only one '#[kani::{}]' attribute is allowed per harness" , kind. as_ref( ) ) ,
748
748
) ;
749
749
}
@@ -774,7 +774,7 @@ impl UnstableAttrParseError<'_> {
774
774
fn report ( & self , tcx : TyCtxt ) -> ErrorGuaranteed {
775
775
tcx. dcx ( )
776
776
. struct_span_err (
777
- self . attr . span ,
777
+ self . attr . span ( ) ,
778
778
format ! ( "failed to parse `#[kani::unstable_feature]`: {}" , self . reason) ,
779
779
)
780
780
. with_note ( format ! (
@@ -817,7 +817,7 @@ impl<'a> TryFrom<&'a Attribute> for UnstableAttribute {
817
817
fn expect_no_args ( tcx : TyCtxt , kind : KaniAttributeKind , attr : & Attribute ) {
818
818
if !attr. is_word ( ) {
819
819
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( ) ) )
821
821
. with_help ( "remove the extra argument" )
822
822
. emit ( ) ;
823
823
}
@@ -830,7 +830,7 @@ fn parse_unwind(tcx: TyCtxt, attr: &Attribute) -> Option<u32> {
830
830
None => {
831
831
// There are no integers or too many arguments given to the attribute
832
832
tcx. dcx ( ) . span_err (
833
- attr. span ,
833
+ attr. span ( ) ,
834
834
"invalid argument for `unwind` attribute, expected an integer" ,
835
835
) ;
836
836
None
@@ -839,7 +839,7 @@ fn parse_unwind(tcx: TyCtxt, attr: &Attribute) -> Option<u32> {
839
839
if let Ok ( val) = unwind_integer_value. try_into ( ) {
840
840
Some ( val)
841
841
} 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" ) ;
843
843
None
844
844
}
845
845
}
@@ -854,13 +854,13 @@ fn parse_stubs(tcx: TyCtxt, harness: DefId, attributes: &[&Attribute]) -> Vec<St
854
854
Ok ( FnResolution :: Fn ( _) ) => { /* no-op */ }
855
855
Ok ( FnResolution :: FnImpl { .. } ) => {
856
856
tcx. dcx ( ) . span_err (
857
- attr. span ,
857
+ attr. span ( ) ,
858
858
"Kani currently does not support stubbing trait implementations." ,
859
859
) ;
860
860
}
861
861
Err ( err) => {
862
862
tcx. dcx ( ) . span_err (
863
- attr. span ,
863
+ attr. span ( ) ,
864
864
format ! ( "failed to resolve `{}`: {err}" , pretty_type_path( path) ) ,
865
865
) ;
866
866
}
@@ -871,7 +871,7 @@ fn parse_stubs(tcx: TyCtxt, harness: DefId, attributes: &[&Attribute]) -> Vec<St
871
871
. filter_map ( |attr| {
872
872
let paths = parse_paths ( tcx, attr) . unwrap_or_else ( |_| {
873
873
tcx. dcx ( ) . span_err (
874
- attr. span ,
874
+ attr. span ( ) ,
875
875
format ! (
876
876
"attribute `kani::{}` takes two path arguments; found argument that is not a path" ,
877
877
KaniAttributeKind :: Stub . as_ref( ) )
@@ -893,7 +893,7 @@ fn parse_stubs(tcx: TyCtxt, harness: DefId, attributes: &[&Attribute]) -> Vec<St
893
893
}
894
894
_ => {
895
895
tcx. dcx ( ) . span_err (
896
- attr. span ,
896
+ attr. span ( ) ,
897
897
format ! (
898
898
"attribute `kani::stub` takes two path arguments; found {}" ,
899
899
paths. len( )
@@ -912,15 +912,15 @@ fn parse_solver(tcx: TyCtxt, attr: &Attribute) -> Option<CbmcSolver> {
912
912
const ATTRIBUTE : & str = "#[kani::solver]" ;
913
913
let invalid_arg_err = |attr : & Attribute | {
914
914
tcx. dcx ( ) . span_err (
915
- attr. span ,
915
+ attr. span ( ) ,
916
916
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>\" `)" ) ,
917
917
)
918
918
} ;
919
919
920
920
let attr_args = attr. meta_item_list ( ) . unwrap ( ) ;
921
921
if attr_args. len ( ) != 1 {
922
922
tcx. dcx ( ) . span_err (
923
- attr. span ,
923
+ attr. span ( ) ,
924
924
format ! (
925
925
"the `{ATTRIBUTE}` attribute expects a single argument. Got {} arguments." ,
926
926
attr_args. len( )
@@ -943,7 +943,7 @@ fn parse_solver(tcx: TyCtxt, attr: &Attribute) -> Option<CbmcSolver> {
943
943
match solver {
944
944
Ok ( solver) => Some ( solver) ,
945
945
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}`" ) ) ;
947
947
None
948
948
}
949
949
}
@@ -1016,27 +1016,47 @@ fn parse_str_value(attr: &Attribute) -> Option<String> {
1016
1016
1017
1017
/// If the attribute is named `kanitool::name`, this extracts `name`
1018
1018
fn 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
1037
1035
}
1038
- _ => None ,
1036
+ } else {
1037
+ None
1039
1038
}
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
+ // }
1040
1060
}
1041
1061
1042
1062
/// Parse an attribute using `syn`.
@@ -1099,7 +1119,7 @@ fn pretty_type_path(path: &TypePath) -> String {
1099
1119
/// Retrieve the value of the `fn_marker` attribute for the given definition if it has one.
1100
1120
pub ( crate ) fn fn_marker < T : CrateDef > ( def : T ) -> Option < String > {
1101
1121
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 ( ) ?;
1103
1123
let attribute = syn_attr_stable ( & marker) ;
1104
1124
let meta_name = attribute. meta . require_name_value ( ) . unwrap_or_else ( |_| {
1105
1125
panic ! ( "Expected name value attribute for `kanitool::fn_marker`, but found: `{:?}`" , marker)
0 commit comments