1
1
use std:: num:: IntErrorKind ;
2
2
3
- use crate :: session_diagnostics :: LimitInvalid ;
3
+ use rustc_hir :: limit :: Limit ;
4
4
5
5
use super :: prelude:: * ;
6
+ use crate :: session_diagnostics:: LimitInvalid ;
6
7
7
8
impl < S : Stage > AcceptContext < ' _ , ' _ , S > {
8
- fn parse_limit_int ( & self , nv : & NameValueParser ) -> Option < usize > {
9
+ fn parse_limit_int ( & self , nv : & NameValueParser ) -> Option < Limit > {
9
10
let Some ( limit) = nv. value_as_str ( ) else {
10
11
self . expected_string_literal ( nv. value_span , Some ( nv. value_as_lit ( ) ) ) ;
11
12
return None ;
12
13
} ;
13
14
14
15
let error_str = match limit. as_str ( ) . parse ( ) {
15
- Ok ( i) => return Some ( i ) ,
16
+ Ok ( i) => return Some ( Limit :: new ( i ) ) ,
16
17
Err ( e) => match e. kind ( ) {
17
18
IntErrorKind :: PosOverflow => "`limit` is too large" ,
18
19
IntErrorKind :: Empty => "`limit` must be a non-negative integer" ,
@@ -44,8 +45,8 @@ impl<S: Stage> SingleAttributeParser<S> for CrateNameParser {
44
45
const TEMPLATE : AttributeTemplate = template ! ( NameValueStr : "name" ) ;
45
46
const TYPE : AttributeType = AttributeType :: CrateLevel ;
46
47
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 duplicate warnings
49
50
const ALLOWED_TARGETS : AllowedTargets = AllowedTargets :: AllowList ( ALL_TARGETS ) ;
50
51
51
52
fn convert ( cx : & mut AcceptContext < ' _ , ' _ , S > , args : & ArgParser < ' _ > ) -> Option < AttributeKind > {
@@ -77,8 +78,8 @@ impl<S: Stage> SingleAttributeParser<S> for RecursionLimitParser {
77
78
const TEMPLATE : AttributeTemplate = template ! ( NameValueStr : "N" , "https://doc.rust-lang.org/reference/attributes/limits.html#the-recursion_limit-attribute" ) ;
78
79
const TYPE : AttributeType = AttributeType :: CrateLevel ;
79
80
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 duplicate warnings
82
83
const ALLOWED_TARGETS : AllowedTargets = AllowedTargets :: AllowList ( ALL_TARGETS ) ;
83
84
84
85
fn convert ( cx : & mut AcceptContext < ' _ , ' _ , S > , args : & ArgParser < ' _ > ) -> Option < AttributeKind > {
@@ -102,10 +103,11 @@ impl<S: Stage> SingleAttributeParser<S> for MoveSizeLimitParser {
102
103
const ATTRIBUTE_ORDER : AttributeOrder = AttributeOrder :: KeepOutermost ;
103
104
const ON_DUPLICATE : OnDuplicate < S > = OnDuplicate :: Error ;
104
105
const TEMPLATE : AttributeTemplate = template ! ( NameValueStr : "N" ) ;
106
+ const TYPE : AttributeType = AttributeType :: CrateLevel ;
105
107
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 duplicate warnings
110
+ const ALLOWED_TARGETS : AllowedTargets = AllowedTargets :: AllowList ( ALL_TARGETS ) ;
109
111
110
112
fn convert ( cx : & mut AcceptContext < ' _ , ' _ , S > , args : & ArgParser < ' _ > ) -> Option < AttributeKind > {
111
113
let ArgParser :: NameValue ( nv) = args else {
@@ -130,9 +132,9 @@ impl<S: Stage> SingleAttributeParser<S> for TypeLengthLimitParser {
130
132
const TEMPLATE : AttributeTemplate = template ! ( NameValueStr : "N" ) ;
131
133
const TYPE : AttributeType = AttributeType :: CrateLevel ;
132
134
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 duplicate warnings
137
+ const ALLOWED_TARGETS : AllowedTargets = AllowedTargets :: AllowList ( ALL_TARGETS ) ;
136
138
137
139
fn convert ( cx : & mut AcceptContext < ' _ , ' _ , S > , args : & ArgParser < ' _ > ) -> Option < AttributeKind > {
138
140
let ArgParser :: NameValue ( nv) = args else {
@@ -157,9 +159,9 @@ impl<S: Stage> SingleAttributeParser<S> for PatternComplexityLimitParser {
157
159
const TEMPLATE : AttributeTemplate = template ! ( NameValueStr : "N" ) ;
158
160
const TYPE : AttributeType = AttributeType :: CrateLevel ;
159
161
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 duplicate warnings
164
+ const ALLOWED_TARGETS : AllowedTargets = AllowedTargets :: AllowList ( ALL_TARGETS ) ;
163
165
164
166
fn convert ( cx : & mut AcceptContext < ' _ , ' _ , S > , args : & ArgParser < ' _ > ) -> Option < AttributeKind > {
165
167
let ArgParser :: NameValue ( nv) = args else {
0 commit comments