Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 3dec18a

Browse files
committed
Add doc comment
1 parent 20bdb2f commit 3dec18a

File tree

5 files changed

+81
-45
lines changed

5 files changed

+81
-45
lines changed

config_proc_macro/src/attrs.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,39 @@
1+
//! This module provides utilities for handling attributes on variants
2+
//! of `config_type` enum. Currently there are two types of attributes
3+
//! that could appear on the variants of `config_type` enum: `doc_hint`
4+
//! and `value`. Both comes in the form of name-value pair whose value
5+
//! is string literal.
6+
7+
/// Returns the value of the first `doc_hint` attribute in the given slice or
8+
/// `None` if `doc_hint` attribute is not available.
19
pub fn find_doc_hint(attrs: &[syn::Attribute]) -> Option<String> {
210
attrs.iter().filter_map(doc_hint).next()
311
}
412

13+
/// Returns `true` if the given attribute is a `doc_hint` attribute.
514
pub fn is_doc_hint(attr: &syn::Attribute) -> bool {
615
is_attr_name_value(attr, "doc_hint")
716
}
817

18+
/// Returns a string literal value if the given attribute is `doc_hint`
19+
/// attribute or `None` otherwise.
920
pub fn doc_hint(attr: &syn::Attribute) -> Option<String> {
1021
get_name_value_str_lit(attr, "doc_hint")
1122
}
1223

24+
/// Returns the value of the first `value` attribute in the given slice or
25+
/// `None` if `value` attribute is not available.
1326
pub fn find_config_value(attrs: &[syn::Attribute]) -> Option<String> {
1427
attrs.iter().filter_map(config_value).next()
1528
}
1629

30+
/// Returns a string literal value if the given attribute is `value`
31+
/// attribute or `None` otherwise.
1732
pub fn config_value(attr: &syn::Attribute) -> Option<String> {
1833
get_name_value_str_lit(attr, "value")
1934
}
2035

36+
/// Returns `true` if the given attribute is a `value` attribute.
2137
pub fn is_config_value(attr: &syn::Attribute) -> bool {
2238
is_attr_name_value(attr, "value")
2339
}

config_proc_macro/src/config_type.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ use proc_macro2::TokenStream;
33
use crate::item_enum::define_config_type_on_enum;
44
use crate::item_struct::define_config_type_on_struct;
55

