@@ -44,6 +44,7 @@ use std::path::{Component, Path, PathBuf};
44
44
use std:: rc:: Rc ;
45
45
use std:: str;
46
46
use std:: string:: ToString ;
47
+ use std:: sync:: mpsc:: { channel, Receiver } ;
47
48
use std:: sync:: Arc ;
48
49
49
50
use itertools:: Itertools ;
@@ -65,7 +66,7 @@ use serde::{Serialize, Serializer};
65
66
use crate :: clean:: { self , AttributesExt , Deprecation , GetDefId , SelfTy , TypeKind } ;
66
67
use crate :: config:: RenderInfo ;
67
68
use crate :: config:: RenderOptions ;
68
- use crate :: docfs:: { DocFS , ErrorStorage , PathError } ;
69
+ use crate :: docfs:: { DocFS , PathError } ;
69
70
use crate :: doctree;
70
71
use crate :: error:: Error ;
71
72
use crate :: formats:: cache:: { cache, Cache } ;
@@ -113,7 +114,9 @@ crate struct Context {
113
114
id_map : Rc < RefCell < IdMap > > ,
114
115
pub shared : Arc < SharedContext > ,
115
116
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 > > ,
117
120
}
118
121
119
122
crate struct SharedContext {
@@ -403,7 +406,6 @@ impl FormatRenderer for Context {
403
406
} ,
404
407
_ => PathBuf :: new ( ) ,
405
408
} ;
406
- let errors = Arc :: new ( ErrorStorage :: new ( ) ) ;
407
409
// If user passed in `--playground-url` arg, we fill in crate name here
408
410
let mut playground = None ;
409
411
if let Some ( url) = playground_url {
@@ -447,6 +449,7 @@ impl FormatRenderer for Context {
447
449
}
448
450
}
449
451
}
452
+ let ( sender, receiver) = channel ( ) ;
450
453
let mut scx = SharedContext {
451
454
collapsed : krate. collapsed ,
452
455
src_root,
@@ -459,7 +462,7 @@ impl FormatRenderer for Context {
459
462
style_files,
460
463
resource_suffix,
461
464
static_root_path,
462
- fs : DocFS :: new ( & errors ) ,
465
+ fs : DocFS :: new ( & sender ) ,
463
466
edition,
464
467
codes : ErrorCodes :: from ( UnstableFeatures :: from_environment ( ) . is_nightly_build ( ) ) ,
465
468
playground,
@@ -493,7 +496,7 @@ impl FormatRenderer for Context {
493
496
id_map : Rc :: new ( RefCell :: new ( id_map) ) ,
494
497
shared : Arc :: new ( scx) ,
495
498
all : Rc :: new ( RefCell :: new ( AllTypes :: new ( ) ) ) ,
496
- errors,
499
+ errors : Rc :: new ( receiver ) ,
497
500
} ;
498
501
499
502
CURRENT_DEPTH . with ( |s| s. set ( 0 ) ) ;
@@ -506,8 +509,8 @@ impl FormatRenderer for Context {
506
509
}
507
510
508
511
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 ( ) ;
511
514
if nb_errors > 0 {
512
515
Err ( Error :: new ( io:: Error :: new ( io:: ErrorKind :: Other , "I/O error" ) , "" ) )
513
516
} else {
0 commit comments