Skip to content

Commit 05db660

Browse files
committed
remove get_named_span
1 parent 59a768c commit 05db660

File tree

6 files changed

+33
-89
lines changed

6 files changed

+33
-89
lines changed

src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs

+5-39
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ use rustc::hir::def_id::DefId;
1313
use rustc::infer::InferCtxt;
1414
use rustc::mir::{Local, Body};
1515
use rustc::ty::subst::{SubstsRef, GenericArgKind};
16-
use rustc::ty::{self, RegionKind, RegionVid, Ty, TyCtxt};
16+
use rustc::ty::{self, RegionVid, Ty, TyCtxt};
1717
use rustc::ty::print::RegionHighlightMode;
1818
use rustc_index::vec::IndexVec;
1919
use rustc_errors::DiagnosticBuilder;
2020
use syntax::symbol::kw;
2121
use rustc_data_structures::fx::FxHashMap;
22-
use syntax_pos::{Span, symbol::Symbol};
22+
use syntax_pos::{Span, symbol::Symbol, DUMMY_SP};
2323

2424
/// A name for a particular region used in emitting diagnostics. This name could be a generated
2525
/// name like `'1`, a name used by the user like `'a`, or a name like `'static`.
@@ -275,7 +275,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
275275
match error_region {
276276
ty::ReEarlyBound(ebr) => {
277277
if ebr.has_name() {
278-
let span = self.get_named_span(tcx, error_region, ebr.name);
278+
let span = tcx.hir().span_if_local(ebr.def_id).unwrap_or(DUMMY_SP);
279279
Some(RegionName {
280280
name: ebr.name,
281281
source: RegionNameSource::NamedEarlyBoundRegion(span),
@@ -291,9 +291,9 @@ impl<'tcx> RegionInferenceContext<'tcx> {
291291
}),
292292

293293
ty::ReFree(free_region) => match free_region.bound_region {
294-
ty::BoundRegion::BrNamed(_, name) => {
294+
ty::BoundRegion::BrNamed(region_def_id, name) => {
295295
// Get the span to point to, even if we don't use the name.
296-
let span = self.get_named_span(tcx, error_region, name);
296+
let span = tcx.hir().span_if_local(region_def_id).unwrap_or(DUMMY_SP);
297297
debug!("bound region named: {:?}, is_named: {:?}",
298298
name, free_region.bound_region.is_named());
299299

@@ -373,40 +373,6 @@ impl<'tcx> RegionInferenceContext<'tcx> {
373373
}
374374
}
375375

376-
/// Gets a span of a named region to provide context for error messages that
377-
/// mention that span, for example:
378-
///
379-
/// ```
380-
/// |
381-
/// | fn two_regions<'a, 'b, T>(cell: Cell<&'a ()>, t: T)
382-
/// | -- -- lifetime `'b` defined here
383-
/// | |
384-
/// | lifetime `'a` defined here
385-
/// |
386-
/// | with_signature(cell, t, |cell, t| require(cell, t));
387-
/// | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ argument requires that `'b` must
388-
/// | outlive `'a`
389-
/// ```
390-
fn get_named_span(
391-
&self,
392-
tcx: TyCtxt<'tcx>,
393-
error_region: &RegionKind,
394-
name: Symbol,
395-
) -> Span {
396-
let scope = error_region.free_region_binding_scope(tcx);
397-
let node = tcx.hir().as_local_hir_id(scope).unwrap_or(hir::DUMMY_HIR_ID);
398-
399-
let span = tcx.sess.source_map().def_span(tcx.hir().span(node));
400-
if let Some(param) = tcx.hir()
401-
.get_generics(scope)
402-
.and_then(|generics| generics.get_named(name))
403-
{
404-
param.span
405-
} else {
406-
span
407-
}
408-
}
409-
410376
/// Finds an argument that contains `fr` and label it with a fully
411377
/// elaborated type, returning something like `'1`. Result looks
412378
/// like:

src/test/ui/self/arbitrary_self_types_pin_lifetime_mismatch-async.nll.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,18 @@ error: lifetime may not live long enough
1010
--> $DIR/arbitrary_self_types_pin_lifetime_mismatch-async.rs:8:52
1111
|
1212
LL | async fn a(self: Pin<&Foo>, f: &Foo) -> &Foo { f }
13-
| - ^ function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
14-
| |
15-
| let's call the lifetime of this reference `'1`
13+
| - - ^ function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
14+
| | |
15+
| | let's call the lifetime of this reference `'1`
1616
| let's call the lifetime of this reference `'2`
1717

1818
error: lifetime may not live long enough
1919
--> $DIR/arbitrary_self_types_pin_lifetime_mismatch-async.rs:11:75
2020
|
2121
LL | async fn c(self: Pin<&Self>, f: &Foo, g: &Foo) -> (Pin<&Foo>, &Foo) { (self, f) }
22-
| - ^^^^^^^^^ function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
23-
| |
24-
| let's call the lifetime of this reference `'1`
22+
| - - ^^^^^^^^^ function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
23+
| | |
24+
| | let's call the lifetime of this reference `'1`
2525
| let's call the lifetime of this reference `'2`
2626

2727
error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds

src/test/ui/self/elision/lt-ref-self-async.nll.stderr

+6-12
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ error: lifetime may not live long enough
1010
--> $DIR/lt-ref-self-async.rs:13:9
1111
|
1212
LL | async fn ref_self(&self, f: &u32) -> &u32 {
13-
| -
13+
| - - let's call the lifetime of this reference `'1`
1414
| |
15-
| let's call the lifetime of this reference `'1`
1615
| let's call the lifetime of this reference `'2`
1716
LL | f
1817
| ^ function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
@@ -29,9 +28,8 @@ error: lifetime may not live long enough
2928
--> $DIR/lt-ref-self-async.rs:19:9
3029
|
3130
LL | async fn ref_Self(self: &Self, f: &u32) -> &u32 {
32-
| -
31+
| - - let's call the lifetime of this reference `'1`
3332
| |
34-
| let's call the lifetime of this reference `'1`
3533
| let's call the lifetime of this reference `'2`
3634
LL | f
3735
| ^ function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
@@ -48,9 +46,8 @@ error: lifetime may not live long enough
4846
--> $DIR/lt-ref-self-async.rs:23:9
4947
|
5048
LL | async fn box_ref_Self(self: Box<&Self>, f: &u32) -> &u32 {
51-
| -
49+
| - - let's call the lifetime of this reference `'1`
5250
| |
53-
| let's call the lifetime of this reference `'1`
5451
| let's call the lifetime of this reference `'2`
5552
LL | f
5653
| ^ function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
@@ -67,9 +64,8 @@ error: lifetime may not live long enough
6764
--> $DIR/lt-ref-self-async.rs:27:9
6865
|
6966
LL | async fn pin_ref_Self(self: Pin<&Self>, f: &u32) -> &u32 {
70-
| -
67+
| - - let's call the lifetime of this reference `'1`
7168
| |
72-
| let's call the lifetime of this reference `'1`
7369
| let's call the lifetime of this reference `'2`
7470
LL | f
7571
| ^ function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
@@ -86,9 +82,8 @@ error: lifetime may not live long enough
8682
--> $DIR/lt-ref-self-async.rs:31:9
8783
|
8884
LL | async fn box_box_ref_Self(self: Box<Box<&Self>>, f: &u32) -> &u32 {
89-
| -
85+
| - - let's call the lifetime of this reference `'1`
9086
| |
91-
| let's call the lifetime of this reference `'1`
9287
| let's call the lifetime of this reference `'2`
9388
LL | f
9489
| ^ function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
@@ -105,9 +100,8 @@ error: lifetime may not live long enough
105100
--> $DIR/lt-ref-self-async.rs:35:9
106101
|
107102
LL | async fn box_pin_Self(self: Box<Pin<&Self>>, f: &u32) -> &u32 {
108-
| -
103+
| - - let's call the lifetime of this reference `'1`
109104
| |
110-
| let's call the lifetime of this reference `'1`
111105
| let's call the lifetime of this reference `'2`
112106
LL | f
113107
| ^ function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`

src/test/ui/self/elision/ref-mut-self-async.nll.stderr

+6-12
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ error: lifetime may not live long enough
1010
--> $DIR/ref-mut-self-async.rs:13:9
1111
|
1212
LL | async fn ref_self(&mut self, f: &u32) -> &u32 {
13-
| -
13+
| - - let's call the lifetime of this reference `'1`
1414
| |
15-
| let's call the lifetime of this reference `'1`
1615
| let's call the lifetime of this reference `'2`
1716
LL | f
1817
| ^ function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
@@ -29,9 +28,8 @@ error: lifetime may not live long enough
2928
--> $DIR/ref-mut-self-async.rs:19:9
3029
|
3130
LL | async fn ref_Self(self: &mut Self, f: &u32) -> &u32 {
32-
| -
31+
| - - let's call the lifetime of this reference `'1`
3332
| |
34-
| let's call the lifetime of this reference `'1`
3533
| let's call the lifetime of this reference `'2`
3634
LL | f
3735
| ^ function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
@@ -48,9 +46,8 @@ error: lifetime may not live long enough
4846
--> $DIR/ref-mut-self-async.rs:23:9
4947
|
5048
LL | async fn box_ref_Self(self: Box<&mut Self>, f: &u32) -> &u32 {
51-
| -
49+
| - - let's call the lifetime of this reference `'1`
5250
| |
53-
| let's call the lifetime of this reference `'1`
5451
| let's call the lifetime of this reference `'2`
5552
LL | f
5653
| ^ function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
@@ -67,9 +64,8 @@ error: lifetime may not live long enough
6764
--> $DIR/ref-mut-self-async.rs:27:9
6865
|
6966
LL | async fn pin_ref_Self(self: Pin<&mut Self>, f: &u32) -> &u32 {
70-
| -
67+
| - - let's call the lifetime of this reference `'1`
7168
| |
72-
| let's call the lifetime of this reference `'1`
7369
| let's call the lifetime of this reference `'2`
7470
LL | f
7571
| ^ function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
@@ -86,9 +82,8 @@ error: lifetime may not live long enough
8682
--> $DIR/ref-mut-self-async.rs:31:9
8783
|
8884
LL | async fn box_box_ref_Self(self: Box<Box<&mut Self>>, f: &u32) -> &u32 {
89-
| -
85+
| - - let's call the lifetime of this reference `'1`
9086
| |
91-
| let's call the lifetime of this reference `'1`
9287
| let's call the lifetime of this reference `'2`
9388
LL | f
9489
| ^ function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
@@ -105,9 +100,8 @@ error: lifetime may not live long enough
105100
--> $DIR/ref-mut-self-async.rs:35:9
106101
|
107102
LL | async fn box_pin_ref_Self(self: Box<Pin<&mut Self>>, f: &u32) -> &u32 {
108-
| -
103+
| - - let's call the lifetime of this reference `'1`
109104
| |
110-
| let's call the lifetime of this reference `'1`
111105
| let's call the lifetime of this reference `'2`
112106
LL | f
113107
| ^ function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`

src/test/ui/self/elision/ref-mut-struct-async.nll.stderr

+5-10
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ error: lifetime may not live long enough
1010
--> $DIR/ref-mut-struct-async.rs:13:9
1111
|
1212
LL | async fn ref_Struct(self: &mut Struct, f: &u32) -> &u32 {
13-
| -
13+
| - - let's call the lifetime of this reference `'1`
1414
| |
15-
| let's call the lifetime of this reference `'1`
1615
| let's call the lifetime of this reference `'2`
1716
LL | f
1817
| ^ function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
@@ -29,9 +28,8 @@ error: lifetime may not live long enough
2928
--> $DIR/ref-mut-struct-async.rs:17:9
3029
|
3130
LL | async fn box_ref_Struct(self: Box<&mut Struct>, f: &u32) -> &u32 {
32-
| -
31+
| - - let's call the lifetime of this reference `'1`
3332
| |
34-
| let's call the lifetime of this reference `'1`
3533
| let's call the lifetime of this reference `'2`
3634
LL | f
3735
| ^ function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
@@ -48,9 +46,8 @@ error: lifetime may not live long enough
4846
--> $DIR/ref-mut-struct-async.rs:21:9
4947
|
5048
LL | async fn pin_ref_Struct(self: Pin<&mut Struct>, f: &u32) -> &u32 {
51-
| -
49+
| - - let's call the lifetime of this reference `'1`
5250
| |
53-
| let's call the lifetime of this reference `'1`
5451
| let's call the lifetime of this reference `'2`
5552
LL | f
5653
| ^ function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
@@ -67,9 +64,8 @@ error: lifetime may not live long enough
6764
--> $DIR/ref-mut-struct-async.rs:25:9
6865
|
6966
LL | async fn box_box_ref_Struct(self: Box<Box<&mut Struct>>, f: &u32) -> &u32 {
70-
| -
67+
| - - let's call the lifetime of this reference `'1`
7168
| |
72-
| let's call the lifetime of this reference `'1`
7369
| let's call the lifetime of this reference `'2`
7470
LL | f
7571
| ^ function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
@@ -86,9 +82,8 @@ error: lifetime may not live long enough
8682
--> $DIR/ref-mut-struct-async.rs:29:9
8783
|
8884
LL | async fn box_pin_ref_Struct(self: Box<Pin<&mut Struct>>, f: &u32) -> &u32 {
89-
| -
85+
| - - let's call the lifetime of this reference `'1`
9086
| |
91-
| let's call the lifetime of this reference `'1`
9287
| let's call the lifetime of this reference `'2`
9388
LL | f
9489
| ^ function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`

src/test/ui/self/elision/ref-struct-async.nll.stderr

+5-10
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ error: lifetime may not live long enough
1010
--> $DIR/ref-struct-async.rs:13:9
1111
|
1212
LL | async fn ref_Struct(self: &Struct, f: &u32) -> &u32 {
13-
| -
13+
| - - let's call the lifetime of this reference `'1`
1414
| |
15-
| let's call the lifetime of this reference `'1`
1615
| let's call the lifetime of this reference `'2`
1716
LL | f
1817
| ^ function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
@@ -29,9 +28,8 @@ error: lifetime may not live long enough
2928
--> $DIR/ref-struct-async.rs:17:9
3029
|
3130
LL | async fn box_ref_Struct(self: Box<&Struct>, f: &u32) -> &u32 {
32-
| -
31+
| - - let's call the lifetime of this reference `'1`
3332
| |
34-
| let's call the lifetime of this reference `'1`
3533
| let's call the lifetime of this reference `'2`
3634
LL | f
3735
| ^ function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
@@ -48,9 +46,8 @@ error: lifetime may not live long enough
4846
--> $DIR/ref-struct-async.rs:21:9
4947
|
5048
LL | async fn pin_ref_Struct(self: Pin<&Struct>, f: &u32) -> &u32 {
51-
| -
49+
| - - let's call the lifetime of this reference `'1`
5250
| |
53-
| let's call the lifetime of this reference `'1`
5451
| let's call the lifetime of this reference `'2`
5552
LL | f
5653
| ^ function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
@@ -67,9 +64,8 @@ error: lifetime may not live long enough
6764
--> $DIR/ref-struct-async.rs:25:9
6865
|
6966
LL | async fn box_box_ref_Struct(self: Box<Box<&Struct>>, f: &u32) -> &u32 {
70-
| -
67+
| - - let's call the lifetime of this reference `'1`
7168
| |
72-
| let's call the lifetime of this reference `'1`
7369
| let's call the lifetime of this reference `'2`
7470
LL | f
7571
| ^ function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
@@ -86,9 +82,8 @@ error: lifetime may not live long enough
8682
--> $DIR/ref-struct-async.rs:29:9
8783
|
8884
LL | async fn box_pin_Struct(self: Box<Pin<&Struct>>, f: &u32) -> &u32 {
89-
| -
85+
| - - let's call the lifetime of this reference `'1`
9086
| |
91-
| let's call the lifetime of this reference `'1`
9287
| let's call the lifetime of this reference `'2`
9388
LL | f
9489
| ^ function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`

0 commit comments

Comments
 (0)