@@ -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,41 +87,47 @@ 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
- pub fn arg_expand_all ( early_dcx : & EarlyDiagCtxt , at_args : & [ String ] ) -> Vec < String > {
104
+ pub fn arg_expand_all (
105
+ early_dcx : & EarlyDiagCtxt ,
106
+ at_args : & [ String ] ,
107
+ ) -> Result < Vec < String > , ErrorGuaranteed > {
101
108
let mut expander = Expander :: default ( ) ;
109
+ let mut result = Ok ( ( ) ) ;
102
110
for arg in at_args {
103
111
if let Err ( err) = expander. arg ( arg) {
104
- early_dcx. early_fatal ( format ! ( "Failed to load argument file: {err}" ) ) ;
112
+ result = Err ( early_dcx. early_err ( format ! ( "failed to load argument file: {err}" ) ) ) ;
105
113
}
106
114
}
107
- expander. finish ( )
115
+ result . map ( | ( ) | expander. finish ( ) )
108
116
}
109
117
110
118
#[ derive( Debug ) ]
111
- pub enum Error {
112
- Utf8Error ( Option < String > ) ,
119
+ enum Error {
120
+ Utf8Error ( String ) ,
113
121
IOError ( String , io:: Error ) ,
114
122
ShellParseError ( String ) ,
115
123
}
116
124
117
125
impl fmt:: Display for Error {
118
126
fn fmt ( & self , fmt : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
119
127
match self {
120
- Error :: Utf8Error ( None ) => write ! ( fmt, "Utf8 error" ) ,
121
- Error :: Utf8Error ( Some ( path) ) => write ! ( fmt, "Utf8 error in {path}" ) ,
122
- Error :: IOError ( path, err) => write ! ( fmt, "IO Error: {path}: {err}" ) ,
123
- Error :: ShellParseError ( path) => write ! ( fmt, "Invalid shell-style arguments in {path}" ) ,
128
+ Error :: Utf8Error ( path) => write ! ( fmt, "UTF-8 error in {path}" ) ,
129
+ Error :: IOError ( path, err) => write ! ( fmt, "IO error: {path}: {err}" ) ,
130
+ Error :: ShellParseError ( path) => write ! ( fmt, "invalid shell-style arguments in {path}" ) ,
124
131
}
125
132
}
126
133
}
0 commit comments