-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.E-help-wantedCall for participation: Help is requested to fix this issue.Call for participation: Help is requested to fix this issue.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
Part of #59346
In order for the new AnnotateSnippetEmitterWriter
to include suggestions in the output, we essentially have to pass &db.suggestions
to emit_messages_default
and deal with a couple of edge-cases.
Relevant FIXME
:
rust/src/librustc_errors/annotate_snippet_emitter_writer.rs
Lines 35 to 36 in 57a3300
// FIXME(#59346): Collect suggestions (see emitter.rs) | |
let suggestions: &[_] = &[]; |
emitter.rs
equivalent:
rust/src/librustc_errors/emitter.rs
Lines 84 to 115 in 0e4a56b
if let Some((sugg, rest)) = db.suggestions.split_first() { | |
if rest.is_empty() && | |
// don't display multi-suggestions as labels | |
sugg.substitutions.len() == 1 && | |
// don't display multipart suggestions as labels | |
sugg.substitutions[0].parts.len() == 1 && | |
// don't display long messages as labels | |
sugg.msg.split_whitespace().count() < 10 && | |
// don't display multiline suggestions as labels | |
!sugg.substitutions[0].parts[0].snippet.contains('\n') && | |
// when this style is set we want the suggestion to be a message, not inline | |
sugg.style != SuggestionStyle::HideCodeAlways && | |
// trivial suggestion for tooling's sake, never shown | |
sugg.style != SuggestionStyle::CompletelyHidden | |
{ | |
let substitution = &sugg.substitutions[0].parts[0].snippet.trim(); | |
let msg = if substitution.len() == 0 || sugg.style.hide_inline() { | |
// This substitution is only removal or we explicitly don't want to show the | |
// code inline, don't show it | |
format!("help: {}", sugg.msg) | |
} else { | |
format!("help: {}: `{}`", sugg.msg, substitution) | |
}; | |
primary_span.push_span_label(sugg.substitutions[0].parts[0].span, msg); | |
} else { | |
// if there are multiple suggestions, print them all in full | |
// to be consistent. We could try to figure out if we can | |
// make one (or the first one) inline, but that would give | |
// undue importance to a semi-random suggestion | |
suggestions = &db.suggestions; | |
} | |
} |
- The tricky part is figuring out the first half of the conditional. We probably need it in the new emitter, too. Is it enough to just copy it over? Maybe extract that code so that the code is shared in both emitters?
- Otherwise it's just passing
&db.suggestions
through - Should take into account the MAX_SUGGESTIONS value somewhere (add a UI test for this)
This issue has been assigned to @phansch via this comment.
estebank
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.E-help-wantedCall for participation: Help is requested to fix this issue.Call for participation: Help is requested to fix this issue.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.