@@ -6,6 +6,7 @@ use std::sync::{Arc, LazyLock};
66use std:: { env, fs, iter} ;
77
88use rustc_ast as ast;
9+ use rustc_attr_parsing:: { AttributeKind , AttributeParser } ;
910use rustc_codegen_ssa:: traits:: CodegenBackend ;
1011use rustc_data_structures:: parallel;
1112use rustc_data_structures:: steal:: Steal ;
@@ -32,7 +33,7 @@ use rustc_session::output::{collect_crate_types, filename_for_input};
3233use rustc_session:: search_paths:: PathKind ;
3334use rustc_session:: { Limit , Session } ;
3435use rustc_span:: {
35- ErrorGuaranteed , FileName , SourceFileHash , SourceFileHashAlgorithm , Span , Symbol , sym,
36+ DUMMY_SP , ErrorGuaranteed , FileName , SourceFileHash , SourceFileHashAlgorithm , Span , Symbol , sym,
3637} ;
3738use rustc_target:: spec:: PanicStrategy ;
3839use rustc_trait_selection:: traits;
@@ -1119,6 +1120,20 @@ pub(crate) fn start_codegen<'tcx>(
11191120 codegen
11201121}
11211122
1123+ pub ( crate ) fn parse_crate_name (
1124+ sess : & Session ,
1125+ attrs : & [ ast:: Attribute ] ,
1126+ limit_diagnostics : bool ,
1127+ ) -> Option < ( Symbol , Span ) > {
1128+ let rustc_hir:: Attribute :: Parsed ( AttributeKind :: CrateName { name, name_span, .. } ) =
1129+ AttributeParser :: parse_limited ( sess, & attrs, sym:: crate_name, DUMMY_SP , limit_diagnostics) ?
1130+ else {
1131+ unreachable ! ( "crate_name is the only attr we could've parsed here" ) ;
1132+ } ;
1133+
1134+ Some ( ( name, name_span) )
1135+ }
1136+
11221137/// Compute and validate the crate name.
11231138pub fn get_crate_name ( sess : & Session , krate_attrs : & [ ast:: Attribute ] ) -> Symbol {
11241139 // We validate *all* occurrences of `#![crate_name]`, pick the first find and
@@ -1128,8 +1143,7 @@ pub fn get_crate_name(sess: &Session, krate_attrs: &[ast::Attribute]) -> Symbol
11281143 // in all code paths that require the crate name very early on, namely before
11291144 // macro expansion.
11301145
1131- let attr_crate_name =
1132- validate_and_find_value_str_builtin_attr ( sym:: crate_name, sess, krate_attrs) ;
1146+ let attr_crate_name = parse_crate_name ( sess, krate_attrs, false ) ;
11331147
11341148 let validate = |name, span| {
11351149 rustc_session:: output:: validate_crate_name ( sess, name, span) ;
0 commit comments