@@ -24,7 +24,7 @@ use rustc_hashes::Hash64;
2424use rustc_macros:: { Decodable , Encodable , HashStable_Generic } ;
2525use rustc_span:: edition:: { DEFAULT_EDITION , EDITION_NAME_LIST , Edition , LATEST_STABLE_EDITION } ;
2626use rustc_span:: source_map:: FilePathMapping ;
27- use rustc_span:: { FileName , SourceFileHashAlgorithm , Symbol , sym} ;
27+ use rustc_span:: { FileName , RealFileName , SourceFileHashAlgorithm , Symbol , sym} ;
2828use rustc_target:: spec:: {
2929 FramePointer , LinkSelfContainedComponents , LinkerFeatures , PanicStrategy , SplitDebuginfo ,
3030 Target , TargetTuple ,
@@ -1358,6 +1358,17 @@ fn file_path_mapping(
13581358
13591359impl Default for Options {
13601360 fn default ( ) -> Options {
1361+ let unstable_opts = UnstableOptions :: default ( ) ;
1362+
1363+ // FIXME(Urgau): This is a hack that ideally shouldn't exist, but rustdoc
1364+ // currently uses this `Default` implementation, so we have no choice but
1365+ // to create a default working directory.
1366+ let working_dir = {
1367+ let working_dir = std:: env:: current_dir ( ) . unwrap ( ) ;
1368+ let file_mapping = file_path_mapping ( Vec :: new ( ) , & unstable_opts) ;
1369+ file_mapping. to_real_filename ( & RealFileName :: empty ( ) , & working_dir)
1370+ } ;
1371+
13611372 Options {
13621373 assert_incr_state : None ,
13631374 crate_types : Vec :: new ( ) ,
@@ -1374,7 +1385,7 @@ impl Default for Options {
13741385 test : false ,
13751386 incremental : None ,
13761387 untracked_state_hash : Default :: default ( ) ,
1377- unstable_opts : Default :: default ( ) ,
1388+ unstable_opts,
13781389 prints : Vec :: new ( ) ,
13791390 cg : Default :: default ( ) ,
13801391 error_format : ErrorOutputType :: default ( ) ,
@@ -1398,7 +1409,7 @@ impl Default for Options {
13981409 json_unused_externs : JsonUnusedExterns :: No ,
13991410 json_future_incompat : false ,
14001411 pretty : None ,
1401- working_dir : RealFileName :: LocalPath ( std :: env :: current_dir ( ) . unwrap ( ) ) ,
1412+ working_dir,
14021413 color : ColorConfig :: Auto ,
14031414 logical_env : FxIndexMap :: default ( ) ,
14041415 verbose : false ,
@@ -2752,12 +2763,16 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
27522763 . collect ( )
27532764 } ;
27542765
2755- let working_dir = std:: env:: current_dir ( ) . unwrap_or_else ( |e| {
2756- early_dcx. early_fatal ( format ! ( "Current directory is invalid: {e}" ) ) ;
2757- } ) ;
2766+ // Ideally we would use `SourceMap::working_dir` instead, but we don't have access to it
2767+ // so we manually create the potentially-remapped working directory
2768+ let working_dir = {
2769+ let working_dir = std:: env:: current_dir ( ) . unwrap_or_else ( |e| {
2770+ early_dcx. early_fatal ( format ! ( "Current directory is invalid: {e}" ) ) ;
2771+ } ) ;
27582772
2759- let file_mapping = file_path_mapping ( remap_path_prefix. clone ( ) , & unstable_opts) ;
2760- let working_dir = file_mapping. to_real_filename ( & working_dir) ;
2773+ let file_mapping = file_path_mapping ( remap_path_prefix. clone ( ) , & unstable_opts) ;
2774+ file_mapping. to_real_filename ( & RealFileName :: empty ( ) , & working_dir)
2775+ } ;
27612776
27622777 let verbose = matches. opt_present ( "verbose" ) || unstable_opts. verbose_internals ;
27632778
0 commit comments