-
Notifications
You must be signed in to change notification settings - Fork 13k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rustc --cfg parsing is lax; ICEs on --cfg "" #23301
Comments
IMHO, this is a bug in diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs
index b999929..dc8f9fe 100644
--- a/src/librustc/session/config.rs
+++ b/src/librustc/session/config.rs
@@ -849,6 +849,9 @@ pub fn rustc_optgroups() -> Vec<RustcOptGroup> {
// Convert strings provided as --cfg [cfgspec] into a crate_cfg
pub fn parse_cfgspecs(cfgspecs: Vec<String> ) -> ast::CrateConfig {
cfgspecs.into_iter().map(|s| {
+ if &s == "" {
+ early_error("empty --cfg argument");
+ }
parse::parse_meta_from_source_str("cfgspec".to_string(),
s.to_string(),
Vec::new(), fn lookup_filemap_idx(&self, pos: BytePos) -> usize {
let files = self.files.borrow();
let files = &*files;
let len = files.len();
let mut a = 0;
let mut b = len;
while b - a > 1 {
let m = (a + b) / 2;
if files[m].start_pos > pos {
b = m;
} else {
a = m;
}
}
// There can be filemaps with length 0. These have the same start_pos as
// the previous filemap, but are not the filemaps we want (because they
// are length 0, they cannot contain what we are looking for). So,
// rewind until we find a useful filemap.
loop {
let lines = files[a].lines.borrow();
let lines = lines;
if !lines.is_empty() {
break;
}
if a == 0 {
panic!("position {} does not resolve to a source location",
pos.to_usize());
}
a -= 1;
}
if a >= len {
panic!("position {} does not resolve to a source location",
pos.to_usize())
}
return a;
} |
The compiler is trying to report that the
--cfg
argument is invalid, but I guess it's not prepared to handle 0-length source code?I also think it's a little strange that I can pass arbitrary source code to the
--cfg
command-line argument, and trailing source code is frequently ignored:e.g. I think these two invocations are equivalent:
I'm also wondering if the syntax could be just
--cfg feature=A
. The quoting is inconvenient.The text was updated successfully, but these errors were encountered: