Skip to content

Commit 10f7769

Browse files
committed
Remove textual span from diagnostic string
1 parent 074f636 commit 10f7769

File tree

121 files changed

+325
-372
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

121 files changed

+325
-372
lines changed

compiler/rustc_infer/src/infer/error_reporting/mod.rs

Lines changed: 10 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ fn msg_span_from_free_region(
135135
) -> (String, Option<Span>) {
136136
match *region {
137137
ty::ReEarlyBound(_) | ty::ReFree(_) => {
138-
msg_span_from_early_bound_and_free_regions(tcx, region)
138+
let (msg, span) = msg_span_from_early_bound_and_free_regions(tcx, region);
139+
(msg, Some(span))
139140
}
140141
ty::ReStatic => ("the static lifetime".to_owned(), alt_span),
141142
ty::ReEmpty(ty::UniverseIndex::ROOT) => ("an empty lifetime".to_owned(), alt_span),
@@ -147,28 +148,20 @@ fn msg_span_from_free_region(
147148
fn msg_span_from_early_bound_and_free_regions(
148149
tcx: TyCtxt<'tcx>,
149150
region: ty::Region<'tcx>,
150-
) -> (String, Option<Span>) {
151+
) -> (String, Span) {
151152
let sm = tcx.sess.source_map();
152153

153154
let scope = region.free_region_binding_scope(tcx);
154155
let node = tcx.hir().local_def_id_to_hir_id(scope.expect_local());
155-
let tag = match tcx.hir().find(node) {
156-
Some(Node::Block(_) | Node::Expr(_)) => "body",
157-
Some(Node::Item(it)) => item_scope_tag(&it),
158-
Some(Node::TraitItem(it)) => trait_item_scope_tag(&it),
159-
Some(Node::ImplItem(it)) => impl_item_scope_tag(&it),
160-
Some(Node::ForeignItem(it)) => foreign_item_scope_tag(&it),
161-
_ => unreachable!(),
162-
};
163-
let (prefix, span) = match *region {
156+
match *region {
164157
ty::ReEarlyBound(ref br) => {
165158
let mut sp = sm.guess_head_span(tcx.hir().span(node));
166159
if let Some(param) =
167160
tcx.hir().get_generics(scope).and_then(|generics| generics.get_named(br.name))
168161
{
169162
sp = param.span;
170163
}
171-
(format!("the lifetime `{}` as defined on", br.name), sp)
164+
(format!("the lifetime `{}` as defined here", br.name), sp)
172165
}
173166
ty::ReFree(ty::FreeRegion {
174167
bound_region: ty::BoundRegionKind::BrNamed(_, name), ..
@@ -179,28 +172,26 @@ fn msg_span_from_early_bound_and_free_regions(
179172
{
180173
sp = param.span;
181174
}
182-
(format!("the lifetime `{}` as defined on", name), sp)
175+
(format!("the lifetime `{}` as defined here", name), sp)
183176
}
184177
ty::ReFree(ref fr) => match fr.bound_region {
185178
ty::BrAnon(idx) => {
186179
if let Some((ty, _)) = find_anon_type(tcx, region, &fr.bound_region) {
187-
("the anonymous lifetime defined on".to_string(), ty.span)
180+
("the anonymous lifetime defined here".to_string(), ty.span)
188181
} else {
189182
(
190-
format!("the anonymous lifetime #{} defined on", idx + 1),
183+
format!("the anonymous lifetime #{} defined here", idx + 1),
191184
tcx.hir().span(node),
192185
)
193186
}
194187
}
195188
_ => (
196-
format!("the lifetime `{}` as defined on", region),
189+
format!("the lifetime `{}` as defined here", region),
197190
sm.guess_head_span(tcx.hir().span(node)),
198191
),
199192
},
200193
_ => bug!(),
201-
};
202-
let (msg, opt_span) = explain_span(tcx, tag, span);
203-
(format!("{} {}", prefix, msg), opt_span)
194+
}
204195
}
205196

206197
fn emit_msg_span(
@@ -219,44 +210,6 @@ fn emit_msg_span(
219210
}
220211
}
221212

222-
fn item_scope_tag(item: &hir::Item<'_>) -> &'static str {
223-
match item.kind {
224-
hir::ItemKind::Impl { .. } => "impl",
225-
hir::ItemKind::Struct(..) => "struct",
226-
hir::ItemKind::Union(..) => "union",
227-
hir::ItemKind::Enum(..) => "enum",
228-
hir::ItemKind::Trait(..) => "trait",
229-
hir::ItemKind::Fn(..) => "function body",
230-
_ => "item",
231-
}
232-
}
233-
234-
fn trait_item_scope_tag(item: &hir::TraitItem<'_>) -> &'static str {
235-
match item.kind {
236-
hir::TraitItemKind::Fn(..) => "method body",
237-
hir::TraitItemKind::Const(..) | hir::TraitItemKind::Type(..) => "associated item",
238-
}
239-
}
240-
241-
fn impl_item_scope_tag(item: &hir::ImplItem<'_>) -> &'static str {
242-
match item.kind {
243-
hir::ImplItemKind::Fn(..) => "method body",
244-
hir::ImplItemKind::Const(..) | hir::ImplItemKind::TyAlias(..) => "associated item",
245-
}
246-
}
247-
248-
fn foreign_item_scope_tag(item: &hir::ForeignItem<'_>) -> &'static str {
249-
match item.kind {
250-
hir::ForeignItemKind::Fn(..) => "method body",
251-
hir::ForeignItemKind::Static(..) | hir::ForeignItemKind::Type => "associated item",
252-
}
253-
}
254-
255-
fn explain_span(tcx: TyCtxt<'tcx>, heading: &str, span: Span) -> (String, Option<Span>) {
256-
let lo = tcx.sess.source_map().lookup_char_pos(span.lo());
257-
(format!("the {} at {}:{}", heading, lo.line, lo.col.to_usize() + 1), Some(span))
258-
}
259-
260213
pub fn unexpected_hidden_region_diagnostic(
261214
tcx: TyCtxt<'tcx>,
262215
span: Span,

src/test/ui/associated-consts/associated-const-impl-wrong-lifetime.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ LL | const NAME: &'a str = "unit";
66
|
77
= note: expected reference `&'static str`
88
found reference `&'a str`
9-
note: the lifetime `'a` as defined on the impl at 6:6...
9+
note: the lifetime `'a` as defined here...
1010
--> $DIR/associated-const-impl-wrong-lifetime.rs:6:6
1111
|
1212
LL | impl<'a> Foo for &'a () {

src/test/ui/borrowck/regions-bound-missing-bound-in-impl.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ LL | fn wrong_bound1<'b,'c,'d:'a+'c>(self, b: Inv<'b>, c: Inv<'c>, d: Inv<'d
2424
|
2525
= note: expected fn pointer `fn(&'a isize, Inv<'c>, Inv<'c>, Inv<'_>)`
2626
found fn pointer `fn(&'a isize, Inv<'_>, Inv<'c>, Inv<'_>)`
27-
note: the lifetime `'c` as defined on the method body at 27:24...
27+
note: the lifetime `'c` as defined here...
2828
--> $DIR/regions-bound-missing-bound-in-impl.rs:27:24
2929
|
3030
LL | fn wrong_bound1<'b,'c,'d:'a+'c>(self, b: Inv<'b>, c: Inv<'c>, d: Inv<'d>) {
3131
| ^^
32-
note: ...does not necessarily outlive the lifetime `'c` as defined on the method body at 27:24
32+
note: ...does not necessarily outlive the lifetime `'c` as defined here
3333
--> $DIR/regions-bound-missing-bound-in-impl.rs:27:24
3434
|
3535
LL | fn wrong_bound1<'b,'c,'d:'a+'c>(self, b: Inv<'b>, c: Inv<'c>, d: Inv<'d>) {
@@ -43,12 +43,12 @@ LL | fn wrong_bound1<'b,'c,'d:'a+'c>(self, b: Inv<'b>, c: Inv<'c>, d: Inv<'d
4343
|
4444
= note: expected fn pointer `fn(&'a isize, Inv<'c>, Inv<'c>, Inv<'_>)`
4545
found fn pointer `fn(&'a isize, Inv<'_>, Inv<'c>, Inv<'_>)`
46-
note: the lifetime `'c` as defined on the method body at 27:24...
46+
note: the lifetime `'c` as defined here...
4747
--> $DIR/regions-bound-missing-bound-in-impl.rs:27:24
4848
|
4949
LL | fn wrong_bound1<'b,'c,'d:'a+'c>(self, b: Inv<'b>, c: Inv<'c>, d: Inv<'d>) {
5050
| ^^
51-
note: ...does not necessarily outlive the lifetime `'c` as defined on the method body at 27:24
51+
note: ...does not necessarily outlive the lifetime `'c` as defined here
5252
--> $DIR/regions-bound-missing-bound-in-impl.rs:27:24
5353
|
5454
LL | fn wrong_bound1<'b,'c,'d:'a+'c>(self, b: Inv<'b>, c: Inv<'c>, d: Inv<'d>) {

src/test/ui/c-variadic/issue-86053-1.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,12 @@ error[E0491]: in type `&'a &'b usize`, reference has a longer lifetime than the
8484
LL | self , ... , self , self , ... ) where F : FnOnce ( & 'a & 'b usize ) {
8585
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
8686
|
87-
note: the pointer is valid for the lifetime `'a` as defined on the function body at 10:16
87+
note: the pointer is valid for the lifetime `'a` as defined here
8888
--> $DIR/issue-86053-1.rs:10:16
8989
|
9090
LL | fn ordering4 < 'a , 'b > ( a : , self , self , self ,
9191
| ^^
92-
note: but the referenced data is only valid for the lifetime `'b` as defined on the function body at 10:21
92+
note: but the referenced data is only valid for the lifetime `'b` as defined here
9393
--> $DIR/issue-86053-1.rs:10:21
9494
|
9595
LL | fn ordering4 < 'a , 'b > ( a : , self , self , self ,

src/test/ui/c-variadic/issue-86053-2.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | unsafe extern "C" fn ordering4<'a, F: H<&'static &'a ()>>(_: (), ...) {}
55
| ^^^^^^^^^^^^^^^^^^
66
|
77
= note: the pointer is valid for the static lifetime
8-
note: but the referenced data is only valid for the lifetime `'a` as defined on the function body at 8:32
8+
note: but the referenced data is only valid for the lifetime `'a` as defined here
99
--> $DIR/issue-86053-2.rs:8:32
1010
|
1111
LL | unsafe extern "C" fn ordering4<'a, F: H<&'static &'a ()>>(_: (), ...) {}

src/test/ui/closure-expected-type/expect-fn-supply-fn.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ LL | with_closure_expecting_fn_with_free_region(|x: fn(&'x u32), y| {});
66
|
77
= note: expected fn pointer `fn(&u32)`
88
found fn pointer `fn(&'x u32)`
9-
note: the anonymous lifetime #1 defined on the body at 16:48...
9+
note: the anonymous lifetime #1 defined here...
1010
--> $DIR/expect-fn-supply-fn.rs:16:48
1111
|
1212
LL | with_closure_expecting_fn_with_free_region(|x: fn(&'x u32), y| {});
1313
| ^^^^^^^^^^^^^^^^^^^^^^
14-
note: ...does not necessarily outlive the lifetime `'x` as defined on the function body at 13:36
14+
note: ...does not necessarily outlive the lifetime `'x` as defined here
1515
--> $DIR/expect-fn-supply-fn.rs:13:36
1616
|
1717
LL | fn expect_free_supply_free_from_fn<'x>(x: &'x u32) {
@@ -25,12 +25,12 @@ LL | with_closure_expecting_fn_with_free_region(|x: fn(&'x u32), y| {});
2525
|
2626
= note: expected fn pointer `fn(&u32)`
2727
found fn pointer `fn(&'x u32)`
28-
note: the lifetime `'x` as defined on the function body at 13:36...
28+
note: the lifetime `'x` as defined here...
2929
--> $DIR/expect-fn-supply-fn.rs:13:36
3030
|
3131
LL | fn expect_free_supply_free_from_fn<'x>(x: &'x u32) {
3232
| ^^
33-
note: ...does not necessarily outlive the anonymous lifetime #1 defined on the body at 16:48
33+
note: ...does not necessarily outlive the anonymous lifetime #1 defined here
3434
--> $DIR/expect-fn-supply-fn.rs:16:48
3535
|
3636
LL | with_closure_expecting_fn_with_free_region(|x: fn(&'x u32), y| {});

src/test/ui/closures/closure-expected-type/expect-region-supply-region-2.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ LL | closure_expecting_bound(|x: &'x u32| {
66
|
77
= note: expected reference `&u32`
88
found reference `&'x u32`
9-
note: the anonymous lifetime #1 defined on the body at 14:29...
9+
note: the anonymous lifetime #1 defined here...
1010
--> $DIR/expect-region-supply-region-2.rs:14:29
1111
|
1212
LL | closure_expecting_bound(|x: &'x u32| {
@@ -18,7 +18,7 @@ LL | |
1818
LL | | f = Some(x);
1919
LL | | });
2020
| |_____^
21-
note: ...does not necessarily outlive the lifetime `'x` as defined on the function body at 9:30
21+
note: ...does not necessarily outlive the lifetime `'x` as defined here
2222
--> $DIR/expect-region-supply-region-2.rs:9:30
2323
|
2424
LL | fn expect_bound_supply_named<'x>() {
@@ -32,12 +32,12 @@ LL | closure_expecting_bound(|x: &'x u32| {
3232
|
3333
= note: expected reference `&u32`
3434
found reference `&'x u32`
35-
note: the lifetime `'x` as defined on the function body at 9:30...
35+
note: the lifetime `'x` as defined here...
3636
--> $DIR/expect-region-supply-region-2.rs:9:30
3737
|
3838
LL | fn expect_bound_supply_named<'x>() {
3939
| ^^
40-
note: ...does not necessarily outlive the anonymous lifetime #1 defined on the body at 14:29
40+
note: ...does not necessarily outlive the anonymous lifetime #1 defined here
4141
--> $DIR/expect-region-supply-region-2.rs:14:29
4242
|
4343
LL | closure_expecting_bound(|x: &'x u32| {

src/test/ui/dropck/reject-specialized-drops-8142.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ LL | impl Drop for N<'static> { fn drop(&mut self) { } }
3030
|
3131
= note: expected struct `N<'n>`
3232
found struct `N<'static>`
33-
note: the lifetime `'n` as defined on the struct at 7:10...
33+
note: the lifetime `'n` as defined here...
3434
--> $DIR/reject-specialized-drops-8142.rs:7:10
3535
|
3636
LL | struct N<'n> { x: &'n i8 }
@@ -91,12 +91,12 @@ error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'lw`
9191
LL | impl<'lw> Drop for W<'lw,'lw> { fn drop(&mut self) { } } // REJECT
9292
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9393
|
94-
note: first, the lifetime cannot outlive the lifetime `'l1` as defined on the struct at 16:10...
94+
note: first, the lifetime cannot outlive the lifetime `'l1` as defined here...
9595
--> $DIR/reject-specialized-drops-8142.rs:16:10
9696
|
9797
LL | struct W<'l1, 'l2> { x: &'l1 i8, y: &'l2 u8 }
9898
| ^^^
99-
note: ...but the lifetime must also be valid for the lifetime `'l2` as defined on the struct at 16:15...
99+
note: ...but the lifetime must also be valid for the lifetime `'l2` as defined here...
100100
--> $DIR/reject-specialized-drops-8142.rs:16:15
101101
|
102102
LL | struct W<'l1, 'l2> { x: &'l1 i8, y: &'l2 u8 }

src/test/ui/error-codes/E0308-2.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ LL | impl Eq for &dyn DynEq {}
66
|
77
= note: expected trait `PartialEq`
88
found trait `PartialEq`
9-
note: the lifetime `'_` as defined on the impl at 9:13...
9+
note: the lifetime `'_` as defined here...
1010
--> $DIR/E0308-2.rs:9:13
1111
|
1212
LL | impl Eq for &dyn DynEq {}

src/test/ui/error-codes/E0478.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ error[E0478]: lifetime bound not satisfied
44
LL | child: Box<dyn Wedding<'kiss> + 'SnowWhite>,
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
7-
note: lifetime parameter instantiated with the lifetime `'SnowWhite` as defined on the struct at 3:22
7+
note: lifetime parameter instantiated with the lifetime `'SnowWhite` as defined here
88
--> $DIR/E0478.rs:3:22
99
|
1010
LL | struct Prince<'kiss, 'SnowWhite> {
1111
| ^^^^^^^^^^
12-
note: but lifetime parameter must outlive the lifetime `'kiss` as defined on the struct at 3:15
12+
note: but lifetime parameter must outlive the lifetime `'kiss` as defined here
1313
--> $DIR/E0478.rs:3:15
1414
|
1515
LL | struct Prince<'kiss, 'SnowWhite> {

src/test/ui/error-codes/E0490.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ error[E0490]: a value of type `&'b ()` is borrowed for too long
44
LL | let x: &'a _ = &y;
55
| ^^
66
|
7-
note: the type is valid for the lifetime `'a` as defined on the function body at 1:6
7+
note: the type is valid for the lifetime `'a` as defined here
88
--> $DIR/E0490.rs:1:6
99
|
1010
LL | fn f<'a, 'b>(y: &'b ()) {
1111
| ^^
12-
note: but the borrow lasts for the lifetime `'b` as defined on the function body at 1:10
12+
note: but the borrow lasts for the lifetime `'b` as defined here
1313
--> $DIR/E0490.rs:1:10
1414
|
1515
LL | fn f<'a, 'b>(y: &'b ()) {
@@ -21,7 +21,7 @@ error[E0495]: cannot infer an appropriate lifetime for borrow expression due to
2121
LL | let x: &'a _ = &y;
2222
| ^^
2323
|
24-
note: first, the lifetime cannot outlive the lifetime `'b` as defined on the function body at 1:10...
24+
note: first, the lifetime cannot outlive the lifetime `'b` as defined here...
2525
--> $DIR/E0490.rs:1:10
2626
|
2727
LL | fn f<'a, 'b>(y: &'b ()) {
@@ -31,7 +31,7 @@ note: ...so that the type `&'b ()` is not borrowed for too long
3131
|
3232
LL | let x: &'a _ = &y;
3333
| ^^
34-
note: but, the lifetime must be valid for the lifetime `'a` as defined on the function body at 1:6...
34+
note: but, the lifetime must be valid for the lifetime `'a` as defined here...
3535
--> $DIR/E0490.rs:1:6
3636
|
3737
LL | fn f<'a, 'b>(y: &'b ()) {
@@ -48,7 +48,7 @@ error[E0495]: cannot infer an appropriate lifetime due to conflicting requiremen
4848
LL | let x: &'a _ = &y;
4949
| ^^
5050
|
51-
note: first, the lifetime cannot outlive the lifetime `'b` as defined on the function body at 1:10...
51+
note: first, the lifetime cannot outlive the lifetime `'b` as defined here...
5252
--> $DIR/E0490.rs:1:10
5353
|
5454
LL | fn f<'a, 'b>(y: &'b ()) {
@@ -60,7 +60,7 @@ LL | let x: &'a _ = &y;
6060
| ^^
6161
= note: expected `&'a &()`
6262
found `&'a &'b ()`
63-
note: but, the lifetime must be valid for the lifetime `'a` as defined on the function body at 1:6...
63+
note: but, the lifetime must be valid for the lifetime `'a` as defined here...
6464
--> $DIR/E0490.rs:1:6
6565
|
6666
LL | fn f<'a, 'b>(y: &'b ()) {

src/test/ui/explicit/explicit-self-lifetime-mismatch.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ LL | Foo<'b,'a>
66
|
77
= note: expected struct `Foo<'a, 'b>`
88
found struct `Foo<'b, 'a>`
9-
note: the lifetime `'b` as defined on the impl at 6:9...
9+
note: the lifetime `'b` as defined here...
1010
--> $DIR/explicit-self-lifetime-mismatch.rs:6:9
1111
|
1212
LL | impl<'a,'b> Foo<'a,'b> {
1313
| ^^
14-
note: ...does not necessarily outlive the lifetime `'a` as defined on the impl at 6:6
14+
note: ...does not necessarily outlive the lifetime `'a` as defined here
1515
--> $DIR/explicit-self-lifetime-mismatch.rs:6:6
1616
|
1717
LL | impl<'a,'b> Foo<'a,'b> {
@@ -25,12 +25,12 @@ LL | Foo<'b,'a>
2525
|
2626
= note: expected struct `Foo<'a, 'b>`
2727
found struct `Foo<'b, 'a>`
28-
note: the lifetime `'a` as defined on the impl at 6:6...
28+
note: the lifetime `'a` as defined here...
2929
--> $DIR/explicit-self-lifetime-mismatch.rs:6:6
3030
|
3131
LL | impl<'a,'b> Foo<'a,'b> {
3232
| ^^
33-
note: ...does not necessarily outlive the lifetime `'b` as defined on the impl at 6:9
33+
note: ...does not necessarily outlive the lifetime `'b` as defined here
3434
--> $DIR/explicit-self-lifetime-mismatch.rs:6:9
3535
|
3636
LL | impl<'a,'b> Foo<'a,'b> {

src/test/ui/generator/resume-arg-late-bound.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ LL | test(gen);
66
|
77
= note: expected type `for<'a> Generator<&'a mut bool>`
88
found type `Generator<&mut bool>`
9-
note: the required lifetime does not necessarily outlive the anonymous lifetime #1 defined on the body at 11:15
9+
note: the required lifetime does not necessarily outlive the anonymous lifetime #1 defined here
1010
--> $DIR/resume-arg-late-bound.rs:11:15
1111
|
1212
LL | let gen = |arg: &mut bool| {
@@ -29,7 +29,7 @@ LL | test(gen);
2929
|
3030
= note: expected type `for<'a> Generator<&'a mut bool>`
3131
found type `Generator<&mut bool>`
32-
note: the anonymous lifetime #1 defined on the body at 11:15 doesn't meet the lifetime requirements
32+
note: the anonymous lifetime #1 defined here doesn't meet the lifetime requirements
3333
--> $DIR/resume-arg-late-bound.rs:11:15
3434
|
3535
LL | let gen = |arg: &mut bool| {

0 commit comments

Comments
 (0)