diff options
| author | beetrees <b@beetr.ee> | 2023-05-15 18:34:32 +0000 |
|---|---|---|
| committer | beetrees <b@beetr.ee> | 2024-03-07 00:19:55 +0000 |
| commit | 63091b105d08b7b0db19d699d3be3060acde04ad (patch) | |
| tree | 82ededcd7e6022139b1570cd3cbed16493c57a07 /compiler/rustc_driver_impl/src/args.rs | |
| parent | 7d3702e472b99be0f5de6608dd87af1df8f99428 (diff) | |
| download | rust-63091b105d08b7b0db19d699d3be3060acde04ad.tar.gz rust-63091b105d08b7b0db19d699d3be3060acde04ad.zip | |
Make `arg_expand_all` not short-circuit on first error
Diffstat (limited to 'compiler/rustc_driver_impl/src/args.rs')
| -rw-r--r-- | compiler/rustc_driver_impl/src/args.rs | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/compiler/rustc_driver_impl/src/args.rs b/compiler/rustc_driver_impl/src/args.rs index 8b6fb5fd660..8c03f54bb59 100644 --- a/compiler/rustc_driver_impl/src/args.rs +++ b/compiler/rustc_driver_impl/src/args.rs @@ -4,6 +4,7 @@ use std::fs; use std::io; use rustc_session::EarlyDiagCtxt; +use rustc_span::ErrorGuaranteed; /// Expands argfiles in command line arguments. #[derive(Default)] @@ -86,7 +87,7 @@ impl Expander { fn read_file(path: &str) -> Result<String, Error> { fs::read_to_string(path).map_err(|e| { if e.kind() == io::ErrorKind::InvalidData { - Error::Utf8Error(Some(path.to_string())) + Error::Utf8Error(path.to_string()) } else { Error::IOError(path.to_string(), e) } @@ -94,23 +95,30 @@ impl Expander { } } +/// Replaces any `@file` arguments with the contents of `file`, with each line of `file` as a +/// separate argument. +/// /// **Note:** This function doesn't interpret argument 0 in any special way. /// If this function is intended to be used with command line arguments, /// `argv[0]` must be removed prior to calling it manually. #[allow(rustc::untranslatable_diagnostic)] // FIXME: make this translatable -pub fn arg_expand_all(early_dcx: &EarlyDiagCtxt, at_args: &[String]) -> Vec<String> { +pub fn arg_expand_all( + early_dcx: &EarlyDiagCtxt, + at_args: &[String], +) -> Result<Vec<String>, ErrorGuaranteed> { let mut expander = Expander::default(); + let mut result = Ok(()); for arg in at_args { if let Err(err) = expander.arg(arg) { - early_dcx.early_fatal(format!("Failed to load argument file: {err}")); + result = Err(early_dcx.early_err(format!("failed to load argument file: {err}"))); } } - expander.finish() + result.map(|()| expander.finish()) } #[derive(Debug)] -pub enum Error { - Utf8Error(Option<String>), +enum Error { + Utf8Error(String), IOError(String, io::Error), ShellParseError(String), } @@ -118,10 +126,9 @@ pub enum Error { impl fmt::Display for Error { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { match self { - Error::Utf8Error(None) => write!(fmt, "Utf8 error"), - Error::Utf8Error(Some(path)) => write!(fmt, "Utf8 error in {path}"), - Error::IOError(path, err) => write!(fmt, "IO Error: {path}: {err}"), - Error::ShellParseError(path) => write!(fmt, "Invalid shell-style arguments in {path}"), + Error::Utf8Error(path) => write!(fmt, "UTF-8 error in {path}"), + Error::IOError(path, err) => write!(fmt, "IO error: {path}: {err}"), + Error::ShellParseError(path) => write!(fmt, "invalid shell-style arguments in {path}"), } } } |
