Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example in "Getting diagnostic through rustc_interface" is outdated and meaningless #1834

Closed
CSharperMantle opened this issue Dec 11, 2023 · 0 comments · Fixed by #1857
Closed

Comments

@CSharperMantle
Copy link

CSharperMantle commented Dec 11, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant