@@ -4,6 +4,7 @@ use std::fs;
4
4
use std:: io;
5
5
6
6
use rustc_session:: EarlyDiagCtxt ;
7
+ use rustc_span:: ErrorGuaranteed ;
7
8
8
9
/// Expands argfiles in command line arguments.
9
10
#[ derive( Default ) ]
@@ -86,42 +87,48 @@ impl Expander {
86
87
fn read_file ( path : & str ) -> Result < String , Error > {
87
88
fs:: read_to_string ( path) . map_err ( |e| {
88
89
if e. kind ( ) == io:: ErrorKind :: InvalidData {
89
- Error :: Utf8Error ( Some ( path. to_string ( ) ) )
90
+ Error :: Utf8Error ( path. to_string ( ) )
90
91
} else {
91
92
Error :: IOError ( path. to_string ( ) , e)
92
93
}
93
94
} )
94
95
}
95
96
}
96
97
98
+ /// Replaces any `@file` arguments with the contents of `file`, with each line of `file` as a
99
+ /// separate argument.
100
+ ///
97
101
/// **Note:** This function doesn't interpret argument 0 in any special way.
98
102
/// If this function is intended to be used with command line arguments,
99
103
/// `argv[0]` must be removed prior to calling it manually.
100
104
#[ allow( rustc:: untranslatable_diagnostic) ] // FIXME: make this translatable
101
- pub fn arg_expand_all ( early_dcx : & EarlyDiagCtxt , at_args : & [ String ] ) -> Vec < String > {
105
+ pub fn arg_expand_all (
106
+ early_dcx : & EarlyDiagCtxt ,
107
+ at_args : & [ String ] ,
108
+ ) -> Result < Vec < String > , ErrorGuaranteed > {
102
109
let mut expander = Expander :: default ( ) ;
110
+ let mut result = Ok ( ( ) ) ;
103
111
for arg in at_args {
104
112
if let Err ( err) = expander. arg ( arg) {
105
- early_dcx. early_fatal ( format ! ( "Failed to load argument file: {err}" ) ) ;
113
+ result = Err ( early_dcx. early_err ( format ! ( "failed to load argument file: {err}" ) ) ) ;
106
114
}
107
115
}
108
- expander. finish ( )
116
+ result . map ( | ( ) | expander. finish ( ) )
109
117
}
110
118
111
119
#[ derive( Debug ) ]
112
- pub enum Error {
113
- Utf8Error ( Option < String > ) ,
120
+ enum Error {
121
+ Utf8Error ( String ) ,
114
122
IOError ( String , io:: Error ) ,
115
123
ShellParseError ( String ) ,
116
124
}
117
125
118
126
impl fmt:: Display for Error {
119
127
fn fmt ( & self , fmt : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
120
128
match self {
121
- Error :: Utf8Error ( None ) => write ! ( fmt, "Utf8 error" ) ,
122
- Error :: Utf8Error ( Some ( path) ) => write ! ( fmt, "Utf8 error in {path}" ) ,
123
- Error :: IOError ( path, err) => write ! ( fmt, "IO Error: {path}: {err}" ) ,
124
- Error :: ShellParseError ( path) => write ! ( fmt, "Invalid shell-style arguments in {path}" ) ,
129
+ Error :: Utf8Error ( path) => write ! ( fmt, "UTF-8 error in {path}" ) ,
130
+ Error :: IOError ( path, err) => write ! ( fmt, "IO error: {path}: {err}" ) ,
131
+ Error :: ShellParseError ( path) => write ! ( fmt, "invalid shell-style arguments in {path}" ) ,
125
132
}
126
133
}
127
134
}
0 commit comments