10
10
//! just peeks and looks for that attribute.
11
11
12
12
use crate :: bug;
13
- use rustc_ast as ast;
14
- use rustc_data_structures:: sync:: OnceCell ;
13
+ use crate :: ty;
14
+ use rustc_ast:: Attribute ;
15
+ use rustc_session:: Limit ;
15
16
use rustc_session:: Session ;
16
17
use rustc_span:: symbol:: { sym, Symbol } ;
17
18
18
19
use std:: num:: IntErrorKind ;
19
20
20
- pub fn update_limits ( sess : & Session , krate : & ast:: Crate ) {
21
- update_limit ( sess, krate, & sess. recursion_limit , sym:: recursion_limit, 128 ) ;
22
- update_limit ( sess, krate, & sess. move_size_limit , sym:: move_size_limit, 0 ) ;
23
- update_limit ( sess, krate, & sess. type_length_limit , sym:: type_length_limit, 1048576 ) ;
24
- update_limit ( sess, krate, & sess. const_eval_limit , sym:: const_eval_limit, 1_000_000 ) ;
21
+ pub fn provide ( providers : & mut ty:: query:: Providers ) {
22
+ providers. recursion_limit = |tcx, ( ) | get_recursion_limit ( tcx. hir ( ) . krate_attrs ( ) , tcx. sess ) ;
23
+ providers. move_size_limit =
24
+ |tcx, ( ) | get_limit ( tcx. hir ( ) . krate_attrs ( ) , tcx. sess , sym:: move_size_limit, 0 ) . 0 ;
25
+ providers. type_length_limit =
26
+ |tcx, ( ) | get_limit ( tcx. hir ( ) . krate_attrs ( ) , tcx. sess , sym:: type_length_limit, 1048576 ) ;
27
+ providers. const_eval_limit =
28
+ |tcx, ( ) | get_limit ( tcx. hir ( ) . krate_attrs ( ) , tcx. sess , sym:: const_eval_limit, 1_000_000 ) ;
25
29
}
26
30
27
- fn update_limit (
28
- sess : & Session ,
29
- krate : & ast:: Crate ,
30
- limit : & OnceCell < impl From < usize > + std:: fmt:: Debug > ,
31
- name : Symbol ,
32
- default : usize ,
33
- ) {
34
- for attr in & krate. attrs {
31
+ pub fn get_recursion_limit ( krate_attrs : & [ Attribute ] , sess : & Session ) -> Limit {
32
+ get_limit ( krate_attrs, sess, sym:: recursion_limit, 128 )
33
+ }
34
+
35
+ fn get_limit ( krate_attrs : & [ Attribute ] , sess : & Session , name : Symbol , default : usize ) -> Limit {
36
+ for attr in krate_attrs {
35
37
if !sess. check_name ( attr, name) {
36
38
continue ;
37
39
}
38
40
39
41
if let Some ( s) = attr. value_str ( ) {
40
42
match s. as_str ( ) . parse ( ) {
41
- Ok ( n) => {
42
- limit. set ( From :: from ( n) ) . unwrap ( ) ;
43
- return ;
44
- }
43
+ Ok ( n) => return Limit :: new ( n) ,
45
44
Err ( e) => {
46
45
let mut err =
47
46
sess. struct_span_err ( attr. span , "`limit` must be a non-negative integer" ) ;
@@ -68,5 +67,5 @@ fn update_limit(
68
67
}
69
68
}
70
69
}
71
- limit . set ( From :: from ( default) ) . unwrap ( ) ;
70
+ return Limit :: new ( default) ;
72
71
}
0 commit comments