@@ -22,12 +22,13 @@ pub struct DiagnosticBuilder<'a>(Box<DiagnosticBuilderInner<'a>>);
22
22
/// (RVO) should avoid unnecessary copying. In practice, it does not (at the
23
23
/// time of writing). The split between `DiagnosticBuilder` and
24
24
/// `DiagnosticBuilderInner` exists to avoid many `memcpy` calls.
25
+ // FIXME(eddyb) try having two pointers in `DiagnosticBuilder`, by only boxing
26
+ // `Diagnostic` (i.e. `struct DiagnosticBuilder(&Handler, Box<Diagnostic>);`).
25
27
#[ must_use]
26
28
#[ derive( Clone ) ]
27
29
struct DiagnosticBuilderInner < ' a > {
28
30
handler : & ' a Handler ,
29
31
diagnostic : Diagnostic ,
30
- allow_suggestions : bool ,
31
32
}
32
33
33
34
/// In general, the `DiagnosticBuilder` uses deref to allow access to
@@ -244,164 +245,79 @@ impl<'a> DiagnosticBuilder<'a> {
244
245
) -> & mut Self ) ;
245
246
forward ! ( pub fn set_is_lint( & mut self , ) -> & mut Self ) ;
246
247
247
- /// See [`Diagnostic::multipart_suggestion()`].
248
- pub fn multipart_suggestion (
248
+ forward ! ( pub fn disable_suggestions( & mut self , ) -> & mut Self ) ;
249
+
250
+ forward ! ( pub fn multipart_suggestion(
249
251
& mut self ,
250
252
msg: & str ,
251
253
suggestion: Vec <( Span , String ) >,
252
254
applicability: Applicability ,
253
- ) -> & mut Self {
254
- if !self . 0 . allow_suggestions {
255
- return self ;
256
- }
257
- self . 0 . diagnostic . multipart_suggestion ( msg, suggestion, applicability) ;
258
- self
259
- }
260
-
261
- /// See [`Diagnostic::multipart_suggestion()`].
262
- pub fn multipart_suggestion_verbose (
255
+ ) -> & mut Self ) ;
256
+ forward ! ( pub fn multipart_suggestion_verbose(
263
257
& mut self ,
264
258
msg: & str ,
265
259
suggestion: Vec <( Span , String ) >,
266
260
applicability: Applicability ,
267
- ) -> & mut Self {
268
- if !self . 0 . allow_suggestions {
269
- return self ;
270
- }
271
- self . 0 . diagnostic . multipart_suggestion_verbose ( msg, suggestion, applicability) ;
272
- self
273
- }
274
-
275
- /// See [`Diagnostic::tool_only_multipart_suggestion()`].
276
- pub fn tool_only_multipart_suggestion (
261
+ ) -> & mut Self ) ;
262
+ forward ! ( pub fn tool_only_multipart_suggestion(
277
263
& mut self ,
278
264
msg: & str ,
279
265
suggestion: Vec <( Span , String ) >,
280
266
applicability: Applicability ,
281
- ) -> & mut Self {
282
- if !self . 0 . allow_suggestions {
283
- return self ;
284
- }
285
- self . 0 . diagnostic . tool_only_multipart_suggestion ( msg, suggestion, applicability) ;
286
- self
287
- }
288
-
289
- /// See [`Diagnostic::span_suggestion()`].
290
- pub fn span_suggestion (
267
+ ) -> & mut Self ) ;
268
+ forward ! ( pub fn span_suggestion(
291
269
& mut self ,
292
270
sp: Span ,
293
271
msg: & str ,
294
272
suggestion: String ,
295
273
applicability: Applicability ,
296
- ) -> & mut Self {
297
- if !self . 0 . allow_suggestions {
298
- return self ;
299
- }
300
- self . 0 . diagnostic . span_suggestion ( sp, msg, suggestion, applicability) ;
301
- self
302
- }
303
-
304
- /// See [`Diagnostic::span_suggestions()`].
305
- pub fn span_suggestions (
274
+ ) -> & mut Self ) ;
275
+ forward ! ( pub fn span_suggestions(
306
276
& mut self ,
307
277
sp: Span ,
308
278
msg: & str ,
309
279
suggestions: impl Iterator <Item = String >,
310
280
applicability: Applicability ,
311
- ) -> & mut Self {
312
- if !self . 0 . allow_suggestions {
313
- return self ;
314
- }
315
- self . 0 . diagnostic . span_suggestions ( sp, msg, suggestions, applicability) ;
316
- self
317
- }
318
-
319
- /// See [`Diagnostic::multipart_suggestions()`].
320
- pub fn multipart_suggestions (
281
+ ) -> & mut Self ) ;
282
+ forward ! ( pub fn multipart_suggestions(
321
283
& mut self ,
322
284
msg: & str ,
323
285
suggestions: impl Iterator <Item = Vec <( Span , String ) >>,
324
286
applicability: Applicability ,
325
- ) -> & mut Self {
326
- if !self . 0 . allow_suggestions {
327
- return self ;
328
- }
329
- self . 0 . diagnostic . multipart_suggestions ( msg, suggestions, applicability) ;
330
- self
331
- }
332
-
333
- /// See [`Diagnostic::span_suggestion_short()`].
334
- pub fn span_suggestion_short (
287
+ ) -> & mut Self ) ;
288
+ forward ! ( pub fn span_suggestion_short(
335
289
& mut self ,
336
290
sp: Span ,
337
291
msg: & str ,
338
292
suggestion: String ,
339
293
applicability: Applicability ,
340
- ) -> & mut Self {
341
- if !self . 0 . allow_suggestions {
342
- return self ;
343
- }
344
- self . 0 . diagnostic . span_suggestion_short ( sp, msg, suggestion, applicability) ;
345
- self
346
- }
347
-
348
- /// See [`Diagnostic::span_suggestion_verbose()`].
349
- pub fn span_suggestion_verbose (
294
+ ) -> & mut Self ) ;
295
+ forward ! ( pub fn span_suggestion_verbose(
350
296
& mut self ,
351
297
sp: Span ,
352
298
msg: & str ,
353
299
suggestion: String ,
354
300
applicability: Applicability ,
355
- ) -> & mut Self {
356
- if !self . 0 . allow_suggestions {
357
- return self ;
358
- }
359
- self . 0 . diagnostic . span_suggestion_verbose ( sp, msg, suggestion, applicability) ;
360
- self
361
- }
362
-
363
- /// See [`Diagnostic::span_suggestion_hidden()`].
364
- pub fn span_suggestion_hidden (
301
+ ) -> & mut Self ) ;
302
+ forward ! ( pub fn span_suggestion_hidden(
365
303
& mut self ,
366
304
sp: Span ,
367
305
msg: & str ,
368
306
suggestion: String ,
369
307
applicability: Applicability ,
370
- ) -> & mut Self {
371
- if !self . 0 . allow_suggestions {
372
- return self ;
373
- }
374
- self . 0 . diagnostic . span_suggestion_hidden ( sp, msg, suggestion, applicability) ;
375
- self
376
- }
377
-
378
- /// See [`Diagnostic::tool_only_span_suggestion()`] for more information.
379
- pub fn tool_only_span_suggestion (
308
+ ) -> & mut Self ) ;
309
+ forward ! ( pub fn tool_only_span_suggestion(
380
310
& mut self ,
381
311
sp: Span ,
382
312
msg: & str ,
383
313
suggestion: String ,
384
314
applicability: Applicability ,
385
- ) -> & mut Self {
386
- if !self . 0 . allow_suggestions {
387
- return self ;
388
- }
389
- self . 0 . diagnostic . tool_only_span_suggestion ( sp, msg, suggestion, applicability) ;
390
- self
391
- }
315
+ ) -> & mut Self ) ;
392
316
393
317
forward ! ( pub fn set_primary_message<M : Into <String >>( & mut self , msg: M ) -> & mut Self ) ;
394
318
forward ! ( pub fn set_span<S : Into <MultiSpan >>( & mut self , sp: S ) -> & mut Self ) ;
395
319
forward ! ( pub fn code( & mut self , s: DiagnosticId ) -> & mut Self ) ;
396
320
397
- /// Allow attaching suggestions this diagnostic.
398
- /// If this is set to `false`, then any suggestions attached with the `span_suggestion_*`
399
- /// methods after this is set to `false` will be ignored.
400
- pub fn allow_suggestions ( & mut self , allow : bool ) -> & mut Self {
401
- self . 0 . allow_suggestions = allow;
402
- self
403
- }
404
-
405
321
/// Convenience function for internal use, clients should use one of the
406
322
/// `struct_*` methods on [`Handler`].
407
323
crate fn new ( handler : & ' a Handler , level : Level , message : & str ) -> DiagnosticBuilder < ' a > {
@@ -424,11 +340,7 @@ impl<'a> DiagnosticBuilder<'a> {
424
340
/// diagnostic.
425
341
crate fn new_diagnostic ( handler : & ' a Handler , diagnostic : Diagnostic ) -> DiagnosticBuilder < ' a > {
426
342
debug ! ( "Created new diagnostic" ) ;
427
- DiagnosticBuilder ( Box :: new ( DiagnosticBuilderInner {
428
- handler,
429
- diagnostic,
430
- allow_suggestions : true ,
431
- } ) )
343
+ DiagnosticBuilder ( Box :: new ( DiagnosticBuilderInner { handler, diagnostic } ) )
432
344
}
433
345
}
434
346
0 commit comments