linux/Documentation/process
Miguel Ojeda 56f64b3706 rust: upgrade to Rust 1.78.0
This is the next upgrade to the Rust toolchain, from 1.77.1 to 1.78.0
(i.e. the latest) [1].

See the upgrade policy [2] and the comments on the first upgrade in
commit 3ed03f4da0 ("rust: upgrade to Rust 1.68.2").

It is much smaller than previous upgrades, since the `alloc` fork was
dropped in commit 9d0441bab7 ("rust: alloc: remove our fork of the
`alloc` crate") [3].

# Unstable features

There have been no changes to the set of unstable features used in
our own code. Therefore, the only unstable features allowed to be used
outside the `kernel` crate is still `new_uninit`.

However, since we finally dropped our `alloc` fork [3], all the unstable
features used by `alloc` (~30 language ones, ~60 library ones) are not
a concern anymore. This reduces the maintenance burden, increases the
chances of new compiler versions working without changes and gets us
closer to the goal of supporting several compiler versions.

It also means that, ignoring non-language/library features, we are
currently left with just the few language features needed to implement the
kernel `Arc`, the `new_uninit` library feature, the `compiler_builtins`
marker and the few `no_*` `cfg`s we pass when compiling `core`/`alloc`.

Please see [4] for details.

# Required changes

## LLVM's data layout

Rust 1.77.0 (i.e. the previous upgrade) introduced a check for matching
LLVM data layouts [5]. Then, Rust 1.78.0 upgraded LLVM's bundled major
version from 17 to 18 [6], which changed the data layout in x86 [7]. Thus
update the data layout in our custom target specification for x86 so
that the compiler does not complain about the mismatch:

    error: data-layout for target `target-5559158138856098584`,
    `e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128`,
    differs from LLVM target's `x86_64-linux-gnu` default layout,
    `e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128`

In the future, the goal is to drop the custom target specifications.
Meanwhile, if we want to support other LLVM versions used in `rustc`
(e.g. for LTO), we will need to add some extra logic (e.g. conditional on
LLVM's version, or extracting the data layout from an existing built-in
target specification).

## `unused_imports`

Rust's `unused_imports` lint covers both unused and redundant imports.
Now, in 1.78.0, the lint detects more cases of redundant imports [8].
Thus one of the previous patches cleaned them up.

## Clippy's `new_without_default`

Clippy now suggests to implement `Default` even when `new()` is `const`,
since `Default::default()` may call `const` functions even if it is not
`const` itself [9]. Thus one of the previous patches implemented it.

# Other changes in Rust

Rust 1.78.0 introduced `feature(asm_goto)` [10] [11]. This feature was
discussed in the past [12].

Rust 1.78.0 introduced `feature(const_refs_to_static)` [13] to allow
referencing statics in constants and extended `feature(const_mut_refs)`
to allow raw mutable pointers in constants. Together, this should cover
the kernel's `VTABLE` use case. In fact, the implementation [14] in
upstream Rust added a test case for it [15].

Rust 1.78.0 with debug assertions enabled (i.e. `-Cdebug-assertions=y`,
kernel's `CONFIG_RUST_DEBUG_ASSERTIONS=y`) now always checks all unsafe
preconditions, though without a way to opt-out for particular cases [16].
It would be ideal to have a way to selectively disable certain checks
per-call site for this one (i.e. not just per check but for particular
instances of a check), even if the vast majority of the checks remain
in place [17].

Rust 1.78.0 also improved a couple issues we reported when giving feedback
for the new `--check-cfg` feature [18] [19].

# `alloc` upgrade and reviewing

As mentioned above, compiler upgrades will not update `alloc` anymore,
since we dropped our `alloc` fork [3].

Link: https://github.com/rust-lang/rust/blob/stable/RELEASES.md#version-1780-2024-05-02 [1]
Link: https://rust-for-linux.com/rust-version-policy [2]
Link: https://lore.kernel.org/rust-for-linux/20240328013603.206764-1-wedsonaf@gmail.com/ [3]
Link: https://github.com/Rust-for-Linux/linux/issues/2 [4]
Link: https://github.com/rust-lang/rust/pull/120062 [5]
Link: https://github.com/rust-lang/rust/pull/120055 [6]
Link: https://reviews.llvm.org/D86310 [7]
Link: https://github.com/rust-lang/rust/pull/117772 [8]
Link: https://github.com/rust-lang/rust-clippy/pull/10903 [9]
Link: https://github.com/rust-lang/rust/pull/119365 [10]
Link: https://github.com/rust-lang/rust/issues/119364 [11]
Link: https://lore.kernel.org/rust-for-linux/ZWipTZysC2YL7qsq@Boquns-Mac-mini.home/ [12]
Link: https://github.com/rust-lang/rust/issues/119618 [13]
Link: https://github.com/rust-lang/rust/pull/120932 [14]
Link: https://github.com/rust-lang/rust/pull/120932/files#diff-e6fc1622c46054cd46b1d225c5386c5554564b3b0fa8a03c2dc2d8627a1079d9 [15]
Link: https://github.com/rust-lang/rust/issues/120969 [16]
Link: https://github.com/Rust-for-Linux/linux/issues/354 [17]
Link: https://github.com/rust-lang/rust/pull/121202 [18]
Link: https://github.com/rust-lang/rust/pull/121237 [19]
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Link: https://lore.kernel.org/r/20240401212303.537355-4-ojeda@kernel.org
[ Added a few more details and links I mentioned in the list. - Miguel ]
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2024-05-05 20:17:25 +02:00
..
1.Intro.rst
2.Process.rst docs: process: fix a typoed cross-reference 2023-05-20 08:07:04 -06:00
3.Early-stage.rst
4.Coding.rst Add .editorconfig file for basic formatting 2023-12-28 16:22:47 +09:00
5.Posting.rst docs: process: allow Closes tags with links 2023-04-18 16:39:31 -07:00
6.Followthrough.rst docs: remove the tips on how to submit patches from MAINTAINERS 2023-07-03 08:35:23 -06:00
7.AdvancedTopics.rst docs: try to encourage (netdev?) reviewers 2023-10-15 14:26:51 +01:00
8.Conclusion.rst
adding-syscalls.rst
applying-patches.rst
backporting.rst docs: backporting: address feedback 2023-10-26 11:49:16 -06:00
botching-up-ioctls.rst Documentation: Fix typos 2023-08-18 11:29:03 -06:00
changes.rst rust: upgrade to Rust 1.78.0 2024-05-05 20:17:25 +02:00
clang-format.rst
code-of-conduct-interpretation.rst docs: update mediator contact information in CoC doc 2022-11-10 18:45:11 +01:00
code-of-conduct.rst
coding-style.rst Documentation: coding-style: Update syntax highlighting for code-blocks 2024-02-05 10:21:50 -07:00
contribution-maturity-model.rst Documentation/process: Add Linux Kernel Contribution Maturity Model 2023-03-14 12:22:59 -06:00
cve.rst Documentation: Document the Linux Kernel CVE process 2024-02-17 14:46:39 +01:00
deprecated.rst docs: deprecated.rst: Update an example 2023-07-14 13:36:31 -06:00
development-process.rst docs: use toctree :caption: and move introduction 2023-11-17 13:05:26 -07:00
email-clients.rst Documentation: process: Document suitability of Proton Mail for kernel development 2023-01-13 09:26:19 -07:00
embargoed-hardware-issues.rst Documentation: embargoed-hardware-issues.rst: Fix Trilok's email 2024-02-14 15:06:10 -07:00
handling-regressions.rst docs: handling-regressions.rst: Update regzbot command fixed-by to fix 2024-03-18 03:40:15 -06:00
howto.rst Documentation: multiple .rst files: Fix grammar and more consistent formatting 2024-02-05 10:24:54 -07:00
index.rst Documentation: Document the Linux Kernel CVE process 2024-02-17 14:46:39 +01:00
kernel-docs.rst Documentation: Fix typos 2023-08-18 11:29:03 -06:00
kernel-driver-statement.rst
kernel-enforcement-statement.rst
license-rules.rst
magic-number.rst char: pcmcia: remove all the drivers 2023-03-09 17:30:27 +01:00
maintainer-handbooks.rst Documentation/process: maintainer-soc: add clean platforms profile 2023-08-12 14:04:51 +02:00
maintainer-kvm-x86.rst Documentation/process: Add a maintainer handbook for KVM x86 2023-06-22 14:25:38 -07:00
maintainer-netdev.rst docs: netdev: update the link to the CI repo 2024-02-20 11:52:41 +01:00
maintainer-pgp-guide.rst docs: maintainer-pgp-guide: update for latest gnupg defaults 2023-01-02 16:37:18 -07:00
maintainer-soc-clean-dts.rst Documentation/process: maintainer-soc: add clean platforms profile 2023-08-12 14:04:51 +02:00
maintainer-soc.rst Documentation/process: maintainer-soc: document dtbs_check requirement for Samsung 2023-08-12 14:05:34 +02:00
maintainer-tip.rst Documentation/maintainer-tip: Add C++ tail comments exception 2024-02-13 13:19:40 +01:00
maintainers.rst
management-style.rst
programming-language.rst docs: programming-language: add Rust programming language section 2023-03-07 10:24:40 -07:00
researcher-guidelines.rst Documentation: update mailing list addresses 2024-02-21 13:44:21 -07:00
security-bugs.rst Documentation: Document the Linux Kernel CVE process 2024-02-17 14:46:39 +01:00
stable-api-nonsense.rst
stable-kernel-rules.rst Documentation: stable: clarify patch series prerequisites 2023-10-05 13:43:45 +02:00
submit-checklist.rst docs: submit-checklist: use subheadings 2024-03-03 08:41:33 -07:00
submitting-patches.rst docs: submitting-patches: improve the base commit explanation 2023-11-27 11:00:16 -07:00
volatile-considered-harmful.rst