@@ -14,7 +14,7 @@ use crate::errors::{
1414 UnsupportedAttributesInWhere ,
1515} ;
1616use crate :: session_diagnostics:: InvalidTarget ;
17- use crate :: target_checking:: Policy :: Allow ;
17+ use crate :: target_checking:: Policy :: { Allow , Warn } ;
1818
1919#[ derive( Debug ) ]
2020pub ( crate ) enum AllowedTargets {
@@ -394,10 +394,82 @@ fn filter_targets(
394394 added_fake_targets. push ( target_group_name) ;
395395}
396396
397+ /// This is a list of default targets to which a attribute can be applied
398+ /// This is used for attributes that are not parted to the new target checking system yet can use this list as a placeholder.
399+ /// This excludes `Target::MacroCall`, as attributes on macro calls are otherwise not checked for parsed attributes.
400+ pub ( crate ) const DEFAULT_TARGETS : & ' static [ Policy ] = {
401+ use Policy :: Allow ;
402+ & [
403+ Allow ( Target :: ExternCrate ) ,
404+ Allow ( Target :: Use ) ,
405+ Allow ( Target :: Static ) ,
406+ Allow ( Target :: Const ) ,
407+ Allow ( Target :: Fn ) ,
408+ Allow ( Target :: Closure ) ,
409+ Allow ( Target :: Mod ) ,
410+ Allow ( Target :: ForeignMod ) ,
411+ Allow ( Target :: GlobalAsm ) ,
412+ Allow ( Target :: TyAlias ) ,
413+ Allow ( Target :: Enum ) ,
414+ Allow ( Target :: Variant ) ,
415+ Allow ( Target :: Struct ) ,
416+ Allow ( Target :: Field ) ,
417+ Allow ( Target :: Union ) ,
418+ Allow ( Target :: Trait ) ,
419+ Allow ( Target :: TraitAlias ) ,
420+ Allow ( Target :: Impl { of_trait : false } ) ,
421+ Allow ( Target :: Impl { of_trait : true } ) ,
422+ Allow ( Target :: Expression ) ,
423+ Allow ( Target :: Statement ) ,
424+ Allow ( Target :: Arm ) ,
425+ Allow ( Target :: AssocConst ) ,
426+ Allow ( Target :: Method ( MethodKind :: Inherent ) ) ,
427+ Allow ( Target :: Method ( MethodKind :: Trait { body : false } ) ) ,
428+ Allow ( Target :: Method ( MethodKind :: Trait { body : true } ) ) ,
429+ Allow ( Target :: Method ( MethodKind :: TraitImpl ) ) ,
430+ Allow ( Target :: AssocTy ) ,
431+ Allow ( Target :: ForeignFn ) ,
432+ Allow ( Target :: ForeignStatic ) ,
433+ Allow ( Target :: ForeignTy ) ,
434+ Allow ( Target :: MacroDef ) ,
435+ Allow ( Target :: Param ) ,
436+ Allow ( Target :: PatField ) ,
437+ Allow ( Target :: ExprField ) ,
438+ Allow ( Target :: WherePredicate ) ,
439+ Allow ( Target :: Crate ) ,
440+ Allow ( Target :: Delegation { mac : false } ) ,
441+ Allow ( Target :: Delegation { mac : true } ) ,
442+ Allow ( Target :: GenericParam {
443+ kind : rustc_hir:: target:: GenericParamKind :: Const ,
444+ has_default : false ,
445+ } ) ,
446+ Allow ( Target :: GenericParam {
447+ kind : rustc_hir:: target:: GenericParamKind :: Const ,
448+ has_default : true ,
449+ } ) ,
450+ Allow ( Target :: GenericParam {
451+ kind : rustc_hir:: target:: GenericParamKind :: Lifetime ,
452+ has_default : false ,
453+ } ) ,
454+ Allow ( Target :: GenericParam {
455+ kind : rustc_hir:: target:: GenericParamKind :: Lifetime ,
456+ has_default : true ,
457+ } ) ,
458+ Allow ( Target :: GenericParam {
459+ kind : rustc_hir:: target:: GenericParamKind :: Type ,
460+ has_default : false ,
461+ } ) ,
462+ Allow ( Target :: GenericParam {
463+ kind : rustc_hir:: target:: GenericParamKind :: Type ,
464+ has_default : true ,
465+ } ) ,
466+ Warn ( Target :: MacroCall ) ,
467+ ]
468+ } ;
469+
397470/// This is the list of all targets to which a attribute can be applied
398471/// This is used for:
399- /// - `rustc_dummy`, which can be applied to all targets
400- /// - Attributes that are not parted to the new target system yet can use this list as a placeholder
472+ /// - Attributes that are not parted to the new target checking system yet can use this list as a placeholder
401473pub ( crate ) const ALL_TARGETS : & ' static [ Policy ] = {
402474 use Policy :: Allow ;
403475 & [
0 commit comments