about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2018-07-10 11:19:31 +0000
committerbors <bors@rust-lang.org>2018-07-10 11:19:31 +0000
commitfc491526dd0b5d8c8c25faa6400599e08ede1907 (patch)
tree8d5b3b48095d6d724f878f80f0d6e6385f2ab72e /src/libsyntax
parente46bfa2879e92d3b8f1e204e3b786932c68047fe (diff)
parenta6adb1ebff51dd4ff2e724bf980c9b8586142beb (diff)
downloadrust-fc491526dd0b5d8c8c25faa6400599e08ede1907.tar.gz
rust-fc491526dd0b5d8c8c25faa6400599e08ede1907.zip
Auto merge of #52168 - nikomatsakis:nll-region-name, r=estebank
find and highlight the `&` or `'_` in `region_name`

Before:

```
   --> $DIR/dyn-trait-underscore.rs:18:5
    |
 LL | fn a<T>(items: &[T]) -> Box<dyn Iterator<Item=&T>> {
-   |         ----- lifetime `'1` appears in this argument
 LL |     Box::new(items.iter()) //~ ERROR cannot infer an appropriate lifetime
    |     ^^^^^^^^^^^^^^^^^^^^^^ cast requires that `'1` must outlive `'static`
```

After:

```
   --> $DIR/dyn-trait-underscore.rs:18:5
    |
 LL | fn a<T>(items: &[T]) -> Box<dyn Iterator<Item=&T>> {
+   |                - let's call the lifetime of this reference `'1`
 LL |     Box::new(items.iter()) //~ ERROR cannot infer an appropriate lifetime
    |     ^^^^^^^^^^^^^^^^^^^^^^ cast requires that `'1` must outlive `'static`
```

Not intended as the final end point necessarily in any sense. I intentionally left some to-do points to fill in later:

- Does not apply to upvars in closures yet (should be relatively easy)
- Does not handle the case where we can't find a precise match very well
- And of course we can still tweak wording

but shows the basic idea of how to make the `Ty` and `hir::Ty` to find a good spot to highlight.

r? @estebank
cc @davidtwco
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/codemap.rs9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs
index ea6b39504e8..8381adaea79 100644
--- a/src/libsyntax/codemap.rs
+++ b/src/libsyntax/codemap.rs
@@ -689,6 +689,15 @@ impl CodeMap {
         self.span_until_char(sp, '{')
     }
 
+    /// Returns a new span representing just the start-point of this span
+    pub fn start_point(&self, sp: Span) -> Span {
+        let pos = sp.lo().0;
+        let width = self.find_width_of_character_at_span(sp, false);
+        let corrected_start_position = pos.checked_add(width).unwrap_or(pos);
+        let end_point = BytePos(cmp::max(corrected_start_position, sp.lo().0));
+        sp.with_hi(end_point)
+    }
+
     /// Returns a new span representing just the end-point of this span
     pub fn end_point(&self, sp: Span) -> Span {
         let pos = sp.hi().0;