6+
/// Defines `config_type` on enum or struct.
7+
// FIXME: Implement this on struct.
68
pub fn define_config_type(input: &syn::Item) -> TokenStream {
79
match input {
810
syn::Item::Struct(st) => define_config_type_on_struct(st),

config_proc_macro/src/item_enum.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use crate::utils::*;
66

77
type Variants = syn::punctuated::Punctuated<syn::Variant, syn::Token![,]>;
88

9+
/// Defines and implements `config_type` enum.
910
pub fn define_config_type_on_enum(em: &syn::ItemEnum) -> syn::Result<TokenStream> {
1011
let syn::ItemEnum {
1112
vis,

src/config/lists.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ impl DefinitiveListTactic {
2828
/// their comments.
2929
#[config_type]
3030
pub enum ListTactic {
31-
// One item per row.
31+
/// One item per row.
3232
Vertical,
33-
// All items on one row.
33+
/// All items on one row.
3434
Horizontal,
35-
// Try Horizontal layout, if that fails then vertical.
35+
/// Try Horizontal layout, if that fails then vertical.
3636
HorizontalVertical,
37-
// HorizontalVertical with a soft limit of n characters.
37+
/// HorizontalVertical with a soft limit of n characters.
3838
LimitedHorizontalVertical(usize),
39-
// Pack as many items as possible per row over (possibly) many rows.
39+
/// Pack as many items as possible per row over (possibly) many rows.
4040
Mixed,
4141
}
4242

src/config/options.rs

Lines changed: 57 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,14 @@ use crate::config::Config;
1111

1212
#[config_type]
1313
pub enum NewlineStyle {
14-
Auto, // Auto-detect based on the raw source input
15-
Windows, // \r\n
16-
Unix, // \n
17-
Native, // \r\n in Windows, \n on other platforms
14+
/// Auto-detect based on the raw source input.
15+
Auto,
16+
/// Force CRLF (`\r\n`).
17+
Windows,
18+
/// Force CR (`\n).
19+
Unix,
20+
/// `\r\n` in Windows, `\n`` on other platforms.
21+
Native,
1822
}
1923

2024
impl NewlineStyle {
@@ -74,58 +78,66 @@ impl NewlineStyle {
7478
}
7579

7680
#[config_type]
81+
/// Where to put the opening brace of items (`fn`, `impl`, etc.).
7782
pub enum BraceStyle {
83+
/// Put the opening brace on the next line.
7884
AlwaysNextLine,
85+
/// Put the opening brace on the same line, if possible.
7986
PreferSameLine,
80-
// Prefer same line except where there is a where-clause, in which case force
81-
// the brace to the next line.
87+
/// Prefer the same line except where there is a where-clause, in which
88+
/// case force the brace to be put on the next line.
8289
SameLineWhere,
8390
}
8491

8592
#[config_type]
93+
/// Where to put the opening brace of conditional expressions (`if`, `match`, etc.).
8694
pub enum ControlBraceStyle {
87-
// K&R style, Rust community default
95+
/// K&R style, Rust community default
8896
AlwaysSameLine,
89-
// Stroustrup style
97+
/// Stroustrup style
9098
ClosingNextLine,
91-
// Allman style
99+
/// Allman style
92100
AlwaysNextLine,
93101
}
94102

95103
#[config_type]
104+
/// How to indent.
96105
pub enum IndentStyle {
97-
// First line on the same line as the opening brace, all lines aligned with
98-
// the first line.
106+
/// First line on the same line as the opening brace, all lines aligned with
107+
/// the first line.
99108
Visual,
100-
// First line is on a new line and all lines align with block indent.
109+
/// First line is on a new line and all lines align with **block** indent.
101110
Block,
102111
}
103112

104113
#[config_type]
114+
/// How to place a list-like items.
105115
pub enum Density {
106-
// Fit as much on one line as possible.
116+
/// Fit as much on one line as possible.
107117
Compressed,
108-
// Use more lines.
118+
/// Use more lines.
109119
Tall,
110-
// Place every item on a separate line.
120+
/// Place every item on a separate line.
111121
Vertical,
112122
}
113123

114124
#[config_type]
125+
/// Spacing around type combinators.
115126
pub enum TypeDensity {
116-
// No spaces around "=" and "+"
127+
/// No spaces around "=" and "+"
117128
Compressed,
118-
// Spaces around " = " and " + "
129+
/// Spaces around " = " and " + "
119130
Wide,
120131
}
121132

122133
#[config_type]
134+
/// To what extent does rustfmt pursue its heuristics?
123135
pub enum Heuristics {
124-
// Turn off any heuristics
136+
/// Turn off any heuristics
125137
Off,
126-
// Turn on max heuristics
138+
/// Turn on max heuristics
127139
Max,
128-
// Use Rustfmt's defaults
140+
/// Use Rustfmt's defaults
129141
Default,
130142
}
131143

@@ -147,42 +159,44 @@ pub enum ReportTactic {
147159
Never,
148160
}
149161

150-
// What Rustfmt should emit. Mostly corresponds to the `--emit` command line
151-
// option.
162+
/// What Rustfmt should emit. Mostly corresponds to the `--emit` command line
163+
/// option.
152164
#[config_type]
153165
pub enum EmitMode {
154-
// Emits to files.
166+
/// Emits to files.
155167
Files,
156-
// Writes the output to stdout.
168+
/// Writes the output to stdout.
157169
Stdout,
158-
// Displays how much of the input file was processed
170+
/// Displays how much of the input file was processed
159171
Coverage,
160-
// Unfancy stdout
172+
/// Unfancy stdout
161173
Checkstyle,
162-
// Output the changed lines (for internal value only)
174+
/// Output the changed lines (for internal value only)
163175
ModifiedLines,
164-
// Checks if a diff can be generated. If so, rustfmt outputs a diff and quits with exit code 1.
165-
// This option is designed to be run in CI where a non-zero exit signifies non-standard code
166-
// formatting. Used for `--check`.
176+
/// Checks if a diff can be generated. If so, rustfmt outputs a diff and
177+
/// quits with exit code 1.
178+
/// This option is designed to be run in CI where a non-zero exit signifies
179+
/// non-standard code formatting. Used for `--check`.
167180
Diff,
168181
}
169182

170-
// Client-preference for coloured output.
183+
/// Client-preference for coloured output.
171184
#[config_type]
172185
pub enum Color {
173-
// Always use color, whether it is a piped or terminal output
186+
/// Always use color, whether it is a piped or terminal output
174187
Always,
175-
// Never use color
188+
/// Never use color
176189
Never,
177-
// Automatically use color, if supported by terminal
190+
/// Automatically use color, if supported by terminal
178191
Auto,
179192
}
180193

181194
#[config_type]
195+
/// rustfmt format style version.
182196
pub enum Version {
183-
// 1.x.y
197+
/// 1.x.y. When specified, rustfmt will format in the same style as 1.0.0.
184198
One,
185-
// 2.x.y
199+
/// 2.x.y. When specified, rustfmt will formatin the the latest style.
186200
Two,
187201
}
188202

@@ -197,13 +211,14 @@ impl Color {
197211
}
198212
}
199213

200-
// How chatty should Rustfmt be?
214+
/// How chatty should Rustfmt be?
201215
#[config_type]
202216
pub enum Verbosity {
203-
// Emit more.
217+
/// Emit more.
204218
Verbose,
219+
/// Default.
205220
Normal,
206-
// Emit as little as possible.
221+
/// Emit as little as possible.
207222
Quiet,
208223
}
209224

@@ -369,14 +384,16 @@ pub trait CliOptions {
369384
fn config_path(&self) -> Option<&Path>;
370385
}
371386

372-
// The edition of the compiler (RFC 2052)
387+
/// The edition of the syntax and semntics of code (RFC 2052).
373388
#[config_type]
374389
pub enum Edition {
375390
#[value = "2015"]
376391
#[doc_hint = "2015"]
392+
/// Edition 2015.
377393
Edition2015,
378394
#[value = "2018"]
379395
#[doc_hint = "2018"]
396+
/// Edition 2018.
380397
Edition2018,
381398
}
382399

0 commit comments

Comments
 (0)