11use std:: num:: IntErrorKind ;
22
3- use crate :: session_diagnostics :: LimitInvalid ;
3+ use rustc_hir :: limit :: Limit ;
44
55use super :: prelude:: * ;
6+ use crate :: session_diagnostics:: LimitInvalid ;
67
78impl < S : Stage > AcceptContext < ' _ , ' _ , S > {
8- fn parse_limit_int ( & self , nv : & NameValueParser ) -> Option < usize > {
9+ fn parse_limit_int ( & self , nv : & NameValueParser ) -> Option < Limit > {
910 let Some ( limit) = nv. value_as_str ( ) else {
1011 self . expected_string_literal ( nv. value_span , Some ( nv. value_as_lit ( ) ) ) ;
1112 return None ;
1213 } ;
1314
1415 let error_str = match limit. as_str ( ) . parse ( ) {
15- Ok ( i) => return Some ( i ) ,
16+ Ok ( i) => return Some ( Limit :: new ( i ) ) ,
1617 Err ( e) => match e. kind ( ) {
1718 IntErrorKind :: PosOverflow => "`limit` is too large" ,
1819 IntErrorKind :: Empty => "`limit` must be a non-negative integer" ,
@@ -44,8 +45,8 @@ impl<S: Stage> SingleAttributeParser<S> for CrateNameParser {
4445 const TEMPLATE : AttributeTemplate = template ! ( NameValueStr : "name" ) ;
4546 const TYPE : AttributeType = AttributeType :: CrateLevel ;
4647
47- // FIXME: crate name is allowed on all targets and ignored,
48- // even though it should only be valid on crates of course
48+ // because it's a crate-level attribute, we already warn about it.
49+ // Putting target limitations here would give dupliate warnings
4950 const ALLOWED_TARGETS : AllowedTargets = AllowedTargets :: AllowList ( ALL_TARGETS ) ;
5051
5152 fn convert ( cx : & mut AcceptContext < ' _ , ' _ , S > , args : & ArgParser < ' _ > ) -> Option < AttributeKind > {
@@ -77,8 +78,8 @@ impl<S: Stage> SingleAttributeParser<S> for RecursionLimitParser {
7778 const TEMPLATE : AttributeTemplate = template ! ( NameValueStr : "N" , "https://doc.rust-lang.org/reference/attributes/limits.html#the-recursion_limit-attribute" ) ;
7879 const TYPE : AttributeType = AttributeType :: CrateLevel ;
7980
80- // FIXME: recursion limit is allowed on all targets and ignored,
81- // even though it should only be valid on crates of course
81+ // because it's a crate-level attribute, we already warn about it.
82+ // Putting target limitations here would give dupliate warnings
8283 const ALLOWED_TARGETS : AllowedTargets = AllowedTargets :: AllowList ( ALL_TARGETS ) ;
8384
8485 fn convert ( cx : & mut AcceptContext < ' _ , ' _ , S > , args : & ArgParser < ' _ > ) -> Option < AttributeKind > {
@@ -102,10 +103,11 @@ impl<S: Stage> SingleAttributeParser<S> for MoveSizeLimitParser {
102103 const ATTRIBUTE_ORDER : AttributeOrder = AttributeOrder :: KeepOutermost ;
103104 const ON_DUPLICATE : OnDuplicate < S > = OnDuplicate :: Error ;
104105 const TEMPLATE : AttributeTemplate = template ! ( NameValueStr : "N" ) ;
106+ const TYPE : AttributeType = AttributeType :: CrateLevel ;
105107
106- // FIXME: move size limit is allowed on all targets and ignored,
107- // even though it should only be valid on crates of course
108- const ALLOWED_TARGETS : AllowedTargets = AllowedTargets :: AllowList ( & [ Allow ( Target :: Crate ) ] ) ;
108+ // because it's a crate-level attribute, we already warn about it.
109+ // Putting target limitations here would give dupliate warnings
110+ const ALLOWED_TARGETS : AllowedTargets = AllowedTargets :: AllowList ( ALL_TARGETS ) ;
109111
110112 fn convert ( cx : & mut AcceptContext < ' _ , ' _ , S > , args : & ArgParser < ' _ > ) -> Option < AttributeKind > {
111113 let ArgParser :: NameValue ( nv) = args else {
@@ -130,9 +132,9 @@ impl<S: Stage> SingleAttributeParser<S> for TypeLengthLimitParser {
130132 const TEMPLATE : AttributeTemplate = template ! ( NameValueStr : "N" ) ;
131133 const TYPE : AttributeType = AttributeType :: CrateLevel ;
132134
133- // FIXME: recursion limit is allowed on all targets and ignored,
134- // even though it should only be valid on crates of course
135- const ALLOWED_TARGETS : AllowedTargets = AllowedTargets :: AllowListWarnRest ( & [ Target :: Crate ] ) ;
135+ // because it's a crate-level attribute, we already warn about it.
136+ // Putting target limitations here would give dupliate warnings
137+ const ALLOWED_TARGETS : AllowedTargets = AllowedTargets :: AllowList ( ALL_TARGETS ) ;
136138
137139 fn convert ( cx : & mut AcceptContext < ' _ , ' _ , S > , args : & ArgParser < ' _ > ) -> Option < AttributeKind > {
138140 let ArgParser :: NameValue ( nv) = args else {
@@ -157,9 +159,9 @@ impl<S: Stage> SingleAttributeParser<S> for PatternComplexityLimitParser {
157159 const TEMPLATE : AttributeTemplate = template ! ( NameValueStr : "N" ) ;
158160 const TYPE : AttributeType = AttributeType :: CrateLevel ;
159161
160- // FIXME: recursion limit is allowed on all targets and ignored,
161- // even though it should only be valid on crates of course
162- const ALLOWED_TARGETS : AllowedTargets = AllowedTargets :: AllowList ( & [ Allow ( Target :: Crate ) ] ) ;
162+ // because it's a crate-level attribute, we already warn about it.
163+ // Putting target limitations here would give dupliate warnings
164+ const ALLOWED_TARGETS : AllowedTargets = AllowedTargets :: AllowList ( ALL_TARGETS ) ;
163165
164166 fn convert ( cx : & mut AcceptContext < ' _ , ' _ , S > , args : & ArgParser < ' _ > ) -> Option < AttributeKind > {
165167 let ArgParser :: NameValue ( nv) = args else {
0 commit comments