diff options
| author | Manish Goregaokar <manishsmail@gmail.com> | 2021-08-26 12:38:06 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-08-26 12:38:06 -0700 |
| commit | 8aa46e51dfc20f6bc01207d67a5f666239ed8e07 (patch) | |
| tree | 7fadae32b3ab315d7f23f275a749fbe9b9d8b788 /compiler/rustc_ty_utils/src | |
| parent | fb7959774c9a7050c1061bd8d7825d78e1945ea9 (diff) | |
| parent | 8a6501d28831d864a3af6adf2e0bd83a773062ed (diff) | |
| download | rust-8aa46e51dfc20f6bc01207d67a5f666239ed8e07.tar.gz rust-8aa46e51dfc20f6bc01207d67a5f666239ed8e07.zip | |
Rollup merge of #88123 - camelid:tup-pat-precise-spans, r=estebank
Make spans for tuple patterns in E0023 more precise As suggested in #86307. Closes #86307. r? ````@estebank````
Diffstat (limited to 'compiler/rustc_ty_utils/src')
| -rw-r--r-- | compiler/rustc_ty_utils/src/ty.rs | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/compiler/rustc_ty_utils/src/ty.rs b/compiler/rustc_ty_utils/src/ty.rs index 8332e738411..c10f6dc3401 100644 --- a/compiler/rustc_ty_utils/src/ty.rs +++ b/compiler/rustc_ty_utils/src/ty.rs @@ -223,7 +223,18 @@ fn associated_items(tcx: TyCtxt<'_>, def_id: DefId) -> ty::AssocItems<'_> { } fn def_ident_span(tcx: TyCtxt<'_>, def_id: DefId) -> Option<Span> { - tcx.hir().get_if_local(def_id).and_then(|node| node.ident()).map(|ident| ident.span) + tcx.hir() + .get_if_local(def_id) + .and_then(|node| match node { + // A `Ctor` doesn't have an identifier itself, but its parent + // struct/variant does. Compare with `hir::Map::opt_span`. + hir::Node::Ctor(ctor) => ctor + .ctor_hir_id() + .and_then(|ctor_id| tcx.hir().find(tcx.hir().get_parent_node(ctor_id))) + .and_then(|parent| parent.ident()), + _ => node.ident(), + }) + .map(|ident| ident.span) } /// If the given `DefId` describes an item belonging to a trait, |
