diff options
| author | Yuki Okushi <huyuumi.dev@gmail.com> | 2021-02-13 16:36:46 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-02-13 16:36:46 +0900 |
| commit | 14b217c43e5ad90d881af2957be4fcb0049902a0 (patch) | |
| tree | 0fb073e928fefd8c9798c038fa35badfb3ae1b59 /compiler | |
| parent | a3902069ba3977174c538f4274531d3ac25eb377 (diff) | |
| parent | fcce998d564678d7736f8382861f0fbb5e549dd2 (diff) | |
| download | rust-14b217c43e5ad90d881af2957be4fcb0049902a0.tar.gz rust-14b217c43e5ad90d881af2957be4fcb0049902a0.zip | |
Rollup merge of #81995 - 0yoyoyo:fix-issue-81650-explicit-lifetime-error, r=estebank
Fix suggestion to introduce explicit lifetime
Addresses #81650
Error message after fix:
```
error[E0311]: the parameter type `T` may not live long enough
--> src/main.rs:25:11
|
24 | fn play_with<T: Animal + Send>(scope: &Scope, animal: T) {
| -- help: consider adding an explicit lifetime bound...: `T: 'a +`
25 | scope.spawn(move |_| {
| ^^^^^
|
note: the parameter type `T` must be valid for the anonymous lifetime #2 defined on the function body at 24:1...
--> src/main.rs:24:1
|
24 | fn play_with<T: Animal + Send>(scope: &Scope, animal: T) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...so that the type `[closure@src/main.rs:25:17: 27:6]` will meet its required lifetime bounds
--> src/main.rs:25:11
|
25 | scope.spawn(move |_| {
| ^^^^^
```
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_infer/src/infer/error_reporting/mod.rs | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs index 84aa19aedeb..63f8a7293d8 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs @@ -2248,13 +2248,18 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { "...", ); if let Some(infer::RelateParamBound(_, t)) = origin { + let return_impl_trait = self + .in_progress_typeck_results + .map(|typeck_results| typeck_results.borrow().hir_owner) + .and_then(|owner| self.tcx.return_type_impl_trait(owner)) + .is_some(); let t = self.resolve_vars_if_possible(t); match t.kind() { // We've got: // fn get_later<G, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ // suggest: // fn get_later<'a, G: 'a, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ + 'a - ty::Closure(_, _substs) | ty::Opaque(_, _substs) => { + ty::Closure(_, _substs) | ty::Opaque(_, _substs) if return_impl_trait => { new_binding_suggestion(&mut err, type_param_span, bound_kind); } _ => { |
