6 fn arg_expand(arg: String) -> Result<Vec<String>, Error> {
7 if let Some(path) = arg.strip_prefix('@') {
8 let file = match fs::read_to_string(path) {
10 Err(ref err) if err.kind() == io::ErrorKind::InvalidData => {
11 return Err(Error::Utf8Error(Some(path.to_string())));
13 Err(err) => return Err(Error::IOError(path.to_string(), err)),
15 Ok(file.lines().map(ToString::to_string).collect())
21 pub fn arg_expand_all(at_args: &[String]) -> Vec<String> {
22 let mut args = Vec::new();
24 match arg_expand(arg.clone()) {
25 Ok(arg) => args.extend(arg),
26 Err(err) => rustc_session::early_error(
27 rustc_session::config::ErrorOutputType::default(),
28 &format!("Failed to load argument file: {}", err),
37 Utf8Error(Option<String>),
38 IOError(String, io::Error),
41 impl fmt::Display for Error {
42 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
44 Error::Utf8Error(None) => write!(fmt, "Utf8 error"),
45 Error::Utf8Error(Some(path)) => write!(fmt, "Utf8 error in {}", path),
46 Error::IOError(path, err) => write!(fmt, "IO Error: {}: {}", path, err),
51 impl error::Error for Error {}