diff --git a/compiler/rustc_ast_lowering/src/item.rs b/compiler/rustc_ast_lowering/src/item.rs index 00248220212..3cb1a9e994f 100644 --- a/compiler/rustc_ast_lowering/src/item.rs +++ b/compiler/rustc_ast_lowering/src/item.rs @@ -802,6 +802,7 @@ impl<'hir> LoweringContext<'_, 'hir> { self.lower_ty(&f.ty, ImplTraitContext::disallowed()) }; let hir_id = self.lower_node_id(f.id); + self.lower_attrs(hir_id, &f.attrs); hir::StructField { span: f.span, hir_id, @@ -812,7 +813,6 @@ impl<'hir> LoweringContext<'_, 'hir> { }, vis: self.lower_visibility(&f.vis, None), ty, - attrs: self.lower_attrs(hir_id, &f.attrs), } } diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index 0b767d41312..5f56cca5fc9 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -2631,7 +2631,6 @@ pub struct StructField<'hir> { pub vis: Visibility<'hir>, pub hir_id: HirId, pub ty: &'hir Ty<'hir>, - pub attrs: &'hir [Attribute], } impl StructField<'_> { diff --git a/compiler/rustc_hir_pretty/src/lib.rs b/compiler/rustc_hir_pretty/src/lib.rs index 19e038df6bb..5f2498c231e 100644 --- a/compiler/rustc_hir_pretty/src/lib.rs +++ b/compiler/rustc_hir_pretty/src/lib.rs @@ -888,7 +888,7 @@ impl<'a> State<'a> { self.popen(); self.commasep(Inconsistent, struct_def.fields(), |s, field| { s.maybe_print_comment(field.span.lo()); - s.print_outer_attributes(&field.attrs); + s.print_outer_attributes(s.attrs(field.hir_id)); s.print_visibility(&field.vis); s.print_type(&field.ty) }); @@ -910,7 +910,7 @@ impl<'a> State<'a> { for field in struct_def.fields() { self.hardbreak_if_not_bol(); self.maybe_print_comment(field.span.lo()); - self.print_outer_attributes(&field.attrs); + self.print_outer_attributes(self.attrs(field.hir_id)); self.print_visibility(&field.vis); self.print_ident(field.ident); self.word_nbsp(":"); diff --git a/compiler/rustc_save_analysis/src/lib.rs b/compiler/rustc_save_analysis/src/lib.rs index b3f281bcabc..2bd7aa58afa 100644 --- a/compiler/rustc_save_analysis/src/lib.rs +++ b/compiler/rustc_save_analysis/src/lib.rs @@ -387,6 +387,7 @@ impl<'tcx> SaveContext<'tcx> { let id = id_from_def_id(field_def_id); let span = self.span_from_span(field.ident.span); + let attrs = self.tcx.hir().attrs(field.hir_id); Some(Def { kind: DefKind::Field, @@ -398,9 +399,9 @@ impl<'tcx> SaveContext<'tcx> { parent: Some(id_from_def_id(scope_def_id)), children: vec![], decl_id: None, - docs: self.docs_for_attrs(&field.attrs), + docs: self.docs_for_attrs(attrs), sig: sig::field_signature(field, self), - attributes: lower_attributes(field.attrs.to_vec(), self), + attributes: lower_attributes(attrs.to_vec(), self), }) } diff --git a/src/tools/clippy/clippy_lints/src/missing_doc.rs b/src/tools/clippy/clippy_lints/src/missing_doc.rs index 8665a2d71b6..e82fe9f0100 100644 --- a/src/tools/clippy/clippy_lints/src/missing_doc.rs +++ b/src/tools/clippy/clippy_lints/src/missing_doc.rs @@ -187,7 +187,8 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc { fn check_struct_field(&mut self, cx: &LateContext<'tcx>, sf: &'tcx hir::StructField<'_>) { if !sf.is_positional() { - self.check_missing_docs_attrs(cx, &sf.attrs, sf.span, "a", "struct field"); + let attrs = cx.tcx.hir().attrs(sf.hir_id); + self.check_missing_docs_attrs(cx, attrs, sf.span, "a", "struct field"); } }