Skip to content

Commit cc737c1

Browse files
Remove emit_fatal_malformed_builtin_attribute
1 parent 540f43a commit cc737c1

2 files changed

Lines changed: 17 additions & 16 deletions

File tree

compiler/rustc_attr_parsing/src/validate_attr.rs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_ast::tokenstream::DelimSpan;
88
use rustc_ast::{
99
self as ast, AttrArgs, Attribute, DelimArgs, MetaItem, MetaItemInner, MetaItemKind, Safety,
1010
};
11-
use rustc_errors::{Applicability, FatalError, PResult};
11+
use rustc_errors::{Applicability, PResult};
1212
use rustc_feature::{AttributeTemplate, BUILTIN_ATTRIBUTE_MAP, BuiltinAttribute};
1313
use rustc_hir::AttrPath;
1414
use rustc_hir::lints::AttributeLintKind;
@@ -169,7 +169,7 @@ pub fn check_builtin_meta_item(
169169
}
170170
}
171171

172-
fn emit_malformed_attribute(
172+
pub fn emit_malformed_attribute(
173173
psess: &ParseSess,
174174
style: ast::AttrStyle,
175175
span: Span,
@@ -231,15 +231,3 @@ fn emit_malformed_attribute(
231231
err.emit();
232232
}
233233
}
234-
235-
pub fn emit_fatal_malformed_builtin_attribute(
236-
psess: &ParseSess,
237-
attr: &Attribute,
238-
name: Symbol,
239-
) -> ! {
240-
let template = BUILTIN_ATTRIBUTE_MAP.get(&name).expect("builtin attr defined").template;
241-
emit_malformed_attribute(psess, attr.style, attr.span, name, template);
242-
// This is fatal, otherwise it will likely cause a cascade of other errors
243-
// (and an error here is expected to be very rare).
244-
FatalError.raise()
245-
}

compiler/rustc_expand/src/module.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ use std::iter::once;
22
use std::path::{self, Path, PathBuf};
33

44
use rustc_ast::{AttrVec, Attribute, Inline, Item, ModSpans};
5-
use rustc_attr_parsing::validate_attr;
5+
use rustc_attr_parsing::validate_attr::emit_malformed_attribute;
66
use rustc_errors::{Diag, ErrorGuaranteed};
7+
use rustc_feature::template;
78
use rustc_parse::lexer::StripTokens;
89
use rustc_parse::{exp, new_parser_from_file, unwrap_or_emit_fatal};
910
use rustc_session::Session;
1011
use rustc_session::parse::ParseSess;
12+
use rustc_span::fatal_error::FatalError;
1113
use rustc_span::{Ident, Span, sym};
1214
use 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

Comments
 (0)