]> git.lizzy.rs Git - rust.git/commitdiff
Rollup merge of #67285 - ohadravid:indicate-origin-of-where-type-parameter, r=estebank
authorMazdak Farrokhzad <twingoow@gmail.com>
Fri, 20 Dec 2019 11:17:23 +0000 (12:17 +0100)
committerGitHub <noreply@github.com>
Fri, 20 Dec 2019 11:17:23 +0000 (12:17 +0100)
Indicate origin of where type parameter for uninferred types

Based on #65951 (which is not merge yet), fixes #67277.

This PR improves a little the diagnostic for code like:

```
 async fn foo() {
     bar().await;
}

 async fn bar<T>() -> () {}
```

by showing:
```
error[E0698]: type inside `async fn` body must be known in this context
 --> unresolved_type_param.rs:9:5
  |
9 |     bar().await;
  |     ^^^ cannot infer type for type parameter `T` declared on the function `bar`
  |
...
```
(The
```
declared on the function `bar`
```
part is new)

A small side note: `Vec` and `slice` seem to resist this change, because querying `item_name()` panics, and `get_opt_name()` returns `None`.

r? @estebank

1  2 
src/librustc/traits/error_reporting.rs

index 701c19085bec586e20beabe1b5eaf98d55c2f513,018bed96664879c6efb6420936777032c7c64fc3..4839974d6255cc4d9007916226594c1b32a600cd
@@@ -2113,7 -2113,7 +2113,7 @@@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> 
                      self.var_map.entry(ty).or_insert_with(||
                          infcx.next_ty_var(
                              TypeVariableOrigin {
-                                 kind: TypeVariableOriginKind::TypeParameterDefinition(name),
+                                 kind: TypeVariableOriginKind::TypeParameterDefinition(name, None),
                                  span: DUMMY_SP,
                              }
                          )
              let message = if let Some(name) = last_generator
                  .and_then(|generator_did| self.tcx.parent(generator_did))
                  .and_then(|parent_did| self.tcx.hir().as_local_hir_id(parent_did))
 -                .map(|parent_hir_id| self.tcx.hir().name(parent_hir_id))
 +                .and_then(|parent_hir_id| self.tcx.hir().opt_name(parent_hir_id))
              {
                  format!("future returned by `{}` is not {}", name, trait_name)
              } else {