Skip to content

Commit

Permalink
Recover missing suggestion part under NLL
Browse files Browse the repository at this point in the history
  • Loading branch information
marmeladema committed Apr 24, 2022
1 parent 7b0db3e commit 53120b5
Show file tree
Hide file tree
Showing 15 changed files with 26 additions and 17 deletions.
5 changes: 4 additions & 1 deletion compiler/rustc_borrowck/src/diagnostics/region_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use rustc_errors::{Applicability, Diagnostic, DiagnosticBuilder, ErrorGuaranteed
use rustc_infer::infer::{
error_reporting::nice_region_error::NiceRegionError,
error_reporting::unexpected_hidden_region_diagnostic, NllRegionVariableOrigin,
RelateParamBound,
};
use rustc_middle::hir::place::PlaceBase;
use rustc_middle::mir::{ConstraintCategory, ReturnConstraint};
Expand Down Expand Up @@ -166,9 +167,11 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
let type_test_span = type_test.locations.span(&self.body);

if let Some(lower_bound_region) = lower_bound_region {
let generic_ty = type_test.generic_kind.to_ty(self.infcx.tcx);
let origin = RelateParamBound(type_test_span, generic_ty, None);
self.buffer_error(self.infcx.construct_generic_bound_failure(
type_test_span,
None,
Some(origin),
type_test.generic_kind,
lower_bound_region,
self.body.source.def_id().as_local(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ LL | | // This function call requires that
... |
LL | | require(value);
LL | | });
| |_____^
| |_____^ ...so that the type `T` will meet its required lifetime bounds

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 @@ -5,7 +5,7 @@ LL | fn no_region<'a, T>(x: Box<T>) -> impl Debug + 'a
| - help: consider adding an explicit lifetime bound...: `T: 'a`
...
LL | x
| ^
| ^ ...so that the type `T` will meet its required lifetime bounds

error[E0309]: the parameter type `T` may not live long enough
--> $DIR/impl-trait-outlives.rs:26:5
Expand All @@ -14,7 +14,7 @@ LL | fn wrong_region<'a, 'b, T>(x: Box<T>) -> impl Debug + 'a
| - help: consider adding an explicit lifetime bound...: `T: 'a`
...
LL | x
| ^
| ^ ...so that the type `T` will meet its required lifetime bounds

error: aborting due to 2 previous errors

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ error[E0310]: the parameter type `T` may not live long enough
LL | fn generic2<T: Iterator>(value: T) {
| -- help: consider adding an explicit lifetime bound...: `T: 'static +`
LL | twice(value, |value_ref, item| invoke2(value_ref, item));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds

error: aborting due to previous error

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ LL | with_signature(x, |mut y| Box::new(y.next()))
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: consider adding an explicit lifetime bound `<T as Iterator>::Item: 'a`...
= note: ...so that the type `<T as Iterator>::Item` will meet its required lifetime bounds

note: external requirements
--> $DIR/projection-no-regions-closure.rs:34:23
Expand Down Expand Up @@ -96,6 +97,7 @@ LL | with_signature(x, |mut y| Box::new(y.next()))
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: consider adding an explicit lifetime bound `<T as Iterator>::Item: 'a`...
= note: ...so that the type `<T as Iterator>::Item` will meet its required lifetime bounds

note: external requirements
--> $DIR/projection-no-regions-closure.rs:52:23
Expand Down
2 changes: 2 additions & 0 deletions src/test/ui/nll/ty-outlives/projection-no-regions-fn.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ LL | Box::new(x.next())
| ^^^^^^^^^^^^^^^^^^
|
= help: consider adding an explicit lifetime bound `<T as Iterator>::Item: 'a`...
= note: ...so that the type `<T as Iterator>::Item` will meet its required lifetime bounds

error[E0309]: the associated type `<T as Iterator>::Item` may not live long enough
--> $DIR/projection-no-regions-fn.rs:28:5
Expand All @@ -13,6 +14,7 @@ LL | Box::new(x.next())
| ^^^^^^^^^^^^^^^^^^
|
= help: consider adding an explicit lifetime bound `<T as Iterator>::Item: 'a`...
= note: ...so that the type `<T as Iterator>::Item` will meet its required lifetime bounds

error: aborting due to 2 previous errors

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ LL | fn no_relationships_late<'a, 'b, T>(cell: Cell<&'a ()>, t: T)
| - help: consider adding an explicit lifetime bound...: `T: 'a`
...
LL | with_signature(cell, t, |cell, t| require(cell, t));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds

error: lifetime may not live long enough
--> $DIR/projection-one-region-closure.rs:45:39
Expand Down Expand Up @@ -86,7 +86,7 @@ LL | fn no_relationships_early<'a, 'b, T>(cell: Cell<&'a ()>, t: T)
| - help: consider adding an explicit lifetime bound...: `T: 'a`
...
LL | with_signature(cell, t, |cell, t| require(cell, t));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds

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 @@ -34,6 +34,7 @@ LL | with_signature(cell, t, |cell, t| require(cell, t));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: consider adding an explicit lifetime bound `<T as Anything<ReEarlyBound(0, 'b), ReEarlyBound(1, 'c)>>::AssocType: 'a`...
= note: ...so that the type `<T as Anything<ReEarlyBound(0, 'b), ReEarlyBound(1, 'c)>>::AssocType` will meet its required lifetime bounds

note: external requirements
--> $DIR/projection-two-region-trait-bound-closure.rs:48:29
Expand Down Expand Up @@ -70,6 +71,7 @@ LL | with_signature(cell, t, |cell, t| require(cell, t));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: consider adding an explicit lifetime bound `<T as Anything<ReEarlyBound(1, 'b), ReEarlyBound(2, 'c)>>::AssocType: 'a`...
= note: ...so that the type `<T as Anything<ReEarlyBound(1, 'b), ReEarlyBound(2, 'c)>>::AssocType` will meet its required lifetime bounds

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 @@ -5,7 +5,7 @@ LL | fn foo<'a, T>() -> &'a ()
| - help: consider adding an explicit lifetime bound...: `T: 'a`
...
LL | bar::<T::Output>()
| ^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds

error: aborting due to previous error

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ error[E0309]: the parameter type `T` may not live long enough
LL | fn generic_fail<'a, T>(cell: Cell<&'a ()>, value: T) {
| - help: consider adding an explicit lifetime bound...: `T: 'a`
LL | twice(cell, value, |a, b| invoke(a, b));
| ^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds

error: aborting due to previous error

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ LL | fn no_region<'a, T>(x: Box<T>) -> Box<dyn Debug + 'a>
| - help: consider adding an explicit lifetime bound...: `T: 'a`
...
LL | with_signature(x, |y| y)
| ^^^^^
| ^^^^^ ...so that the type `T` will meet its required lifetime bounds

error[E0309]: the parameter type `T` may not live long enough
--> $DIR/ty-param-closure-outlives-from-return-type.rs:41:5
Expand All @@ -42,7 +42,7 @@ LL | fn wrong_region<'a, 'b, T>(x: Box<T>) -> Box<Debug + 'a>
| - help: consider adding an explicit lifetime bound...: `T: 'a`
...
LL | x
| ^
| ^ ...so that the type `T` will meet its required lifetime bounds

error: aborting due to 2 previous errors

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ LL | | // See `correct_region`, which explains the point of this
... |
LL | | require(&x, &y)
LL | | })
| |_____^
| |_____^ ...so that the type `T` will meet its required lifetime bounds

note: external requirements
--> $DIR/ty-param-closure-outlives-from-where-clause.rs:43:26
Expand Down Expand Up @@ -130,7 +130,7 @@ LL | |
LL | | // See `correct_region`
LL | | require(&x, &y)
LL | | })
| |_____^
| |_____^ ...so that the type `T` will meet its required lifetime bounds

note: external requirements
--> $DIR/ty-param-closure-outlives-from-where-clause.rs:77:26
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/nll/ty-outlives/ty-param-fn-body.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ error[E0309]: the parameter type `T` may not live long enough
LL | fn region_static<'a, T>(cell: Cell<&'a usize>, t: T) {
| - help: consider adding an explicit lifetime bound...: `T: 'a`
LL | outlives(cell, t)
| ^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds

error: aborting due to previous error

Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/nll/ty-outlives/ty-param-fn.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LL | fn no_region<'a, T>(x: Box<T>) -> Box<Debug + 'a>
| - help: consider adding an explicit lifetime bound...: `T: 'a`
...
LL | x
| ^
| ^ ...so that the type `T` will meet its required lifetime bounds

error[E0309]: the parameter type `T` may not live long enough
--> $DIR/ty-param-fn.rs:26:5
Expand All @@ -14,7 +14,7 @@ LL | fn wrong_region<'a, 'b, T>(x: Box<T>) -> Box<Debug + 'a>
| - help: consider adding an explicit lifetime bound...: `T: 'a`
...
LL | x
| ^
| ^ ...so that the type `T` will meet its required lifetime bounds

error: aborting due to 2 previous errors

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ error[E0310]: the parameter type `T` may not live long enough
LL | fn wrong_generic<T>(t: T) -> WrongGeneric<T> {
| - help: consider adding an explicit lifetime bound...: `T: 'static`
LL | t
| ^
| ^ ...so that the type `T` will meet its required lifetime bounds

error: aborting due to 3 previous errors

Expand Down

0 comments on commit 53120b5

Please sign in to comment.