rustdoc: make main more like rustc's.

By making non-unicode arguments a fatal error instead of a warning, we
don't need to handle what comes after, which avoids the need for an
`unchecked_claim_error_was_emitted` call.
This commit is contained in:
Nicholas Nethercote 2024-02-06 20:47:47 +11:00
parent e55df623ea
commit e6794ddfb0

View File

@ -177,13 +177,16 @@ pub fn main() {
init_logging(&early_dcx);
rustc_driver::init_logger(&early_dcx, rustc_log::LoggerConfig::from_env("RUSTDOC_LOG"));
let exit_code = rustc_driver::catch_with_exit_code(|| match get_args(&early_dcx) {
Some(args) => main_args(&mut early_dcx, &args, using_internal_features),
_ =>
{
#[allow(deprecated)]
Err(ErrorGuaranteed::unchecked_claim_error_was_emitted())
}
let exit_code = rustc_driver::catch_with_exit_code(|| {
let args = env::args_os()
.enumerate()
.map(|(i, arg)| {
arg.into_string().unwrap_or_else(|arg| {
early_dcx.early_fatal(format!("argument {i} is not valid Unicode: {arg:?}"))
})
})
.collect::<Vec<_>>();
main_args(&mut early_dcx, &args, using_internal_features)
});
process::exit(exit_code);
}
@ -219,19 +222,6 @@ fn init_logging(early_dcx: &EarlyDiagCtxt) {
tracing::subscriber::set_global_default(subscriber).unwrap();
}
fn get_args(early_dcx: &EarlyDiagCtxt) -> Option<Vec<String>> {
env::args_os()
.enumerate()
.map(|(i, arg)| {
arg.into_string()
.map_err(|arg| {
early_dcx.early_warn(format!("Argument {i} is not valid Unicode: {arg:?}"));
})
.ok()
})
.collect()
}
fn opts() -> Vec<RustcOptGroup> {
let stable: fn(_, fn(&mut getopts::Options) -> &mut _) -> _ = RustcOptGroup::stable;
let unstable: fn(_, fn(&mut getopts::Options) -> &mut _) -> _ = RustcOptGroup::unstable;