|
4 | 4 |
|
5 | 5 | use rustc_data_structures::fx::FxIndexSet;
|
6 | 6 | use rustc_errors::{Applicability, Diagnostic, DiagnosticBuilder, ErrorGuaranteed, MultiSpan};
|
| 7 | +use rustc_hir as hir; |
7 | 8 | use rustc_hir::def_id::DefId;
|
8 | 9 | use rustc_hir::intravisit::Visitor;
|
9 |
| -use rustc_hir::{self as hir, Item, ItemKind, Node}; |
10 | 10 | use rustc_infer::infer::{
|
11 | 11 | error_reporting::nice_region_error::{
|
12 | 12 | self, find_anon_type, find_param_with_region, suggest_adding_lifetime_params,
|
@@ -291,71 +291,6 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
291 | 291 | outlives_suggestion.add_suggestion(self);
|
292 | 292 | }
|
293 | 293 |
|
294 |
| - fn get_impl_ident_and_self_ty_from_trait( |
295 |
| - &self, |
296 |
| - def_id: DefId, |
297 |
| - trait_objects: &FxIndexSet<DefId>, |
298 |
| - ) -> Option<(Ident, &'tcx hir::Ty<'tcx>)> { |
299 |
| - let tcx = self.infcx.tcx; |
300 |
| - match tcx.hir().get_if_local(def_id) { |
301 |
| - Some(Node::ImplItem(impl_item)) => { |
302 |
| - match tcx.hir().find_by_def_id(tcx.hir().get_parent_item(impl_item.hir_id()).def_id) |
303 |
| - { |
304 |
| - Some(Node::Item(Item { |
305 |
| - kind: ItemKind::Impl(hir::Impl { self_ty, .. }), |
306 |
| - .. |
307 |
| - })) => Some((impl_item.ident, self_ty)), |
308 |
| - _ => None, |
309 |
| - } |
310 |
| - } |
311 |
| - Some(Node::TraitItem(trait_item)) => { |
312 |
| - let trait_did = tcx.hir().get_parent_item(trait_item.hir_id()); |
313 |
| - match tcx.hir().find_by_def_id(trait_did.def_id) { |
314 |
| - Some(Node::Item(Item { kind: ItemKind::Trait(..), .. })) => { |
315 |
| - // The method being called is defined in the `trait`, but the `'static` |
316 |
| - // obligation comes from the `impl`. Find that `impl` so that we can point |
317 |
| - // at it in the suggestion. |
318 |
| - let trait_did = trait_did.to_def_id(); |
319 |
| - match tcx |
320 |
| - .hir() |
321 |
| - .trait_impls(trait_did) |
322 |
| - .iter() |
323 |
| - .filter_map(|&impl_did| { |
324 |
| - match tcx.hir().get_if_local(impl_did.to_def_id()) { |
325 |
| - Some(Node::Item(Item { |
326 |
| - kind: ItemKind::Impl(hir::Impl { self_ty, .. }), |
327 |
| - .. |
328 |
| - })) if trait_objects.iter().all(|did| { |
329 |
| - // FIXME: we should check `self_ty` against the receiver |
330 |
| - // type in the `UnifyReceiver` context, but for now, use |
331 |
| - // this imperfect proxy. This will fail if there are |
332 |
| - // multiple `impl`s for the same trait like |
333 |
| - // `impl Foo for Box<dyn Bar>` and `impl Foo for dyn Bar`. |
334 |
| - // In that case, only the first one will get suggestions. |
335 |
| - let mut traits = vec![]; |
336 |
| - let mut hir_v = HirTraitObjectVisitor(&mut traits, *did); |
337 |
| - hir_v.visit_ty(self_ty); |
338 |
| - !traits.is_empty() |
339 |
| - }) => |
340 |
| - { |
341 |
| - Some(self_ty) |
342 |
| - } |
343 |
| - _ => None, |
344 |
| - } |
345 |
| - }) |
346 |
| - .next() |
347 |
| - { |
348 |
| - Some(self_ty) => Some((trait_item.ident, self_ty)), |
349 |
| - _ => None, |
350 |
| - } |
351 |
| - } |
352 |
| - _ => None, |
353 |
| - } |
354 |
| - } |
355 |
| - _ => None, |
356 |
| - } |
357 |
| - } |
358 |
| - |
359 | 294 | /// Report an error because the universal region `fr` was required to outlive
|
360 | 295 | /// `outlived_fr` but it is not known to do so. For example:
|
361 | 296 | ///
|
@@ -850,7 +785,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
850 | 785 | visitor.visit_ty(param.param_ty);
|
851 | 786 |
|
852 | 787 | let Some((ident, self_ty)) =
|
853 |
| - self.get_impl_ident_and_self_ty_from_trait(instance.def_id(), &visitor.0) else {return}; |
| 788 | + NiceRegionError::get_impl_ident_and_self_ty_from_trait(tcx, instance.def_id(), &visitor.0) else { return; }; |
854 | 789 |
|
855 | 790 | self.suggest_constrain_dyn_trait_in_impl(diag, &visitor.0, ident, self_ty);
|
856 | 791 | }
|
|
0 commit comments