@@ -2,8 +2,9 @@ use std::iter::once;
22use std:: path:: { self , Path , PathBuf } ;
33
44use rustc_ast:: { AttrVec , Attribute , Inline , Item , ModSpans } ;
5- use rustc_attr_parsing:: validate_attr ;
5+ use rustc_attr_parsing:: AttributeParser ;
66use rustc_errors:: { Diag , ErrorGuaranteed } ;
7+ use rustc_hir:: attrs:: AttributeKind ;
78use rustc_parse:: lexer:: StripTokens ;
89use rustc_parse:: { exp, new_parser_from_file, unwrap_or_emit_fatal} ;
910use rustc_session:: Session ;
@@ -185,19 +186,11 @@ pub(crate) fn mod_file_path_from_attr(
185186 dir_path : & Path ,
186187) -> Option < PathBuf > {
187188 // Extract path string from first `#[path = "path_string"]` attribute.
188- let first_path = attrs. iter ( ) . find ( |at| at. has_name ( sym:: path) ) ?;
189- let Some ( path_sym) = first_path. value_str ( ) else {
190- // This check is here mainly to catch attempting to use a macro,
191- // such as `#[path = concat!(...)]`. This isn't supported because
192- // otherwise the `InvocationCollector` would need to defer loading
193- // a module until the `#[path]` attribute was expanded, and it
194- // doesn't support that (and would likely add a bit of complexity).
195- // Usually bad forms are checked during semantic analysis via
196- // `TyCtxt::check_mod_attrs`), but by the time that runs the macro
197- // is expanded, and it doesn't give an error.
198- validate_attr:: emit_fatal_malformed_builtin_attribute ( & sess. psess , first_path, sym:: path) ;
189+ let Some ( rustc_hir:: Attribute :: Parsed ( AttributeKind :: Path ( path_sym, _) ) ) =
190+ AttributeParser :: parse_limited ( sess, attrs, sym:: path, None )
191+ else {
192+ return None ;
199193 } ;
200-
201194 let path_str = path_sym. as_str ( ) ;
202195
203196 // On windows, the base path might have the form
0 commit comments