From e3516a128e55ffd175527add83ac9ca721a94ed7 Mon Sep 17 00:00:00 2001 From: Philipp Hansch Date: Sun, 9 Jun 2019 12:04:40 +0200 Subject: [PATCH 1/2] librustc_errors: Add some more documentation --- src/librustc/session/config.rs | 8 ++++++-- src/librustc_errors/diagnostic_builder.rs | 2 +- src/librustc_errors/emitter.rs | 9 +++++++++ src/librustc_errors/lib.rs | 4 ++++ 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index 003fdd501a35a..d70ea1ee8e6c7 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -227,13 +227,17 @@ impl OutputType { } } +/// The type of diagnostics output to generate #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum ErrorOutputType { + /// Output meant for the consumption of humans. HumanReadable(HumanReadableErrorType), + /// Output that's consumed by other tools such as `rustfix` or the `RLS`. Json { - /// Render the json in a human readable way (with indents and newlines) + /// Render the JSON in a human readable way (with indents and newlines) pretty: bool, - /// The way the `rendered` field is created + /// The JSON output includes a `rendered` field that includes the rendered + /// human output. json_rendered: HumanReadableErrorType, }, } diff --git a/src/librustc_errors/diagnostic_builder.rs b/src/librustc_errors/diagnostic_builder.rs index 31f697a724a03..b130a9d5a2309 100644 --- a/src/librustc_errors/diagnostic_builder.rs +++ b/src/librustc_errors/diagnostic_builder.rs @@ -348,7 +348,7 @@ impl<'a> DiagnosticBuilder<'a> { /// Convenience function for internal use, clients should use one of the /// struct_* methods on Handler. - pub fn new_with_code(handler: &'a Handler, + pub(crate) fn new_with_code(handler: &'a Handler, level: Level, code: Option, message: &str) diff --git a/src/librustc_errors/emitter.rs b/src/librustc_errors/emitter.rs index 3bf477efe35f9..fca8298409a61 100644 --- a/src/librustc_errors/emitter.rs +++ b/src/librustc_errors/emitter.rs @@ -1,3 +1,12 @@ +//! The current rustc diagnostics emitter. +//! +//! An `Emitter` takes care of generating the output from a `DiagnosticBuilder` struct. +//! +//! There are various `Emitter` implementations that generate different output formats such as +//! JSON and human readable output. +//! +//! The output types are defined in `librustc::session::config::ErrorOutputType`. + use Destination::*; use syntax_pos::{SourceFile, Span, MultiSpan}; diff --git a/src/librustc_errors/lib.rs b/src/librustc_errors/lib.rs index cc3180c783bdf..589e93f48b30c 100644 --- a/src/librustc_errors/lib.rs +++ b/src/librustc_errors/lib.rs @@ -1,3 +1,7 @@ +//! Diagnostics creation and emission for rustc +//! +//! This module contains the code for creating and emitting diagnostics. + #![doc(html_root_url = "https://doc.rust-lang.org/nightly/")] #![allow(unused_attributes)] From 33137ffdd5ffd7b80b01dafa88f2f4f301ef6b25 Mon Sep 17 00:00:00 2001 From: Philipp Hansch Date: Mon, 10 Jun 2019 10:59:03 +0200 Subject: [PATCH 2/2] Address review comments Co-Authored-By: Mazdak Farrokhzad --- src/librustc/session/config.rs | 4 ++-- src/librustc_errors/diagnostic_builder.rs | 2 +- src/librustc_errors/lib.rs | 3 ++- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index d70ea1ee8e6c7..86a606b5fd3d6 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -227,14 +227,14 @@ impl OutputType { } } -/// The type of diagnostics output to generate +/// The type of diagnostics output to generate. #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum ErrorOutputType { /// Output meant for the consumption of humans. HumanReadable(HumanReadableErrorType), /// Output that's consumed by other tools such as `rustfix` or the `RLS`. Json { - /// Render the JSON in a human readable way (with indents and newlines) + /// Render the JSON in a human readable way (with indents and newlines). pretty: bool, /// The JSON output includes a `rendered` field that includes the rendered /// human output. diff --git a/src/librustc_errors/diagnostic_builder.rs b/src/librustc_errors/diagnostic_builder.rs index b130a9d5a2309..fc74e43ff5739 100644 --- a/src/librustc_errors/diagnostic_builder.rs +++ b/src/librustc_errors/diagnostic_builder.rs @@ -348,7 +348,7 @@ impl<'a> DiagnosticBuilder<'a> { /// Convenience function for internal use, clients should use one of the /// struct_* methods on Handler. - pub(crate) fn new_with_code(handler: &'a Handler, + crate fn new_with_code(handler: &'a Handler, level: Level, code: Option, message: &str) diff --git a/src/librustc_errors/lib.rs b/src/librustc_errors/lib.rs index 589e93f48b30c..6ec1b90cd91cd 100644 --- a/src/librustc_errors/lib.rs +++ b/src/librustc_errors/lib.rs @@ -1,9 +1,10 @@ -//! Diagnostics creation and emission for rustc +//! Diagnostics creation and emission for `rustc`. //! //! This module contains the code for creating and emitting diagnostics. #![doc(html_root_url = "https://doc.rust-lang.org/nightly/")] +#![feature(crate_visibility_modifier)] #![allow(unused_attributes)] #![cfg_attr(unix, feature(libc))] #![feature(nll)]