diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2022-05-06 20:05:44 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-05-06 20:05:44 +0200 |
| commit | 6db969ec95010b5e0e9164a5be6ec9d0fc54f9a1 (patch) | |
| tree | d873b53b880e9b32f8bde11a7b48a14e975b0783 /compiler | |
| parent | bcfb95afd394610ffd97fca7dbef7ac92b782dbe (diff) | |
| parent | 857eb02abe3931271db6d85a899fccba6d3ab65e (diff) | |
| download | rust-6db969ec95010b5e0e9164a5be6ec9d0fc54f9a1.tar.gz rust-6db969ec95010b5e0e9164a5be6ec9d0fc54f9a1.zip | |
Rollup merge of #96772 - TaKO8Ki:suggest-fully-qualified-path-with-appropriate-params, r=compiler-errors
Suggest fully qualified path with appropriate params closes #96291
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs b/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs index b1eb9f0da87..78e0864d918 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs @@ -731,6 +731,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { // | help: specify type like: `<Impl as Into<u32>>::into(foo_impl)` // | // = note: cannot satisfy `Impl: Into<_>` + debug!(?segment); if !impl_candidates.is_empty() && e.span.contains(span) && let Some(expr) = exprs.first() && let ExprKind::Path(hir::QPath::Resolved(_, path)) = expr.kind @@ -739,9 +740,29 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { let mut eraser = TypeParamEraser(self.tcx); let candidate_len = impl_candidates.len(); let mut suggestions: Vec<_> = impl_candidates.iter().map(|candidate| { + let trait_item = self.tcx + .associated_items(candidate.def_id) + .find_by_name_and_kind( + self.tcx, + segment.ident, + ty::AssocKind::Fn, + candidate.def_id + ); + let prefix = if let Some(trait_item) = trait_item + && let Some(trait_m) = trait_item.def_id.as_local() + && let hir::TraitItemKind::Fn(fn_, _) = &self.tcx.hir().trait_item(hir::TraitItemId { def_id: trait_m }).kind + { + match fn_.decl.implicit_self { + hir::ImplicitSelfKind::ImmRef => "&", + hir::ImplicitSelfKind::MutRef => "&mut ", + _ => "", + } + } else { + "" + }; let candidate = candidate.super_fold_with(&mut eraser); vec