Skip to content

Commit

Permalink
Merge pull request rust-lang#2512 from topecongiro/rustc-ap-syntax
Browse files Browse the repository at this point in the history
Update rustc-ap-syntax
  • Loading branch information
nrc authored Mar 8, 2018
2 parents f0d179d + 9889678 commit 06d509c
Show file tree
Hide file tree
Showing 12 changed files with 394 additions and 215 deletions.
156 changes: 109 additions & 47 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ serde_derive = "1.0"
serde_json = "1.0"
unicode-segmentation = "1.0.0"
regex = "0.2"
term = "0.4"
term = "0.5"
diff = "0.1"
log = "0.4"
env_logger = "0.5"
getopts = "0.2"
derive-new = "0.5"
cargo_metadata = "0.4"
rustc-ap-syntax = "29.0.0"
rustc-ap-rustc_errors = "29.0.0"
cargo_metadata = "0.5"
rustc-ap-syntax = "57.0.0"
rustc-ap-rustc_errors = "57.0.0"

[dev-dependencies]
lazy_static = "1.0.0"
Expand Down
18 changes: 9 additions & 9 deletions src/codemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub trait SpanUtils {
fn span_after_last(&self, original: Span, needle: &str) -> BytePos;
fn span_before(&self, original: Span, needle: &str) -> BytePos;
fn opt_span_after(&self, original: Span, needle: &str) -> Option<BytePos>;
fn opt_span_before(&self, original: Span, needle: &str) -> Option<BytePos>;
}

pub trait LineRangeUtils {
Expand All @@ -35,10 +36,7 @@ pub trait LineRangeUtils {

impl<'a> SpanUtils for SnippetProvider<'a> {
fn span_after(&self, original: Span, needle: &str) -> BytePos {
let snippet = self.span_to_snippet(original).expect("Bad snippet");
let offset = snippet.find_uncommented(needle).expect("Bad offset") + needle.len();

original.lo() + BytePos(offset as u32)
self.opt_span_after(original, needle).expect("bad span")
}

fn span_after_last(&self, original: Span, needle: &str) -> BytePos {
Expand All @@ -53,15 +51,17 @@ impl<'a> SpanUtils for SnippetProvider<'a> {
}

fn span_before(&self, original: Span, needle: &str) -> BytePos {
let snippet = self.span_to_snippet(original).unwrap();
let offset = snippet.find_uncommented(needle).unwrap();

original.lo() + BytePos(offset as u32)
self.opt_span_before(original, needle).expect("bad span")
}

fn opt_span_after(&self, original: Span, needle: &str) -> Option<BytePos> {
self.opt_span_before(original, needle)
.map(|bytepos| bytepos + BytePos(needle.len() as u32))
}

fn opt_span_before(&self, original: Span, needle: &str) -> Option<BytePos> {
let snippet = self.span_to_snippet(original)?;
let offset = snippet.find_uncommented(needle)? + needle.len();
let offset = snippet.find_uncommented(needle)?;

Some(original.lo() + BytePos(offset as u32))
}
Expand Down
Loading

0 comments on commit 06d509c

Please sign in to comment.