Skip to content
Permalink
Browse files

Better handling of the sender channel part in rustdoc file writing

  • Loading branch information...
GuillaumeGomez committed Jun 20, 2019
1 parent 3eeb543 commit 65f12950b64cbea42e97f1425952c77cf024d5ed
Showing with 8 additions and 8 deletions.
  1. +6 −6 src/librustdoc/docfs.rs
  2. +2 −2 src/librustdoc/html/render.rs
@@ -11,7 +11,6 @@

use errors;

use std::cell::RefCell;
use std::fs;
use std::io;
use std::path::Path;
@@ -32,23 +31,24 @@ pub trait PathError {
}

pub struct ErrorStorage {
sender: Sender<Option<String>>,
sender: Option<Sender<Option<String>>>,
receiver: Receiver<Option<String>>,
}

impl ErrorStorage {
pub fn new() -> ErrorStorage {
let (sender, receiver) = channel();
ErrorStorage {
sender,
sender: Some(sender),
receiver,
}
}

/// Prints all stored errors. Returns the number of printed errors.
pub fn write_errors(&self, diag: &errors::Handler) -> usize {
pub fn write_errors(&mut self, diag: &errors::Handler) -> usize {
let mut printed = 0;
drop(self.sender);
// In order to drop the sender part of the channel.
self.sender = None;

for msg in self.receiver.iter() {
if let Some(ref error) = msg {
@@ -95,7 +95,7 @@ impl DocFS {
// be to create the file sync so errors are reported eagerly.
let contents = contents.as_ref().to_vec();
let path = path.as_ref().to_path_buf();
let sender = self.errors.sender.clone();
let sender = self.errors.sender.clone().unwrap();
rayon::spawn(move || {
match fs::write(&path, &contents) {
Ok(_) => {
@@ -552,7 +552,7 @@ pub fn run(mut krate: clean::Crate,
},
_ => PathBuf::new(),
};
let errors = Arc::new(ErrorStorage::new());
let mut errors = Arc::new(ErrorStorage::new());
let mut scx = SharedContext {
src_root,
passes,
@@ -722,7 +722,7 @@ pub fn run(mut krate: clean::Crate,

// And finally render the whole crate's documentation
let ret = cx.krate(krate);
let nb_errors = errors.write_errors(diag);
let nb_errors = Arc::get_mut(&mut errors).map_or_else(|| 0, |errors| errors.write_errors(diag));
if ret.is_err() {
ret
} else if nb_errors > 0 {

0 comments on commit 65f1295

Please sign in to comment.
You can’t perform that action at this time.