@@ -2,12 +2,14 @@ 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:: validate_attr:: emit_malformed_attribute ;
66use rustc_errors:: { Diag , ErrorGuaranteed } ;
7+ use rustc_feature:: template;
78use rustc_parse:: lexer:: StripTokens ;
89use rustc_parse:: { exp, new_parser_from_file, unwrap_or_emit_fatal} ;
910use rustc_session:: Session ;
1011use rustc_session:: parse:: ParseSess ;
12+ use rustc_span:: fatal_error:: FatalError ;
1113use rustc_span:: { Ident , Span , sym} ;
1214use thin_vec:: ThinVec ;
1315
@@ -184,6 +186,7 @@ pub(crate) fn mod_file_path_from_attr(
184186 attrs : & [ Attribute ] ,
185187 dir_path : & Path ,
186188) -> Option < PathBuf > {
189+ // FIXME(154781) use a parsed attribute here
187190 // Extract path string from first `#[path = "path_string"]` attribute.
188191 let first_path = attrs. iter ( ) . find ( |at| at. has_name ( sym:: path) ) ?;
189192 let Some ( path_sym) = first_path. value_str ( ) else {
@@ -195,7 +198,17 @@ pub(crate) fn mod_file_path_from_attr(
195198 // Usually bad forms are checked during semantic analysis via
196199 // `TyCtxt::check_mod_attrs`), but by the time that runs the macro
197200 // is expanded, and it doesn't give an error.
198- validate_attr:: emit_fatal_malformed_builtin_attribute ( & sess. psess , first_path, sym:: path) ;
201+ emit_malformed_attribute (
202+ & sess. psess ,
203+ first_path. style ,
204+ first_path. span ,
205+ sym:: path,
206+ template ! (
207+ NameValueStr : "file" ,
208+ "https://doc.rust-lang.org/reference/items/modules.html#the-path-attribute"
209+ ) ,
210+ ) ;
211+ FatalError . raise ( )
199212 } ;
200213
201214 let path_str = path_sym. as_str ( ) ;
0 commit comments