code suggestion for non-shorthand field patterns lint

We also edit the lint description to clarify that this is different from
the struct field init shorthand.
This commit is contained in:
Zack M. Davis 2017-10-11 23:06:45 -07:00
parent e596c1d0b8
commit f98939c6fd
2 changed files with 20 additions and 5 deletions

View file

@ -471,6 +471,17 @@ impl CodeMap {
}
}
/// Given a `Span`, try to get a shorter span ending just after the first
/// occurrence of `char` `c`.
pub fn span_through_char(&self, sp: Span, c: char) -> Span {
if let Ok(snippet) = self.span_to_snippet(sp) {
if let Some(offset) = snippet.find(c) {
return sp.with_hi(BytePos(sp.lo().0 + (offset + c.len_utf8()) as u32));
}
}
sp
}
pub fn def_span(&self, sp: Span) -> Span {
self.span_until_char(sp, '{')
}