Skip to content

Commit 56ddef8

Browse files
authored
Rollup merge of #86680 - camsteffen:dbg-opt-error, r=petrochenkov
Improve error for missing -Z with debugging option Before: ```text ❯ rustc --unpretty=hir error: Unrecognized option: 'unpretty' ``` After: ```text ❯ rustc --unpretty=hir error: Unrecognized option: 'unpretty'. Did you mean `-Z unpretty`? ```
2 parents 1823b3f + 2a60f09 commit 56ddef8

File tree

5 files changed

+19
-4
lines changed

5 files changed

+19
-4
lines changed

compiler/rustc_driver/src/lib.rs

+13-4
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use rustc_middle::middle::cstore::MetadataLoader;
2929
use rustc_save_analysis as save;
3030
use rustc_save_analysis::DumpHandler;
3131
use rustc_serialize::json::{self, ToJson};
32-
use rustc_session::config::nightly_options;
32+
use rustc_session::config::{nightly_options, CG_OPTIONS, DB_OPTIONS};
3333
use rustc_session::config::{ErrorOutputType, Input, OutputType, PrintRequest, TrimmedDefPaths};
3434
use rustc_session::getopts;
3535
use rustc_session::lint::{Lint, LintId};
@@ -1017,9 +1017,18 @@ pub fn handle_options(args: &[String]) -> Option<getopts::Matches> {
10171017
for option in config::rustc_optgroups() {
10181018
(option.apply)(&mut options);
10191019
}
1020-
let matches = options
1021-
.parse(args)
1022-
.unwrap_or_else(|f| early_error(ErrorOutputType::default(), &f.to_string()));
1020+
let matches = options.parse(args).unwrap_or_else(|e| {
1021+
let msg = match e {
1022+
getopts::Fail::UnrecognizedOption(ref opt) => CG_OPTIONS
1023+
.iter()
1024+
.map(|&(name, ..)| ('C', name))
1025+
.chain(DB_OPTIONS.iter().map(|&(name, ..)| ('Z', name)))
1026+
.find(|&(_, name)| *opt == name.replace("_", "-"))
1027+
.map(|(flag, _)| format!("{}. Did you mean `-{} {}`?", e, flag, opt)),
1028+
_ => None,
1029+
};
1030+
early_error(ErrorOutputType::default(), &msg.unwrap_or_else(|| e.to_string()));
1031+
});
10231032

10241033
// For all options we just parsed, we check a few aspects:
10251034
//
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// compile-flags: --llvm-args
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
error: Unrecognized option: 'llvm-args'. Did you mean `-C llvm-args`?
2+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// compile-flags: --unpretty=hir
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
error: Unrecognized option: 'unpretty'. Did you mean `-Z unpretty`?
2+

0 commit comments

Comments
 (0)