From ac891ea374947b5cd6793402506119e519c32ce4 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 2 Mar 2022 17:58:10 +0100 Subject: [PATCH 1/4] Extend unused_doc_comments lint to check on blocks --- compiler/rustc_lint/src/builtin.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs index 46b90baa585..72b8d8bb297 100644 --- a/compiler/rustc_lint/src/builtin.rs +++ b/compiler/rustc_lint/src/builtin.rs @@ -1086,6 +1086,16 @@ impl EarlyLintPass for UnusedDocComment { fn check_generic_param(&mut self, cx: &EarlyContext<'_>, param: &ast::GenericParam) { warn_if_doc(cx, param.ident.span, "generic parameters", ¶m.attrs); } + + fn check_block(&mut self, cx: &EarlyContext<'_>, block: &ast::Block) { + warn_if_doc(cx, block.span, "block", &block.attrs()); + } + + fn check_item(&mut self, cx: &EarlyContext<'_>, item: &ast::Item) { + if let ast::ItemKind::ForeignMod(_) = item.kind { + warn_if_doc(cx, item.span, "extern block", &item.attrs); + } + } } declare_lint! { From 628fbdf9b7a831a35e948abdb97f72f071c79ba5 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 2 Mar 2022 17:58:33 +0100 Subject: [PATCH 2/4] Fix unused_doc_comments lint errors --- compiler/rustc_codegen_llvm/src/llvm/ffi.rs | 4 ++-- library/portable-simd/crates/core_simd/src/intrinsics.rs | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs index 4a8894983b9..6e9e0332faf 100644 --- a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs +++ b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs @@ -576,12 +576,12 @@ pub enum PassKind { Module, } -/// LLVMRustThinLTOData +// LLVMRustThinLTOData extern "C" { pub type ThinLTOData; } -/// LLVMRustThinLTOBuffer +// LLVMRustThinLTOBuffer extern "C" { pub type ThinLTOBuffer; } diff --git a/library/portable-simd/crates/core_simd/src/intrinsics.rs b/library/portable-simd/crates/core_simd/src/intrinsics.rs index 4c68d11e893..cf2c0a02351 100644 --- a/library/portable-simd/crates/core_simd/src/intrinsics.rs +++ b/library/portable-simd/crates/core_simd/src/intrinsics.rs @@ -18,9 +18,10 @@ //! //! Unless stated otherwise, all intrinsics for binary operations require SIMD vectors of equal types and lengths. -/// These intrinsics aren't linked directly from LLVM and are mostly undocumented, however they are -/// mostly lowered to the matching LLVM instructions by the compiler in a fairly straightforward manner. -/// The associated LLVM instruction or intrinsic is documented alongside each Rust intrinsic function. + +// These intrinsics aren't linked directly from LLVM and are mostly undocumented, however they are +// mostly lowered to the matching LLVM instructions by the compiler in a fairly straightforward manner. +// The associated LLVM instruction or intrinsic is documented alongside each Rust intrinsic function. extern "platform-intrinsic" { /// add/fadd pub(crate) fn simd_add(x: T, y: T) -> T; From fce6cecf7a9247ca8abc9f1ac55ce30f93ad4346 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 2 Mar 2022 17:58:49 +0100 Subject: [PATCH 3/4] Update unused_doc_comments ui test --- .../unused/unused-doc-comments-edge-cases.rs | 14 ++++++++++ .../unused-doc-comments-edge-cases.stderr | 28 ++++++++++++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/test/ui/lint/unused/unused-doc-comments-edge-cases.rs b/src/test/ui/lint/unused/unused-doc-comments-edge-cases.rs index 258f9e4831f..54d86c31fb4 100644 --- a/src/test/ui/lint/unused/unused-doc-comments-edge-cases.rs +++ b/src/test/ui/lint/unused/unused-doc-comments-edge-cases.rs @@ -29,4 +29,18 @@ fn doc_comment_on_expr(num: u8) -> bool { fn doc_comment_on_generic<#[doc = "x"] T>(val: T) {} //~^ ERROR: unused doc comment +fn doc_comment_on_block() { + /// unused doc comment + //~^ ERROR: unused doc comment + { + let x = 12; + } +} + +/// unused doc comment +//~^ ERROR: unused doc comment +extern "C" { + fn foo(); +} + fn main() {} diff --git a/src/test/ui/lint/unused/unused-doc-comments-edge-cases.stderr b/src/test/ui/lint/unused/unused-doc-comments-edge-cases.stderr index 3ce1df71a2e..30a96af583a 100644 --- a/src/test/ui/lint/unused/unused-doc-comments-edge-cases.stderr +++ b/src/test/ui/lint/unused/unused-doc-comments-edge-cases.stderr @@ -49,6 +49,32 @@ LL | fn doc_comment_on_generic<#[doc = "x"] T>(val: T) {} | = help: use `//` for a plain comment +error: unused doc comment + --> $DIR/unused-doc-comments-edge-cases.rs:33:5 + | +LL | /// unused doc comment + | ^^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | / { +LL | | let x = 12; +LL | | } + | |_____- rustdoc does not generate documentation for expressions + | + = help: use `//` for a plain comment + +error: unused doc comment + --> $DIR/unused-doc-comments-edge-cases.rs:40:1 + | +LL | /// unused doc comment + | ^^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | / extern "C" { +LL | | fn foo(); +LL | | } + | |_- rustdoc does not generate documentation for extern block + | + = help: use `//` for a plain comment + error[E0308]: mismatched types --> $DIR/unused-doc-comments-edge-cases.rs:14:9 | @@ -63,7 +89,7 @@ help: you might have meant to return this value LL | return true; | ++++++ + -error: aborting due to 6 previous errors +error: aborting due to 8 previous errors Some errors have detailed explanations: E0308, E0658. For more information about an error, try `rustc --explain E0308`. From 6f0eb2a4e17a952302f4ee8e0a2cc7c43d71d766 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 2 Mar 2022 19:50:08 +0100 Subject: [PATCH 4/4] Update stdarch submodule --- library/stdarch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/stdarch b/library/stdarch index b4a0e07552c..bcbe010614f 160000 --- a/library/stdarch +++ b/library/stdarch @@ -1 +1 @@ -Subproject commit b4a0e07552cf90ef8f1a5b775bf70e4db94b3d63 +Subproject commit bcbe010614f398ec86f3a9274d22e33e5f2ee60b