@@ -6,11 +6,9 @@ use std::collections::{BTreeMap, HashSet};
6
6
7
7
use kani_metadata:: { CbmcSolver , HarnessAttributes , HarnessKind , Stub } ;
8
8
use 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} ;
12
10
use rustc_errors:: ErrorGuaranteed ;
13
- use rustc_hir:: { def:: DefKind , def_id:: DefId } ;
11
+ use rustc_hir:: { AttrArgs , AttrKind , Attribute , def:: DefKind , def_id:: DefId } ;
14
12
use rustc_middle:: ty:: { Instance , TyCtxt , TyKind } ;
15
13
use rustc_session:: Session ;
16
14
use rustc_smir:: rustc_internal;
@@ -673,31 +671,12 @@ fn expect_key_string_value(
673
671
attr : & Attribute ,
674
672
) -> Result < rustc_span:: Symbol , ErrorGuaranteed > {
675
673
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 {
677
675
return Err ( sess
678
676
. dcx ( )
679
677
. span_err ( span, "Expected attribute of the form #[attr = \" value\" ]" ) ) ;
680
678
} ;
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 ( ) ;
701
680
if let Some ( str) = maybe_str {
702
681
Ok ( str)
703
682
} else {
@@ -841,7 +820,7 @@ fn parse_stubs(tcx: TyCtxt, harness: DefId, attributes: &[&Attribute]) -> Vec<St
841
820
attributes
842
821
. iter ( )
843
822
. filter_map ( |attr| {
844
- let paths = parse_paths ( attr) . unwrap_or_else ( |_| {
823
+ let paths = parse_paths ( tcx , attr) . unwrap_or_else ( |_| {
845
824
tcx. dcx ( ) . span_err (
846
825
attr. span ,
847
826
format ! (
@@ -952,8 +931,8 @@ fn parse_integer(attr: &Attribute) -> Option<u128> {
952
931
/// Extracts a vector with the path arguments of an attribute.
953
932
///
954
933
/// 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) ;
957
936
let parser = Punctuated :: < TypePath , syn:: Token ![ , ] > :: parse_terminated;
958
937
let paths = syn_attr. parse_args_with ( parser) ?;
959
938
Ok ( paths. into_iter ( ) . collect ( ) )
@@ -990,11 +969,11 @@ fn parse_str_value(attr: &Attribute) -> Option<String> {
990
969
fn attr_kind ( tcx : TyCtxt , attr : & Attribute ) -> Option < KaniAttributeKind > {
991
970
match & attr. kind {
992
971
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" {
995
974
let ident_str = segments[ 1 ..]
996
975
. iter ( )
997
- . map ( |segment| segment. ident . as_str ( ) )
976
+ . map ( |segment| segment. as_str ( ) )
998
977
. intersperse ( "::" )
999
978
. collect :: < String > ( ) ;
1000
979
KaniAttributeKind :: try_from ( ident_str. as_str ( ) )
@@ -1014,8 +993,8 @@ fn attr_kind(tcx: TyCtxt, attr: &Attribute) -> Option<KaniAttributeKind> {
1014
993
/// Parse an attribute using `syn`.
1015
994
///
1016
995
/// 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) ;
1019
998
let parser = syn:: Attribute :: parse_outer;
1020
999
parser. parse_str ( & attr_str) . unwrap ( ) . pop ( ) . unwrap ( )
1021
1000
}
0 commit comments