feat: Implement lifetime elision hints

This commit is contained in:
Lukas Wirth 2022-03-18 18:11:16 +01:00
parent 890f98f21f
commit 673e2b1d8f
5 changed files with 242 additions and 17 deletions

View file

@ -306,15 +306,15 @@ fn extract_line_annotations(mut line: &str) -> Vec<LineAnnotation> {
let end_marker = line_no_caret.find(|c| c == '$');
let next = line_no_caret.find(marker).map_or(line.len(), |it| it + len);
let mut content = match end_marker {
Some(end_marker)
if end_marker < next
&& line_no_caret[end_marker..]
let cond = |end_marker| {
end_marker < next
&& (line_no_caret[end_marker + 1..].is_empty()
|| line_no_caret[end_marker + 1..]
.strip_prefix(|c: char| c.is_whitespace() || c == '^')
.is_some() =>
{
&line_no_caret[..end_marker]
}
.is_some())
};
let mut content = match end_marker {
Some(end_marker) if cond(end_marker) => &line_no_caret[..end_marker],
_ => line_no_caret[..next - len].trim_end(),
};