1
Fork 0

diagnostics: do not suggest fn foo({ <body> }

Instead of suggesting that the body always replace the last character on the
line, presuming it must be a semicolon, the parser should instead check what
the last character is, and append the body if it is anything else.

Fixes #83104
This commit is contained in:
Michael Howell 2022-03-22 15:29:07 -07:00
parent 64137f0b15
commit 3729b17b7e
2 changed files with 9 additions and 4 deletions

View file

@ -471,10 +471,17 @@ impl<'a> AstValidator<'a> {
}
fn error_item_without_body(&self, sp: Span, ctx: &str, msg: &str, sugg: &str) {
let source_map = self.session.source_map();
let end = source_map.end_point(sp);
let replace_span = if source_map.span_to_snippet(end).map(|s| s == ";").unwrap_or(false) {
end
} else {
sp.shrink_to_hi()
};
self.err_handler()
.struct_span_err(sp, msg)
.span_suggestion(
self.session.source_map().end_point(sp),
replace_span,
&format!("provide a definition for the {}", ctx),
sugg.to_string(),
Applicability::HasPlaceholders,