@@ -22,12 +22,13 @@ pub struct DiagnosticBuilder<'a>(Box<DiagnosticBuilderInner<'a>>);
2222/// (RVO) should avoid unnecessary copying. In practice, it does not (at the
2323/// time of writing). The split between `DiagnosticBuilder` and
2424/// `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>);`).
2527#[ must_use]
2628#[ derive( Clone ) ]
2729struct DiagnosticBuilderInner < ' a > {
2830 handler : & ' a Handler ,
2931 diagnostic : Diagnostic ,
30- allow_suggestions : bool ,
3132}
3233
3334/// In general, the `DiagnosticBuilder` uses deref to allow access to
@@ -244,164 +245,79 @@ impl<'a> DiagnosticBuilder<'a> {
244245 ) -> & mut Self ) ;
245246 forward ! ( pub fn set_is_lint( & mut self , ) -> & mut Self ) ;
246247
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(
249251 & mut self ,
250252 msg: & str ,
251253 suggestion: Vec <( Span , String ) >,
252254 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(
263257 & mut self ,
264258 msg: & str ,
265259 suggestion: Vec <( Span , String ) >,
266260 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(
277263 & mut self ,
278264 msg: & str ,
279265 suggestion: Vec <( Span , String ) >,
280266 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(
291269 & mut self ,
292270 sp: Span ,
293271 msg: & str ,
294272 suggestion: String ,
295273 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(
306276 & mut self ,
307277 sp: Span ,
308278 msg: & str ,
309279 suggestions: impl Iterator <Item = String >,
310280 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(
321283 & mut self ,
322284 msg: & str ,
323285 suggestions: impl Iterator <Item = Vec <( Span , String ) >>,
324286 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(
335289 & mut self ,
336290 sp: Span ,
337291 msg: & str ,
338292 suggestion: String ,
339293 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(
350296 & mut self ,
351297 sp: Span ,
352298 msg: & str ,
353299 suggestion: String ,
354300 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(
365303 & mut self ,
366304 sp: Span ,
367305 msg: & str ,
368306 suggestion: String ,
369307 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(
380310 & mut self ,
381311 sp: Span ,
382312 msg: & str ,
383313 suggestion: String ,
384314 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 ) ;
392316
393317 forward ! ( pub fn set_primary_message<M : Into <String >>( & mut self , msg: M ) -> & mut Self ) ;
394318 forward ! ( pub fn set_span<S : Into <MultiSpan >>( & mut self , sp: S ) -> & mut Self ) ;
395319 forward ! ( pub fn code( & mut self , s: DiagnosticId ) -> & mut Self ) ;
396320
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-
405321 /// Convenience function for internal use, clients should use one of the
406322 /// `struct_*` methods on [`Handler`].
407323 crate fn new ( handler : & ' a Handler , level : Level , message : & str ) -> DiagnosticBuilder < ' a > {
@@ -424,11 +340,7 @@ impl<'a> DiagnosticBuilder<'a> {
424340 /// diagnostic.
425341 crate fn new_diagnostic ( handler : & ' a Handler , diagnostic : Diagnostic ) -> DiagnosticBuilder < ' a > {
426342 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 } ) )
432344 }
433345}
434346
0 commit comments