@@ -6,7 +6,7 @@ use std::sync::{Arc, LazyLock, OnceLock};
66use std:: { env, fs, iter} ;
77
88use rustc_ast as ast;
9- use rustc_attr_parsing:: validate_attr;
9+ use rustc_attr_parsing:: { AttributeParser , ShouldEmit , validate_attr} ;
1010use rustc_codegen_ssa:: traits:: CodegenBackend ;
1111use rustc_data_structures:: jobserver:: Proxy ;
1212use rustc_data_structures:: steal:: Steal ;
@@ -16,6 +16,7 @@ use rustc_errors::timings::TimingSection;
1616use rustc_expand:: base:: { ExtCtxt , LintStoreExpand } ;
1717use rustc_feature:: Features ;
1818use rustc_fs_util:: try_canonicalize;
19+ use rustc_hir:: attrs:: AttributeKind ;
1920use rustc_hir:: def_id:: { LOCAL_CRATE , StableCrateId , StableCrateIdMap } ;
2021use rustc_hir:: definitions:: Definitions ;
2122use rustc_incremental:: setup_dep_graph;
@@ -1244,8 +1245,7 @@ pub fn get_crate_name(sess: &Session, krate_attrs: &[ast::Attribute]) -> Symbol
12441245 // in all code paths that require the crate name very early on, namely before
12451246 // macro expansion.
12461247
1247- let attr_crate_name =
1248- validate_and_find_value_str_builtin_attr ( sym:: crate_name, sess, krate_attrs) ;
1248+ let attr_crate_name = parse_crate_name ( sess, krate_attrs, ShouldEmit :: EarlyFatal ) ;
12491249
12501250 let validate = |name, span| {
12511251 rustc_session:: output:: validate_crate_name ( sess, name, span) ;
@@ -1283,6 +1283,28 @@ pub fn get_crate_name(sess: &Session, krate_attrs: &[ast::Attribute]) -> Symbol
12831283 sym:: rust_out
12841284}
12851285
1286+ pub ( crate ) fn parse_crate_name (
1287+ sess : & Session ,
1288+ attrs : & [ ast:: Attribute ] ,
1289+ emit_errors : ShouldEmit ,
1290+ ) -> Option < ( Symbol , Span ) > {
1291+ let rustc_hir:: Attribute :: Parsed ( AttributeKind :: CrateName { name, name_span, .. } ) =
1292+ AttributeParser :: parse_limited_should_emit (
1293+ sess,
1294+ & attrs,
1295+ sym:: crate_name,
1296+ DUMMY_SP ,
1297+ rustc_ast:: node_id:: CRATE_NODE_ID ,
1298+ None ,
1299+ emit_errors,
1300+ ) ?
1301+ else {
1302+ unreachable ! ( "crate_name is the only attr we could've parsed here" ) ;
1303+ } ;
1304+
1305+ Some ( ( name, name_span) )
1306+ }
1307+
12861308fn get_recursion_limit ( krate_attrs : & [ ast:: Attribute ] , sess : & Session ) -> Limit {
12871309 // We don't permit macro calls inside of the attribute (e.g., #![recursion_limit = `expand!()`])
12881310 // because that would require expanding this while in the middle of expansion, which needs to
0 commit comments