Skip to content

Use better bound names in -Zverbose mode #68545

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/librustc/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1778,8 +1778,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ LL | | require(value);
LL | | });
| |_____^
|
= help: consider adding an explicit lifetime bound `T: ReEarlyBound(0, 'a)`...
= help: consider adding an explicit lifetime bound `T: 'a`...

error: aborting due to previous error

Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/nll/ty-outlives/impl-trait-outlives.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ error[E0309]: the parameter type `T` may not live long enough
LL | fn no_region<'a, T>(x: Box<T>) -> impl Debug + 'a
| ^^^^^^^^^^^^^^^
|
= help: consider adding an explicit lifetime bound `T: ReEarlyBound(0, 'a)`...
= help: consider adding an explicit lifetime bound `T: 'a`...

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

error: aborting due to 2 previous errors

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

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

note: external requirements
--> $DIR/projection-no-regions-closure.rs:52:23
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/nll/ty-outlives/projection-no-regions-fn.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ error[E0309]: the associated type `<T as std::iter::Iterator>::Item` may not liv
LL | Box::new(x.next())
| ^^^^^^^^^^^^^^^^^^
|
= help: consider adding an explicit lifetime bound `<T as std::iter::Iterator>::Item: ReEarlyBound(0, 'a)`...
= help: consider adding an explicit lifetime bound `<T as std::iter::Iterator>::Item: 'a`...

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

error: aborting due to 2 previous errors

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ error[E0309]: the parameter type `T` may not live long enough
LL | with_signature(cell, t, |cell, t| require(cell, t));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= 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))`...
= help: consider adding an explicit lifetime bound `T: 'a`...

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

error: lifetime may not live long enough
--> $DIR/projection-one-region-closure.rs:56:39
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ error[E0309]: the associated type `<T as Anything<'_#5r, '_#6r>>::AssocType` may
LL | with_signature(cell, t, |cell, t| require(cell, t));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= 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))`...
= help: consider adding an explicit lifetime bound `<T as Anything<'_#5r, '_#6r>>::AssocType: 'a`...

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

note: external requirements
--> $DIR/projection-two-region-trait-bound-closure.rs:61:29
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ error[E0309]: the parameter type `T` may not live long enough
LL | twice(cell, value, |a, b| invoke(a, b));
| ^^^^^^^^^^^^^^^^^^^
|
= 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))`...
= help: consider adding an explicit lifetime bound `T: 'a`...

error: aborting due to previous error

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ error[E0309]: the parameter type `T` may not live long enough
LL | with_signature(x, |y| y)
| ^^^^^
|
= help: consider adding an explicit lifetime bound `T: ReEarlyBound(0, 'a)`...
= help: consider adding an explicit lifetime bound `T: 'a`...

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

error: aborting due to 2 previous errors

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ LL | | require(&x, &y)
LL | | })
| |_____^
|
= 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))`...
= help: consider adding an explicit lifetime bound `T: 'a`...

note: external requirements
--> $DIR/ty-param-closure-outlives-from-where-clause.rs:43:26
Expand Down Expand Up @@ -126,7 +126,7 @@ LL | | require(&x, &y)
LL | | })
| |_____^
|
= 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))`...
= help: consider adding an explicit lifetime bound `T: 'a`...

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