@@ -183,6 +183,7 @@ impl CheckAttrVisitor<'_> {
183
183
| sym:: rustc_allowed_through_unstable_modules
184
184
| sym:: rustc_promotable => self . check_stability_promotable ( & attr, span, target) ,
185
185
sym:: link_ordinal => self . check_link_ordinal ( & attr, span, target) ,
186
+ sym:: refine => self . check_refine ( & attr, span, target, hir_id) ,
186
187
sym:: rustc_confusables => self . check_confusables ( & attr, target) ,
187
188
_ => true ,
188
189
} ;
@@ -2304,6 +2305,37 @@ impl CheckAttrVisitor<'_> {
2304
2305
self . abort . set ( true ) ;
2305
2306
}
2306
2307
}
2308
+
2309
+ fn check_refine ( & self , attr : & Attribute , span : Span , target : Target , hir_id : HirId ) -> bool {
2310
+ let attr_span = attr. span ;
2311
+ match target {
2312
+ Target :: Method ( _) | Target :: AssocTy => {
2313
+ let parent_def_id = self . tcx . hir ( ) . get_parent_item ( hir_id) . def_id ;
2314
+ match self . tcx . hir ( ) . expect_item ( parent_def_id) . kind {
2315
+ hir:: ItemKind :: Impl ( impl_) if impl_. of_trait . is_some ( ) => true ,
2316
+ hir:: ItemKind :: Impl ( ..) => {
2317
+ self . tcx
2318
+ . sess
2319
+ . emit_err ( errors:: BadRefineAttr :: InherentImpl { span, attr_span } ) ;
2320
+ false
2321
+ }
2322
+ hir:: ItemKind :: Trait ( ..) => {
2323
+ self . tcx . sess . emit_err ( errors:: BadRefineAttr :: Trait { span, attr_span } ) ;
2324
+ false
2325
+ }
2326
+ _ => unreachable ! ( "only expect assoc ty and method on trait/impl" ) ,
2327
+ }
2328
+ }
2329
+ Target :: AssocConst => {
2330
+ self . tcx . sess . emit_err ( errors:: BadRefineAttr :: AssocConst { span, attr_span } ) ;
2331
+ false
2332
+ }
2333
+ _ => {
2334
+ self . tcx . sess . emit_err ( errors:: BadRefineAttr :: OtherItem { span, attr_span } ) ;
2335
+ false
2336
+ }
2337
+ }
2338
+ }
2307
2339
}
2308
2340
2309
2341
impl < ' tcx > Visitor < ' tcx > for CheckAttrVisitor < ' tcx > {
0 commit comments