@@ -15,13 +15,16 @@ use rustc_middle::hir::nested_filter;
1515use rustc_middle:: ty:: { ParamEnv , Ty , TyCtxt } ;
1616use rustc_session:: config:: { self , CrateType , ErrorOutputType , ResolveDocLinks } ;
1717use rustc_session:: lint;
18+ use rustc_session:: EarlyDiagCtxt ;
1819use rustc_session:: Session ;
1920use rustc_span:: symbol:: sym;
20- use rustc_span:: { source_map, Span } ;
21+ use rustc_span:: { source_map, FileName , Span } ;
2122
2223use std:: cell:: RefCell ;
2324use std:: io;
25+ use std:: io:: Read ;
2426use std:: mem;
27+ use std:: path:: PathBuf ;
2528use std:: rc:: Rc ;
2629use std:: sync:: LazyLock ;
2730use std:: sync:: { atomic:: AtomicBool , Arc } ;
@@ -174,10 +177,30 @@ pub(crate) fn new_dcx(
174177 rustc_errors:: DiagCtxt :: new ( emitter) . with_flags ( unstable_opts. dcx_flags ( true ) )
175178}
176179
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+
177200/// Parse, resolve, and typecheck the given crate.
178201pub ( crate ) fn create_config (
179202 RustdocOptions {
180- input,
203+ input : _ ,
181204 crate_name,
182205 proc_macro_crate,
183206 error_format,
@@ -199,13 +222,12 @@ pub(crate) fn create_config(
199222 ..
200223 } : RustdocOptions ,
201224 RenderOptions { document_private, .. } : & RenderOptions ,
225+ input : Input ,
202226 using_internal_features : Arc < AtomicBool > ,
203227) -> rustc_interface:: Config {
204228 // Add the doc cfg into the doc build.
205229 cfgs. push ( "doc" . to_string ( ) ) ;
206230
207- let input = Input :: File ( input) ;
208-
209231 // By default, rustdoc ignores all lints.
210232 // Specifically unblock lints relevant to documentation or the lint machinery itself.
211233 let mut lints_to_show = vec ! [
0 commit comments