Skip to content

Commit 698fcd3

Browse files
committed
Auto merge of #68545 - estebank:verbose-bound-display, r=petrochenkov
Use better bound names in `-Zverbose` mode r? @petrochenkov as per https://github.com/rust-lang/rust/pull/67951/files#r365524015
2 parents 3d8778d + 3fb1810 commit 698fcd3

10 files changed

+23
-19
lines changed

src/librustc/infer/error_reporting/mod.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -1778,8 +1778,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
17781778
}
17791779

17801780
let mut err = match *sub {
1781-
ty::ReEarlyBound(_)
1782-
| ty::ReFree(ty::FreeRegion { bound_region: ty::BrNamed(..), .. }) => {
1781+
ty::ReEarlyBound(ty::EarlyBoundRegion { name, .. })
1782+
| ty::ReFree(ty::FreeRegion { bound_region: ty::BrNamed(_, name), .. }) => {
17831783
// Does the required lifetime have a nice name we can print?
17841784
let mut err = struct_span_err!(
17851785
self.tcx.sess,
@@ -1788,7 +1788,11 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
17881788
"{} may not live long enough",
17891789
labeled_user_string
17901790
);
1791-
binding_suggestion(&mut err, type_param_span, bound_kind, sub);
1791+
// Explicitely use the name instead of `sub`'s `Display` impl. The `Display` impl
1792+
// for the bound is not suitable for suggestions when `-Zverbose` is set because it
1793+
// uses `Debug` output, so we handle it specially here so that suggestions are
1794+
// always correct.
1795+
binding_suggestion(&mut err, type_param_span, bound_kind, name);
17921796
err
17931797
}
17941798

src/test/ui/nll/closure-requirements/propagate-from-trait-match.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ LL | | require(value);
4545
LL | | });
4646
| |_____^
4747
|
48-
= help: consider adding an explicit lifetime bound `T: ReEarlyBound(0, 'a)`...
48+
= help: consider adding an explicit lifetime bound `T: 'a`...
4949

5050
error: aborting due to previous error
5151

src/test/ui/nll/ty-outlives/impl-trait-outlives.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ error[E0309]: the parameter type `T` may not live long enough
44
LL | fn no_region<'a, T>(x: Box<T>) -> impl Debug + 'a
55
| ^^^^^^^^^^^^^^^
66
|
7-
= help: consider adding an explicit lifetime bound `T: ReEarlyBound(0, 'a)`...
7+
= help: consider adding an explicit lifetime bound `T: 'a`...
88

99
error[E0309]: the parameter type `T` may not live long enough
1010
--> $DIR/impl-trait-outlives.rs:22:42
1111
|
1212
LL | fn wrong_region<'a, 'b, T>(x: Box<T>) -> impl Debug + 'a
1313
| ^^^^^^^^^^^^^^^
1414
|
15-
= help: consider adding an explicit lifetime bound `T: ReEarlyBound(0, 'a)`...
15+
= help: consider adding an explicit lifetime bound `T: 'a`...
1616

1717
error: aborting due to 2 previous errors
1818

src/test/ui/nll/ty-outlives/projection-no-regions-closure.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ error[E0309]: the associated type `<T as std::iter::Iterator>::Item` may not liv
3131
LL | with_signature(x, |mut y| Box::new(y.next()))
3232
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
3333
|
34-
= help: consider adding an explicit lifetime bound `<T as std::iter::Iterator>::Item: ReEarlyBound(0, 'a)`...
34+
= help: consider adding an explicit lifetime bound `<T as std::iter::Iterator>::Item: 'a`...
3535

3636
note: external requirements
3737
--> $DIR/projection-no-regions-closure.rs:34:23
@@ -92,7 +92,7 @@ error[E0309]: the associated type `<T as std::iter::Iterator>::Item` may not liv
9292
LL | with_signature(x, |mut y| Box::new(y.next()))
9393
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
9494
|
95-
= help: consider adding an explicit lifetime bound `<T as std::iter::Iterator>::Item: ReEarlyBound(0, 'a)`...
95+
= help: consider adding an explicit lifetime bound `<T as std::iter::Iterator>::Item: 'a`...
9696

9797
note: external requirements
9898
--> $DIR/projection-no-regions-closure.rs:52:23

src/test/ui/nll/ty-outlives/projection-no-regions-fn.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ error[E0309]: the associated type `<T as std::iter::Iterator>::Item` may not liv
44
LL | Box::new(x.next())
55
| ^^^^^^^^^^^^^^^^^^
66
|
7-
= help: consider adding an explicit lifetime bound `<T as std::iter::Iterator>::Item: ReEarlyBound(0, 'a)`...
7+
= help: consider adding an explicit lifetime bound `<T as std::iter::Iterator>::Item: 'a`...
88

99
error[E0309]: the associated type `<T as std::iter::Iterator>::Item` may not live long enough
1010
--> $DIR/projection-no-regions-fn.rs:28:5
1111
|
1212
LL | Box::new(x.next())
1313
| ^^^^^^^^^^^^^^^^^^
1414
|
15-
= help: consider adding an explicit lifetime bound `<T as std::iter::Iterator>::Item: ReEarlyBound(0, 'a)`...
15+
= help: consider adding an explicit lifetime bound `<T as std::iter::Iterator>::Item: 'a`...
1616

1717
error: aborting due to 2 previous errors
1818

