Skip to content

Commit e8ee0d7

Browse files
committed
macros: add more documentation comments
Documentation comments are always good. Signed-off-by: David Wood <[email protected]>
1 parent 2647a48 commit e8ee0d7

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

compiler/rustc_macros/src/diagnostics/diagnostic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use std::collections::HashMap;
1414
use syn::{spanned::Spanned, Attribute, Meta, MetaList, MetaNameValue, Type};
1515
use synstructure::Structure;
1616

17-
/// The central struct for constructing the `as_error` method from an annotated struct.
17+
/// The central struct for constructing the `into_diagnostic` method from an annotated struct.
1818
pub(crate) struct SessionDiagnosticDerive<'a> {
1919
structure: Structure<'a>,
2020
builder: SessionDiagnosticDeriveBuilder,

compiler/rustc_macros/src/diagnostics/subdiagnostic.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ use std::str::FromStr;
1616
use syn::{spanned::Spanned, Meta, MetaList, MetaNameValue};
1717
use synstructure::{BindingInfo, Structure, VariantInfo};
1818

19+
/// `Applicability` of a suggestion - mirrors `rustc_errors::Applicability` - and used to represent
20+
/// the user's selection of applicability if specified in an attribute.
1921
enum Applicability {
2022
MachineApplicable,
2123
MaybeIncorrect,
@@ -56,6 +58,7 @@ impl quote::ToTokens for Applicability {
5658
}
5759
}
5860

61+
/// Which kind of suggestion is being created?
5962
#[derive(Clone, Copy)]
6063
enum SubdiagnosticSuggestionKind {
6164
/// `#[suggestion]`
@@ -68,6 +71,7 @@ enum SubdiagnosticSuggestionKind {
6871
Verbose,
6972
}
7073

74+
/// Which kind of subdiagnostic is being created from a variant?
7175
#[derive(Clone, Copy)]
7276
enum SubdiagnosticKind {
7377
/// `#[label(...)]`
@@ -129,6 +133,7 @@ impl quote::IdentFragment for SubdiagnosticKind {
129133
}
130134
}
131135

136+
/// The central struct for constructing the `add_to_diagnostic` method from an annotated struct.
132137
pub(crate) struct SessionSubdiagnosticDerive<'a> {
133138
structure: Structure<'a>,
134139
diag: syn::Ident,
@@ -210,6 +215,10 @@ impl<'a> SessionSubdiagnosticDerive<'a> {
210215
}
211216
}
212217

218+
/// Tracks persistent information required for building up the call to add to the diagnostic
219+
/// for the final generated method. This is a separate struct to `SessionSubdiagnosticDerive`
220+
/// only to be able to destructure and split `self.builder` and the `self.structure` up to avoid a
221+
/// double mut borrow later on.
213222
struct SessionSubdiagnosticDeriveBuilder<'a> {
214223
/// The identifier to use for the generated `DiagnosticBuilder` instance.
215224
diag: &'a syn::Ident,

compiler/rustc_macros/src/diagnostics/utils.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ pub(crate) struct FieldInfo<'a> {
102102
pub(crate) span: &'a proc_macro2::Span,
103103
}
104104

105+
/// Small helper trait for abstracting over `Option` fields that contain a value and a `Span`
106+
/// for error reporting if they are set more than once.
105107
pub(crate) trait SetOnce<T> {
106108
fn set_once(&mut self, value: T);
107109
}
@@ -122,6 +124,7 @@ impl<T> SetOnce<(T, Span)> for Option<(T, Span)> {
122124
}
123125

124126
pub(crate) trait HasFieldMap {
127+
/// Returns the binding for the field with the given name, if it exists on the type.
125128
fn get_field_binding(&self, field: &String) -> Option<&TokenStream>;
126129

127130
/// In the strings in the attributes supplied to this macro, we want callers to be able to

0 commit comments

Comments
 (0)