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

Commit 6ea159e

Browse files
committed
Expose hidden snippet suggestions
1 parent 05b4e7c commit 6ea159e

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

src/librustc_errors/diagnostic.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,29 @@ impl Diagnostic {
323323
self
324324
}
325325

326+
/// Prints out a message with for a suggestion without showing the suggested code.
327+
///
328+
/// This is intended to be used for suggestions that are obvious in what the changes need to
329+
/// be from the message, showing the span label inline would be visually unpleasant
330+
/// (marginally overlapping spans or multiline spans) and showing the snippet window wouldn't
331+
/// improve understandability.
332+
pub fn span_suggestion_hidden(
333+
&mut self, sp: Span, msg: &str, suggestion: String, applicability: Applicability
334+
) -> &mut Self {
335+
self.suggestions.push(CodeSuggestion {
336+
substitutions: vec![Substitution {
337+
parts: vec![SubstitutionPart {
338+
snippet: suggestion,
339+
span: sp,
340+
}],
341+
}],
342+
msg: msg.to_owned(),
343+
style: SuggestionStyle::HideCodeInline,
344+
applicability: applicability,
345+
});
346+
self
347+
}
348+
326349
pub fn set_span<S: Into<MultiSpan>>(&mut self, sp: S) -> &mut Self {
327350
self.span = sp.into();
328351
self

src/librustc_errors/diagnostic_builder.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,26 @@ impl<'a> DiagnosticBuilder<'a> {
261261
);
262262
self
263263
}
264+
265+
pub fn span_suggestion_hidden(
266+
&mut self,
267+
sp: Span,
268+
msg: &str,
269+
suggestion: String,
270+
applicability: Applicability,
271+
) -> &mut Self {
272+
if !self.allow_suggestions {
273+
return self
274+
}
275+
self.diagnostic.span_suggestion_hidden(
276+
sp,
277+
msg,
278+
suggestion,
279+
applicability,
280+
);
281+
self
282+
}
283+
264284
forward!(pub fn set_span<S: Into<MultiSpan>>(&mut self, sp: S) -> &mut Self);
265285
forward!(pub fn code(&mut self, s: DiagnosticId) -> &mut Self);
266286

0 commit comments

Comments
 (0)