@@ -30,6 +30,15 @@ struct DiagnosticBuilderInner<'a> {
3030 allow_suggestions : bool ,
3131}
3232
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+
3342/// In general, the `DiagnosticBuilder` uses deref to allow access to
3443/// the fields and methods of the embedded `diagnostic` in a
3544/// transparent way. *However,* many of the methods are intended to
@@ -45,10 +54,11 @@ macro_rules! forward {
4554 pub fn $n: ident( & self , $( $name: ident: $ty: ty) ,* $( , ) ?) -> & Self
4655 ) => {
4756 $( #[ $attrs] ) *
57+ forward_inner_docs!( concat!( "See [`Diagnostic::" , stringify!( $n) , "()`]." ) =>
4858 pub fn $n( & self , $( $name: $ty) ,* ) -> & Self {
4959 self . diagnostic. $n( $( $name) ,* ) ;
5060 self
51- }
61+ } ) ;
5262 } ;
5363
5464 // Forward pattern for &mut self -> &mut Self
@@ -57,10 +67,11 @@ macro_rules! forward {
5767 pub fn $n: ident( & mut self , $( $name: ident: $ty: ty) ,* $( , ) ?) -> & mut Self
5868 ) => {
5969 $( #[ $attrs] ) *
70+ forward_inner_docs!( concat!( "See [`Diagnostic::" , stringify!( $n) , "()`]." ) =>
6071 pub fn $n( & mut self , $( $name: $ty) ,* ) -> & mut Self {
6172 self . 0 . diagnostic. $n( $( $name) ,* ) ;
6273 self
63- }
74+ } ) ;
6475 } ;
6576
6677 // Forward pattern for &mut self -> &mut Self, with S: Into<MultiSpan>
@@ -74,10 +85,11 @@ macro_rules! forward {
7485 ) -> & mut Self
7586 ) => {
7687 $( #[ $attrs] ) *
88+ forward_inner_docs!( concat!( "See [`Diagnostic::" , stringify!( $n) , "()`]." ) =>
7789 pub fn $n<S : Into <MultiSpan >>( & mut self , $( $name: $ty) ,* ) -> & mut Self {
7890 self . 0 . diagnostic. $n( $( $name) ,* ) ;
7991 self
80- }
92+ } ) ;
8193 } ;
8294}
8395
@@ -116,7 +128,7 @@ impl<'a> DiagnosticBuilder<'a> {
116128
117129 /// Stashes diagnostic for possible later improvement in a different,
118130 /// 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()`] .
120132 ///
121133 /// As with `buffer`, this is unless the handler has disabled such buffering.
122134 pub fn stash ( self , span : Span , key : StashKey ) {
@@ -202,7 +214,7 @@ impl<'a> DiagnosticBuilder<'a> {
202214 }
203215
204216 /// Labels all the given spans with the provided label.
205- /// See ` span_label` for more information.
217+ /// See [`Diagnostic:: span_label()`] for more information.
206218 pub fn span_labels (
207219 & mut self ,
208220 spans : impl IntoIterator < Item = Span > ,
@@ -233,7 +245,7 @@ impl<'a> DiagnosticBuilder<'a> {
233245 found_extra: & dyn fmt:: Display ,
234246 ) -> & mut Self ) ;
235247
236- forward ! ( pub fn note_unsuccessfull_coercion (
248+ forward ! ( pub fn note_unsuccessful_coercion (
237249 & mut self ,
238250 expected: DiagnosticStyledString ,
239251 found: DiagnosticStyledString ,
@@ -254,6 +266,7 @@ impl<'a> DiagnosticBuilder<'a> {
254266 msg: & str ,
255267 ) -> & mut Self ) ;
256268
269+ /// See [`Diagnostic::multipart_suggestion()`].
257270 pub fn multipart_suggestion (
258271 & mut self ,
259272 msg : & str ,
@@ -267,6 +280,7 @@ impl<'a> DiagnosticBuilder<'a> {
267280 self
268281 }
269282
283+ /// See [`Diagnostic::multipart_suggestions()`].
270284 pub fn multipart_suggestions (
271285 & mut self ,
272286 msg : & str ,
@@ -280,6 +294,7 @@ impl<'a> DiagnosticBuilder<'a> {
280294 self
281295 }
282296
297+ /// See [`Diagnostic::tool_only_multipart_suggestion()`].
283298 pub fn tool_only_multipart_suggestion (
284299 & mut self ,
285300 msg : & str ,
@@ -293,6 +308,7 @@ impl<'a> DiagnosticBuilder<'a> {
293308 self
294309 }
295310
311+ /// See [`Diagnostic::span_suggestion()`].
296312 pub fn span_suggestion (
297313 & mut self ,
298314 sp : Span ,
@@ -307,6 +323,7 @@ impl<'a> DiagnosticBuilder<'a> {
307323 self
308324 }
309325
326+ /// See [`Diagnostic::span_suggestions()`].
310327 pub fn span_suggestions (
311328 & mut self ,
312329 sp : Span ,
@@ -321,6 +338,7 @@ impl<'a> DiagnosticBuilder<'a> {
321338 self
322339 }
323340
341+ /// See [`Diagnostic::span_suggestion_short()`].
324342 pub fn span_suggestion_short (
325343 & mut self ,
326344 sp : Span ,
@@ -335,6 +353,7 @@ impl<'a> DiagnosticBuilder<'a> {
335353 self
336354 }
337355
356+ /// See [`Diagnostic::span_suggestion_verbose()`].
338357 pub fn span_suggestion_verbose (
339358 & mut self ,
340359 sp : Span ,
@@ -349,6 +368,7 @@ impl<'a> DiagnosticBuilder<'a> {
349368 self
350369 }
351370
371+ /// See [`Diagnostic::span_suggestion_hidden()`].
352372 pub fn span_suggestion_hidden (
353373 & mut self ,
354374 sp : Span ,
@@ -363,6 +383,7 @@ impl<'a> DiagnosticBuilder<'a> {
363383 self
364384 }
365385
386+ /// See [`Diagnostic::tool_only_span_suggestion()`] for more information.
366387 pub fn tool_only_span_suggestion (
367388 & mut self ,
368389 sp : Span ,
@@ -380,19 +401,22 @@ impl<'a> DiagnosticBuilder<'a> {
380401 forward ! ( pub fn set_span<S : Into <MultiSpan >>( & mut self , sp: S ) -> & mut Self ) ;
381402 forward ! ( pub fn code( & mut self , s: DiagnosticId ) -> & mut Self ) ;
382403
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.
383407 pub fn allow_suggestions ( & mut self , allow : bool ) -> & mut Self {
384408 self . 0 . allow_suggestions = allow;
385409 self
386410 }
387411
388412 /// Convenience function for internal use, clients should use one of the
389- /// struct_* methods on Handler.
413+ /// ` struct_*` methods on [` Handler`] .
390414 crate fn new ( handler : & ' a Handler , level : Level , message : & str ) -> DiagnosticBuilder < ' a > {
391415 DiagnosticBuilder :: new_with_code ( handler, level, None , message)
392416 }
393417
394418 /// Convenience function for internal use, clients should use one of the
395- /// struct_* methods on Handler.
419+ /// ` struct_*` methods on [` Handler`] .
396420 crate fn new_with_code (
397421 handler : & ' a Handler ,
398422 level : Level ,
0 commit comments