@@ -44,6 +44,7 @@ use std::path::{Component, Path, PathBuf};
4444use std:: rc:: Rc ;
4545use std:: str;
4646use std:: string:: ToString ;
47+ use std:: sync:: mpsc:: { channel, Receiver } ;
4748use std:: sync:: Arc ;
4849
4950use itertools:: Itertools ;
@@ -65,7 +66,7 @@ use serde::{Serialize, Serializer};
6566use crate :: clean:: { self , AttributesExt , Deprecation , GetDefId , SelfTy , TypeKind } ;
6667use crate :: config:: RenderInfo ;
6768use crate :: config:: RenderOptions ;
68- use crate :: docfs:: { DocFS , ErrorStorage , PathError } ;
69+ use crate :: docfs:: { DocFS , PathError } ;
6970use crate :: doctree;
7071use crate :: error:: Error ;
7172use crate :: formats:: cache:: { cache, Cache } ;
@@ -113,7 +114,9 @@ crate struct Context {
113114 id_map : Rc < RefCell < IdMap > > ,
114115 pub shared : Arc < SharedContext > ,
115116 all : Rc < RefCell < AllTypes > > ,
116- pub errors : Arc < ErrorStorage > ,
117+ /// Storage for the errors produced while generating documentation so they
118+ /// can be printed together at the end.
119+ pub errors : Rc < Receiver < String > > ,
117120}
118121
119122crate struct SharedContext {
@@ -403,7 +406,6 @@ impl FormatRenderer for Context {
403406 } ,
404407 _ => PathBuf :: new ( ) ,
405408 } ;
406- let errors = Arc :: new ( ErrorStorage :: new ( ) ) ;
407409 // If user passed in `--playground-url` arg, we fill in crate name here
408410 let mut playground = None ;
409411 if let Some ( url) = playground_url {
@@ -447,6 +449,7 @@ impl FormatRenderer for Context {
447449 }
448450 }
449451 }
452+ let ( sender, receiver) = channel ( ) ;
450453 let mut scx = SharedContext {
451454 collapsed : krate. collapsed ,
452455 src_root,
@@ -459,7 +462,7 @@ impl FormatRenderer for Context {
459462 style_files,
460463 resource_suffix,
461464 static_root_path,
462- fs : DocFS :: new ( & errors ) ,
465+ fs : DocFS :: new ( & sender ) ,
463466 edition,
464467 codes : ErrorCodes :: from ( UnstableFeatures :: from_environment ( ) . is_nightly_build ( ) ) ,
465468 playground,
@@ -493,7 +496,7 @@ impl FormatRenderer for Context {
493496 id_map : Rc :: new ( RefCell :: new ( id_map) ) ,
494497 shared : Arc :: new ( scx) ,
495498 all : Rc :: new ( RefCell :: new ( AllTypes :: new ( ) ) ) ,
496- errors,
499+ errors : Rc :: new ( receiver ) ,
497500 } ;
498501
499502 CURRENT_DEPTH . with ( |s| s. set ( 0 ) ) ;
@@ -506,8 +509,8 @@ impl FormatRenderer for Context {
506509 }
507510
508511 fn after_run ( & mut self , diag : & rustc_errors:: Handler ) -> Result < ( ) , Error > {
509- let nb_errors =
510- Arc :: get_mut ( & mut self . errors ) . map_or_else ( || 0 , |errors| errors . write_errors ( diag ) ) ;
512+ Arc :: get_mut ( & mut self . shared ) . unwrap ( ) . fs . close ( ) ;
513+ let nb_errors = self . errors . iter ( ) . map ( |err| diag . struct_err ( & err ) . emit ( ) ) . count ( ) ;
511514 if nb_errors > 0 {
512515 Err ( Error :: new ( io:: Error :: new ( io:: ErrorKind :: Other , "I/O error" ) , "" ) )
513516 } else {
0 commit comments