@@ -11,7 +11,6 @@ use rustc_hir::{HirId, MethodKind, Target, CRATE_HIR_ID};
1111use rustc_middle:: hir:: map:: Map ;
1212use rustc_middle:: ty:: query:: Providers ;
1313use rustc_middle:: ty:: TyCtxt ;
14- use std:: fmt;
1514use std:: rc:: Rc ;
1615
1716// FIXME(eddyb) make this reusable from somewhere in `rustc`.
@@ -38,56 +37,15 @@ pub(crate) fn target_from_impl_item<'tcx>(
3837 }
3938}
4039
41- // HACK(eddyb) current `Target` (after rust-lang/rust#80641 + rust-lang/rust#80920),
42- // emulated before we can rustup to that point and use the new variants directly.
43- enum TargetNew {
44- Old ( Target ) ,
45-
46- // Added by rust-lang/rust#80641.
47- Field ,
48- Arm ,
49- MacroDef ,
50-
51- // Added by rust-lang/rust#80920.
52- Param ,
53- }
54-
55- impl From < Target > for TargetNew {
56- fn from ( target : Target ) -> Self {
57- Self :: Old ( target)
58- }
59- }
60-
61- impl fmt:: Display for TargetNew {
62- fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
63- let description = match self {
64- Self :: Old ( target) => return write ! ( f, "{}" , target) ,
65-
66- Self :: Field => "struct field" ,
67- Self :: Arm => "match arm" ,
68- Self :: MacroDef => "macro def" ,
69-
70- Self :: Param => "function param" ,
71- } ;
72- f. write_str ( description)
73- }
74- }
75-
7640struct CheckSpirvAttrVisitor < ' tcx > {
7741 tcx : TyCtxt < ' tcx > ,
7842 sym : Rc < Symbols > ,
7943}
8044
8145impl CheckSpirvAttrVisitor < ' _ > {
82- fn check_spirv_attributes (
83- & self ,
84- hir_id : HirId ,
85- attrs : & [ Attribute ] ,
86- target : impl Into < TargetNew > ,
87- ) {
46+ fn check_spirv_attributes ( & self , hir_id : HirId , attrs : & [ Attribute ] , target : Target ) {
8847 let parse_attrs = |attrs| crate :: symbols:: parse_attrs_for_checking ( & self . sym , attrs) ;
8948
90- let target = target. into ( ) ;
9149 for ( attr, parse_attr_result) in parse_attrs ( attrs) {
9250 // Make sure to mark the whole `#[spirv(...)]` attribute as used,
9351 // to avoid warnings about unused attributes.
@@ -109,7 +67,7 @@ impl CheckSpirvAttrVisitor<'_> {
10967 | SpirvAttribute :: DescriptorSet ( _)
11068 | SpirvAttribute :: Binding ( _)
11169 | SpirvAttribute :: Flat => match target {
112- TargetNew :: Param => {
70+ Target :: Param => {
11371 let parent_hir_id = self . tcx . hir ( ) . get_parent_node ( hir_id) ;
11472 let parent_is_entry_point =
11573 parse_attrs ( self . tcx . hir ( ) . attrs ( parent_hir_id) )
@@ -128,9 +86,9 @@ impl CheckSpirvAttrVisitor<'_> {
12886 } ,
12987
13088 SpirvAttribute :: Entry ( _) => match target {
131- TargetNew :: Old ( Target :: Fn )
132- | TargetNew :: Old ( Target :: Method ( MethodKind :: Trait { body : true } ) )
133- | TargetNew :: Old ( Target :: Method ( MethodKind :: Inherent ) ) => {
89+ Target :: Fn
90+ | Target :: Method ( MethodKind :: Trait { body : true } )
91+ | Target :: Method ( MethodKind :: Inherent ) => {
13492 // FIXME(eddyb) further check entry-point attribute validity,
13593 // e.g. signature, shouldn't have `#[inline]` or generics, etc.
13694 Ok ( ( ) )
@@ -140,10 +98,10 @@ impl CheckSpirvAttrVisitor<'_> {
14098 } ,
14199
142100 SpirvAttribute :: UnrollLoops => match target {
143- TargetNew :: Old ( Target :: Fn )
144- | TargetNew :: Old ( Target :: Closure )
145- | TargetNew :: Old ( Target :: Method ( MethodKind :: Trait { body : true } ) )
146- | TargetNew :: Old ( Target :: Method ( MethodKind :: Inherent ) ) => Ok ( ( ) ) ,
101+ Target :: Fn
102+ | Target :: Closure
103+ | Target :: Method ( MethodKind :: Trait { body : true } )
104+ | Target :: Method ( MethodKind :: Inherent ) => Ok ( ( ) ) ,
147105
148106 _ => Err ( Expected ( "function or closure" ) ) ,
149107 } ,
@@ -153,7 +111,7 @@ impl CheckSpirvAttrVisitor<'_> {
153111 | SpirvAttribute :: Sampler
154112 | SpirvAttribute :: SampledImage
155113 | SpirvAttribute :: Block => match target {
156- TargetNew :: Old ( Target :: Struct ) => {
114+ Target :: Struct => {
157115 // FIXME(eddyb) further check type attribute validity,
158116 // e.g. layout, generics, other attributes, etc.
159117 Ok ( ( ) )
@@ -203,12 +161,12 @@ impl<'tcx> Visitor<'tcx> for CheckSpirvAttrVisitor<'tcx> {
203161 }
204162
205163 fn visit_struct_field ( & mut self , struct_field : & ' tcx hir:: StructField < ' tcx > ) {
206- self . check_spirv_attributes ( struct_field. hir_id , struct_field. attrs , TargetNew :: Field ) ;
164+ self . check_spirv_attributes ( struct_field. hir_id , struct_field. attrs , Target :: Field ) ;
207165 intravisit:: walk_struct_field ( self , struct_field) ;
208166 }
209167
210168 fn visit_arm ( & mut self , arm : & ' tcx hir:: Arm < ' tcx > ) {
211- self . check_spirv_attributes ( arm. hir_id , arm. attrs , TargetNew :: Arm ) ;
169+ self . check_spirv_attributes ( arm. hir_id , arm. attrs , Target :: Arm ) ;
212170 intravisit:: walk_arm ( self , arm) ;
213171 }
214172
@@ -253,12 +211,12 @@ impl<'tcx> Visitor<'tcx> for CheckSpirvAttrVisitor<'tcx> {
253211 }
254212
255213 fn visit_macro_def ( & mut self , macro_def : & ' tcx hir:: MacroDef < ' tcx > ) {
256- self . check_spirv_attributes ( macro_def. hir_id ( ) , macro_def. attrs , TargetNew :: MacroDef ) ;
214+ self . check_spirv_attributes ( macro_def. hir_id ( ) , macro_def. attrs , Target :: MacroDef ) ;
257215 intravisit:: walk_macro_def ( self , macro_def) ;
258216 }
259217
260218 fn visit_param ( & mut self , param : & ' tcx hir:: Param < ' tcx > ) {
261- self . check_spirv_attributes ( param. hir_id , param. attrs , TargetNew :: Param ) ;
219+ self . check_spirv_attributes ( param. hir_id , param. attrs , Target :: Param ) ;
262220
263221 intravisit:: walk_param ( self , param) ;
264222 }
0 commit comments