@@ -23,7 +23,7 @@ use rustc_middle::middle::cstore::{MetadataLoader, MetadataLoaderDyn};
23
23
use rustc_middle:: ty:: query:: Providers ;
24
24
use rustc_middle:: ty:: { self , GlobalCtxt , ResolverOutputs , TyCtxt } ;
25
25
use rustc_mir_build as mir_build;
26
- use rustc_parse:: { parse_crate_from_file, parse_crate_from_source_str} ;
26
+ use rustc_parse:: { parse_crate_from_file, parse_crate_from_source_str, validate_attr } ;
27
27
use rustc_passes:: { self , hir_stats, layout_test} ;
28
28
use rustc_plugin_impl as plugin;
29
29
use rustc_query_impl:: { OnDiskCache , Queries as TcxQueries } ;
@@ -33,8 +33,8 @@ use rustc_session::config::{CrateType, Input, OutputFilenames, OutputType, PpMod
33
33
use rustc_session:: lint;
34
34
use rustc_session:: output:: { filename_for_input, filename_for_metadata} ;
35
35
use rustc_session:: search_paths:: PathKind ;
36
- use rustc_session:: Session ;
37
- use rustc_span:: symbol:: { Ident , Symbol } ;
36
+ use rustc_session:: { Limit , Session } ;
37
+ use rustc_span:: symbol:: { sym , Ident , Symbol } ;
38
38
use rustc_span:: FileName ;
39
39
use rustc_trait_selection:: traits;
40
40
use rustc_typeck as typeck;
@@ -311,8 +311,7 @@ pub fn configure_and_expand(
311
311
312
312
// Create the config for macro expansion
313
313
let features = sess. features_untracked ( ) ;
314
- let recursion_limit =
315
- rustc_middle:: middle:: limits:: get_recursion_limit ( & krate. attrs , & sess) ;
314
+ let recursion_limit = get_recursion_limit ( & krate. attrs , & sess) ;
316
315
let cfg = rustc_expand:: expand:: ExpansionConfig {
317
316
features : Some ( & features) ,
318
317
recursion_limit,
@@ -1070,3 +1069,24 @@ pub fn start_codegen<'tcx>(
1070
1069
1071
1070
codegen
1072
1071
}
1072
+
1073
+ fn get_recursion_limit ( krate_attrs : & [ ast:: Attribute ] , sess : & Session ) -> Limit {
1074
+ if let Some ( attr) = krate_attrs
1075
+ . iter ( )
1076
+ . find ( |attr| attr. has_name ( sym:: recursion_limit) && attr. value_str ( ) . is_none ( ) )
1077
+ {
1078
+ // This is here mainly to check for using a macro, such as
1079
+ // #![recursion_limit = foo!()]. That is not supported since that
1080
+ // would require expanding this while in the middle of expansion,
1081
+ // which needs to know the limit before expanding. Otherwise,
1082
+ // validation would normally be caught in AstValidator (via
1083
+ // `check_builtin_attribute`), but by the time that runs the macro
1084
+ // is expanded, and it doesn't give an error.
1085
+ validate_attr:: emit_fatal_malformed_builtin_attribute (
1086
+ & sess. parse_sess ,
1087
+ attr,
1088
+ sym:: recursion_limit,
1089
+ ) ;
1090
+ }
1091
+ rustc_middle:: middle:: limits:: get_recursion_limit ( krate_attrs, sess)
1092
+ }
0 commit comments