From 0b269f33f4d848b57cd2bb44ce22c1d305ae32ea Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Sat, 8 Jan 2022 14:21:38 +0100 Subject: [PATCH 01/19] add kernel target for RustyHermit Currently, we are thinking to use *-unknown-none targets instead to define for every platform our own one (see hermitcore/rusty-hermit#197). However, the current target aarch64-unknown-none-softfloat doesn't support dynamic relocation. Our kernel uses this feature and consequently we define a new target aarch64-unknown-hermitkernel to support it. --- .../src/spec/aarch64_unknown_hermit.rs | 1 + .../src/spec/aarch64_unknown_hermitkernel.rs | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 compiler/rustc_target/src/spec/aarch64_unknown_hermitkernel.rs diff --git a/compiler/rustc_target/src/spec/aarch64_unknown_hermit.rs b/compiler/rustc_target/src/spec/aarch64_unknown_hermit.rs index 44beb2f6ad8d3..f8e1e1b02f5a2 100644 --- a/compiler/rustc_target/src/spec/aarch64_unknown_hermit.rs +++ b/compiler/rustc_target/src/spec/aarch64_unknown_hermit.rs @@ -3,6 +3,7 @@ use crate::spec::Target; pub fn target() -> Target { let mut base = super::hermit_base::opts(); base.max_atomic_width = Some(128); + base.features = "+strict-align,+neon,+fp-armv8".to_string(); Target { llvm_target: "aarch64-unknown-hermit".to_string(), diff --git a/compiler/rustc_target/src/spec/aarch64_unknown_hermitkernel.rs b/compiler/rustc_target/src/spec/aarch64_unknown_hermitkernel.rs new file mode 100644 index 0000000000000..6e9d6c6221ccc --- /dev/null +++ b/compiler/rustc_target/src/spec/aarch64_unknown_hermitkernel.rs @@ -0,0 +1,16 @@ +use crate::spec::Target; + +pub fn target() -> Target { + let mut base = super::hermit_kernel_base::opts(); + base.max_atomic_width = Some(128); + base.abi = "softfloat".to_string(); + base.features = "+strict-align,-neon,-fp-armv8".to_string(); + + Target { + llvm_target: "aarch64-unknown-hermit".to_string(), + pointer_width: 64, + data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(), + arch: "aarch64".to_string(), + options: base, + } +} From 10ae04a157125445ff2e2d10d142d81e3cc8acad Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Mon, 7 Feb 2022 00:13:45 +0100 Subject: [PATCH 02/19] add missing description of the target aarch64-unknown-none-hermitkernel --- src/doc/rustc/src/platform-support.md | 7 +- .../aarch64-unknown-none-hermitkernel.md | 77 +++++++++++++++++++ 2 files changed, 81 insertions(+), 3 deletions(-) create mode 100644 src/doc/rustc/src/platform-support/aarch64-unknown-none-hermitkernel.md diff --git a/src/doc/rustc/src/platform-support.md b/src/doc/rustc/src/platform-support.md index b6ae8c9333f31..1cdc1372c2127 100644 --- a/src/doc/rustc/src/platform-support.md +++ b/src/doc/rustc/src/platform-support.md @@ -204,7 +204,8 @@ target | std | host | notes `aarch64-apple-tvos` | * | | ARM64 tvOS [`aarch64-kmc-solid_asp3`](platform-support/kmc-solid.md) | ✓ | | ARM64 SOLID with TOPPERS/ASP3 `aarch64-unknown-freebsd` | ✓ | ✓ | ARM64 FreeBSD -`aarch64-unknown-hermit` | ? | | +`aarch64_unknown_hermit` | ✓ | |ARM64 HermitCore +[`aarch64_unknown_none_hermitkernel`](platform-support/aarch64-unknown-none-hermitkernel.md) | * | | ARM64 HermitCore kernel `aarch64-unknown-uefi` | * | | ARM64 UEFI `aarch64-unknown-linux-gnu_ilp32` | ✓ | ✓ | ARM64 Linux (ILP32 ABI) `aarch64-unknown-netbsd` | ✓ | ✓ | @@ -286,10 +287,10 @@ target | std | host | notes `x86_64-sun-solaris` | ? | | Deprecated target for 64-bit Solaris 10/11, illumos `x86_64-unknown-dragonfly` | ✓ | ✓ | 64-bit DragonFlyBSD `x86_64-unknown-haiku` | ✓ | ✓ | 64-bit Haiku -`x86_64-unknown-hermit` | ? | | +`x86_64-unknown-hermit` | ✓ | | HermitCore `x86_64-unknown-l4re-uclibc` | ? | | [`x86_64-unknown-none`](platform-support/x86_64-unknown-none.md) | * | | Freestanding/bare-metal x86_64, softfloat -`x86_64-unknown-none-hermitkernel` | ? | | HermitCore kernel +`x86_64-unknown-none-hermitkernel` | * | | HermitCore kernel `x86_64-unknown-none-linuxkernel` | * | | Linux kernel modules [`x86_64-unknown-openbsd`](platform-support/openbsd.md) | ✓ | ✓ | 64-bit OpenBSD `x86_64-unknown-uefi` | * | | 64-bit UEFI diff --git a/src/doc/rustc/src/platform-support/aarch64-unknown-none-hermitkernel.md b/src/doc/rustc/src/platform-support/aarch64-unknown-none-hermitkernel.md new file mode 100644 index 0000000000000..b8967f631878c --- /dev/null +++ b/src/doc/rustc/src/platform-support/aarch64-unknown-none-hermitkernel.md @@ -0,0 +1,77 @@ +# `aarch64-unknown-none-hermitkernel` + +**Tier: 3** + +Required to build the kernel for [HermitCore](https://github.com/hermitcore/hermit-playground) +or [RustyHermit](https://github.com/hermitcore/rusty-hermit). +The result is a bare-metal aarch64 binary in ELF format. + +## Target maintainers + +- Stefan Lankes, https://github.com/stlankes + +## Requirements + +This target is cross-compiled. There is no support for `std`, but the +library operating system provides a simple allocator to use `alloc`. + +By default, Rust code generated for this target does not use any vector or +floating-point registers. This allows the generated code to build the library +operaring system, which may need to avoid the use of such +registers or which may have special considerations about the use of such +registers (e.g. saving and restoring them to avoid breaking userspace code +using the same registers). In contrast to `aarch64-unknown-none-softfloat`, +the target is completly relocatable, which is a required feature of RustyHermit. + +By default, code generated with this target should run on any `aarch64` +hardware; enabling additional target features may raise this baseline. +On `aarch64-unknown-none-hermitkernel`, `extern "C"` uses the [standard System V calling +convention](https://github.com/ARM-software/abi-aa/releases/download/2021Q3/sysvabi64.pdf), +without red zones. + +This target generated binaries in the ELF format. + +## Building the target + +Typical you should not use the target directly. The target `aarch64-unknown-hermit` +builds the _user space_ of RustyHermit and supports red zones and floating-point +operations. +To build and link the kernel to the application, the crate +[hermit-sys](https://github.com/hermitcore/rusty-hermit/tree/master/hermit-sys) +should be used by adding the following lines to the `Cargo.toml` file of +your application. + +```toml +[target.'cfg(target_os = "hermit")'.dependencies] +hermit-sys = "0.1.*" +``` + +The crate `hermit-sys` uses the target `aarch64-unknown-none-hermitkernel` +to build the kernel. + +## Building Rust programs + +Rust does not yet ship pre-compiled artifacts for this target. To compile for +this target, you need to build the crate `hermit-sys` (see +"Building the target" above). + +## Testing + +As `aarch64-unknown-none-hermitkernel` does not support `std` +and does not support running any Rust testsuite. + +## Cross-compilation toolchains and C code + +If you want to compile C code along with Rust you will need an +appropriate `aarch64` toolchain. + +Rust *may* be able to use an `aarch64-linux-gnu-` toolchain with appropriate +standalone flags to build for this toolchain (depending on the assumptions of +that toolchain, see below), or you may wish to use a separate +`aarch64-unknown-none` (or `aarch64-elf-`) toolchain. + +On some `aarch64` hosts that use ELF binaries, you *may* be able to use the host +C toolchain, if it does not introduce assumptions about the host environment +that don't match the expectations of a standalone environment. Otherwise, you +may need a separate toolchain for standalone/freestanding development, just as +when cross-compiling from a non-`aarch64` platform. From 9225df3ca7c69a2d8d78e88f32020207e185a8ce Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Mon, 7 Feb 2022 07:44:32 +0100 Subject: [PATCH 03/19] remove typos --- src/doc/rustc/src/platform-support.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/rustc/src/platform-support.md b/src/doc/rustc/src/platform-support.md index 1cdc1372c2127..dc3a1f2a0e2f2 100644 --- a/src/doc/rustc/src/platform-support.md +++ b/src/doc/rustc/src/platform-support.md @@ -205,7 +205,7 @@ target | std | host | notes [`aarch64-kmc-solid_asp3`](platform-support/kmc-solid.md) | ✓ | | ARM64 SOLID with TOPPERS/ASP3 `aarch64-unknown-freebsd` | ✓ | ✓ | ARM64 FreeBSD `aarch64_unknown_hermit` | ✓ | |ARM64 HermitCore -[`aarch64_unknown_none_hermitkernel`](platform-support/aarch64-unknown-none-hermitkernel.md) | * | | ARM64 HermitCore kernel +[`aarch64-unknown-none-hermitkernel`](platform-support/aarch64-unknown-none-hermitkernel.md) | * | | ARM64 HermitCore kernel `aarch64-unknown-uefi` | * | | ARM64 UEFI `aarch64-unknown-linux-gnu_ilp32` | ✓ | ✓ | ARM64 Linux (ILP32 ABI) `aarch64-unknown-netbsd` | ✓ | ✓ | From 1acf739563611909e2857ff971c138c8ac6ac911 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Mon, 7 Feb 2022 07:45:04 +0100 Subject: [PATCH 04/19] add missing link --- src/doc/rustc/src/SUMMARY.md | 1 + 1 file changed, 1 insertion(+) diff --git a/src/doc/rustc/src/SUMMARY.md b/src/doc/rustc/src/SUMMARY.md index 2cf2660327384..aecd892ce8b3b 100644 --- a/src/doc/rustc/src/SUMMARY.md +++ b/src/doc/rustc/src/SUMMARY.md @@ -17,6 +17,7 @@ - [aarch64-apple-ios-sim](platform-support/aarch64-apple-ios-sim.md) - [armv7-unknown-linux-uclibceabi](platform-support/armv7-unknown-linux-uclibceabi.md) - [armv7-unknown-linux-uclibceabihf](platform-support/armv7-unknown-linux-uclibceabihf.md) + - [aarch64-unknown-none-hermitkernel](platform-support/aarch64-unknown-none-hermitkernel.md) - [\*-kmc-solid_\*](platform-support/kmc-solid.md) - [*-unknown-openbsd](platform-support/openbsd.md) - [x86_64-unknown-none](platform-support/x86_64-unknown-none.md) From c7f65ae401411c78e353f96eb4e03cc98efd9733 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Mon, 7 Feb 2022 09:09:50 +0100 Subject: [PATCH 05/19] remove typo --- src/doc/rustc/src/platform-support.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/rustc/src/platform-support.md b/src/doc/rustc/src/platform-support.md index dc3a1f2a0e2f2..0685a39fa7065 100644 --- a/src/doc/rustc/src/platform-support.md +++ b/src/doc/rustc/src/platform-support.md @@ -204,7 +204,7 @@ target | std | host | notes `aarch64-apple-tvos` | * | | ARM64 tvOS [`aarch64-kmc-solid_asp3`](platform-support/kmc-solid.md) | ✓ | | ARM64 SOLID with TOPPERS/ASP3 `aarch64-unknown-freebsd` | ✓ | ✓ | ARM64 FreeBSD -`aarch64_unknown_hermit` | ✓ | |ARM64 HermitCore +`aarch64-unknown-hermit` | ✓ | |ARM64 HermitCore [`aarch64-unknown-none-hermitkernel`](platform-support/aarch64-unknown-none-hermitkernel.md) | * | | ARM64 HermitCore kernel `aarch64-unknown-uefi` | * | | ARM64 UEFI `aarch64-unknown-linux-gnu_ilp32` | ✓ | ✓ | ARM64 Linux (ILP32 ABI) From beb042ae8fb70d503130537e295825ae352c8301 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Mon, 7 Feb 2022 15:43:54 +0100 Subject: [PATCH 06/19] add missing targert for library operating system RustyHermit --- compiler/rustc_target/src/spec/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs index 4407f22b90599..d735f3d41fdb0 100644 --- a/compiler/rustc_target/src/spec/mod.rs +++ b/compiler/rustc_target/src/spec/mod.rs @@ -964,6 +964,7 @@ supported_targets! { ("aarch64-unknown-hermit", aarch64_unknown_hermit), ("x86_64-unknown-hermit", x86_64_unknown_hermit), + ("aarch64-unknown-none-hermitkernel", aarch64_unknown_none_hermitkernel), ("x86_64-unknown-none-hermitkernel", x86_64_unknown_none_hermitkernel), ("riscv32i-unknown-none-elf", riscv32i_unknown_none_elf), From b5c1dc09fc03392756cfbebead053d5908a3c3d2 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Mon, 7 Feb 2022 16:30:06 +0100 Subject: [PATCH 07/19] rename file to use the correct naming convention --- ...known_hermitkernel.rs => aarch64_unknown_none_hermitkernel.rs} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename compiler/rustc_target/src/spec/{aarch64_unknown_hermitkernel.rs => aarch64_unknown_none_hermitkernel.rs} (100%) diff --git a/compiler/rustc_target/src/spec/aarch64_unknown_hermitkernel.rs b/compiler/rustc_target/src/spec/aarch64_unknown_none_hermitkernel.rs similarity index 100% rename from compiler/rustc_target/src/spec/aarch64_unknown_hermitkernel.rs rename to compiler/rustc_target/src/spec/aarch64_unknown_none_hermitkernel.rs From df70adffcee10ed3f5c050642e7e027259652dab Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Tue, 8 Feb 2022 09:26:11 +0100 Subject: [PATCH 08/19] add missing space --- src/doc/rustc/src/platform-support.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/rustc/src/platform-support.md b/src/doc/rustc/src/platform-support.md index 0685a39fa7065..d4a5f0e5a98c2 100644 --- a/src/doc/rustc/src/platform-support.md +++ b/src/doc/rustc/src/platform-support.md @@ -204,7 +204,7 @@ target | std | host | notes `aarch64-apple-tvos` | * | | ARM64 tvOS [`aarch64-kmc-solid_asp3`](platform-support/kmc-solid.md) | ✓ | | ARM64 SOLID with TOPPERS/ASP3 `aarch64-unknown-freebsd` | ✓ | ✓ | ARM64 FreeBSD -`aarch64-unknown-hermit` | ✓ | |ARM64 HermitCore +`aarch64-unknown-hermit` | ✓ | | ARM64 HermitCore [`aarch64-unknown-none-hermitkernel`](platform-support/aarch64-unknown-none-hermitkernel.md) | * | | ARM64 HermitCore kernel `aarch64-unknown-uefi` | * | | ARM64 UEFI `aarch64-unknown-linux-gnu_ilp32` | ✓ | ✓ | ARM64 Linux (ILP32 ABI) From 6aad08f13ffba2a18428c4f5ad03977bc1503f5d Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 9 Feb 2022 14:43:44 +0100 Subject: [PATCH 09/19] Unify headings indent and remove useless anchor --- src/librustdoc/html/markdown.rs | 2 +- src/librustdoc/html/markdown/tests.rs | 20 ++++++++++---------- src/librustdoc/html/render/mod.rs | 2 +- src/librustdoc/html/static/css/rustdoc.css | 21 --------------------- 4 files changed, 12 insertions(+), 33 deletions(-) diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs index a40181352f6c0..1c0448828a279 100644 --- a/src/librustdoc/html/markdown.rs +++ b/src/librustdoc/html/markdown.rs @@ -565,7 +565,7 @@ impl<'a, 'b, 'ids, I: Iterator>> Iterator self.buf.push_back((Event::Html(format!("", level).into()), 0..0)); let start_tags = format!( - "\ + "\ ", id = id, level = level diff --git a/src/librustdoc/html/markdown/tests.rs b/src/librustdoc/html/markdown/tests.rs index ea6575d179d86..6b44e447b5111 100644 --- a/src/librustdoc/html/markdown/tests.rs +++ b/src/librustdoc/html/markdown/tests.rs @@ -161,23 +161,23 @@ fn test_header() { t( "# Foo bar", - "

Foo bar

", + "

Foo bar

", ); t( "## Foo-bar_baz qux", - "

\ + "

\ Foo-bar_baz qux

", ); t( "### **Foo** *bar* baz!?!& -_qux_-%", - "

\ + "

\ Foo \ bar baz!?!& -qux-%\

", ); t( "#### **Foo?** & \\*bar?!* _`baz`_ ❤ #qux", - "
\ + "
\ Foo? & *bar?!* \ baz ❤ #qux\
", @@ -204,32 +204,32 @@ fn test_header_ids_multiple_blocks() { t( &mut map, "# Example", - "

Example

", + "

Example

", ); t( &mut map, "# Panics", - "

Panics

", + "

Panics

", ); t( &mut map, "# Example", - "

Example

", + "

Example

", ); t( &mut map, "# Search", - "

Search

", + "

Search

", ); t( &mut map, "# Example", - "

Example

", + "

Example

", ); t( &mut map, "# Panics", - "

Panics

", + "

Panics

", ); } diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index f3e65df6b1497..19b5fef4e092e 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -2567,7 +2567,7 @@ fn render_call_locations(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item) { w, "
\ \ -
\ +
\ Examples found in repository\
", id = id diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index 04112c9779b36..78e7c97d71d25 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -1141,16 +1141,6 @@ a.test-arrow { a.test-arrow:hover{ text-decoration: none; } -.section-header:hover a:before { - position: absolute; - left: -25px; - padding-right: 10px; /* avoid gap that causes hover to disappear */ - content: '\2002\00a7\2002'; -} - -.section-header:hover a { - text-decoration: none; -} .code-attribute { font-weight: 300; @@ -1196,17 +1186,6 @@ h3.variant { margin-top: 3px; } -.top-doc .docblock > .section-header:first-child { - margin-left: 15px; -} -.top-doc .docblock > .section-header:first-child:hover > a:before { - left: -10px; -} - -.docblock > .section-header:first-child { - margin-top: 0; -} - :target > code, :target > .code-header { opacity: 1; } From e8d5ae41a118364bc9897d01fa67a3838712b7c2 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 9 Feb 2022 14:44:10 +0100 Subject: [PATCH 10/19] Update rustdoc tests for headings indent --- src/librustdoc/html/markdown/tests.rs | 41 +++++------------------- src/test/rustdoc-gui/anchors.goml | 42 ------------------------- src/test/rustdoc-gui/headers-color.goml | 9 ++++-- 3 files changed, 13 insertions(+), 79 deletions(-) diff --git a/src/librustdoc/html/markdown/tests.rs b/src/librustdoc/html/markdown/tests.rs index 6b44e447b5111..5c0bf0ed942f4 100644 --- a/src/librustdoc/html/markdown/tests.rs +++ b/src/librustdoc/html/markdown/tests.rs @@ -159,10 +159,7 @@ fn test_header() { assert_eq!(output, expect, "original: {}", input); } - t( - "# Foo bar", - "

Foo bar

", - ); + t("# Foo bar", "

Foo bar

"); t( "## Foo-bar_baz qux", "

\ @@ -201,36 +198,12 @@ fn test_header_ids_multiple_blocks() { assert_eq!(output, expect, "original: {}", input); } - t( - &mut map, - "# Example", - "

Example

", - ); - t( - &mut map, - "# Panics", - "

Panics

", - ); - t( - &mut map, - "# Example", - "

Example

", - ); - t( - &mut map, - "# Search", - "

Search

", - ); - t( - &mut map, - "# Example", - "

Example

", - ); - t( - &mut map, - "# Panics", - "

Panics

", - ); + t(&mut map, "# Example", "

Example

"); + t(&mut map, "# Panics", "

Panics

"); + t(&mut map, "# Example", "

Example

"); + t(&mut map, "# Search", "

Search

"); + t(&mut map, "# Example", "

Example

"); + t(&mut map, "# Panics", "

Panics

"); } #[test] diff --git a/src/test/rustdoc-gui/anchors.goml b/src/test/rustdoc-gui/anchors.goml index 26e4503a5d086..ddfb23a4f86ba 100644 --- a/src/test/rustdoc-gui/anchors.goml +++ b/src/test/rustdoc-gui/anchors.goml @@ -31,46 +31,4 @@ assert-css: ("h2#implementations a.anchor", {"color": "rgb(0, 0, 0)"}) move-cursor-to: "#impl" assert-css: ("#impl a.anchor", {"color": "rgb(0, 0, 0)"}) -// Now we check the positions: only the first heading of the top doc comment should -// have a different position. -move-cursor-to: ".top-doc .docblock .section-header:first-child" -assert-css: ( - ".top-doc .docblock .section-header:first-child > a::before", - {"left": "-10px", "padding-right": "10px"}, -) -// We also check that the heading itself has a different indent. -assert-css: (".top-doc .docblock .section-header:first-child", {"margin-left": "15px"}) - -move-cursor-to: ".top-doc .docblock .section-header:not(:first-child)" -assert-css: ( - ".top-doc .docblock .section-header:not(:first-child) > a::before", - {"left": "-25px", "padding-right": "10px"}, -) -assert-css: (".top-doc .docblock .section-header:not(:first-child)", {"margin-left": "0px"}) - -// Now let's check some other docblock headings... -// First the impl block docs. -move-cursor-to: "#title-for-struct-impl-doc" -assert-css: ( - "#title-for-struct-impl-doc > a::before", - {"left": "-25px", "padding-right": "10px"}, -) -assert-css: ("#title-for-struct-impl-doc", {"margin-left": "0px"}) -// Now a method docs. -move-cursor-to: "#title-for-struct-impl-item-doc" -assert-css: ( - "#title-for-struct-impl-item-doc > a::before", - {"left": "-25px", "padding-right": "10px"}, -) assert-css: ("#title-for-struct-impl-item-doc", {"margin-left": "0px"}) - -// Finally, we want to ensure that if the first element of the doc block isn't a heading, -// if there is a heading afterwards, it won't have the indent. -goto: file://|DOC_PATH|/test_docs/enum.WhoLetTheDogOut.html - -move-cursor-to: ".top-doc .docblock .section-header" -assert-css: ( - ".top-doc .docblock .section-header > a::before", - {"left": "-25px", "padding-right": "10px"}, -) -assert-css: (".top-doc .docblock .section-header", {"margin-left": "0px"}) diff --git a/src/test/rustdoc-gui/headers-color.goml b/src/test/rustdoc-gui/headers-color.goml index d58ca13a6291f..cf9caa2d5866a 100644 --- a/src/test/rustdoc-gui/headers-color.goml +++ b/src/test/rustdoc-gui/headers-color.goml @@ -40,7 +40,8 @@ goto: file://|DOC_PATH|/test_docs/index.html assert-css: (".small-section-header a", {"color": "rgb(197, 197, 197)"}, ALL) goto: file://|DOC_PATH|/test_docs/struct.HeavilyDocumentedStruct.html -assert-css: (".section-header a", {"color": "rgb(57, 175, 215)"}, ALL) +// We select headings (h2, h3, h...). +assert-css: (".docblock > :not(p) > a", {"color": "rgb(57, 175, 215)"}, ALL) // Dark theme local-storage: { @@ -78,7 +79,8 @@ goto: file://|DOC_PATH|/test_docs/index.html assert-css: (".small-section-header a", {"color": "rgb(221, 221, 221)"}, ALL) goto: file://|DOC_PATH|/test_docs/struct.HeavilyDocumentedStruct.html -assert-css: (".section-header a", {"color": "rgb(210, 153, 29)"}, ALL) +// We select headings (h2, h3, h...). +assert-css: (".docblock > :not(p) > a", {"color": "rgb(210, 153, 29)"}, ALL) // Light theme local-storage: {"rustdoc-theme": "light", "rustdoc-use-system-theme": "false"} @@ -111,4 +113,5 @@ goto: file://|DOC_PATH|/test_docs/index.html assert-css: (".small-section-header a", {"color": "rgb(0, 0, 0)"}, ALL) goto: file://|DOC_PATH|/test_docs/struct.HeavilyDocumentedStruct.html -assert-css: (".section-header a", {"color": "rgb(56, 115, 173)"}, ALL) +// We select headings (h2, h3, h...). +assert-css: (".docblock > :not(p) > a", {"color": "rgb(56, 115, 173)"}, ALL) From 49d48231126c3e83614f399bea653f45c2d8daf9 Mon Sep 17 00:00:00 2001 From: Amanieu d'Antras Date: Wed, 9 Feb 2022 18:14:35 +0000 Subject: [PATCH 11/19] Stabilize cfg_target_has_atomic Closes #32976 --- compiler/rustc_feature/src/accepted.rs | 2 + compiler/rustc_feature/src/active.rs | 4 +- compiler/rustc_feature/src/builtin_attrs.rs | 6 +- compiler/rustc_span/src/symbol.rs | 1 + library/alloc/src/lib.rs | 2 +- library/core/src/lib.rs | 3 +- library/core/tests/lib.rs | 2 +- library/std/src/lib.rs | 2 +- .../atomic-lock-free/atomic_lock_free.rs | 2 +- ...e-cfg-target-has-atomic-equal-alignment.rs | 14 + ...g-target-has-atomic-equal-alignment.stderr | 57 ++++ .../feature-gate-cfg-target-has-atomic.rs | 118 -------- .../feature-gate-cfg-target-has-atomic.stderr | 273 ------------------ 13 files changed, 84 insertions(+), 402 deletions(-) create mode 100644 src/test/ui/feature-gates/feature-gate-cfg-target-has-atomic-equal-alignment.rs create mode 100644 src/test/ui/feature-gates/feature-gate-cfg-target-has-atomic-equal-alignment.stderr delete mode 100644 src/test/ui/feature-gates/feature-gate-cfg-target-has-atomic.rs delete mode 100644 src/test/ui/feature-gates/feature-gate-cfg-target-has-atomic.stderr diff --git a/compiler/rustc_feature/src/accepted.rs b/compiler/rustc_feature/src/accepted.rs index 32a9d081ed8c5..88edaec916972 100644 --- a/compiler/rustc_feature/src/accepted.rs +++ b/compiler/rustc_feature/src/accepted.rs @@ -72,6 +72,8 @@ declare_features! ( (accepted, cfg_doctest, "1.40.0", Some(62210), None), /// Allows `cfg(target_feature = "...")`. (accepted, cfg_target_feature, "1.27.0", Some(29717), None), + /// Allows `cfg(target_has_atomic = "...")`. + (accepted, cfg_target_has_atomic, "1.60.0", Some(32976), None), /// Allows `cfg(target_vendor = "...")`. (accepted, cfg_target_vendor, "1.33.0", Some(29718), None), /// Allows implementing `Clone` for closures where possible (RFC 2132). diff --git a/compiler/rustc_feature/src/active.rs b/compiler/rustc_feature/src/active.rs index e5232bf3dd019..71b9419bab512 100644 --- a/compiler/rustc_feature/src/active.rs +++ b/compiler/rustc_feature/src/active.rs @@ -309,8 +309,8 @@ declare_features! ( (active, cfg_sanitize, "1.41.0", Some(39699), None), /// Allows `cfg(target_abi = "...")`. (active, cfg_target_abi, "1.55.0", Some(80970), None), - /// Allows `cfg(target_has_atomic = "...")`. - (active, cfg_target_has_atomic, "1.9.0", Some(32976), None), + /// Allows `cfg(target_has_atomic_equal_alignment = "...")`. + (active, cfg_target_has_atomic_equal_alignment, "1.60.0", Some(93822), None), /// Allows `cfg(target_thread_local)`. (active, cfg_target_thread_local, "1.7.0", Some(29594), None), /// Allow conditional compilation depending on rust version diff --git a/compiler/rustc_feature/src/builtin_attrs.rs b/compiler/rustc_feature/src/builtin_attrs.rs index cb2562d09a525..7ebef8e19ad22 100644 --- a/compiler/rustc_feature/src/builtin_attrs.rs +++ b/compiler/rustc_feature/src/builtin_attrs.rs @@ -26,12 +26,10 @@ const GATED_CFGS: &[GatedCfg] = &[ // (name in cfg, feature, function to check if the feature is enabled) (sym::target_abi, sym::cfg_target_abi, cfg_fn!(cfg_target_abi)), (sym::target_thread_local, sym::cfg_target_thread_local, cfg_fn!(cfg_target_thread_local)), - (sym::target_has_atomic, sym::cfg_target_has_atomic, cfg_fn!(cfg_target_has_atomic)), - (sym::target_has_atomic_load_store, sym::cfg_target_has_atomic, cfg_fn!(cfg_target_has_atomic)), ( sym::target_has_atomic_equal_alignment, - sym::cfg_target_has_atomic, - cfg_fn!(cfg_target_has_atomic), + sym::cfg_target_has_atomic_equal_alignment, + cfg_fn!(cfg_target_has_atomic_equal_alignment), ), (sym::sanitize, sym::cfg_sanitize, cfg_fn!(cfg_sanitize)), (sym::version, sym::cfg_version, cfg_fn!(cfg_version)), diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 70fad4911f9c7..95f6e19e5910f 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -421,6 +421,7 @@ symbols! { cfg_target_abi, cfg_target_feature, cfg_target_has_atomic, + cfg_target_has_atomic_equal_alignment, cfg_target_thread_local, cfg_target_vendor, cfg_version, diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs index a07071cb6fba3..ab9f0b9d7378f 100644 --- a/library/alloc/src/lib.rs +++ b/library/alloc/src/lib.rs @@ -140,7 +140,7 @@ #![feature(associated_type_bounds)] #![feature(box_syntax)] #![feature(cfg_sanitize)] -#![feature(cfg_target_has_atomic)] +#![cfg_attr(bootstrap, feature(cfg_target_has_atomic))] #![feature(const_deref)] #![feature(const_fn_trait_bound)] #![feature(const_mut_refs)] diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs index e52d52e954c8f..72d8e1b39030a 100644 --- a/library/core/src/lib.rs +++ b/library/core/src/lib.rs @@ -155,7 +155,8 @@ #![feature(allow_internal_unstable)] #![feature(associated_type_bounds)] #![feature(auto_traits)] -#![feature(cfg_target_has_atomic)] +#![cfg_attr(bootstrap, feature(cfg_target_has_atomic))] +#![cfg_attr(not(bootstrap), feature(cfg_target_has_atomic_equal_alignment))] #![feature(const_fn_floating_point_arithmetic)] #![feature(const_fn_fn_ptr_basics)] #![feature(const_fn_trait_bound)] diff --git a/library/core/tests/lib.rs b/library/core/tests/lib.rs index a993def0a818e..1c512471c95cb 100644 --- a/library/core/tests/lib.rs +++ b/library/core/tests/lib.rs @@ -7,7 +7,7 @@ #![feature(box_syntax)] #![feature(cell_update)] #![feature(cfg_panic)] -#![feature(cfg_target_has_atomic)] +#![cfg_attr(bootstrap, feature(cfg_target_has_atomic))] #![feature(const_assume)] #![feature(const_black_box)] #![feature(const_bool_to_option)] diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index 4f44a3183a6ec..2aae29f21544d 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -242,7 +242,7 @@ #![feature(c_variadic)] #![feature(cfg_accessible)] #![feature(cfg_eval)] -#![feature(cfg_target_has_atomic)] +#![cfg_attr(bootstrap, feature(cfg_target_has_atomic))] #![feature(cfg_target_thread_local)] #![feature(char_error_internals)] #![feature(char_internals)] diff --git a/src/test/run-make-fulldeps/atomic-lock-free/atomic_lock_free.rs b/src/test/run-make-fulldeps/atomic-lock-free/atomic_lock_free.rs index bc7951a04da86..e9b28504a907a 100644 --- a/src/test/run-make-fulldeps/atomic-lock-free/atomic_lock_free.rs +++ b/src/test/run-make-fulldeps/atomic-lock-free/atomic_lock_free.rs @@ -1,4 +1,4 @@ -#![feature(cfg_target_has_atomic, no_core, intrinsics, lang_items)] +#![feature(no_core, intrinsics, lang_items)] #![crate_type="rlib"] #![no_core] diff --git a/src/test/ui/feature-gates/feature-gate-cfg-target-has-atomic-equal-alignment.rs b/src/test/ui/feature-gates/feature-gate-cfg-target-has-atomic-equal-alignment.rs new file mode 100644 index 0000000000000..3d692a0700197 --- /dev/null +++ b/src/test/ui/feature-gates/feature-gate-cfg-target-has-atomic-equal-alignment.rs @@ -0,0 +1,14 @@ +fn main() { + cfg!(target_has_atomic_equal_alignment = "8"); + //~^ ERROR `cfg(target_has_atomic_equal_alignment)` is experimental and subject to change + cfg!(target_has_atomic_equal_alignment = "16"); + //~^ ERROR `cfg(target_has_atomic_equal_alignment)` is experimental and subject to change + cfg!(target_has_atomic_equal_alignment = "32"); + //~^ ERROR `cfg(target_has_atomic_equal_alignment)` is experimental and subject to change + cfg!(target_has_atomic_equal_alignment = "64"); + //~^ ERROR `cfg(target_has_atomic_equal_alignment)` is experimental and subject to change + cfg!(target_has_atomic_equal_alignment = "128"); + //~^ ERROR `cfg(target_has_atomic_equal_alignment)` is experimental and subject to change + cfg!(target_has_atomic_equal_alignment = "ptr"); + //~^ ERROR `cfg(target_has_atomic_equal_alignment)` is experimental and subject to change +} diff --git a/src/test/ui/feature-gates/feature-gate-cfg-target-has-atomic-equal-alignment.stderr b/src/test/ui/feature-gates/feature-gate-cfg-target-has-atomic-equal-alignment.stderr new file mode 100644 index 0000000000000..8ad3b034aa51f --- /dev/null +++ b/src/test/ui/feature-gates/feature-gate-cfg-target-has-atomic-equal-alignment.stderr @@ -0,0 +1,57 @@ +error[E0658]: `cfg(target_has_atomic_equal_alignment)` is experimental and subject to change + --> $DIR/feature-gate-cfg-target-has-atomic-equal-alignment.rs:2:10 + | +LL | cfg!(target_has_atomic_equal_alignment = "8"); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: see issue #93822 for more information + = help: add `#![feature(cfg_target_has_atomic_equal_alignment)]` to the crate attributes to enable + +error[E0658]: `cfg(target_has_atomic_equal_alignment)` is experimental and subject to change + --> $DIR/feature-gate-cfg-target-has-atomic-equal-alignment.rs:4:10 + | +LL | cfg!(target_has_atomic_equal_alignment = "16"); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: see issue #93822 for more information + = help: add `#![feature(cfg_target_has_atomic_equal_alignment)]` to the crate attributes to enable + +error[E0658]: `cfg(target_has_atomic_equal_alignment)` is experimental and subject to change + --> $DIR/feature-gate-cfg-target-has-atomic-equal-alignment.rs:6:10 + | +LL | cfg!(target_has_atomic_equal_alignment = "32"); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: see issue #93822 for more information + = help: add `#![feature(cfg_target_has_atomic_equal_alignment)]` to the crate attributes to enable + +error[E0658]: `cfg(target_has_atomic_equal_alignment)` is experimental and subject to change + --> $DIR/feature-gate-cfg-target-has-atomic-equal-alignment.rs:8:10 + | +LL | cfg!(target_has_atomic_equal_alignment = "64"); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: see issue #93822 for more information + = help: add `#![feature(cfg_target_has_atomic_equal_alignment)]` to the crate attributes to enable + +error[E0658]: `cfg(target_has_atomic_equal_alignment)` is experimental and subject to change + --> $DIR/feature-gate-cfg-target-has-atomic-equal-alignment.rs:10:10 + | +LL | cfg!(target_has_atomic_equal_alignment = "128"); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: see issue #93822 for more information + = help: add `#![feature(cfg_target_has_atomic_equal_alignment)]` to the crate attributes to enable + +error[E0658]: `cfg(target_has_atomic_equal_alignment)` is experimental and subject to change + --> $DIR/feature-gate-cfg-target-has-atomic-equal-alignment.rs:12:10 + | +LL | cfg!(target_has_atomic_equal_alignment = "ptr"); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: see issue #93822 for more information + = help: add `#![feature(cfg_target_has_atomic_equal_alignment)]` to the crate attributes to enable + +error: aborting due to 6 previous errors + +For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/feature-gates/feature-gate-cfg-target-has-atomic.rs b/src/test/ui/feature-gates/feature-gate-cfg-target-has-atomic.rs deleted file mode 100644 index 049fdd84d8c22..0000000000000 --- a/src/test/ui/feature-gates/feature-gate-cfg-target-has-atomic.rs +++ /dev/null @@ -1,118 +0,0 @@ -#![feature(intrinsics, lang_items, no_core, rustc_attrs)] - -#![crate_type="rlib"] -#![no_core] - -extern "rust-intrinsic" { - fn atomic_xadd(dst: *mut T, src: T) -> T; -} - -#[lang = "sized"] -trait Sized {} -#[lang = "copy"] -trait Copy {} - -#[cfg(target_has_atomic = "8")] -//~^ ERROR `cfg(target_has_atomic)` is experimental and subject to change -pub unsafe fn atomic_u8(x: *mut u8) { - atomic_xadd(x, 1); - atomic_xadd(x, 1); -} -#[cfg(target_has_atomic = "8")] -//~^ ERROR `cfg(target_has_atomic)` is experimental and subject to change -pub unsafe fn atomic_i8(x: *mut i8) { - atomic_xadd(x, 1); -} -#[cfg(target_has_atomic = "16")] -//~^ ERROR `cfg(target_has_atomic)` is experimental and subject to change -pub unsafe fn atomic_u16(x: *mut u16) { - atomic_xadd(x, 1); -} -#[cfg(target_has_atomic = "16")] -//~^ ERROR `cfg(target_has_atomic)` is experimental and subject to change -pub unsafe fn atomic_i16(x: *mut i16) { - atomic_xadd(x, 1); -} -#[cfg(target_has_atomic = "32")] -//~^ ERROR `cfg(target_has_atomic)` is experimental and subject to change -pub unsafe fn atomic_u32(x: *mut u32) { - atomic_xadd(x, 1); -} -#[cfg(target_has_atomic = "32")] -//~^ ERROR `cfg(target_has_atomic)` is experimental and subject to change -pub unsafe fn atomic_i32(x: *mut i32) { - atomic_xadd(x, 1); -} -#[cfg(target_has_atomic = "64")] -//~^ ERROR `cfg(target_has_atomic)` is experimental and subject to change -pub unsafe fn atomic_u64(x: *mut u64) { - atomic_xadd(x, 1); -} -#[cfg(target_has_atomic = "64")] -//~^ ERROR `cfg(target_has_atomic)` is experimental and subject to change -pub unsafe fn atomic_i64(x: *mut i64) { - atomic_xadd(x, 1); -} -#[cfg(target_has_atomic = "128")] -//~^ ERROR `cfg(target_has_atomic)` is experimental and subject to change -pub unsafe fn atomic_u128(x: *mut u128) { - atomic_xadd(x, 1); -} -#[cfg(target_has_atomic = "128")] -//~^ ERROR `cfg(target_has_atomic)` is experimental and subject to change -pub unsafe fn atomic_i128(x: *mut i128) { - atomic_xadd(x, 1); -} -#[cfg(target_has_atomic = "ptr")] -//~^ ERROR `cfg(target_has_atomic)` is experimental and subject to change -pub unsafe fn atomic_usize(x: *mut usize) { - atomic_xadd(x, 1); -} -#[cfg(target_has_atomic = "ptr")] -//~^ ERROR `cfg(target_has_atomic)` is experimental and subject to change -pub unsafe fn atomic_isize(x: *mut isize) { - atomic_xadd(x, 1); -} - -fn main() { - cfg!(target_has_atomic = "8"); - //~^ ERROR `cfg(target_has_atomic)` is experimental and subject to change - cfg!(target_has_atomic = "16"); - //~^ ERROR `cfg(target_has_atomic)` is experimental and subject to change - cfg!(target_has_atomic = "32"); - //~^ ERROR `cfg(target_has_atomic)` is experimental and subject to change - cfg!(target_has_atomic = "64"); - //~^ ERROR `cfg(target_has_atomic)` is experimental and subject to change - cfg!(target_has_atomic = "128"); - //~^ ERROR `cfg(target_has_atomic)` is experimental and subject to change - cfg!(target_has_atomic = "ptr"); - //~^ ERROR `cfg(target_has_atomic)` is experimental and subject to change - cfg!(target_has_atomic_load_store = "8"); - //~^ ERROR `cfg(target_has_atomic_load_store)` is experimental and subject to change - cfg!(target_has_atomic_load_store = "16"); - //~^ ERROR `cfg(target_has_atomic_load_store)` is experimental and subject to change - cfg!(target_has_atomic_load_store = "32"); - //~^ ERROR `cfg(target_has_atomic_load_store)` is experimental and subject to change - cfg!(target_has_atomic_load_store = "64"); - //~^ ERROR `cfg(target_has_atomic_load_store)` is experimental and subject to change - cfg!(target_has_atomic_load_store = "128"); - //~^ ERROR `cfg(target_has_atomic_load_store)` is experimental and subject to change - cfg!(target_has_atomic_load_store = "ptr"); - //~^ ERROR `cfg(target_has_atomic_load_store)` is experimental and subject to change - cfg!(target_has_atomic_equal_alignment = "8"); - //~^ ERROR `cfg(target_has_atomic_equal_alignment)` is experimental and subject to change - cfg!(target_has_atomic_equal_alignment = "16"); - //~^ ERROR `cfg(target_has_atomic_equal_alignment)` is experimental and subject to change - cfg!(target_has_atomic_equal_alignment = "32"); - //~^ ERROR `cfg(target_has_atomic_equal_alignment)` is experimental and subject to change - cfg!(target_has_atomic_equal_alignment = "64"); - //~^ ERROR `cfg(target_has_atomic_equal_alignment)` is experimental and subject to change - cfg!(target_has_atomic_equal_alignment = "128"); - //~^ ERROR `cfg(target_has_atomic_equal_alignment)` is experimental and subject to change - cfg!(target_has_atomic_equal_alignment = "ptr"); - //~^ ERROR `cfg(target_has_atomic_equal_alignment)` is experimental and subject to change -} - -#[macro_export] -#[rustc_builtin_macro] -macro_rules! cfg { () => () } diff --git a/src/test/ui/feature-gates/feature-gate-cfg-target-has-atomic.stderr b/src/test/ui/feature-gates/feature-gate-cfg-target-has-atomic.stderr deleted file mode 100644 index 16e1dc6440084..0000000000000 --- a/src/test/ui/feature-gates/feature-gate-cfg-target-has-atomic.stderr +++ /dev/null @@ -1,273 +0,0 @@ -error[E0658]: `cfg(target_has_atomic)` is experimental and subject to change - --> $DIR/feature-gate-cfg-target-has-atomic.rs:15:7 - | -LL | #[cfg(target_has_atomic = "8")] - | ^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #32976 for more information - = help: add `#![feature(cfg_target_has_atomic)]` to the crate attributes to enable - -error[E0658]: `cfg(target_has_atomic)` is experimental and subject to change - --> $DIR/feature-gate-cfg-target-has-atomic.rs:21:7 - | -LL | #[cfg(target_has_atomic = "8")] - | ^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #32976 for more information - = help: add `#![feature(cfg_target_has_atomic)]` to the crate attributes to enable - -error[E0658]: `cfg(target_has_atomic)` is experimental and subject to change - --> $DIR/feature-gate-cfg-target-has-atomic.rs:26:7 - | -LL | #[cfg(target_has_atomic = "16")] - | ^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #32976 for more information - = help: add `#![feature(cfg_target_has_atomic)]` to the crate attributes to enable - -error[E0658]: `cfg(target_has_atomic)` is experimental and subject to change - --> $DIR/feature-gate-cfg-target-has-atomic.rs:31:7 - | -LL | #[cfg(target_has_atomic = "16")] - | ^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #32976 for more information - = help: add `#![feature(cfg_target_has_atomic)]` to the crate attributes to enable - -error[E0658]: `cfg(target_has_atomic)` is experimental and subject to change - --> $DIR/feature-gate-cfg-target-has-atomic.rs:36:7 - | -LL | #[cfg(target_has_atomic = "32")] - | ^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #32976 for more information - = help: add `#![feature(cfg_target_has_atomic)]` to the crate attributes to enable - -error[E0658]: `cfg(target_has_atomic)` is experimental and subject to change - --> $DIR/feature-gate-cfg-target-has-atomic.rs:41:7 - | -LL | #[cfg(target_has_atomic = "32")] - | ^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #32976 for more information - = help: add `#![feature(cfg_target_has_atomic)]` to the crate attributes to enable - -error[E0658]: `cfg(target_has_atomic)` is experimental and subject to change - --> $DIR/feature-gate-cfg-target-has-atomic.rs:46:7 - | -LL | #[cfg(target_has_atomic = "64")] - | ^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #32976 for more information - = help: add `#![feature(cfg_target_has_atomic)]` to the crate attributes to enable - -error[E0658]: `cfg(target_has_atomic)` is experimental and subject to change - --> $DIR/feature-gate-cfg-target-has-atomic.rs:51:7 - | -LL | #[cfg(target_has_atomic = "64")] - | ^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #32976 for more information - = help: add `#![feature(cfg_target_has_atomic)]` to the crate attributes to enable - -error[E0658]: `cfg(target_has_atomic)` is experimental and subject to change - --> $DIR/feature-gate-cfg-target-has-atomic.rs:56:7 - | -LL | #[cfg(target_has_atomic = "128")] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #32976 for more information - = help: add `#![feature(cfg_target_has_atomic)]` to the crate attributes to enable - -error[E0658]: `cfg(target_has_atomic)` is experimental and subject to change - --> $DIR/feature-gate-cfg-target-has-atomic.rs:61:7 - | -LL | #[cfg(target_has_atomic = "128")] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #32976 for more information - = help: add `#![feature(cfg_target_has_atomic)]` to the crate attributes to enable - -error[E0658]: `cfg(target_has_atomic)` is experimental and subject to change - --> $DIR/feature-gate-cfg-target-has-atomic.rs:66:7 - | -LL | #[cfg(target_has_atomic = "ptr")] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #32976 for more information - = help: add `#![feature(cfg_target_has_atomic)]` to the crate attributes to enable - -error[E0658]: `cfg(target_has_atomic)` is experimental and subject to change - --> $DIR/feature-gate-cfg-target-has-atomic.rs:71:7 - | -LL | #[cfg(target_has_atomic = "ptr")] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #32976 for more information - = help: add `#![feature(cfg_target_has_atomic)]` to the crate attributes to enable - -error[E0658]: `cfg(target_has_atomic)` is experimental and subject to change - --> $DIR/feature-gate-cfg-target-has-atomic.rs:78:10 - | -LL | cfg!(target_has_atomic = "8"); - | ^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #32976 for more information - = help: add `#![feature(cfg_target_has_atomic)]` to the crate attributes to enable - -error[E0658]: `cfg(target_has_atomic)` is experimental and subject to change - --> $DIR/feature-gate-cfg-target-has-atomic.rs:80:10 - | -LL | cfg!(target_has_atomic = "16"); - | ^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #32976 for more information - = help: add `#![feature(cfg_target_has_atomic)]` to the crate attributes to enable - -error[E0658]: `cfg(target_has_atomic)` is experimental and subject to change - --> $DIR/feature-gate-cfg-target-has-atomic.rs:82:10 - | -LL | cfg!(target_has_atomic = "32"); - | ^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #32976 for more information - = help: add `#![feature(cfg_target_has_atomic)]` to the crate attributes to enable - -error[E0658]: `cfg(target_has_atomic)` is experimental and subject to change - --> $DIR/feature-gate-cfg-target-has-atomic.rs:84:10 - | -LL | cfg!(target_has_atomic = "64"); - | ^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #32976 for more information - = help: add `#![feature(cfg_target_has_atomic)]` to the crate attributes to enable - -error[E0658]: `cfg(target_has_atomic)` is experimental and subject to change - --> $DIR/feature-gate-cfg-target-has-atomic.rs:86:10 - | -LL | cfg!(target_has_atomic = "128"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #32976 for more information - = help: add `#![feature(cfg_target_has_atomic)]` to the crate attributes to enable - -error[E0658]: `cfg(target_has_atomic)` is experimental and subject to change - --> $DIR/feature-gate-cfg-target-has-atomic.rs:88:10 - | -LL | cfg!(target_has_atomic = "ptr"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #32976 for more information - = help: add `#![feature(cfg_target_has_atomic)]` to the crate attributes to enable - -error[E0658]: `cfg(target_has_atomic_load_store)` is experimental and subject to change - --> $DIR/feature-gate-cfg-target-has-atomic.rs:90:10 - | -LL | cfg!(target_has_atomic_load_store = "8"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #32976 for more information - = help: add `#![feature(cfg_target_has_atomic)]` to the crate attributes to enable - -error[E0658]: `cfg(target_has_atomic_load_store)` is experimental and subject to change - --> $DIR/feature-gate-cfg-target-has-atomic.rs:92:10 - | -LL | cfg!(target_has_atomic_load_store = "16"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #32976 for more information - = help: add `#![feature(cfg_target_has_atomic)]` to the crate attributes to enable - -error[E0658]: `cfg(target_has_atomic_load_store)` is experimental and subject to change - --> $DIR/feature-gate-cfg-target-has-atomic.rs:94:10 - | -LL | cfg!(target_has_atomic_load_store = "32"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #32976 for more information - = help: add `#![feature(cfg_target_has_atomic)]` to the crate attributes to enable - -error[E0658]: `cfg(target_has_atomic_load_store)` is experimental and subject to change - --> $DIR/feature-gate-cfg-target-has-atomic.rs:96:10 - | -LL | cfg!(target_has_atomic_load_store = "64"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #32976 for more information - = help: add `#![feature(cfg_target_has_atomic)]` to the crate attributes to enable - -error[E0658]: `cfg(target_has_atomic_load_store)` is experimental and subject to change - --> $DIR/feature-gate-cfg-target-has-atomic.rs:98:10 - | -LL | cfg!(target_has_atomic_load_store = "128"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #32976 for more information - = help: add `#![feature(cfg_target_has_atomic)]` to the crate attributes to enable - -error[E0658]: `cfg(target_has_atomic_load_store)` is experimental and subject to change - --> $DIR/feature-gate-cfg-target-has-atomic.rs:100:10 - | -LL | cfg!(target_has_atomic_load_store = "ptr"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #32976 for more information - = help: add `#![feature(cfg_target_has_atomic)]` to the crate attributes to enable - -error[E0658]: `cfg(target_has_atomic_equal_alignment)` is experimental and subject to change - --> $DIR/feature-gate-cfg-target-has-atomic.rs:102:10 - | -LL | cfg!(target_has_atomic_equal_alignment = "8"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #32976 for more information - = help: add `#![feature(cfg_target_has_atomic)]` to the crate attributes to enable - -error[E0658]: `cfg(target_has_atomic_equal_alignment)` is experimental and subject to change - --> $DIR/feature-gate-cfg-target-has-atomic.rs:104:10 - | -LL | cfg!(target_has_atomic_equal_alignment = "16"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #32976 for more information - = help: add `#![feature(cfg_target_has_atomic)]` to the crate attributes to enable - -error[E0658]: `cfg(target_has_atomic_equal_alignment)` is experimental and subject to change - --> $DIR/feature-gate-cfg-target-has-atomic.rs:106:10 - | -LL | cfg!(target_has_atomic_equal_alignment = "32"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #32976 for more information - = help: add `#![feature(cfg_target_has_atomic)]` to the crate attributes to enable - -error[E0658]: `cfg(target_has_atomic_equal_alignment)` is experimental and subject to change - --> $DIR/feature-gate-cfg-target-has-atomic.rs:108:10 - | -LL | cfg!(target_has_atomic_equal_alignment = "64"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #32976 for more information - = help: add `#![feature(cfg_target_has_atomic)]` to the crate attributes to enable - -error[E0658]: `cfg(target_has_atomic_equal_alignment)` is experimental and subject to change - --> $DIR/feature-gate-cfg-target-has-atomic.rs:110:10 - | -LL | cfg!(target_has_atomic_equal_alignment = "128"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #32976 for more information - = help: add `#![feature(cfg_target_has_atomic)]` to the crate attributes to enable - -error[E0658]: `cfg(target_has_atomic_equal_alignment)` is experimental and subject to change - --> $DIR/feature-gate-cfg-target-has-atomic.rs:112:10 - | -LL | cfg!(target_has_atomic_equal_alignment = "ptr"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #32976 for more information - = help: add `#![feature(cfg_target_has_atomic)]` to the crate attributes to enable - -error: aborting due to 30 previous errors - -For more information about this error, try `rustc --explain E0658`. From fa400ace11f9db1e299fef3992d3301ccd985bf0 Mon Sep 17 00:00:00 2001 From: Noah Lev Date: Fri, 7 Jan 2022 16:12:11 -0800 Subject: [PATCH 12/19] rustdoc: Create enum for sections holding items --- src/librustdoc/html/render/mod.rs | 151 ++++++++++++++++++----- src/librustdoc/html/render/print_item.rs | 14 +-- 2 files changed, 128 insertions(+), 37 deletions(-) diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index 32e4a82918421..3fd94fb9dc522 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -2409,33 +2409,124 @@ fn sidebar_enum(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, e: &clean: } } -fn item_ty_to_strs(ty: ItemType) -> (&'static str, &'static str) { +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +enum ItemSection { + Reexports, + Modules, + Structs, + Unions, + Enums, + Functions, + TypeDefinitions, + Statics, + Constants, + Traits, + Implementations, + TypeMethods, + Methods, + StructFields, + Variants, + Macros, + PrimitiveTypes, + AssociatedTypes, + AssociatedConstants, + ForeignTypes, + Keywords, + OpaqueTypes, + AttributeMacros, + DeriveMacros, + TraitAliases, +} + +impl ItemSection { + fn id(self) -> &'static str { + match self { + Self::Reexports => "reexports", + Self::Modules => "modules", + Self::Structs => "structs", + Self::Unions => "unions", + Self::Enums => "enums", + Self::Functions => "functions", + Self::TypeDefinitions => "types", + Self::Statics => "statics", + Self::Constants => "constants", + Self::Traits => "traits", + Self::Implementations => "impls", + Self::TypeMethods => "tymethods", + Self::Methods => "methods", + Self::StructFields => "fields", + Self::Variants => "variants", + Self::Macros => "macros", + Self::PrimitiveTypes => "primitives", + Self::AssociatedTypes => "associated-types", + Self::AssociatedConstants => "associated-consts", + Self::ForeignTypes => "foreign-types", + Self::Keywords => "keywords", + Self::OpaqueTypes => "opaque-types", + Self::AttributeMacros => "attributes", + Self::DeriveMacros => "derives", + Self::TraitAliases => "trait-aliases", + } + } + + fn name(self) -> &'static str { + match self { + Self::Reexports => "Re-exports", + Self::Modules => "Modules", + Self::Structs => "Structs", + Self::Unions => "Unions", + Self::Enums => "Enums", + Self::Functions => "Functions", + Self::TypeDefinitions => "Type Definitions", + Self::Statics => "Statics", + Self::Constants => "Constants", + Self::Traits => "Traits", + Self::Implementations => "Implementations", + Self::TypeMethods => "Type Methods", + Self::Methods => "Methods", + Self::StructFields => "Struct Fields", + Self::Variants => "Variants", + Self::Macros => "Macros", + Self::PrimitiveTypes => "Primitive Types", + Self::AssociatedTypes => "Associated Types", + Self::AssociatedConstants => "Associated Constants", + Self::ForeignTypes => "Foreign Types", + Self::Keywords => "Keywords", + Self::OpaqueTypes => "Opaque Types", + Self::AttributeMacros => "Attribute Macros", + Self::DeriveMacros => "Derive Macros", + Self::TraitAliases => "Trait aliases", + } + } +} + +fn item_ty_to_section(ty: ItemType) -> ItemSection { match ty { - ItemType::ExternCrate | ItemType::Import => ("reexports", "Re-exports"), - ItemType::Module => ("modules", "Modules"), - ItemType::Struct => ("structs", "Structs"), - ItemType::Union => ("unions", "Unions"), - ItemType::Enum => ("enums", "Enums"), - ItemType::Function => ("functions", "Functions"), - ItemType::Typedef => ("types", "Type Definitions"), - ItemType::Static => ("statics", "Statics"), - ItemType::Constant => ("constants", "Constants"), - ItemType::Trait => ("traits", "Traits"), - ItemType::Impl => ("impls", "Implementations"), - ItemType::TyMethod => ("tymethods", "Type Methods"), - ItemType::Method => ("methods", "Methods"), - ItemType::StructField => ("fields", "Struct Fields"), - ItemType::Variant => ("variants", "Variants"), - ItemType::Macro => ("macros", "Macros"), - ItemType::Primitive => ("primitives", "Primitive Types"), - ItemType::AssocType => ("associated-types", "Associated Types"), - ItemType::AssocConst => ("associated-consts", "Associated Constants"), - ItemType::ForeignType => ("foreign-types", "Foreign Types"), - ItemType::Keyword => ("keywords", "Keywords"), - ItemType::OpaqueTy => ("opaque-types", "Opaque Types"), - ItemType::ProcAttribute => ("attributes", "Attribute Macros"), - ItemType::ProcDerive => ("derives", "Derive Macros"), - ItemType::TraitAlias => ("trait-aliases", "Trait aliases"), + ItemType::ExternCrate | ItemType::Import => ItemSection::Reexports, + ItemType::Module => ItemSection::Modules, + ItemType::Struct => ItemSection::Structs, + ItemType::Union => ItemSection::Unions, + ItemType::Enum => ItemSection::Enums, + ItemType::Function => ItemSection::Functions, + ItemType::Typedef => ItemSection::TypeDefinitions, + ItemType::Static => ItemSection::Statics, + ItemType::Constant => ItemSection::Constants, + ItemType::Trait => ItemSection::Traits, + ItemType::Impl => ItemSection::Implementations, + ItemType::TyMethod => ItemSection::TypeMethods, + ItemType::Method => ItemSection::Methods, + ItemType::StructField => ItemSection::StructFields, + ItemType::Variant => ItemSection::Variants, + ItemType::Macro => ItemSection::Macros, + ItemType::Primitive => ItemSection::PrimitiveTypes, + ItemType::AssocType => ItemSection::AssociatedTypes, + ItemType::AssocConst => ItemSection::AssociatedConstants, + ItemType::ForeignType => ItemSection::ForeignTypes, + ItemType::Keyword => ItemSection::Keywords, + ItemType::OpaqueTy => ItemSection::OpaqueTypes, + ItemType::ProcAttribute => ItemSection::AttributeMacros, + ItemType::ProcDerive => ItemSection::DeriveMacros, + ItemType::TraitAlias => ItemSection::TraitAliases, ItemType::Generic => unreachable!(), } } @@ -2449,8 +2540,8 @@ fn sidebar_module(buf: &mut Buffer, items: &[clean::Item]) { && (it.type_() == ItemType::ExternCrate || (it.type_() == ItemType::Import && !it.is_stripped())) }) { - let (id, name) = item_ty_to_strs(ItemType::Import); - sidebar.push_str(&format!("
  • {}
  • ", id, name)); + let sec = item_ty_to_section(ItemType::Import); + sidebar.push_str(&format!("
  • {}
  • ", sec.id(), sec.name())); } // ordering taken from item_module, reorder, where it prioritized elements in a certain order @@ -2478,8 +2569,8 @@ fn sidebar_module(buf: &mut Buffer, items: &[clean::Item]) { ItemType::Keyword, ] { if items.iter().any(|it| !it.is_stripped() && it.type_() == myty && it.name.is_some()) { - let (id, name) = item_ty_to_strs(myty); - sidebar.push_str(&format!("
  • {}
  • ", id, name)); + let sec = item_ty_to_section(myty); + sidebar.push_str(&format!("
  • {}
  • ", sec.id(), sec.name())); } } diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index f2c111495edfb..d73bc658f9fd3 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -16,10 +16,10 @@ use rustc_span::symbol::{kw, sym, Symbol}; use rustc_target::abi::{Layout, Primitive, TagEncoding, Variants}; use super::{ - collect_paths_for_type, document, ensure_trailing_slash, item_ty_to_strs, notable_traits_decl, - render_assoc_item, render_assoc_items, render_attributes_in_code, render_attributes_in_pre, - render_impl, render_stability_since_raw, write_srclink, AssocItemLink, Context, - ImplRenderingParameters, + collect_paths_for_type, document, ensure_trailing_slash, item_ty_to_section, + notable_traits_decl, render_assoc_item, render_assoc_items, render_attributes_in_code, + render_attributes_in_pre, render_impl, render_stability_since_raw, write_srclink, + AssocItemLink, Context, ImplRenderingParameters, }; use crate::clean; use crate::formats::item_type::ItemType; @@ -288,15 +288,15 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl w.write_str(ITEM_TABLE_CLOSE); } curty = myty; - let (short, name) = item_ty_to_strs(myty.unwrap()); + let sec = item_ty_to_section(myty.unwrap()); write!( w, "

    \ {name}\

    \n{}", ITEM_TABLE_OPEN, - id = cx.derive_id(short.to_owned()), - name = name + id = cx.derive_id(sec.id().to_owned()), + name = sec.name(), ); } From 1115f69bf4bc96201a130c876f1a2e866f58c907 Mon Sep 17 00:00:00 2001 From: Noah Lev Date: Fri, 7 Jan 2022 16:20:53 -0800 Subject: [PATCH 13/19] Deduplicate item sections --- src/librustdoc/html/render/mod.rs | 15 +++++---------- src/librustdoc/html/render/print_item.rs | 20 ++++++++------------ 2 files changed, 13 insertions(+), 22 deletions(-) diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index 3fd94fb9dc522..279047a2d1cc3 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -2534,19 +2534,11 @@ fn item_ty_to_section(ty: ItemType) -> ItemSection { fn sidebar_module(buf: &mut Buffer, items: &[clean::Item]) { let mut sidebar = String::new(); - // Re-exports are handled a bit differently because they can be extern crates or imports. - if items.iter().any(|it| { - it.name.is_some() - && (it.type_() == ItemType::ExternCrate - || (it.type_() == ItemType::Import && !it.is_stripped())) - }) { - let sec = item_ty_to_section(ItemType::Import); - sidebar.push_str(&format!("
  • {}
  • ", sec.id(), sec.name())); - } - + let mut already_emitted_sections = FxHashSet::default(); // ordering taken from item_module, reorder, where it prioritized elements in a certain order // to print its headings for &myty in &[ + ItemType::Import, ItemType::Primitive, ItemType::Module, ItemType::Macro, @@ -2570,6 +2562,9 @@ fn sidebar_module(buf: &mut Buffer, items: &[clean::Item]) { ] { if items.iter().any(|it| !it.is_stripped() && it.type_() == myty && it.name.is_some()) { let sec = item_ty_to_section(myty); + if !already_emitted_sections.insert(sec) { + continue; + } sidebar.push_str(&format!("
  • {}
  • ", sec.id(), sec.name())); } } diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index d73bc658f9fd3..e781e3c1ef476 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -271,7 +271,7 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl }); debug!("{:?}", indices); - let mut curty = None; + let mut last_section = None; for &idx in &indices { let myitem = &items[idx]; @@ -279,24 +279,20 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl continue; } - let myty = Some(myitem.type_()); - if curty == Some(ItemType::ExternCrate) && myty == Some(ItemType::Import) { - // Put `extern crate` and `use` re-exports in the same section. - curty = myty; - } else if myty != curty { - if curty.is_some() { + let my_section = item_ty_to_section(myitem.type_()); + if Some(my_section) != last_section { + if last_section.is_some() { w.write_str(ITEM_TABLE_CLOSE); } - curty = myty; - let sec = item_ty_to_section(myty.unwrap()); + last_section = Some(my_section); write!( w, "

    \ {name}\

    \n{}", ITEM_TABLE_OPEN, - id = cx.derive_id(sec.id().to_owned()), - name = sec.name(), + id = cx.derive_id(my_section.id().to_owned()), + name = my_section.name(), ); } @@ -408,7 +404,7 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl } } - if curty.is_some() { + if last_section.is_some() { w.write_str(ITEM_TABLE_CLOSE); } } From 163a8004ae61e0c1d35f6411d65868bc03556bf9 Mon Sep 17 00:00:00 2001 From: Noah Lev Date: Fri, 7 Jan 2022 16:30:01 -0800 Subject: [PATCH 14/19] Refactor sidebar printing code The new code is much simpler and easier to understand. In fact, the old code actually had a subtle bug where it excluded a few item types, including trait aliases, from the sidebar, even though they are rendered on the page itself! Now, all sections should show up in the sidebar. --- src/librustdoc/html/render/mod.rs | 84 +++++++++++++----------- src/librustdoc/html/render/print_item.rs | 4 +- 2 files changed, 48 insertions(+), 40 deletions(-) diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index 279047a2d1cc3..6dd730c3f8861 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -2412,22 +2412,22 @@ fn sidebar_enum(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, e: &clean: #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] enum ItemSection { Reexports, + PrimitiveTypes, Modules, + Macros, Structs, - Unions, Enums, - Functions, - TypeDefinitions, - Statics, Constants, + Statics, Traits, + Functions, + TypeDefinitions, + Unions, Implementations, TypeMethods, Methods, StructFields, Variants, - Macros, - PrimitiveTypes, AssociatedTypes, AssociatedConstants, ForeignTypes, @@ -2439,6 +2439,38 @@ enum ItemSection { } impl ItemSection { + const ALL: &'static [Self] = { + use ItemSection::*; + // NOTE: The order here affects the order in the UI. + &[ + Reexports, + PrimitiveTypes, + Modules, + Macros, + Structs, + Enums, + Constants, + Statics, + Traits, + Functions, + TypeDefinitions, + Unions, + Implementations, + TypeMethods, + Methods, + StructFields, + Variants, + AssociatedTypes, + AssociatedConstants, + ForeignTypes, + Keywords, + OpaqueTypes, + AttributeMacros, + DeriveMacros, + TraitAliases, + ] + }; + fn id(self) -> &'static str { match self { Self::Reexports => "reexports", @@ -2534,39 +2566,13 @@ fn item_ty_to_section(ty: ItemType) -> ItemSection { fn sidebar_module(buf: &mut Buffer, items: &[clean::Item]) { let mut sidebar = String::new(); - let mut already_emitted_sections = FxHashSet::default(); - // ordering taken from item_module, reorder, where it prioritized elements in a certain order - // to print its headings - for &myty in &[ - ItemType::Import, - ItemType::Primitive, - ItemType::Module, - ItemType::Macro, - ItemType::Struct, - ItemType::Enum, - ItemType::Constant, - ItemType::Static, - ItemType::Trait, - ItemType::Function, - ItemType::Typedef, - ItemType::Union, - ItemType::Impl, - ItemType::TyMethod, - ItemType::Method, - ItemType::StructField, - ItemType::Variant, - ItemType::AssocType, - ItemType::AssocConst, - ItemType::ForeignType, - ItemType::Keyword, - ] { - if items.iter().any(|it| !it.is_stripped() && it.type_() == myty && it.name.is_some()) { - let sec = item_ty_to_section(myty); - if !already_emitted_sections.insert(sec) { - continue; - } - sidebar.push_str(&format!("
  • {}
  • ", sec.id(), sec.name())); - } + let item_sections_in_use: FxHashSet<_> = items + .iter() + .filter(|it| !it.is_stripped() && it.name.is_some()) + .map(|it| item_ty_to_section(it.type_())) + .collect(); + for &sec in ItemSection::ALL.iter().filter(|sec| item_sections_in_use.contains(sec)) { + sidebar.push_str(&format!("
  • {}
  • ", sec.id(), sec.name())); } if !sidebar.is_empty() { diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index e781e3c1ef476..6e466ae8218c7 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -222,7 +222,9 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl ) -> Ordering { let ty1 = i1.type_(); let ty2 = i2.type_(); - if ty1 != ty2 { + if item_ty_to_section(ty1) != item_ty_to_section(ty2) + || (ty1 != ty2 && (ty1 == ItemType::ExternCrate || ty2 == ItemType::ExternCrate)) + { return (reorder(ty1), idx1).cmp(&(reorder(ty2), idx2)); } let s1 = i1.stability(tcx).as_ref().map(|s| s.level); From 504f3f037d6c42606740637eb711a891d071bf53 Mon Sep 17 00:00:00 2001 From: Noah Lev Date: Fri, 7 Jan 2022 15:30:50 -0800 Subject: [PATCH 15/19] Title-case trait aliases section for consistency --- src/librustdoc/html/render/mod.rs | 2 +- src/test/rustdoc/trait_alias.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index 6dd730c3f8861..f3e46c93d2794 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -2527,7 +2527,7 @@ impl ItemSection { Self::OpaqueTypes => "Opaque Types", Self::AttributeMacros => "Attribute Macros", Self::DeriveMacros => "Derive Macros", - Self::TraitAliases => "Trait aliases", + Self::TraitAliases => "Trait Aliases", } } } diff --git a/src/test/rustdoc/trait_alias.rs b/src/test/rustdoc/trait_alias.rs index dec7fe3f6a5d9..a0c657d9a054d 100644 --- a/src/test/rustdoc/trait_alias.rs +++ b/src/test/rustdoc/trait_alias.rs @@ -8,7 +8,7 @@ use std::fmt::Debug; // @has foo/all.html '//a[@href="traitalias.Alias2.html"]' 'Alias2' // @has foo/all.html '//a[@href="traitalias.Foo.html"]' 'Foo' -// @has foo/index.html '//h2[@id="trait-aliases"]' 'Trait aliases' +// @has foo/index.html '//h2[@id="trait-aliases"]' 'Trait Aliases' // @has foo/index.html '//a[@class="traitalias"]' 'CopyAlias' // @has foo/index.html '//a[@class="traitalias"]' 'Alias2' // @has foo/index.html '//a[@class="traitalias"]' 'Foo' From 69cd826a85fe046ea102f3144f66b5b4b1b8accf Mon Sep 17 00:00:00 2001 From: Tyler Mandry Date: Tue, 8 Feb 2022 01:56:53 +0000 Subject: [PATCH 16/19] Add llvm.build-config option --- config.toml.example | 3 +++ src/bootstrap/config.rs | 4 ++++ src/bootstrap/native.rs | 4 ++++ 3 files changed, 11 insertions(+) diff --git a/config.toml.example b/config.toml.example index f24f8e81a7944..8e7b40b22481d 100644 --- a/config.toml.example +++ b/config.toml.example @@ -157,6 +157,9 @@ changelog-seen = 2 # Whether to build the clang compiler. #clang = false +# Custom CMake defines to set when building LLVM. +#build-config = {} + # ============================================================================= # General build configuration options # ============================================================================= diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs index 683cfc630e771..d6f77fe6cd6d0 100644 --- a/src/bootstrap/config.rs +++ b/src/bootstrap/config.rs @@ -108,6 +108,7 @@ pub struct Config { pub llvm_polly: bool, pub llvm_clang: bool, pub llvm_from_ci: bool, + pub llvm_build_config: HashMap, pub use_lld: bool, pub lld_enabled: bool, @@ -477,6 +478,7 @@ derive_merge! { polly: Option, clang: Option, download_ci_llvm: Option, + build_config: Option>, } } @@ -807,6 +809,7 @@ impl Config { config.llvm_allow_old_toolchain = llvm.allow_old_toolchain.unwrap_or(false); config.llvm_polly = llvm.polly.unwrap_or(false); config.llvm_clang = llvm.clang.unwrap_or(false); + config.llvm_build_config = llvm.build_config.clone().unwrap_or(Default::default()); config.llvm_from_ci = match llvm.download_ci_llvm { Some(StringOrBool::String(s)) => { assert!(s == "if-available", "unknown option `{}` for download-ci-llvm", s); @@ -876,6 +879,7 @@ impl Config { check_ci_llvm!(llvm.allow_old_toolchain); check_ci_llvm!(llvm.polly); check_ci_llvm!(llvm.clang); + check_ci_llvm!(llvm.build_config); check_ci_llvm!(llvm.plugins); // CI-built LLVM can be either dynamic or static. diff --git a/src/bootstrap/native.rs b/src/bootstrap/native.rs index 4a754e6da1209..14de1531f73ab 100644 --- a/src/bootstrap/native.rs +++ b/src/bootstrap/native.rs @@ -353,6 +353,10 @@ impl Step for Llvm { configure_cmake(builder, target, &mut cfg, true); + for (key, val) in &builder.config.llvm_build_config { + cfg.define(key, val); + } + // FIXME: we don't actually need to build all LLVM tools and all LLVM // libraries here, e.g., we just want a few components and a few // tools. Figure out how to filter them down and only build the right From bdc9508bb6e227979045c5ba3937151635a32ec0 Mon Sep 17 00:00:00 2001 From: Tomoaki Kawada Date: Wed, 9 Feb 2022 14:34:27 +0900 Subject: [PATCH 17/19] kmc-solid: Fix wait queue manipulation errors in the `Condvar` implementation --- library/std/src/sys/itron/condvar.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/library/std/src/sys/itron/condvar.rs b/library/std/src/sys/itron/condvar.rs index dac4b8abfc47f..84b0f4c866ab2 100644 --- a/library/std/src/sys/itron/condvar.rs +++ b/library/std/src/sys/itron/condvar.rs @@ -15,10 +15,12 @@ unsafe impl Sync for Condvar {} pub type MovableCondvar = Condvar; impl Condvar { + #[inline] pub const fn new() -> Condvar { Condvar { waiters: SpinMutex::new(waiter_queue::WaiterQueue::new()) } } + #[inline] pub unsafe fn init(&mut self) {} pub unsafe fn notify_one(&self) { @@ -206,7 +208,7 @@ mod waiter_queue { if let Some(mut insert_after) = insert_after { // Insert `waiter` after `insert_after` - let insert_before = insert_after.as_ref().prev; + let insert_before = insert_after.as_ref().next; waiter.prev = Some(insert_after); insert_after.as_mut().next = Some(waiter_ptr); @@ -214,6 +216,8 @@ mod waiter_queue { waiter.next = insert_before; if let Some(mut insert_before) = insert_before { insert_before.as_mut().prev = Some(waiter_ptr); + } else { + head.last = waiter_ptr; } } else { // Insert `waiter` to the front @@ -240,11 +244,11 @@ mod waiter_queue { match (waiter.prev, waiter.next) { (Some(mut prev), Some(mut next)) => { prev.as_mut().next = Some(next); - next.as_mut().next = Some(prev); + next.as_mut().prev = Some(prev); } (None, Some(mut next)) => { head.first = next; - next.as_mut().next = None; + next.as_mut().prev = None; } (Some(mut prev), None) => { prev.as_mut().next = None; @@ -271,6 +275,7 @@ mod waiter_queue { unsafe { waiter.as_ref().task != 0 } } + #[inline] pub fn pop_front(&mut self) -> Option { unsafe { let head = self.head.as_mut()?; From 1d180caf1a14b3316652fa856499e44abec393b2 Mon Sep 17 00:00:00 2001 From: Tomoaki Kawada Date: Thu, 10 Feb 2022 11:26:46 +0900 Subject: [PATCH 18/19] kmc-solid: Wait queue should be sorted in the descending order of task priorities In ITRON, lower priority values mean higher priorities. --- library/std/src/sys/itron/condvar.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/std/src/sys/itron/condvar.rs b/library/std/src/sys/itron/condvar.rs index 84b0f4c866ab2..2992a6a542901 100644 --- a/library/std/src/sys/itron/condvar.rs +++ b/library/std/src/sys/itron/condvar.rs @@ -192,7 +192,7 @@ mod waiter_queue { let insert_after = { let mut cursor = head.last; loop { - if waiter.priority <= cursor.as_ref().priority { + if waiter.priority >= cursor.as_ref().priority { // `cursor` and all previous waiters have the same or higher // priority than `current_task_priority`. Insert the new // waiter right after `cursor`. From 76c562f3b30e0d033902d004fdb0069d5584d78a Mon Sep 17 00:00:00 2001 From: lcnr Date: Wed, 9 Feb 2022 12:29:43 +0100 Subject: [PATCH 19/19] fix min_const_generics oversight --- compiler/rustc_typeck/src/astconv/mod.rs | 25 ++++++++++++++++--- .../forbid-self-no-normalize.rs | 15 +++++++++++ .../forbid-self-no-normalize.stderr | 14 +++++++++++ 3 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 src/test/ui/const-generics/min_const_generics/forbid-self-no-normalize.rs create mode 100644 src/test/ui/const-generics/min_const_generics/forbid-self-no-normalize.stderr diff --git a/compiler/rustc_typeck/src/astconv/mod.rs b/compiler/rustc_typeck/src/astconv/mod.rs index 0ad2242f6677c..aa054043c4e88 100644 --- a/compiler/rustc_typeck/src/astconv/mod.rs +++ b/compiler/rustc_typeck/src/astconv/mod.rs @@ -2281,8 +2281,27 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { assert_eq!(opt_self_ty, None); self.prohibit_generics(path.segments); // Try to evaluate any array length constants. - let normalized_ty = self.normalize_ty(span, tcx.at(span).type_of(def_id)); - if forbid_generic && normalized_ty.needs_subst() { + let ty = tcx.at(span).type_of(def_id); + // HACK(min_const_generics): Forbid generic `Self` types + // here as we can't easily do that during nameres. + // + // We do this before normalization as we otherwise allow + // ```rust + // trait AlwaysApplicable { type Assoc; } + // impl AlwaysApplicable for T { type Assoc = usize; } + // + // trait BindsParam { + // type ArrayTy; + // } + // impl BindsParam for ::Assoc { + // type ArrayTy = [u8; Self::MAX]; + // } + // ``` + // Note that the normalization happens in the param env of + // the anon const, which is empty. This is why the + // `AlwaysApplicable` impl needs a `T: ?Sized` bound for + // this to compile if we were to normalize here. + if forbid_generic && ty.needs_subst() { let mut err = tcx.sess.struct_span_err( path.span, "generic `Self` types are currently not permitted in anonymous constants", @@ -2297,7 +2316,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { err.emit(); tcx.ty_error() } else { - normalized_ty + self.normalize_ty(span, ty) } } Res::Def(DefKind::AssocTy, def_id) => { diff --git a/src/test/ui/const-generics/min_const_generics/forbid-self-no-normalize.rs b/src/test/ui/const-generics/min_const_generics/forbid-self-no-normalize.rs new file mode 100644 index 0000000000000..e1cf7b579aa5a --- /dev/null +++ b/src/test/ui/const-generics/min_const_generics/forbid-self-no-normalize.rs @@ -0,0 +1,15 @@ +trait AlwaysApplicable { + type Assoc; +} +impl AlwaysApplicable for T { + type Assoc = usize; +} + +trait BindsParam { + type ArrayTy; +} +impl BindsParam for ::Assoc { + type ArrayTy = [u8; Self::MAX]; //~ ERROR generic `Self` types +} + +fn main() {} diff --git a/src/test/ui/const-generics/min_const_generics/forbid-self-no-normalize.stderr b/src/test/ui/const-generics/min_const_generics/forbid-self-no-normalize.stderr new file mode 100644 index 0000000000000..bda8859700680 --- /dev/null +++ b/src/test/ui/const-generics/min_const_generics/forbid-self-no-normalize.stderr @@ -0,0 +1,14 @@ +error: generic `Self` types are currently not permitted in anonymous constants + --> $DIR/forbid-self-no-normalize.rs:12:25 + | +LL | type ArrayTy = [u8; Self::MAX]; + | ^^^^ + | +note: not a concrete type + --> $DIR/forbid-self-no-normalize.rs:11:27 + | +LL | impl BindsParam for ::Assoc { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to previous error +