@@ -30,6 +30,15 @@ struct DiagnosticBuilderInner<'a> {
30
30
allow_suggestions : bool ,
31
31
}
32
32
33
+ /// This is a helper macro for [`forward!`] that allows automatically adding documentation
34
+ /// that uses tokens from [`forward!`]'s input.
35
+ macro_rules! forward_inner_docs {
36
+ ( $e: expr => $i: item) => {
37
+ #[ doc = $e]
38
+ $i
39
+ }
40
+ }
41
+
33
42
/// In general, the `DiagnosticBuilder` uses deref to allow access to
34
43
/// the fields and methods of the embedded `diagnostic` in a
35
44
/// transparent way. *However,* many of the methods are intended to
@@ -45,10 +54,11 @@ macro_rules! forward {
45
54
pub fn $n: ident( & self , $( $name: ident: $ty: ty) ,* $( , ) ?) -> & Self
46
55
) => {
47
56
$( #[ $attrs] ) *
57
+ forward_inner_docs!( concat!( "See [`Diagnostic::" , stringify!( $n) , "()`]." ) =>
48
58
pub fn $n( & self , $( $name: $ty) ,* ) -> & Self {
49
59
self . diagnostic. $n( $( $name) ,* ) ;
50
60
self
51
- }
61
+ } ) ;
52
62
} ;
53
63
54
64
// Forward pattern for &mut self -> &mut Self
@@ -57,10 +67,11 @@ macro_rules! forward {
57
67
pub fn $n: ident( & mut self , $( $name: ident: $ty: ty) ,* $( , ) ?) -> & mut Self
58
68
) => {
59
69
$( #[ $attrs] ) *
70
+ forward_inner_docs!( concat!( "See [`Diagnostic::" , stringify!( $n) , "()`]." ) =>
60
71
pub fn $n( & mut self , $( $name: $ty) ,* ) -> & mut Self {
61
72
self . 0 . diagnostic. $n( $( $name) ,* ) ;
62
73
self
63
- }
74
+ } ) ;
64
75
} ;
65
76
66
77
// Forward pattern for &mut self -> &mut Self, with S: Into<MultiSpan>
@@ -74,10 +85,11 @@ macro_rules! forward {
74
85
) -> & mut Self
75
86
) => {
76
87
$( #[ $attrs] ) *
88
+ forward_inner_docs!( concat!( "See [`Diagnostic::" , stringify!( $n) , "()`]." ) =>
77
89
pub fn $n<S : Into <MultiSpan >>( & mut self , $( $name: $ty) ,* ) -> & mut Self {
78
90
self . 0 . diagnostic. $n( $( $name) ,* ) ;
79
91
self
80
- }
92
+ } ) ;
81
93
} ;
82
94
}
83
95
@@ -116,7 +128,7 @@ impl<'a> DiagnosticBuilder<'a> {
116
128
117
129
/// Stashes diagnostic for possible later improvement in a different,
118
130
/// later stage of the compiler. The diagnostic can be accessed with
119
- /// the provided `span` and `key` through `. steal_diagnostic` on `Handler` .
131
+ /// the provided `span` and `key` through [`Handler:: steal_diagnostic()`] .
120
132
///
121
133
/// As with `buffer`, this is unless the handler has disabled such buffering.
122
134
pub fn stash ( self , span : Span , key : StashKey ) {
@@ -202,7 +214,7 @@ impl<'a> DiagnosticBuilder<'a> {
202
214
}
203
215
204
216
/// Labels all the given spans with the provided label.
205
- /// See ` span_label` for more information.
217
+ /// See [`Diagnostic:: span_label()`] for more information.
206
218
pub fn span_labels (
207
219
& mut self ,
208
220
spans : impl IntoIterator < Item = Span > ,
@@ -233,7 +245,7 @@ impl<'a> DiagnosticBuilder<'a> {
233
245
found_extra: & dyn fmt:: Display ,
234
246
) -> & mut Self ) ;
235
247
236
- forward ! ( pub fn note_unsuccessfull_coercion (
248
+ forward ! ( pub fn note_unsuccessful_coercion (
237
249
& mut self ,
238
250
expected: DiagnosticStyledString ,
239
251
found: DiagnosticStyledString ,
@@ -254,6 +266,7 @@ impl<'a> DiagnosticBuilder<'a> {
254
266
msg: & str ,
255
267
) -> & mut Self ) ;
256
268
269
+ /// See [`Diagnostic::multipart_suggestion()`].
257
270
pub fn multipart_suggestion (
258
271
& mut self ,
259
272
msg : & str ,
@@ -267,6 +280,7 @@ impl<'a> DiagnosticBuilder<'a> {
267
280
self
268
281
}
269
282
283
+ /// See [`Diagnostic::multipart_suggestions()`].
270
284
pub fn multipart_suggestions (
271
285
& mut self ,
272
286
msg : & str ,
@@ -280,6 +294,7 @@ impl<'a> DiagnosticBuilder<'a> {
280
294
self
281
295
}
282
296
297
+ /// See [`Diagnostic::tool_only_multipart_suggestion()`].
283
298
pub fn tool_only_multipart_suggestion (
284
299
& mut self ,
285
300
msg : & str ,
@@ -293,6 +308,7 @@ impl<'a> DiagnosticBuilder<'a> {
293
308
self
294
309
}
295
310
311
+ /// See [`Diagnostic::span_suggestion()`].
296
312
pub fn span_suggestion (
297
313
& mut self ,
298
314
sp : Span ,
@@ -307,6 +323,7 @@ impl<'a> DiagnosticBuilder<'a> {
307
323
self
308
324
}
309
325
326
+ /// See [`Diagnostic::span_suggestions()`].
310
327
pub fn span_suggestions (
311
328
& mut self ,
312
329
sp : Span ,
@@ -321,6 +338,7 @@ impl<'a> DiagnosticBuilder<'a> {
321
338
self
322
339
}
323
340
341
+ /// See [`Diagnostic::span_suggestion_short()`].
324
342
pub fn span_suggestion_short (
325
343
& mut self ,
326
344
sp : Span ,
@@ -335,6 +353,7 @@ impl<'a> DiagnosticBuilder<'a> {
335
353
self
336
354
}
337
355
356
+ /// See [`Diagnostic::span_suggestion_verbose()`].
338
357
pub fn span_suggestion_verbose (
339
358
& mut self ,
340
359
sp : Span ,
@@ -349,6 +368,7 @@ impl<'a> DiagnosticBuilder<'a> {
349
368
self
350
369
}
351
370
371
+ /// See [`Diagnostic::span_suggestion_hidden()`].
352
372
pub fn span_suggestion_hidden (
353
373
& mut self ,
354
374
sp : Span ,
@@ -363,6 +383,7 @@ impl<'a> DiagnosticBuilder<'a> {
363
383
self
364
384
}
365
385
386
+ /// See [`Diagnostic::tool_only_span_suggestion()`] for more information.
366
387
pub fn tool_only_span_suggestion (
367
388
& mut self ,
368
389
sp : Span ,
@@ -380,19 +401,22 @@ impl<'a> DiagnosticBuilder<'a> {
380
401
forward ! ( pub fn set_span<S : Into <MultiSpan >>( & mut self , sp: S ) -> & mut Self ) ;
381
402
forward ! ( pub fn code( & mut self , s: DiagnosticId ) -> & mut Self ) ;
382
403
404
+ /// Allow attaching suggestions this diagnostic.
405
+ /// If this is set to `false`, then any suggestions attached with the `span_suggestion_*`
406
+ /// methods after this is set to `false` will be ignored.
383
407
pub fn allow_suggestions ( & mut self , allow : bool ) -> & mut Self {
384
408
self . 0 . allow_suggestions = allow;
385
409
self
386
410
}
387
411
388
412
/// Convenience function for internal use, clients should use one of the
389
- /// struct_* methods on Handler.
413
+ /// ` struct_*` methods on [` Handler`] .
390
414
crate fn new ( handler : & ' a Handler , level : Level , message : & str ) -> DiagnosticBuilder < ' a > {
391
415
DiagnosticBuilder :: new_with_code ( handler, level, None , message)
392
416
}
393
417
394
418
/// Convenience function for internal use, clients should use one of the
395
- /// struct_* methods on Handler.
419
+ /// ` struct_*` methods on [` Handler`] .
396
420
crate fn new_with_code (
397
421
handler : & ' a Handler ,
398
422
level : Level ,
0 commit comments