Skip to content

Commit c4813a3

Browse files
committed
---
yaml --- r: 277430 b: refs/heads/try c: 91b5ed5 h: refs/heads/master
1 parent 39fc3fb commit c4813a3

File tree

3 files changed

+608
-10
lines changed

3 files changed

+608
-10
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 6dbb0e86aec11050480beb76eade6fb805010ba7
33
refs/heads/snap-stage3: 235d77457d80b549dad3ac36d94f235208a1eafb
4-
refs/heads/try: e7b8c5e3ab49e11d0d1ca60d843c90abf213fb4d
4+
refs/heads/try: 91b5ed5ce38e3833e985c2cf023e1902891f30e2
55
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
66
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
77
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try/src/librustc_save_analysis/data.rs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,37 @@ use std::hash::Hasher;
1818
use rustc::hir::def_id::DefId;
1919
use rustc::ty;
2020
use syntax::ast::{CrateNum, NodeId};
21-
use syntax::codemap::Span;
21+
use syntax::codemap::{Span, CodeMap};
22+
23+
#[derive(Debug, Clone, RustcEncodable)]
24+
pub struct SpanData {
25+
file_name: String,
26+
byte_start: u32,
27+
byte_end: u32,
28+
/// 1-based.
29+
line_start: usize,
30+
line_end: usize,
31+
/// 1-based, character offset.
32+
column_start: usize,
33+
column_end: usize,
34+
}
35+
36+
impl SpanData {
37+
pub fn from_span(span: Span, cm: &CodeMap) -> SpanData {
38+
let start = cm.lookup_char_pos(span.lo);
39+
let end = cm.lookup_char_pos(span.hi);
40+
41+
SpanData {
42+
file_name: start.file.name.clone(),
43+
byte_start: span.lo.0,
44+
byte_end: span.hi.0,
45+
line_start: start.line,
46+
line_end: end.line,
47+
column_start: start.col.0 + 1,
48+
column_end: end.col.0 + 1,
49+
}
50+
}
51+
}
2252

2353
pub struct CrateData {
2454
pub name: String,

0 commit comments

Comments
 (0)