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 https://github.com/rust-lang/rust/issues/31496.
This commit is contained in:
Mazdak Farrokhzad 2019-09-16 17:09:41 +02:00 committed by GitHub
commit 75db5711a4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 1 deletions

View file

@ -7,6 +7,7 @@ use crate::session::{early_error, early_warn, Session};
use crate::session::search_paths::SearchPath;
use rustc_data_structures::fx::FxHashSet;
use rustc_data_structures::sync::Lrc;
use rustc_target::spec::{LinkerFlavor, MergeFunctions, PanicStrategy, RelroLevel};
use rustc_target::spec::{Target, TargetTriple};
@ -19,6 +20,7 @@ use syntax::parse::{ParseSess, new_parser_from_source_str};
use syntax::parse::token;
use syntax::symbol::{sym, Symbol};
use syntax::feature_gate::UnstableFeatures;
use syntax::source_map::SourceMap;
use errors::emitter::HumanReadableErrorType;
use errors::{ColorConfig, FatalError, Handler};
@ -1850,11 +1852,20 @@ pub fn rustc_optgroups() -> Vec<RustcOptGroup> {
opts
}
struct NullEmitter;
impl errors::emitter::Emitter for NullEmitter {
fn emit_diagnostic(&mut self, _: &errors::DiagnosticBuilder<'_>) {}
}
// Converts strings provided as `--cfg [cfgspec]` into a `crate_cfg`.
pub fn parse_cfgspecs(cfgspecs: Vec<String>) -> FxHashSet<(String, Option<String>)> {
syntax::with_default_globals(move || {
let cfg = cfgspecs.into_iter().map(|s| {
let sess = ParseSess::new(FilePathMapping::empty());
let cm = Lrc::new(SourceMap::new(FilePathMapping::empty()));
let handler = Handler::with_emitter(false, None, Box::new(NullEmitter));
let sess = ParseSess::with_span_handler(handler, cm);
let filename = FileName::cfg_spec_source_code(&s);
let mut parser = new_parser_from_source_str(&sess, filename, s.to_string());

View file

@ -0,0 +1,3 @@
// compile-flags: --cfg a{
// error-pattern: invalid `--cfg` argument: `a{` (expected `key` or `key="value"`)
fn main() {}

View file

@ -0,0 +1,2 @@
error: invalid `--cfg` argument: `a{` (expected `key` or `key="value"`)