Skip to content

Commit 679af5e

Browse files
committed
Eagerly emit the error in parse_meta
1 parent 64c14e7 commit 679af5e

File tree

3 files changed

+11
-19
lines changed

3 files changed

+11
-19
lines changed

compiler/rustc_expand/src/config.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -370,8 +370,7 @@ impl<'a> StripUnconfigured<'a> {
370370
pub(crate) fn cfg_true(&self, attr: &Attribute) -> (bool, Option<MetaItem>) {
371371
let meta_item = match validate_attr::parse_meta(&self.sess.psess, attr) {
372372
Ok(meta_item) => meta_item,
373-
Err(err) => {
374-
err.emit();
373+
Err(_guar) => {
375374
return (true, None);
376375
}
377376
};

compiler/rustc_expand/src/expand.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -765,10 +765,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
765765
fragment_kind.expect_from_annotatables(items)
766766
}
767767
}
768-
Err(err) => {
769-
let guar = err.emit();
770-
fragment_kind.dummy(span, guar)
771-
}
768+
Err(guar) => fragment_kind.dummy(span, guar),
772769
}
773770
}
774771
SyntaxExtensionKind::NonMacroAttr => {

compiler/rustc_parse/src/validate_attr.rs

+9-13
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ use rustc_ast::{
88
self as ast, AttrArgs, AttrArgsEq, Attribute, DelimArgs, MetaItem, MetaItemKind,
99
NestedMetaItem, Safety,
1010
};
11-
use rustc_errors::{Applicability, FatalError, PResult};
11+
use rustc_errors::{Applicability, FatalError};
1212
use rustc_feature::{
1313
AttributeSafety, AttributeTemplate, BuiltinAttribute, Features, BUILTIN_ATTRIBUTE_MAP,
1414
};
1515
use rustc_session::errors::report_lit_error;
1616
use rustc_session::lint::builtin::{ILL_FORMED_ATTRIBUTE_INPUT, UNSAFE_ATTR_OUTSIDE_UNSAFE};
1717
use rustc_session::lint::BuiltinLintDiag;
1818
use rustc_session::parse::ParseSess;
19-
use rustc_span::{sym, BytePos, Span, Symbol};
19+
use rustc_span::{sym, BytePos, ErrorGuaranteed, Span, Symbol};
2020

2121
pub fn check_attr(features: &Features, psess: &ParseSess, attr: &Attribute) {
2222
if attr.is_doc_comment() {
@@ -81,25 +81,21 @@ pub fn check_attr(features: &Features, psess: &ParseSess, attr: &Attribute) {
8181
Some(BuiltinAttribute { name, template, .. }) if *name != sym::rustc_dummy => {
8282
match parse_meta(psess, attr) {
8383
Ok(meta) => check_builtin_meta_item(psess, &meta, attr.style, *name, *template),
84-
Err(err) => {
85-
err.emit();
86-
}
84+
Err(_guar) => {}
8785
}
8886
}
8987
_ if let AttrArgs::Eq(..) = attr_item.args => {
9088
// All key-value attributes are restricted to meta-item syntax.
9189
match parse_meta(psess, attr) {
9290
Ok(_) => {}
93-
Err(err) => {
94-
err.emit();
95-
}
91+
Err(_guar) => {}
9692
}
9793
}
9894
_ => {}
9995
}
10096
}
10197

102-
pub fn parse_meta<'a>(psess: &'a ParseSess, attr: &Attribute) -> PResult<'a, MetaItem> {
98+
pub fn parse_meta(psess: &ParseSess, attr: &Attribute) -> Result<MetaItem, ErrorGuaranteed> {
10399
let item = attr.get_normal_item();
104100
Ok(MetaItem {
105101
unsafety: item.unsafety,
@@ -109,8 +105,8 @@ pub fn parse_meta<'a>(psess: &'a ParseSess, attr: &Attribute) -> PResult<'a, Met
109105
AttrArgs::Empty => MetaItemKind::Word,
110106
AttrArgs::Delimited(DelimArgs { dspan, delim, tokens }) => {
111107
check_meta_bad_delim(psess, *dspan, *delim);
112-
let nmis =
113-
parse_in(psess, tokens.clone(), "meta list", |p| p.parse_meta_seq_top())?;
108+
let nmis = parse_in(psess, tokens.clone(), "meta list", |p| p.parse_meta_seq_top())
109+
.map_err(|d| d.emit())?;
114110
MetaItemKind::List(nmis)
115111
}
116112
AttrArgs::Eq(_, AttrArgsEq::Ast(expr)) => {
@@ -127,7 +123,7 @@ pub fn parse_meta<'a>(psess: &'a ParseSess, attr: &Attribute) -> PResult<'a, Met
127123
"instead of using a suffixed literal (`1u8`, `1.0f32`, etc.), \
128124
use an unsuffixed version (`1`, `1.0`, etc.)",
129125
);
130-
return Err(err);
126+
return Err(err.emit());
131127
} else {
132128
MetaItemKind::NameValue(lit)
133129
}
@@ -156,7 +152,7 @@ pub fn parse_meta<'a>(psess: &'a ParseSess, attr: &Attribute) -> PResult<'a, Met
156152
if let ast::ExprKind::Err(_) = expr.kind {
157153
err.downgrade_to_delayed_bug();
158154
}
159-
return Err(err);
155+
return Err(err.emit());
160156
}
161157
}
162158
AttrArgs::Eq(_, AttrArgsEq::Hir(lit)) => MetaItemKind::NameValue(lit.clone()),

0 commit comments

Comments
 (0)