diff options
| author | XIAO Tian <tian@example.com> | 2020-05-30 11:26:46 +0800 |
|---|---|---|
| committer | XIAO Tian <tian@example.com> | 2020-05-31 12:13:30 +0800 |
| commit | 1a68c8e8d957e8df19e5adced776879bbe3d5344 (patch) | |
| tree | 8ada5ac397efb2a8d759a3d7935657d81f29fb61 | |
| parent | 3bf9eb0f7a1f2da9df2983aa8cf95a420130cada (diff) | |
| download | rust-1a68c8e8d957e8df19e5adced776879bbe3d5344.tar.gz rust-1a68c8e8d957e8df19e5adced776879bbe3d5344.zip | |
Fix associate type diagnostics
| -rw-r--r-- | src/librustc_trait_selection/traits/wf.rs | 31 |
1 files changed, 12 insertions, 19 deletions
diff --git a/src/librustc_trait_selection/traits/wf.rs b/src/librustc_trait_selection/traits/wf.rs index 714ca7a30cf..39c7528a632 100644 --- a/src/librustc_trait_selection/traits/wf.rs +++ b/src/librustc_trait_selection/traits/wf.rs @@ -172,25 +172,18 @@ fn extend_cause_with_original_assoc_item_obligation<'tcx>( }; match pred.kind() { ty::PredicateKind::Projection(proj) => { - // The obligation comes not from the current `impl` nor the `trait` being - // implemented, but rather from a "second order" obligation, like in - // `src/test/ui/associated-types/point-at-type-on-obligation-failure.rs`. - let trait_assoc_item = tcx.associated_item(proj.projection_def_id()); - if let Some(impl_item_span) = - items.iter().find(|item| item.ident == trait_assoc_item.ident).map(fix_span) - { - cause.span = impl_item_span; - } else { - let kind = &proj.ty().skip_binder().kind; - if let ty::Projection(projection_ty) = kind { - // This happens when an associated type has a projection coming from another - // associated type. See `traits-assoc-type-in-supertrait-bad.rs`. - let trait_assoc_item = tcx.associated_item(projection_ty.item_def_id); - if let Some(impl_item_span) = - items.iter().find(|item| item.ident == trait_assoc_item.ident).map(fix_span) - { - cause.span = impl_item_span; - } + // The obligation comes not from the current `impl` nor the `trait` being implemented, + // but rather from a "second order" obligation, where an associated type has a + // projection coming from another associated type. See + // `src/test/ui/associated-types/point-at-type-on-obligation-failure.rs` and + // `traits-assoc-type-in-supertrait-bad.rs`. + let kind = &proj.ty().skip_binder().kind; + if let ty::Projection(projection_ty) = kind { + let trait_assoc_item = tcx.associated_item(projection_ty.item_def_id); + if let Some(impl_item_span) = + items.iter().find(|item| item.ident == trait_assoc_item.ident).map(fix_span) + { + cause.span = impl_item_span; } } } |
