Skip to content

Commit 2004a51

Browse files
authored
Rollup merge of rust-lang#92468 - NieDzejkob:silent-cfg, r=petrochenkov
Emit an error for `--cfg=)` Fixes rust-lang#73026 See also: rust-lang#64467, rust-lang#89468 The issue stems from a `FatalError` being silently raised in `panictry_buffer`. Normally this is not a problem, because `panictry_buffer` emits the causes of the error, but they are not themselves fatal, so they get filtered out by the silent emitter. To fix this, we use a parser entrypoint which doesn't use `panictry_buffer`, and we handle the error ourselves.
2 parents aa31c97 + 193342e commit 2004a51

File tree

3 files changed

+24
-19
lines changed

3 files changed

+24
-19
lines changed

compiler/rustc_interface/src/interface.rs

+19-19
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_errors::registry::Registry;
1111
use rustc_errors::{ErrorReported, Handler};
1212
use rustc_lint::LintStore;
1313
use rustc_middle::ty;
14-
use rustc_parse::new_parser_from_source_str;
14+
use rustc_parse::maybe_new_parser_from_source_str;
1515
use rustc_query_impl::QueryCtxt;
1616
use rustc_session::config::{self, ErrorOutputType, Input, OutputFilenames};
1717
use rustc_session::early_error;
@@ -91,7 +91,6 @@ pub fn parse_cfgspecs(cfgspecs: Vec<String>) -> FxHashSet<(String, Option<String
9191
s
9292
)));
9393
let filename = FileName::cfg_spec_source_code(&s);
94-
let mut parser = new_parser_from_source_str(&sess, filename, s.to_string());
9594

9695
macro_rules! error {
9796
($reason: expr) => {
@@ -102,26 +101,27 @@ pub fn parse_cfgspecs(cfgspecs: Vec<String>) -> FxHashSet<(String, Option<String
102101
};
103102
}
104103

105-
match &mut parser.parse_meta_item() {
106-
Ok(meta_item) if parser.token == token::Eof => {
107-
if meta_item.path.segments.len() != 1 {
108-
error!("argument key must be an identifier");
109-
}
110-
match &meta_item.kind {
111-
MetaItemKind::List(..) => {
112-
error!(r#"expected `key` or `key="value"`"#);
113-
}
114-
MetaItemKind::NameValue(lit) if !lit.kind.is_str() => {
115-
error!("argument value must be a string");
104+
match maybe_new_parser_from_source_str(&sess, filename, s.to_string()) {
105+
Ok(mut parser) => match &mut parser.parse_meta_item() {
106+
Ok(meta_item) if parser.token == token::Eof => {
107+
if meta_item.path.segments.len() != 1 {
108+
error!("argument key must be an identifier");
116109
}
117-
MetaItemKind::NameValue(..) | MetaItemKind::Word => {
118-
let ident = meta_item.ident().expect("multi-segment cfg key");
119-
return (ident.name, meta_item.value_str());
110+
match &meta_item.kind {
111+
MetaItemKind::List(..) => {}
112+
MetaItemKind::NameValue(lit) if !lit.kind.is_str() => {
113+
error!("argument value must be a string");
114+
}
115+
MetaItemKind::NameValue(..) | MetaItemKind::Word => {
116+
let ident = meta_item.ident().expect("multi-segment cfg key");
117+
return (ident.name, meta_item.value_str());
118+
}
120119
}
121120
}
122-
}
123-
Ok(..) => {}
124-
Err(err) => err.cancel(),
121+
Ok(..) => {}
122+
Err(err) => err.cancel(),
123+
},
124+
Err(errs) => errs.into_iter().for_each(|mut err| err.cancel()),
125125
}
126126

127127
error!(r#"expected `key` or `key="value"`"#);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// compile-flags: --cfg )
2+
// error-pattern: invalid `--cfg` argument: `)` (expected `key` or `key="value"`)
3+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
error: invalid `--cfg` argument: `)` (expected `key` or `key="value"`)
2+

0 commit comments

Comments
 (0)