Skip to content

Commit 27b7c6c

Browse files
committed
docs(rustfix): comments for diagnostic JSON output
Most doc comments are copied from rust-lang/rust repo. The doc for each item is hand-written as there is no comment in the original place.
1 parent 463f307 commit 27b7c6c

File tree

1 file changed

+35
-9
lines changed

1 file changed

+35
-9
lines changed

crates/rustfix/src/diagnostics.rs

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
//! Rustc Diagnostic JSON Output
1+
//! Rustc Diagnostic JSON Output.
22
//!
3-
//! The following data types are copied from [rust-lang/rust](https://github.com/rust-lang/rust/blob/de78655bca47cac8e783dbb563e7e5c25c1fae40/src/libsyntax/json.rs)
3+
//! The following data types are copied from [rust-lang/rust](https://github.com/rust-lang/rust/blob/4fd68eb47bad1c121417ac4450b2f0456150db86/compiler/rustc_errors/src/json.rs).
4+
//!
5+
//! For examples of the JSON output, see JSON fixture files under `tests/` directory.
46
57
use serde::Deserialize;
68

9+
/// The root diagnostic JSON output emitted by the compiler.
710
#[derive(Clone, Deserialize, Debug, Hash, Eq, PartialEq)]
811
pub struct Diagnostic {
912
/// The primary error message.
@@ -14,12 +17,11 @@ pub struct Diagnostic {
1417
pub spans: Vec<DiagnosticSpan>,
1518
/// Associated diagnostic messages.
1619
pub children: Vec<Diagnostic>,
17-
/// The message as rustc would render it. Currently this is only
18-
/// `Some` for "suggestions", but eventually it will include all
19-
/// snippets.
20+
/// The message as rustc would render it.
2021
pub rendered: Option<String>,
2122
}
2223

24+
/// Span information of a diagnostic item.
2325
#[derive(Clone, Deserialize, Debug, Hash, Eq, PartialEq)]
2426
pub struct DiagnosticSpan {
2527
pub file_name: String,
@@ -39,23 +41,43 @@ pub struct DiagnosticSpan {
3941
/// Label that should be placed at this location (if any)
4042
label: Option<String>,
4143
/// If we are suggesting a replacement, this will contain text
42-
/// that should be sliced in atop this span. You may prefer to
43-
/// load the fully rendered version from the parent `Diagnostic`,
44-
/// however.
44+
/// that should be sliced in atop this span.
4545
pub suggested_replacement: Option<String>,
46+
/// If the suggestion is approximate
4647
pub suggestion_applicability: Option<Applicability>,
4748
/// Macro invocations that created the code at this span, if any.
4849
expansion: Option<Box<DiagnosticSpanMacroExpansion>>,
4950
}
5051

52+
/// Indicates the confidence in the correctness of a suggestion.
53+
///
54+
/// All suggestions are marked with an `Applicability`. Tools use the applicability of a suggestion
55+
/// to determine whether it should be automatically applied or if the user should be consulted
56+
/// before applying the suggestion.
5157
#[derive(Copy, Clone, Debug, PartialEq, Deserialize, Hash, Eq)]
5258
pub enum Applicability {
59+
/// The suggestion is definitely what the user intended, or maintains the exact meaning of the code.
60+
/// This suggestion should be automatically applied.
61+
///
62+
/// In case of multiple `MachineApplicable` suggestions (whether as part of
63+
/// the same `multipart_suggestion` or not), all of them should be
64+
/// automatically applied.
5365
MachineApplicable,
54-
HasPlaceholders,
66+
67+
/// The suggestion may be what the user intended, but it is uncertain. The suggestion should
68+
/// result in valid Rust code if it is applied.
5569
MaybeIncorrect,
70+
71+
/// The suggestion contains placeholders like `(...)` or `{ /* fields */ }`. The suggestion
72+
/// cannot be applied automatically because it will not result in valid Rust code. The user
73+
/// will need to fill in the placeholders.
74+
HasPlaceholders,
75+
76+
/// The applicability of the suggestion is unknown.
5677
Unspecified,
5778
}
5879

80+
/// Span information of a single line.
5981
#[derive(Clone, Deserialize, Debug, Eq, PartialEq, Hash)]
6082
pub struct DiagnosticSpanLine {
6183
pub text: String,
@@ -66,6 +88,7 @@ pub struct DiagnosticSpanLine {
6688
pub highlight_end: usize,
6789
}
6890

91+
/// Span information for macro expansions.
6992
#[derive(Clone, Deserialize, Debug, Eq, PartialEq, Hash)]
7093
struct DiagnosticSpanMacroExpansion {
7194
/// span where macro was applied to generate this code; note that
@@ -80,6 +103,9 @@ struct DiagnosticSpanMacroExpansion {
80103
def_site_span: Option<DiagnosticSpan>,
81104
}
82105

106+
/// The error code emitted by the compiler. See [Rust error codes index].
107+
///
108+
/// [Rust error codes index]: https://doc.rust-lang.org/error_codes/error-index.html
83109
#[derive(Clone, Deserialize, Debug, Eq, PartialEq, Hash)]
84110
pub struct DiagnosticCode {
85111
/// The code itself.

0 commit comments

Comments
 (0)