Skip to content

Commit 5b5fb4c

Browse files
committed
get the correct diagnostic for functions, at least
1 parent 55dd216 commit 5b5fb4c

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

compiler/rustc_parse/src/parser/diagnostics.rs

+17-11
Original file line numberDiff line numberDiff line change
@@ -340,21 +340,27 @@ impl<'a> Parser<'a> {
340340
let _ = self.parse_generics().map(|generic| {
341341
// at this point, token should be Ident with the fn name
342342

343-
// FIXME: shreys the span should be the span of where the gneeric SHOULD go.
344343
// FIXME: shreys what does this look like with invalid generic
345344
// FIXME: shreys - what to do if no snippet? probably just HELP not suggestion
346-
347-
let snippet = match self.sess.source_map().span_to_snippet(generic.span) {
348-
Ok(snippet) => snippet,
349-
_ => "".to_string(),
345+
debug!(?generic.span);
346+
347+
match self.sess.source_map().span_to_snippet(generic.span) {
348+
Ok(_snippet) => match self.sess.source_map().span_to_snippet(self.token.span) {
349+
Ok(ident) => {
350+
err.span_suggestion(
351+
generic.span.to(self.token.span),
352+
"help: place the generic parameter list after the function name:",
353+
format!(" {ident}{_snippet}"),
354+
Applicability::MachineApplicable,
355+
);
356+
}
357+
Err(_) => todo!() //FIXME: shreys - what to do here?
358+
}
359+
Err(_) => todo!(), //FIXME: shreys - what to do here?
360+
350361
};
351362

352-
err.span_suggestion(
353-
self.token.span.to(generic.span.shrink_to_hi()),
354-
"help: place the generic parameter list after the function name:",
355-
snippet,
356-
Applicability::MachineApplicable,
357-
);
363+
358364
});
359365
}
360366

0 commit comments

Comments
 (0)