Skip to content

Commit 688fdab

Browse files
committed
Fix argument alias handling for -O and -C opt-level
1 parent d0a6ddf commit 688fdab

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/librustc/session/config.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2181,10 +2181,15 @@ pub fn build_session_options_and_crate_config(
21812181
TargetTriple::from_triple(host_triple())
21822182
};
21832183
let opt_level = {
2184-
if matches.opt_present("O") {
2185-
if cg.opt_level.is_some() {
2186-
early_error(error_format, "-O and -C opt-level both provided");
2184+
let max_o = matches.opt_positions("O").into_iter().max();
2185+
let max_c = matches.opt_strs_pos("C").into_iter().flat_map(|(i, s)| {
2186+
if let Some("opt-level") = s.splitn(2, '=').next() {
2187+
Some(i)
2188+
} else {
2189+
None
21872190
}
2191+
}).max();
2192+
if max_o > max_c {
21882193
OptLevel::Default
21892194
} else {
21902195
match cg.opt_level.as_ref().map(String::as_ref) {

0 commit comments

Comments
 (0)