rust-lang/rustc-dev-guide

Example in "Getting diagnostic through `rustc_interface`" is outdated and meaningless

CSharperMantle opened this issue · 0 comments

Description

The code in the latest tutorial rustc-driver-getting-diagnostics.md no longer functions starting from as far as commit 7352353.

This struct DiagnosticSink is never instantiated, nor is it referenced. The reference to this struct is removed in 7352353 but the definition of it was left there.

// Buffer diagnostics in a Vec<u8>.
#[derive(Clone)]
pub struct DiagnosticSink(sync::Arc<sync::Mutex<Vec<u8>>>);
impl io::Write for DiagnosticSink {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
self.0.lock().unwrap().write(buf)
}
fn flush(&mut self) -> io::Result<()> {
self.0.lock().unwrap().flush()
}
}

This variable buffer is never written into after the removal of DiagnosticSink.

let sysroot = str::from_utf8(&out.stdout).unwrap().trim();
let buffer = sync::Arc::new(sync::Mutex::new(Vec::new()));
let config = rustc_interface::Config {

In commit 4383648, the config::Options did seem to expose the diagnostic_output prop, but it was later removed, rendering the above two definitions useless and the example pointless.

The comments on the Markdown page claim that the examples are tested on some date, and this date has been updated in every commit. Yet it does not seem to reflect the truth. The diagnostics have never been intercepted and stored after the removal of diagnostic_output.

Solutions

Solution 1

Remove this example.

Solution 2

Provide the documentation to an alternative interface to removed diagnostic_output.

Remarks

I came across this issue when I tried to suppress the diagnostics produced by rustc_interface::run_compiler and only fetch the compilation result (success or not). It would be better if a simpler approach to this could be provided.