Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/librustc/session/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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};
Expand Down Expand Up @@ -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());

Expand Down
3 changes: 3 additions & 0 deletions src/test/ui/conditional-compilation/cfg-arg-invalid-6.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// compile-flags: --cfg a{
// error-pattern: invalid `--cfg` argument: `a{` (expected `key` or `key="value"`)
fn main() {}
2 changes: 2 additions & 0 deletions src/test/ui/conditional-compilation/cfg-arg-invalid-6.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
error: invalid `--cfg` argument: `a{` (expected `key` or `key="value"`)