rust: kbuild: clean output before running `rustdoc`

`rustdoc` can get confused when generating documentation into a folder
that contains generated files from other `rustdoc` versions.

For instance, running something like:

rustup default 1.78.0
make LLVM=1 rustdoc
rustup default 1.88.0
make LLVM=1 rustdoc

may generate errors like:

error: couldn't generate documentation: invalid template: last line expected to start with a comment
|
= note: failed to create or modify "./Documentation/output/rust/rustdoc/src-files.js"

Thus just always clean the output folder before generating the
documentation -- we are anyway regenerating it every time the `rustdoc`
target gets called, at least for the time being.

Cc: stable@vger.kernel.org # Needed in 6.12.y and later (Rust is pinned in older LTSs).
Reported-by: Daniel Almeida <daniel.almeida@collabora.com>
Closes: https://rust-for-linux.zulipchat.com/#narrow/channel/288089/topic/x/near/527201113
Reviewed-by: Tamir Duberstein <tamird@kernel.org>
Link: https://lore.kernel.org/r/20250726133435.2460085-1-ojeda@kernel.org
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>

Changed files
+7 -3
rust
+7 -3
rust/Makefile
··· 111 111 rustdoc-macros: private rustdoc_host = yes 112 112 rustdoc-macros: private rustc_target_flags = --crate-type proc-macro \ 113 113 --extern proc_macro 114 - rustdoc-macros: $(src)/macros/lib.rs FORCE 114 + rustdoc-macros: $(src)/macros/lib.rs rustdoc-clean FORCE 115 115 +$(call if_changed,rustdoc) 116 116 117 117 # Starting with Rust 1.82.0, skipping `-Wrustdoc::unescaped_backticks` should 118 118 # not be needed -- see https://github.com/rust-lang/rust/pull/128307. 119 119 rustdoc-core: private skip_flags = --edition=2021 -Wrustdoc::unescaped_backticks 120 120 rustdoc-core: private rustc_target_flags = --edition=$(core-edition) $(core-cfgs) 121 - rustdoc-core: $(RUST_LIB_SRC)/core/src/lib.rs FORCE 121 + rustdoc-core: $(RUST_LIB_SRC)/core/src/lib.rs rustdoc-clean FORCE 122 122 +$(call if_changed,rustdoc) 123 123 124 124 rustdoc-compiler_builtins: $(src)/compiler_builtins.rs rustdoc-core FORCE ··· 130 130 rustdoc-pin_init_internal: private rustdoc_host = yes 131 131 rustdoc-pin_init_internal: private rustc_target_flags = --cfg kernel \ 132 132 --extern proc_macro --crate-type proc-macro 133 - rustdoc-pin_init_internal: $(src)/pin-init/internal/src/lib.rs FORCE 133 + rustdoc-pin_init_internal: $(src)/pin-init/internal/src/lib.rs \ 134 + rustdoc-clean FORCE 134 135 +$(call if_changed,rustdoc) 135 136 136 137 rustdoc-pin_init: private rustdoc_host = yes ··· 148 147 rustdoc-pin_init rustdoc-compiler_builtins $(obj)/$(libmacros_name) \ 149 148 $(obj)/bindings.o FORCE 150 149 +$(call if_changed,rustdoc) 150 + 151 + rustdoc-clean: FORCE 152 + $(Q)rm -rf $(rustdoc_output) 151 153 152 154 quiet_cmd_rustc_test_library = $(RUSTC_OR_CLIPPY_QUIET) TL $< 153 155 cmd_rustc_test_library = \