Skip to content

Commit 544d8e9

Browse files
committed
Fix argument alias handling for -O and -C opt-level
1 parent ef9a876 commit 544d8e9

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/librustc/session/config.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -2184,10 +2184,15 @@ pub fn build_session_options_and_crate_config(
21842184
TargetTriple::from_triple(host_triple())
21852185
};
21862186
let opt_level = {
2187-
if matches.opt_present("O") {
2188-
if cg.opt_level.is_some() {
2189-
early_error(error_format, "-O and -C opt-level both provided");
2187+
let max_o = matches.opt_positions("O").into_iter().max();
2188+
let max_c = matches.opt_strs_pos("C").into_iter().flat_map(|(i, s)| {
2189+
if let Some("opt-level") = s.splitn(2, '=').next() {
2190+
Some(i)
2191+
} else {
2192+
None
21902193
}
2194+
}).max();
2195+
if max_o > max_c {
21912196
OptLevel::Default
21922197
} else {
21932198
match cg.opt_level.as_ref().map(String::as_ref) {

0 commit comments

Comments
 (0)