@@ -6,11 +6,9 @@ use std::collections::{BTreeMap, HashSet};
66
77use kani_metadata:: { CbmcSolver , HarnessAttributes , HarnessKind , Stub } ;
88use quote:: ToTokens ;
9- use rustc_ast:: {
10- AttrArgs , AttrArgsEq , AttrKind , Attribute , ExprKind , LitKind , MetaItem , MetaItemKind , attr,
11- } ;
9+ use rustc_ast:: { LitKind , MetaItem , MetaItemKind , attr} ;
1210use rustc_errors:: ErrorGuaranteed ;
13- use rustc_hir:: { def:: DefKind , def_id:: DefId } ;
11+ use rustc_hir:: { AttrArgs , AttrKind , Attribute , def:: DefKind , def_id:: DefId } ;
1412use rustc_middle:: ty:: { Instance , TyCtxt , TyKind } ;
1513use rustc_session:: Session ;
1614use rustc_smir:: rustc_internal;
@@ -673,31 +671,12 @@ fn expect_key_string_value(
673671 attr : & Attribute ,
674672) -> Result < rustc_span:: Symbol , ErrorGuaranteed > {
675673 let span = attr. span ;
676- let AttrArgs :: Eq { eq_span : _ , value } = & attr. get_normal_item ( ) . args else {
674+ let AttrArgs :: Eq { expr , .. } = & attr. get_normal_item ( ) . args else {
677675 return Err ( sess
678676 . dcx ( )
679677 . span_err ( span, "Expected attribute of the form #[attr = \" value\" ]" ) ) ;
680678 } ;
681- let maybe_str = match value {
682- AttrArgsEq :: Ast ( expr) => {
683- if let ExprKind :: Lit ( tok) = expr. kind {
684- match LitKind :: from_token_lit ( tok) {
685- Ok ( l) => l. str ( ) ,
686- Err ( err) => {
687- return Err ( sess. dcx ( ) . span_err (
688- span,
689- format ! ( "Invalid string literal on right hand side of `=` {err:?}" ) ,
690- ) ) ;
691- }
692- }
693- } else {
694- return Err ( sess
695- . dcx ( )
696- . span_err ( span, "Expected literal string as right hand side of `=`" ) ) ;
697- }
698- }
699- AttrArgsEq :: Hir ( lit) => lit. kind . str ( ) ,
700- } ;
679+ let maybe_str = expr. kind . str ( ) ;
701680 if let Some ( str) = maybe_str {
702681 Ok ( str)
703682 } else {
@@ -841,7 +820,7 @@ fn parse_stubs(tcx: TyCtxt, harness: DefId, attributes: &[&Attribute]) -> Vec<St
841820 attributes
842821 . iter ( )
843822 . filter_map ( |attr| {
844- let paths = parse_paths ( attr) . unwrap_or_else ( |_| {
823+ let paths = parse_paths ( tcx , attr) . unwrap_or_else ( |_| {
845824 tcx. dcx ( ) . span_err (
846825 attr. span ,
847826 format ! (
@@ -952,8 +931,8 @@ fn parse_integer(attr: &Attribute) -> Option<u128> {
952931/// Extracts a vector with the path arguments of an attribute.
953932///
954933/// Emits an error if it couldn't convert any of the arguments and return an empty vector.
955- fn parse_paths ( attr : & Attribute ) -> Result < Vec < TypePath > , syn:: Error > {
956- let syn_attr = syn_attr ( attr) ;
934+ fn parse_paths ( tcx : TyCtxt , attr : & Attribute ) -> Result < Vec < TypePath > , syn:: Error > {
935+ let syn_attr = syn_attr ( tcx , attr) ;
957936 let parser = Punctuated :: < TypePath , syn:: Token ![ , ] > :: parse_terminated;
958937 let paths = syn_attr. parse_args_with ( parser) ?;
959938 Ok ( paths. into_iter ( ) . collect ( ) )
@@ -990,11 +969,11 @@ fn parse_str_value(attr: &Attribute) -> Option<String> {
990969fn attr_kind ( tcx : TyCtxt , attr : & Attribute ) -> Option < KaniAttributeKind > {
991970 match & attr. kind {
992971 AttrKind :: Normal ( normal) => {
993- let segments = & normal. item . path . segments ;
994- if ( !segments. is_empty ( ) ) && segments[ 0 ] . ident . as_str ( ) == "kanitool" {
972+ let segments = & normal. path . segments ;
973+ if ( !segments. is_empty ( ) ) && segments[ 0 ] . as_str ( ) == "kanitool" {
995974 let ident_str = segments[ 1 ..]
996975 . iter ( )
997- . map ( |segment| segment. ident . as_str ( ) )
976+ . map ( |segment| segment. as_str ( ) )
998977 . intersperse ( "::" )
999978 . collect :: < String > ( ) ;
1000979 KaniAttributeKind :: try_from ( ident_str. as_str ( ) )
@@ -1014,8 +993,8 @@ fn attr_kind(tcx: TyCtxt, attr: &Attribute) -> Option<KaniAttributeKind> {
1014993/// Parse an attribute using `syn`.
1015994///
1016995/// This provides a user-friendly interface to manipulate than the internal compiler AST.
1017- fn syn_attr ( attr : & Attribute ) -> syn:: Attribute {
1018- let attr_str = rustc_ast_pretty :: pprust :: attribute_to_string ( attr) ;
996+ fn syn_attr ( tcx : TyCtxt , attr : & Attribute ) -> syn:: Attribute {
997+ let attr_str = rustc_hir_pretty :: attribute_to_string ( & tcx , attr) ;
1019998 let parser = syn:: Attribute :: parse_outer;
1020999 parser. parse_str ( & attr_str) . unwrap ( ) . pop ( ) . unwrap ( )
10211000}
0 commit comments