Skip to content

Commit 75db571

Browse files
authored
Rollup merge of #64467 - Mark-Simulacrum:hide-cfg-failures, r=estebank
Hide diagnostics emitted during --cfg parsing The early error is more than sufficient for fixing the problem. Fixes #31496.
2 parents 7975973 + a678e31 commit 75db571

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

src/librustc/session/config.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use crate::session::{early_error, early_warn, Session};
77
use crate::session::search_paths::SearchPath;
88

99
use rustc_data_structures::fx::FxHashSet;
10+
use rustc_data_structures::sync::Lrc;
1011

1112
use rustc_target::spec::{LinkerFlavor, MergeFunctions, PanicStrategy, RelroLevel};
1213
use rustc_target::spec::{Target, TargetTriple};
@@ -19,6 +20,7 @@ use syntax::parse::{ParseSess, new_parser_from_source_str};
1920
use syntax::parse::token;
2021
use syntax::symbol::{sym, Symbol};
2122
use syntax::feature_gate::UnstableFeatures;
23+
use syntax::source_map::SourceMap;
2224

2325
use errors::emitter::HumanReadableErrorType;
2426
use errors::{ColorConfig, FatalError, Handler};
@@ -1850,11 +1852,20 @@ pub fn rustc_optgroups() -> Vec<RustcOptGroup> {
18501852
opts
18511853
}
18521854

1855+
struct NullEmitter;
1856+
1857+
impl errors::emitter::Emitter for NullEmitter {
1858+
fn emit_diagnostic(&mut self, _: &errors::DiagnosticBuilder<'_>) {}
1859+
}
1860+
18531861
// Converts strings provided as `--cfg [cfgspec]` into a `crate_cfg`.
18541862
pub fn parse_cfgspecs(cfgspecs: Vec<String>) -> FxHashSet<(String, Option<String>)> {
18551863
syntax::with_default_globals(move || {
18561864
let cfg = cfgspecs.into_iter().map(|s| {
1857-
let sess = ParseSess::new(FilePathMapping::empty());
1865+
1866+
let cm = Lrc::new(SourceMap::new(FilePathMapping::empty()));
1867+
let handler = Handler::with_emitter(false, None, Box::new(NullEmitter));
1868+
let sess = ParseSess::with_span_handler(handler, cm);
18581869
let filename = FileName::cfg_spec_source_code(&s);
18591870
let mut parser = new_parser_from_source_str(&sess, filename, s.to_string());
18601871

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// compile-flags: --cfg a{
2+
// error-pattern: invalid `--cfg` argument: `a{` (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: `a{` (expected `key` or `key="value"`)
2+

0 commit comments

Comments
 (0)