about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorZack M. Davis <code@zackmdavis.net>2017-10-11 23:06:45 -0700
committerZack M. Davis <code@zackmdavis.net>2017-10-16 11:19:18 -0700
commitf98939c6fd73e0cb776b7ddbc732827b04a4b2a3 (patch)
tree17434e00740975940a146dd4961b80b4dc68799c /src/libsyntax
parente596c1d0b803dbdcc91ed57372f26f42ae6d32e8 (diff)
downloadrust-f98939c6fd73e0cb776b7ddbc732827b04a4b2a3.tar.gz
rust-f98939c6fd73e0cb776b7ddbc732827b04a4b2a3.zip
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.
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/codemap.rs11
1 files changed, 11 insertions, 0 deletions
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, '{')
     }