Skip to content

Commit 0863f9a

Browse files
Rollup merge of #77032 - lcnr:visit-all-the-item-likes, r=davidtwco
lint missing docs for extern items fixes #76991
2 parents 359615b + d452744 commit 0863f9a

File tree

3 files changed

+50
-2
lines changed

3 files changed

+50
-2
lines changed

compiler/rustc_lint/src/builtin.rs

+13
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,19 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
613613
);
614614
}
615615

616+
fn check_foreign_item(&mut self, cx: &LateContext<'_>, foreign_item: &hir::ForeignItem<'_>) {
617+
let def_id = cx.tcx.hir().local_def_id(foreign_item.hir_id);
618+
let (article, desc) = cx.tcx.article_and_description(def_id.to_def_id());
619+
self.check_missing_docs_attrs(
620+
cx,
621+
Some(foreign_item.hir_id),
622+
&foreign_item.attrs,
623+
foreign_item.span,
624+
article,
625+
desc,
626+
);
627+
}
628+
616629
fn check_struct_field(&mut self, cx: &LateContext<'_>, sf: &hir::StructField<'_>) {
617630
if !sf.is_positional() {
618631
self.check_missing_docs_attrs(

src/test/ui/lint/lint-missing-doc.rs

+18-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// injected intrinsics by the compiler.
33
#![deny(missing_docs)]
44
#![allow(dead_code)]
5-
#![feature(associated_type_defaults)]
5+
#![feature(associated_type_defaults, extern_types)]
66

77
//! Some garbage docs for the crate here
88
#![doc="More garbage"]
@@ -183,4 +183,21 @@ pub mod public_interface {
183183
pub use internal_impl::globbed::*;
184184
}
185185

186+
extern "C" {
187+
/// dox
188+
pub fn extern_fn_documented(f: f32) -> f32;
189+
pub fn extern_fn_undocumented(f: f32) -> f32;
190+
//~^ ERROR: missing documentation for a function
191+
192+
/// dox
193+
pub static EXTERN_STATIC_DOCUMENTED: u8;
194+
pub static EXTERN_STATIC_UNDOCUMENTED: u8;
195+
//~^ ERROR: missing documentation for a static
196+
197+
/// dox
198+
pub type ExternTyDocumented;
199+
pub type ExternTyUndocumented;
200+
//~^ ERROR: missing documentation for a foreign type
201+
}
202+
186203
fn main() {}

src/test/ui/lint/lint-missing-doc.stderr

+19-1
Original file line numberDiff line numberDiff line change
@@ -118,5 +118,23 @@ error: missing documentation for a function
118118
LL | pub fn also_undocumented1() {}
119119
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
120120

121-
error: aborting due to 19 previous errors
121+
error: missing documentation for a function
122+
--> $DIR/lint-missing-doc.rs:189:5
123+
|
124+
LL | pub fn extern_fn_undocumented(f: f32) -> f32;
125+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
126+
127+
error: missing documentation for a static
128+
--> $DIR/lint-missing-doc.rs:194:5
129+
|
130+
LL | pub static EXTERN_STATIC_UNDOCUMENTED: u8;
131+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
132+
133+
error: missing documentation for a foreign type
134+
--> $DIR/lint-missing-doc.rs:199:5
135+
|
136+
LL | pub type ExternTyUndocumented;
137+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
138+
139+
error: aborting due to 22 previous errors
122140

0 commit comments

Comments
 (0)