diff --git a/src/librustc/infer/error_reporting/mod.rs b/src/librustc/infer/error_reporting/mod.rs index 77182b97fd4..58566bdcc35 100644 --- a/src/librustc/infer/error_reporting/mod.rs +++ b/src/librustc/infer/error_reporting/mod.rs @@ -1778,8 +1778,8 @@ fn binding_suggestion<'tcx, S: fmt::Display>( } 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, @@ -1788,7 +1788,11 @@ fn binding_suggestion<'tcx, S: fmt::Display>( "{} 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 } diff --git a/src/test/ui/nll/closure-requirements/propagate-from-trait-match.stderr b/src/test/ui/nll/closure-requirements/propagate-from-trait-match.stderr index 5317bb6a1b1..b705ad9009a 100644 --- a/src/test/ui/nll/closure-requirements/propagate-from-trait-match.stderr +++ b/src/test/ui/nll/closure-requirements/propagate-from-trait-match.stderr @@ -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 diff --git a/src/test/ui/nll/ty-outlives/impl-trait-outlives.stderr b/src/test/ui/nll/ty-outlives/impl-trait-outlives.stderr index 32a494c5d16..053aef951f2 100644 --- a/src/test/ui/nll/ty-outlives/impl-trait-outlives.stderr +++ b/src/test/ui/nll/ty-outlives/impl-trait-outlives.stderr @@ -4,7 +4,7 @@ error[E0309]: the parameter type `T` may not live long enough LL | fn no_region<'a, T>(x: Box) -> 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 @@ -12,7 +12,7 @@ error[E0309]: the parameter type `T` may not live long enough LL | fn wrong_region<'a, 'b, T>(x: Box) -> 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 diff --git a/src/test/ui/nll/ty-outlives/projection-no-regions-closure.stderr b/src/test/ui/nll/ty-outlives/projection-no-regions-closure.stderr index bff8c662d0d..84365465eda 100644 --- a/src/test/ui/nll/ty-outlives/projection-no-regions-closure.stderr +++ b/src/test/ui/nll/ty-outlives/projection-no-regions-closure.stderr @@ -31,7 +31,7 @@ error[E0309]: the associated type `::Item` may not liv LL | with_signature(x, |mut y| Box::new(y.next())) | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: consider adding an explicit lifetime bound `::Item: ReEarlyBound(0, 'a)`... + = help: consider adding an explicit lifetime bound `::Item: 'a`... note: external requirements --> $DIR/projection-no-regions-closure.rs:34:23 @@ -92,7 +92,7 @@ error[E0309]: the associated type `::Item` may not liv LL | with_signature(x, |mut y| Box::new(y.next())) | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: consider adding an explicit lifetime bound `::Item: ReEarlyBound(0, 'a)`... + = help: consider adding an explicit lifetime bound `::Item: 'a`... note: external requirements --> $DIR/projection-no-regions-closure.rs:52:23 diff --git a/src/test/ui/nll/ty-outlives/projection-no-regions-fn.stderr b/src/test/ui/nll/ty-outlives/projection-no-regions-fn.stderr index 190a2cdfc07..b0338de9333 100644 --- a/src/test/ui/nll/ty-outlives/projection-no-regions-fn.stderr +++ b/src/test/ui/nll/ty-outlives/projection-no-regions-fn.stderr @@ -4,7 +4,7 @@ error[E0309]: the associated type `::Item` may not liv LL | Box::new(x.next()) | ^^^^^^^^^^^^^^^^^^ | - = help: consider adding an explicit lifetime bound `::Item: ReEarlyBound(0, 'a)`... + = help: consider adding an explicit lifetime bound `::Item: 'a`... error[E0309]: the associated type `::Item` may not live long enough --> $DIR/projection-no-regions-fn.rs:28:5 @@ -12,7 +12,7 @@ error[E0309]: the associated type `::Item` may not liv LL | Box::new(x.next()) | ^^^^^^^^^^^^^^^^^^ | - = help: consider adding an explicit lifetime bound `::Item: ReEarlyBound(0, 'a)`... + = help: consider adding an explicit lifetime bound `::Item: 'a`... error: aborting due to 2 previous errors diff --git a/src/test/ui/nll/ty-outlives/projection-one-region-closure.stderr b/src/test/ui/nll/ty-outlives/projection-one-region-closure.stderr index 6d1fbcb8f5b..118a849f984 100644 --- a/src/test/ui/nll/ty-outlives/projection-one-region-closure.stderr +++ b/src/test/ui/nll/ty-outlives/projection-one-region-closure.stderr @@ -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 @@ -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 diff --git a/src/test/ui/nll/ty-outlives/projection-two-region-trait-bound-closure.stderr b/src/test/ui/nll/ty-outlives/projection-two-region-trait-bound-closure.stderr index 1bd97c1caa4..ff402f89ae8 100644 --- a/src/test/ui/nll/ty-outlives/projection-two-region-trait-bound-closure.stderr +++ b/src/test/ui/nll/ty-outlives/projection-two-region-trait-bound-closure.stderr @@ -32,7 +32,7 @@ error[E0309]: the associated type `>::AssocType` may LL | with_signature(cell, t, |cell, t| require(cell, t)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: consider adding an explicit lifetime bound `>::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 `>::AssocType: 'a`... note: external requirements --> $DIR/projection-two-region-trait-bound-closure.rs:48:29 @@ -67,7 +67,7 @@ error[E0309]: the associated type `>::AssocType` may LL | with_signature(cell, t, |cell, t| require(cell, t)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: consider adding an explicit lifetime bound `>::AssocType: ReEarlyBound(0, 'a)`... + = help: consider adding an explicit lifetime bound `>::AssocType: 'a`... note: external requirements --> $DIR/projection-two-region-trait-bound-closure.rs:61:29 diff --git a/src/test/ui/nll/ty-outlives/ty-param-closure-approximate-lower-bound.stderr b/src/test/ui/nll/ty-outlives/ty-param-closure-approximate-lower-bound.stderr index a213f423e3c..9b08a107496 100644 --- a/src/test/ui/nll/ty-outlives/ty-param-closure-approximate-lower-bound.stderr +++ b/src/test/ui/nll/ty-outlives/ty-param-closure-approximate-lower-bound.stderr @@ -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 diff --git a/src/test/ui/nll/ty-outlives/ty-param-closure-outlives-from-return-type.stderr b/src/test/ui/nll/ty-outlives/ty-param-closure-outlives-from-return-type.stderr index a488637bbc5..3cd1f435871 100644 --- a/src/test/ui/nll/ty-outlives/ty-param-closure-outlives-from-return-type.stderr +++ b/src/test/ui/nll/ty-outlives/ty-param-closure-outlives-from-return-type.stderr @@ -31,7 +31,7 @@ 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 @@ -39,7 +39,7 @@ error[E0309]: the parameter type `T` may not live long enough 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 diff --git a/src/test/ui/nll/ty-outlives/ty-param-closure-outlives-from-where-clause.stderr b/src/test/ui/nll/ty-outlives/ty-param-closure-outlives-from-where-clause.stderr index 62dfe94e384..4740ed645f1 100644 --- a/src/test/ui/nll/ty-outlives/ty-param-closure-outlives-from-where-clause.stderr +++ b/src/test/ui/nll/ty-outlives/ty-param-closure-outlives-from-where-clause.stderr @@ -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 @@ -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