Skip to content

Commit 06d509c

Browse files
authored
Merge pull request #2512 from topecongiro/rustc-ap-syntax
Update rustc-ap-syntax
2 parents f0d179d + 9889678 commit 06d509c

File tree

12 files changed

+394
-215
lines changed

12 files changed

+394
-215
lines changed

Cargo.lock

Lines changed: 109 additions & 47 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ serde_derive = "1.0"
4141
serde_json = "1.0"
4242
unicode-segmentation = "1.0.0"
4343
regex = "0.2"
44-
term = "0.4"
44+
term = "0.5"
4545
diff = "0.1"
4646
log = "0.4"
4747
env_logger = "0.5"
4848
getopts = "0.2"
4949
derive-new = "0.5"
50-
cargo_metadata = "0.4"
51-
rustc-ap-syntax = "29.0.0"
52-
rustc-ap-rustc_errors = "29.0.0"
50+
cargo_metadata = "0.5"
51+
rustc-ap-syntax = "57.0.0"
52+
rustc-ap-rustc_errors = "57.0.0"
5353

5454
[dev-dependencies]
5555
lazy_static = "1.0.0"

src/codemap.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ pub trait SpanUtils {
2222
fn span_after_last(&self, original: Span, needle: &str) -> BytePos;
2323
fn span_before(&self, original: Span, needle: &str) -> BytePos;
2424
fn opt_span_after(&self, original: Span, needle: &str) -> Option<BytePos>;
25+
fn opt_span_before(&self, original: Span, needle: &str) -> Option<BytePos>;
2526
}
2627

2728
pub trait LineRangeUtils {
@@ -35,10 +36,7 @@ pub trait LineRangeUtils {
3536

3637
impl<'a> SpanUtils for SnippetProvider<'a> {
3738
fn span_after(&self, original: Span, needle: &str) -> BytePos {
38-
let snippet = self.span_to_snippet(original).expect("Bad snippet");
39-
let offset = snippet.find_uncommented(needle).expect("Bad offset") + needle.len();
40-
41-
original.lo() + BytePos(offset as u32)
39+
self.opt_span_after(original, needle).expect("bad span")
4240
}
4341

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

5553
fn span_before(&self, original: Span, needle: &str) -> BytePos {
56-
let snippet = self.span_to_snippet(original).unwrap();
57-
let offset = snippet.find_uncommented(needle).unwrap();
58-
59-
original.lo() + BytePos(offset as u32)
54+
self.opt_span_before(original, needle).expect("bad span")
6055
}
6156

6257
fn opt_span_after(&self, original: Span, needle: &str) -> Option<BytePos> {
58+
self.opt_span_before(original, needle)
59+
.map(|bytepos| bytepos + BytePos(needle.len() as u32))
60+
}
61+
62+
fn opt_span_before(&self, original: Span, needle: &str) -> Option<BytePos> {
6363
let snippet = self.span_to_snippet(original)?;
64-
let offset = snippet.find_uncommented(needle)? + needle.len();
64+
let offset = snippet.find_uncommented(needle)?;
6565

6666
Some(original.lo() + BytePos(offset as u32))
6767
}

0 commit comments

Comments
 (0)