]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_middle/ty/util.rs
On recursive ADT, provide indirection structured suggestion
[rust.git] / src / librustc_middle / ty / util.rs
index c2b794ca4bdd9e0ed5e3d6a2ca0a16ed795551f6..5cdfa6f90128dabf35cd962f265978431c5010c4 100644 (file)
@@ -827,7 +827,15 @@ fn are_inner_types_recursive<'tcx>(
                     // Find non representable fields with their spans
                     fold_repr(def.all_fields().map(|field| {
                         let ty = field.ty(tcx, substs);
-                        let span = tcx.hir().span_if_local(field.did).unwrap_or(sp);
+                        let span = match field
+                            .did
+                            .as_local()
+                            .map(|id| tcx.hir().as_local_hir_id(id))
+                            .and_then(|id| tcx.hir().find(id))
+                        {
+                            Some(hir::Node::Field(field)) => field.ty.span,
+                            _ => sp,
+                        };
                         match is_type_structurally_recursive(
                             tcx,
                             span,