@@ -15,13 +15,16 @@ use rustc_middle::hir::nested_filter;
15
15
use rustc_middle:: ty:: { ParamEnv , Ty , TyCtxt } ;
16
16
use rustc_session:: config:: { self , CrateType , ErrorOutputType , ResolveDocLinks } ;
17
17
use rustc_session:: lint;
18
+ use rustc_session:: EarlyDiagCtxt ;
18
19
use rustc_session:: Session ;
19
20
use rustc_span:: symbol:: sym;
20
- use rustc_span:: { source_map, Span } ;
21
+ use rustc_span:: { source_map, FileName , Span } ;
21
22
22
23
use std:: cell:: RefCell ;
23
24
use std:: io;
25
+ use std:: io:: Read ;
24
26
use std:: mem;
27
+ use std:: path:: PathBuf ;
25
28
use std:: rc:: Rc ;
26
29
use std:: sync:: LazyLock ;
27
30
use std:: sync:: { atomic:: AtomicBool , Arc } ;
@@ -174,10 +177,30 @@ pub(crate) fn new_dcx(
174
177
rustc_errors:: DiagCtxt :: new ( emitter) . with_flags ( unstable_opts. dcx_flags ( true ) )
175
178
}
176
179
180
+ /// Create the input (string or file path)
181
+ pub ( crate ) fn make_input (
182
+ early_dcx : & EarlyDiagCtxt ,
183
+ input : & String ,
184
+ ) -> Result < Input , ErrorGuaranteed > {
185
+ Ok ( if input == "-" {
186
+ let mut src = String :: new ( ) ;
187
+ if io:: stdin ( ) . read_to_string ( & mut src) . is_err ( ) {
188
+ // Immediately stop compilation if there was an issue reading
189
+ // the input (for example if the input stream is not UTF-8).
190
+ let reported =
191
+ early_dcx. early_err ( "couldn't read from stdin, as it did not contain valid UTF-8" ) ;
192
+ return Err ( reported) ;
193
+ }
194
+ Input :: Str { name : FileName :: anon_source_code ( & src) , input : src }
195
+ } else {
196
+ Input :: File ( PathBuf :: from ( input) )
197
+ } )
198
+ }
199
+
177
200
/// Parse, resolve, and typecheck the given crate.
178
201
pub ( crate ) fn create_config (
179
202
RustdocOptions {
180
- input,
203
+ input : _ ,
181
204
crate_name,
182
205
proc_macro_crate,
183
206
error_format,
@@ -199,13 +222,12 @@ pub(crate) fn create_config(
199
222
..
200
223
} : RustdocOptions ,
201
224
RenderOptions { document_private, .. } : & RenderOptions ,
225
+ input : Input ,
202
226
using_internal_features : Arc < AtomicBool > ,
203
227
) -> rustc_interface:: Config {
204
228
// Add the doc cfg into the doc build.
205
229
cfgs. push ( "doc" . to_string ( ) ) ;
206
230
207
- let input = Input :: File ( input) ;
208
-
209
231
// By default, rustdoc ignores all lints.
210
232
// Specifically unblock lints relevant to documentation or the lint machinery itself.
211
233
let mut lints_to_show = vec ! [
0 commit comments