From f98939c6fd73e0cb776b7ddbc732827b04a4b2a3 Mon Sep 17 00:00:00 2001 From: "Zack M. Davis" Date: Wed, 11 Oct 2017 23:06:45 -0700 Subject: 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. --- src/libsyntax/codemap.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/libsyntax/codemap.rs') diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs index efaa5e5e3da..dd46903bb88 100644 --- a/src/libsyntax/codemap.rs +++ b/src/libsyntax/codemap.rs @@ -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, '{') } -- cgit 1.4.1-3-g733a5