src/test/ui/nll/ty-outlives/projection-one-region-closure.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ error[E0309]: the parameter type `T` may not live long enough
3333
LL | with_signature(cell, t, |cell, t| require(cell, t));
3434
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
3535
|
36-
= help: consider adding an explicit lifetime bound `T: ReFree(DefId(0:15 ~ projection_one_region_closure[317d]::no_relationships_late[0]), BrNamed(DefId(0:16 ~ projection_one_region_closure[317d]::no_relationships_late[0]::'a[0]), 'a))`...
36+
= help: consider adding an explicit lifetime bound `T: 'a`...
3737

3838
error: lifetime may not live long enough
3939
--> $DIR/projection-one-region-closure.rs:45:39
@@ -82,7 +82,7 @@ error[E0309]: the parameter type `T` may not live long enough
8282
LL | with_signature(cell, t, |cell, t| require(cell, t));
8383
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
8484
|
85-
= help: consider adding an explicit lifetime bound `T: ReEarlyBound(0, 'a)`...
85+
= help: consider adding an explicit lifetime bound `T: 'a`...
8686

8787
error: lifetime may not live long enough
8888
--> $DIR/projection-one-region-closure.rs:56:39

src/test/ui/nll/ty-outlives/projection-two-region-trait-bound-closure.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ error[E0309]: the associated type `<T as Anything<'_#5r, '_#6r>>::AssocType` may
3232
LL | with_signature(cell, t, |cell, t| require(cell, t));
3333
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
3434
|
35-
= help: consider adding an explicit lifetime bound `<T as Anything<'_#5r, '_#6r>>::AssocType: ReFree(DefId(0:17 ~ projection_two_region_trait_bound_closure[317d]::no_relationships_late[0]), BrNamed(DefId(0:18 ~ projection_two_region_trait_bound_closure[317d]::no_relationships_late[0]::'a[0]), 'a))`...
35+
= help: consider adding an explicit lifetime bound `<T as Anything<'_#5r, '_#6r>>::AssocType: 'a`...
3636

3737
note: external requirements
3838
--> $DIR/projection-two-region-trait-bound-closure.rs:48:29
@@ -67,7 +67,7 @@ error[E0309]: the associated type `<T as Anything<'_#6r, '_#7r>>::AssocType` may
6767
LL | with_signature(cell, t, |cell, t| require(cell, t));
6868
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
6969
|
70-
= help: consider adding an explicit lifetime bound `<T as Anything<'_#6r, '_#7r>>::AssocType: ReEarlyBound(0, 'a)`...
70+
= help: consider adding an explicit lifetime bound `<T as Anything<'_#6r, '_#7r>>::AssocType: 'a`...
7171

7272
note: external requirements
7373
--> $DIR/projection-two-region-trait-bound-closure.rs:61:29

src/test/ui/nll/ty-outlives/ty-param-closure-approximate-lower-bound.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ error[E0309]: the parameter type `T` may not live long enough
5353
LL | twice(cell, value, |a, b| invoke(a, b));
5454
| ^^^^^^^^^^^^^^^^^^^
5555
|
56-
= help: consider adding an explicit lifetime bound `T: ReFree(DefId(0:12 ~ ty_param_closure_approximate_lower_bound[317d]::generic_fail[0]), BrNamed(DefId(0:13 ~ ty_param_closure_approximate_lower_bound[317d]::generic_fail[0]::'a[0]), 'a))`...
56+
= help: consider adding an explicit lifetime bound `T: 'a`...
5757

5858
error: aborting due to previous error
5959

src/test/ui/nll/ty-outlives/ty-param-closure-outlives-from-return-type.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ error[E0309]: the parameter type `T` may not live long enough
3131
LL | with_signature(x, |y| y)
3232
| ^^^^^
3333
|
34-
= help: consider adding an explicit lifetime bound `T: ReEarlyBound(0, 'a)`...
34+
= help: consider adding an explicit lifetime bound `T: 'a`...
3535

3636
error[E0309]: the parameter type `T` may not live long enough
3737
--> $DIR/ty-param-closure-outlives-from-return-type.rs:41:5
3838
|
3939
LL | x
4040
| ^
4141
|
42-
= help: consider adding an explicit lifetime bound `T: ReEarlyBound(0, 'a)`...
42+
= help: consider adding an explicit lifetime bound `T: 'a`...
4343

4444
error: aborting due to 2 previous errors
4545

src/test/ui/nll/ty-outlives/ty-param-closure-outlives-from-where-clause.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ LL | | require(&x, &y)
4646
LL | | })
4747
| |_____^
4848
|
49-
= help: consider adding an explicit lifetime bound `T: ReFree(DefId(0:11 ~ ty_param_closure_outlives_from_where_clause[317d]::no_region[0]), BrNamed(DefId(0:12 ~ ty_param_closure_outlives_from_where_clause[317d]::no_region[0]::'a[0]), 'a))`...
49+
= help: consider adding an explicit lifetime bound `T: 'a`...
5050

5151
note: external requirements
5252
--> $DIR/ty-param-closure-outlives-from-where-clause.rs:43:26
@@ -126,7 +126,7 @@ LL | | require(&x, &y)
126126
LL | | })
127127
| |_____^
128128
|
129-
= help: consider adding an explicit lifetime bound `T: ReFree(DefId(0:19 ~ ty_param_closure_outlives_from_where_clause[317d]::wrong_region[0]), BrNamed(DefId(0:20 ~ ty_param_closure_outlives_from_where_clause[317d]::wrong_region[0]::'a[0]), 'a))`...
129+
= help: consider adding an explicit lifetime bound `T: 'a`...
130130

131131
note: external requirements
132132
--> $DIR/ty-param-closure-outlives-from-where-clause.rs:77:26

0 commit comments

Comments
 (0)