diff options
| author | bors <bors@rust-lang.org> | 2017-04-20 06:28:16 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2017-04-20 06:28:16 +0000 |
| commit | fa6b50fc6282a2c64814b35b16464a22f4ae9265 (patch) | |
| tree | 3c2914f8b96d35eed2b3cbe0a27bc7b89be4272e /src/libsyntax | |
| parent | 1bb1530239c801bb46b705eb2874ac4e5b213e54 (diff) | |
| parent | 204243fcac7dfb646c37cab0138fc037dcb0bd53 (diff) | |
| download | rust-fa6b50fc6282a2c64814b35b16464a22f4ae9265.tar.gz rust-fa6b50fc6282a2c64814b35b16464a22f4ae9265.zip | |
Auto merge of #41413 - frewsxcv:rollup, r=frewsxcv
Rollup of 5 pull requests - Successful merges: #41214, #41369, #41377, #41378, #41390 - Failed merges:
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/codemap.rs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs index 4d67390d442..da2d0a33d1a 100644 --- a/src/libsyntax/codemap.rs +++ b/src/libsyntax/codemap.rs @@ -441,6 +441,25 @@ impl CodeMap { } } + /// Given a `Span`, try to get a shorter span ending before the first occurrence of `c` `char` + pub fn span_until_char(&self, sp: Span, c: char) -> Span { + match self.span_to_snippet(sp) { + Ok(snippet) => { + let snippet = snippet.split(c).nth(0).unwrap_or("").trim_right(); + if snippet.len() > 0 && !snippet.contains('\n') { + Span { hi: BytePos(sp.lo.0 + snippet.len() as u32), ..sp } + } else { + sp + } + } + _ => sp, + } + } + + pub fn def_span(&self, sp: Span) -> Span { + self.span_until_char(sp, '{') + } + pub fn get_filemap(&self, filename: &str) -> Option<Rc<FileMap>> { for fm in self.files.borrow().iter() { if filename == fm.name { |
