From f23d0b9c9dd42ef9153a8b86eecb0fd2fe62b6db Mon Sep 17 00:00:00 2001 From: onur-ozkan Date: Sat, 21 Sep 2024 07:34:34 +0300 Subject: [PATCH 1/8] move enzyme flags from general cargo to rustc-specific cargo Signed-off-by: onur-ozkan --- src/bootstrap/src/core/build_steps/compile.rs | 4 ++++ src/bootstrap/src/core/builder.rs | 6 ------ 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/bootstrap/src/core/build_steps/compile.rs b/src/bootstrap/src/core/build_steps/compile.rs index e1ab1e7599e84..db7b239c0ae29 100644 --- a/src/bootstrap/src/core/build_steps/compile.rs +++ b/src/bootstrap/src/core/build_steps/compile.rs @@ -1057,6 +1057,10 @@ pub fn rustc_cargo( // killed, rather than having an error bubble up and cause a panic. cargo.rustflag("-Zon-broken-pipe=kill"); + if builder.config.llvm_enzyme { + cargo.rustflag("-l").rustflag("Enzyme-19"); + } + // We currently don't support cross-crate LTO in stage0. This also isn't hugely necessary // and may just be a time sink. if compiler.stage != 0 { diff --git a/src/bootstrap/src/core/builder.rs b/src/bootstrap/src/core/builder.rs index 003b11ec7cff4..ef020b00aa5a4 100644 --- a/src/bootstrap/src/core/builder.rs +++ b/src/bootstrap/src/core/builder.rs @@ -1591,12 +1591,6 @@ impl<'a> Builder<'a> { rustflags.arg(sysroot_str); } - // https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/.E2.9C.94.20link.20new.20library.20into.20stage1.2Frustc - if self.config.llvm_enzyme { - rustflags.arg("-l"); - rustflags.arg("Enzyme-19"); - } - let use_new_symbol_mangling = match self.config.rust_new_symbol_mangling { Some(setting) => { // If an explicit setting is given, use that From a35da65409c8a4c834b5df35d8955e287ae569e1 Mon Sep 17 00:00:00 2001 From: Veera Date: Sat, 21 Sep 2024 11:11:11 -0400 Subject: [PATCH 2/8] Update Tests --- .../evade-deduplication-issue-118612.rs | 24 +++++++++++++++++++ .../evade-deduplication-issue-118612.stderr | 20 ++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 tests/ui/consts/const-eval/stable-metric/evade-deduplication-issue-118612.rs create mode 100644 tests/ui/consts/const-eval/stable-metric/evade-deduplication-issue-118612.stderr diff --git a/tests/ui/consts/const-eval/stable-metric/evade-deduplication-issue-118612.rs b/tests/ui/consts/const-eval/stable-metric/evade-deduplication-issue-118612.rs new file mode 100644 index 0000000000000..a2d34eaa384c9 --- /dev/null +++ b/tests/ui/consts/const-eval/stable-metric/evade-deduplication-issue-118612.rs @@ -0,0 +1,24 @@ +//@ check-pass + +#![allow(long_running_const_eval)] + +//@ compile-flags: -Z tiny-const-eval-limit -Z deduplicate-diagnostics=yes +const FOO: () = { + let mut i = 0; + loop { + //~^ WARN is taking a long time + //~| WARN is taking a long time + //~| WARN is taking a long time + //~| WARN is taking a long time + //~| WARN is taking a long time + if i == 1000 { + break; + } else { + i += 1; + } + } +}; + +fn main() { + FOO +} diff --git a/tests/ui/consts/const-eval/stable-metric/evade-deduplication-issue-118612.stderr b/tests/ui/consts/const-eval/stable-metric/evade-deduplication-issue-118612.stderr new file mode 100644 index 0000000000000..b894b7b2132df --- /dev/null +++ b/tests/ui/consts/const-eval/stable-metric/evade-deduplication-issue-118612.stderr @@ -0,0 +1,20 @@ +warning: constant evaluation is taking a long time + --> $DIR/evade-deduplication-issue-118612.rs:8:5 + | +LL | / loop { +LL | | +LL | | +LL | | +... | +LL | | } +LL | | } + | |_____^ the const evaluator is currently interpreting this expression + | +help: the constant being evaluated + --> $DIR/evade-deduplication-issue-118612.rs:6:1 + | +LL | const FOO: () = { + | ^^^^^^^^^^^^^ + +warning: 1 warning emitted + From 669f610f741f41bc8b2bef41d088589db4180355 Mon Sep 17 00:00:00 2001 From: Veera Date: Sat, 21 Sep 2024 11:23:34 -0400 Subject: [PATCH 3/8] Prevent Deduplication of `LongRunningWarn` --- .../src/const_eval/machine.rs | 9 ++- compiler/rustc_const_eval/src/errors.rs | 2 + .../evade-deduplication-issue-118612.stderr | 74 ++++++++++++++++++- 3 files changed, 83 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_const_eval/src/const_eval/machine.rs b/compiler/rustc_const_eval/src/const_eval/machine.rs index 7405ca09342da..2025a465a2289 100644 --- a/compiler/rustc_const_eval/src/const_eval/machine.rs +++ b/compiler/rustc_const_eval/src/const_eval/machine.rs @@ -641,7 +641,14 @@ impl<'tcx> interpret::Machine<'tcx> for CompileTimeMachine<'tcx> { // current number of evaluated terminators is a power of 2. The latter gives us a cheap // way to implement exponential backoff. let span = ecx.cur_span(); - ecx.tcx.dcx().emit_warn(LongRunningWarn { span, item_span: ecx.tcx.span }); + // We store a unique number in `force_duplicate` to evade `-Z deduplicate-diagnostics`. + // `new_steps` is guaranteed to be unique because `ecx.machine.num_evaluated_steps` is + // always increasing. + ecx.tcx.dcx().emit_warn(LongRunningWarn { + span, + item_span: ecx.tcx.span, + force_duplicate: new_steps, + }); } } diff --git a/compiler/rustc_const_eval/src/errors.rs b/compiler/rustc_const_eval/src/errors.rs index 0b366b43f95f6..bdd8c66bc244d 100644 --- a/compiler/rustc_const_eval/src/errors.rs +++ b/compiler/rustc_const_eval/src/errors.rs @@ -243,6 +243,8 @@ pub struct LongRunningWarn { pub span: Span, #[help] pub item_span: Span, + // Used for evading `-Z deduplicate-diagnostics`. + pub force_duplicate: usize, } #[derive(Subdiagnostic)] diff --git a/tests/ui/consts/const-eval/stable-metric/evade-deduplication-issue-118612.stderr b/tests/ui/consts/const-eval/stable-metric/evade-deduplication-issue-118612.stderr index b894b7b2132df..cb19c59b15bc0 100644 --- a/tests/ui/consts/const-eval/stable-metric/evade-deduplication-issue-118612.stderr +++ b/tests/ui/consts/const-eval/stable-metric/evade-deduplication-issue-118612.stderr @@ -16,5 +16,77 @@ help: the constant being evaluated LL | const FOO: () = { | ^^^^^^^^^^^^^ -warning: 1 warning emitted +warning: constant evaluation is taking a long time + --> $DIR/evade-deduplication-issue-118612.rs:8:5 + | +LL | / loop { +LL | | +LL | | +LL | | +... | +LL | | } +LL | | } + | |_____^ the const evaluator is currently interpreting this expression + | +help: the constant being evaluated + --> $DIR/evade-deduplication-issue-118612.rs:6:1 + | +LL | const FOO: () = { + | ^^^^^^^^^^^^^ + +warning: constant evaluation is taking a long time + --> $DIR/evade-deduplication-issue-118612.rs:8:5 + | +LL | / loop { +LL | | +LL | | +LL | | +... | +LL | | } +LL | | } + | |_____^ the const evaluator is currently interpreting this expression + | +help: the constant being evaluated + --> $DIR/evade-deduplication-issue-118612.rs:6:1 + | +LL | const FOO: () = { + | ^^^^^^^^^^^^^ + +warning: constant evaluation is taking a long time + --> $DIR/evade-deduplication-issue-118612.rs:8:5 + | +LL | / loop { +LL | | +LL | | +LL | | +... | +LL | | } +LL | | } + | |_____^ the const evaluator is currently interpreting this expression + | +help: the constant being evaluated + --> $DIR/evade-deduplication-issue-118612.rs:6:1 + | +LL | const FOO: () = { + | ^^^^^^^^^^^^^ + +warning: constant evaluation is taking a long time + --> $DIR/evade-deduplication-issue-118612.rs:8:5 + | +LL | / loop { +LL | | +LL | | +LL | | +... | +LL | | } +LL | | } + | |_____^ the const evaluator is currently interpreting this expression + | +help: the constant being evaluated + --> $DIR/evade-deduplication-issue-118612.rs:6:1 + | +LL | const FOO: () = { + | ^^^^^^^^^^^^^ + +warning: 5 warnings emitted From 114093cdf16867935fa6cda74350f9eb09c4d926 Mon Sep 17 00:00:00 2001 From: BlackHoleFox Date: Sat, 21 Sep 2024 00:22:14 -0500 Subject: [PATCH 4/8] Fixup Apple target's description strings --- compiler/rustc_target/src/spec/targets/aarch64_apple_darwin.rs | 2 +- compiler/rustc_target/src/spec/targets/aarch64_apple_ios.rs | 2 +- .../rustc_target/src/spec/targets/aarch64_apple_ios_macabi.rs | 2 +- compiler/rustc_target/src/spec/targets/aarch64_apple_ios_sim.rs | 2 +- compiler/rustc_target/src/spec/targets/aarch64_apple_tvos.rs | 2 +- .../rustc_target/src/spec/targets/aarch64_apple_tvos_sim.rs | 2 +- compiler/rustc_target/src/spec/targets/aarch64_apple_watchos.rs | 2 +- .../rustc_target/src/spec/targets/aarch64_apple_watchos_sim.rs | 2 +- .../rustc_target/src/spec/targets/arm64_32_apple_watchos.rs | 2 +- compiler/rustc_target/src/spec/targets/armv7s_apple_ios.rs | 2 +- compiler/rustc_target/src/spec/targets/i386_apple_ios.rs | 2 +- compiler/rustc_target/src/spec/targets/i686_apple_darwin.rs | 2 +- compiler/rustc_target/src/spec/targets/x86_64_apple_darwin.rs | 2 +- compiler/rustc_target/src/spec/targets/x86_64_apple_ios.rs | 2 +- .../rustc_target/src/spec/targets/x86_64_apple_ios_macabi.rs | 2 +- compiler/rustc_target/src/spec/targets/x86_64_apple_tvos.rs | 2 +- .../rustc_target/src/spec/targets/x86_64_apple_watchos_sim.rs | 2 +- compiler/rustc_target/src/spec/targets/x86_64h_apple_darwin.rs | 2 +- 18 files changed, 18 insertions(+), 18 deletions(-) diff --git a/compiler/rustc_target/src/spec/targets/aarch64_apple_darwin.rs b/compiler/rustc_target/src/spec/targets/aarch64_apple_darwin.rs index 1061633be175f..7af7de60fcbb1 100644 --- a/compiler/rustc_target/src/spec/targets/aarch64_apple_darwin.rs +++ b/compiler/rustc_target/src/spec/targets/aarch64_apple_darwin.rs @@ -6,7 +6,7 @@ pub(crate) fn target() -> Target { Target { llvm_target, metadata: crate::spec::TargetMetadata { - description: Some("ARM64 macOS (11.0+, Big Sur+)".into()), + description: Some("ARM64 Apple macOS (11.0+, Big Sur+)".into()), tier: Some(1), host_tools: Some(true), std: Some(true), diff --git a/compiler/rustc_target/src/spec/targets/aarch64_apple_ios.rs b/compiler/rustc_target/src/spec/targets/aarch64_apple_ios.rs index caeb9a121e48b..499f05d9ee6d6 100644 --- a/compiler/rustc_target/src/spec/targets/aarch64_apple_ios.rs +++ b/compiler/rustc_target/src/spec/targets/aarch64_apple_ios.rs @@ -6,7 +6,7 @@ pub(crate) fn target() -> Target { Target { llvm_target, metadata: crate::spec::TargetMetadata { - description: Some("ARM64 iOS".into()), + description: Some("ARM64 Apple iOS".into()), tier: Some(2), host_tools: Some(false), std: Some(true), diff --git a/compiler/rustc_target/src/spec/targets/aarch64_apple_ios_macabi.rs b/compiler/rustc_target/src/spec/targets/aarch64_apple_ios_macabi.rs index eee9eca3bcbeb..0fd5d0f83d274 100644 --- a/compiler/rustc_target/src/spec/targets/aarch64_apple_ios_macabi.rs +++ b/compiler/rustc_target/src/spec/targets/aarch64_apple_ios_macabi.rs @@ -6,7 +6,7 @@ pub(crate) fn target() -> Target { Target { llvm_target, metadata: crate::spec::TargetMetadata { - description: Some("Apple Catalyst on ARM64".into()), + description: Some("ARM64 Apple Mac Catalyst".into()), tier: Some(2), host_tools: Some(false), std: Some(true), diff --git a/compiler/rustc_target/src/spec/targets/aarch64_apple_ios_sim.rs b/compiler/rustc_target/src/spec/targets/aarch64_apple_ios_sim.rs index ee58038301d4a..0f58d4e273083 100644 --- a/compiler/rustc_target/src/spec/targets/aarch64_apple_ios_sim.rs +++ b/compiler/rustc_target/src/spec/targets/aarch64_apple_ios_sim.rs @@ -6,7 +6,7 @@ pub(crate) fn target() -> Target { Target { llvm_target, metadata: crate::spec::TargetMetadata { - description: Some("Apple iOS Simulator on ARM64".into()), + description: Some("ARM64 Apple iOS Simulator".into()), tier: Some(2), host_tools: Some(false), std: Some(true), diff --git a/compiler/rustc_target/src/spec/targets/aarch64_apple_tvos.rs b/compiler/rustc_target/src/spec/targets/aarch64_apple_tvos.rs index baca863d442ba..49c7b30817db1 100644 --- a/compiler/rustc_target/src/spec/targets/aarch64_apple_tvos.rs +++ b/compiler/rustc_target/src/spec/targets/aarch64_apple_tvos.rs @@ -6,7 +6,7 @@ pub(crate) fn target() -> Target { Target { llvm_target, metadata: crate::spec::TargetMetadata { - description: Some("ARM64 tvOS".into()), + description: Some("ARM64 Apple tvOS".into()), tier: Some(3), host_tools: Some(false), std: Some(true), diff --git a/compiler/rustc_target/src/spec/targets/aarch64_apple_tvos_sim.rs b/compiler/rustc_target/src/spec/targets/aarch64_apple_tvos_sim.rs index 1a48f8c5acffb..2cb2d0b3fff16 100644 --- a/compiler/rustc_target/src/spec/targets/aarch64_apple_tvos_sim.rs +++ b/compiler/rustc_target/src/spec/targets/aarch64_apple_tvos_sim.rs @@ -6,7 +6,7 @@ pub(crate) fn target() -> Target { Target { llvm_target, metadata: crate::spec::TargetMetadata { - description: Some("ARM64 tvOS Simulator".into()), + description: Some("ARM64 Apple tvOS Simulator".into()), tier: Some(3), host_tools: Some(false), std: Some(true), diff --git a/compiler/rustc_target/src/spec/targets/aarch64_apple_watchos.rs b/compiler/rustc_target/src/spec/targets/aarch64_apple_watchos.rs index 1940a568b3960..6233febd8c59c 100644 --- a/compiler/rustc_target/src/spec/targets/aarch64_apple_watchos.rs +++ b/compiler/rustc_target/src/spec/targets/aarch64_apple_watchos.rs @@ -6,7 +6,7 @@ pub(crate) fn target() -> Target { Target { llvm_target, metadata: crate::spec::TargetMetadata { - description: Some("ARM64 Apple WatchOS".into()), + description: Some("ARM64 Apple watchOS".into()), tier: Some(3), host_tools: Some(false), std: Some(true), diff --git a/compiler/rustc_target/src/spec/targets/aarch64_apple_watchos_sim.rs b/compiler/rustc_target/src/spec/targets/aarch64_apple_watchos_sim.rs index 6beef11c5041f..64d24b8a075a4 100644 --- a/compiler/rustc_target/src/spec/targets/aarch64_apple_watchos_sim.rs +++ b/compiler/rustc_target/src/spec/targets/aarch64_apple_watchos_sim.rs @@ -6,7 +6,7 @@ pub(crate) fn target() -> Target { Target { llvm_target, metadata: crate::spec::TargetMetadata { - description: Some("ARM64 Apple WatchOS Simulator".into()), + description: Some("ARM64 Apple watchOS Simulator".into()), tier: Some(3), host_tools: Some(false), std: Some(true), diff --git a/compiler/rustc_target/src/spec/targets/arm64_32_apple_watchos.rs b/compiler/rustc_target/src/spec/targets/arm64_32_apple_watchos.rs index e9f4d9330d5f2..60b1c1db63aa9 100644 --- a/compiler/rustc_target/src/spec/targets/arm64_32_apple_watchos.rs +++ b/compiler/rustc_target/src/spec/targets/arm64_32_apple_watchos.rs @@ -6,7 +6,7 @@ pub(crate) fn target() -> Target { Target { llvm_target, metadata: crate::spec::TargetMetadata { - description: Some("Arm Apple WatchOS 64-bit with 32-bit pointers".into()), + description: Some("ARM64 Apple watchOS with 32-bit pointers".into()), tier: Some(3), host_tools: Some(false), std: Some(true), diff --git a/compiler/rustc_target/src/spec/targets/armv7s_apple_ios.rs b/compiler/rustc_target/src/spec/targets/armv7s_apple_ios.rs index deee6985f1a43..5af760f68ef02 100644 --- a/compiler/rustc_target/src/spec/targets/armv7s_apple_ios.rs +++ b/compiler/rustc_target/src/spec/targets/armv7s_apple_ios.rs @@ -6,7 +6,7 @@ pub(crate) fn target() -> Target { Target { llvm_target, metadata: crate::spec::TargetMetadata { - description: Some("Armv7-A Apple-A6 Apple iOS".into()), + description: Some("ARMv7-A Apple-A6 Apple iOS".into()), tier: Some(3), host_tools: Some(false), std: Some(true), diff --git a/compiler/rustc_target/src/spec/targets/i386_apple_ios.rs b/compiler/rustc_target/src/spec/targets/i386_apple_ios.rs index dc14cb3ec767f..7078b57e98b77 100644 --- a/compiler/rustc_target/src/spec/targets/i386_apple_ios.rs +++ b/compiler/rustc_target/src/spec/targets/i386_apple_ios.rs @@ -8,7 +8,7 @@ pub(crate) fn target() -> Target { Target { llvm_target, metadata: crate::spec::TargetMetadata { - description: Some("32-bit x86 iOS".into()), + description: Some("x86 Apple iOS Simulator".into()), tier: Some(3), host_tools: Some(false), std: Some(true), diff --git a/compiler/rustc_target/src/spec/targets/i686_apple_darwin.rs b/compiler/rustc_target/src/spec/targets/i686_apple_darwin.rs index 3e27f1f899b72..9d9a8fc630528 100644 --- a/compiler/rustc_target/src/spec/targets/i686_apple_darwin.rs +++ b/compiler/rustc_target/src/spec/targets/i686_apple_darwin.rs @@ -6,7 +6,7 @@ pub(crate) fn target() -> Target { Target { llvm_target, metadata: crate::spec::TargetMetadata { - description: Some("32-bit macOS (10.12+, Sierra+)".into()), + description: Some("x86 Apple macOS (10.12+, Sierra+)".into()), tier: Some(3), host_tools: Some(true), std: Some(true), diff --git a/compiler/rustc_target/src/spec/targets/x86_64_apple_darwin.rs b/compiler/rustc_target/src/spec/targets/x86_64_apple_darwin.rs index 4304dfc3f682d..70211722fa2b4 100644 --- a/compiler/rustc_target/src/spec/targets/x86_64_apple_darwin.rs +++ b/compiler/rustc_target/src/spec/targets/x86_64_apple_darwin.rs @@ -6,7 +6,7 @@ pub(crate) fn target() -> Target { Target { llvm_target, metadata: crate::spec::TargetMetadata { - description: Some("64-bit macOS (10.12+, Sierra+)".into()), + description: Some("x86_64 Apple macOS (10.12+, Sierra+)".into()), tier: Some(1), host_tools: Some(true), std: Some(true), diff --git a/compiler/rustc_target/src/spec/targets/x86_64_apple_ios.rs b/compiler/rustc_target/src/spec/targets/x86_64_apple_ios.rs index 847c4f011f9f5..c021762aed0e0 100644 --- a/compiler/rustc_target/src/spec/targets/x86_64_apple_ios.rs +++ b/compiler/rustc_target/src/spec/targets/x86_64_apple_ios.rs @@ -8,7 +8,7 @@ pub(crate) fn target() -> Target { Target { llvm_target, metadata: crate::spec::TargetMetadata { - description: Some("64-bit x86 iOS".into()), + description: Some("x86_64 Apple iOS Simulator".into()), tier: Some(2), host_tools: Some(false), std: Some(true), diff --git a/compiler/rustc_target/src/spec/targets/x86_64_apple_ios_macabi.rs b/compiler/rustc_target/src/spec/targets/x86_64_apple_ios_macabi.rs index 042079f800b97..a7ba81303cf58 100644 --- a/compiler/rustc_target/src/spec/targets/x86_64_apple_ios_macabi.rs +++ b/compiler/rustc_target/src/spec/targets/x86_64_apple_ios_macabi.rs @@ -6,7 +6,7 @@ pub(crate) fn target() -> Target { Target { llvm_target, metadata: crate::spec::TargetMetadata { - description: Some("Apple Catalyst on x86_64".into()), + description: Some("x86_64 Apple Mac Catalyst".into()), tier: Some(2), host_tools: Some(false), std: Some(true), diff --git a/compiler/rustc_target/src/spec/targets/x86_64_apple_tvos.rs b/compiler/rustc_target/src/spec/targets/x86_64_apple_tvos.rs index 947086097908c..d81220b6b31b1 100644 --- a/compiler/rustc_target/src/spec/targets/x86_64_apple_tvos.rs +++ b/compiler/rustc_target/src/spec/targets/x86_64_apple_tvos.rs @@ -8,7 +8,7 @@ pub(crate) fn target() -> Target { Target { llvm_target, metadata: crate::spec::TargetMetadata { - description: Some("x86 64-bit tvOS".into()), + description: Some("x86_64 Apple tvOS Simulator".into()), tier: Some(3), host_tools: Some(false), std: Some(true), diff --git a/compiler/rustc_target/src/spec/targets/x86_64_apple_watchos_sim.rs b/compiler/rustc_target/src/spec/targets/x86_64_apple_watchos_sim.rs index 1dab95988601d..c7333a0bbcc36 100644 --- a/compiler/rustc_target/src/spec/targets/x86_64_apple_watchos_sim.rs +++ b/compiler/rustc_target/src/spec/targets/x86_64_apple_watchos_sim.rs @@ -6,7 +6,7 @@ pub(crate) fn target() -> Target { Target { llvm_target, metadata: crate::spec::TargetMetadata { - description: Some("x86 64-bit Apple WatchOS simulator".into()), + description: Some("x86_64 Apple watchOS Simulator".into()), tier: Some(3), host_tools: Some(false), std: Some(true), diff --git a/compiler/rustc_target/src/spec/targets/x86_64h_apple_darwin.rs b/compiler/rustc_target/src/spec/targets/x86_64h_apple_darwin.rs index 9fb5a46187a31..e3550b6e11f74 100644 --- a/compiler/rustc_target/src/spec/targets/x86_64h_apple_darwin.rs +++ b/compiler/rustc_target/src/spec/targets/x86_64h_apple_darwin.rs @@ -29,7 +29,7 @@ pub(crate) fn target() -> Target { Target { llvm_target, metadata: crate::spec::TargetMetadata { - description: Some("macOS with late-gen Intel (at least Haswell)".into()), + description: Some("x86_64 Apple macOS with Intel Haswell+".into()), tier: Some(3), host_tools: Some(true), std: Some(true), From e62b5e64a3f5ad34259d8d6ae4ad031083fa6692 Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Sat, 21 Sep 2024 08:52:50 -0700 Subject: [PATCH 5/8] tests: Test that `extern "C" fn` ptrs lint on slices --- tests/ui/lint/extern-C-fnptr-lints-slices.rs | 9 +++++++++ tests/ui/lint/extern-C-fnptr-lints-slices.stderr | 16 ++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 tests/ui/lint/extern-C-fnptr-lints-slices.rs create mode 100644 tests/ui/lint/extern-C-fnptr-lints-slices.stderr diff --git a/tests/ui/lint/extern-C-fnptr-lints-slices.rs b/tests/ui/lint/extern-C-fnptr-lints-slices.rs new file mode 100644 index 0000000000000..0c35eb37a4890 --- /dev/null +++ b/tests/ui/lint/extern-C-fnptr-lints-slices.rs @@ -0,0 +1,9 @@ +#[deny(improper_ctypes_definitions)] + +// It's an improper ctype (a slice) arg in an extern "C" fnptr. + +pub type F = extern "C" fn(&[u8]); +//~^ ERROR: `extern` fn uses type `[u8]`, which is not FFI-safe + + +fn main() {} diff --git a/tests/ui/lint/extern-C-fnptr-lints-slices.stderr b/tests/ui/lint/extern-C-fnptr-lints-slices.stderr new file mode 100644 index 0000000000000..d13f93ca96f22 --- /dev/null +++ b/tests/ui/lint/extern-C-fnptr-lints-slices.stderr @@ -0,0 +1,16 @@ +error: `extern` fn uses type `[u8]`, which is not FFI-safe + --> $DIR/extern-C-fnptr-lints-slices.rs:5:14 + | +LL | pub type F = extern "C" fn(&[u8]); + | ^^^^^^^^^^^^^^^^^^^^ not FFI-safe + | + = help: consider using a raw pointer instead + = note: slices have no C equivalent +note: the lint level is defined here + --> $DIR/extern-C-fnptr-lints-slices.rs:1:8 + | +LL | #[deny(improper_ctypes_definitions)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 1 previous error + From 7c352665525f19d99d4564d461589f47c290ac57 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 21 Sep 2024 15:58:18 +0200 Subject: [PATCH 6/8] Strip last backline from non-rust code examples --- src/librustdoc/html/markdown.rs | 4 +++- src/librustdoc/html/markdown/tests.rs | 6 ++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs index 6f4665db6f1de..050ba60318e6a 100644 --- a/src/librustdoc/html/markdown.rs +++ b/src/librustdoc/html/markdown.rs @@ -261,7 +261,9 @@ impl<'a, I: Iterator>> Iterator for CodeBlocks<'_, 'a, I> { \ ", added_classes = added_classes.join(" "), - text = Escape(&original_text), + text = Escape( + original_text.strip_suffix('\n').unwrap_or(&original_text) + ), ) .into(), )); diff --git a/src/librustdoc/html/markdown/tests.rs b/src/librustdoc/html/markdown/tests.rs index e490099a92e14..3ec60c0efd216 100644 --- a/src/librustdoc/html/markdown/tests.rs +++ b/src/librustdoc/html/markdown/tests.rs @@ -524,15 +524,13 @@ fn test_ascii_with_prepending_hashtag() { ####.###..#....#....#..#. #..#.#....#....#....#..#. #..#.#....#....#....#..#. -#..#.####.####.####..##.. -", +#..#.####.####.####..##..", ); t( r#"```markdown # hello ```"#, "
\
-# hello
-
", +# hello", ); } From 54efd132aeac8e12c6b2b734ab6f1ac3002f09fb Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 21 Sep 2024 15:58:35 +0200 Subject: [PATCH 7/8] Generate line numbers for non-rust code examples as well --- src/librustdoc/html/static/js/main.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/librustdoc/html/static/js/main.js b/src/librustdoc/html/static/js/main.js index a0ec45b5ef38c..0eba80133df12 100644 --- a/src/librustdoc/html/static/js/main.js +++ b/src/librustdoc/html/static/js/main.js @@ -986,7 +986,13 @@ function preLoadCss(cssUrl) { }()); window.rustdoc_add_line_numbers_to_examples = () => { - onEachLazy(document.getElementsByClassName("rust-example-rendered"), x => { + if (document.querySelector(".rustdoc.src")) { + // We are in the source code page, nothing to be done here! + return; + } + onEachLazy(document.querySelectorAll( + ":not(.scraped-example) > .example-wrap > pre:not(.example-line-numbers)", + ), x => { const parent = x.parentNode; const line_numbers = parent.querySelectorAll(".example-line-numbers"); if (line_numbers.length > 0) { @@ -1005,12 +1011,8 @@ function preLoadCss(cssUrl) { }; window.rustdoc_remove_line_numbers_from_examples = () => { - onEachLazy(document.getElementsByClassName("rust-example-rendered"), x => { - const parent = x.parentNode; - const line_numbers = parent.querySelectorAll(".example-line-numbers"); - for (const node of line_numbers) { - parent.removeChild(node); - } + onEachLazy(document.querySelectorAll(".example-wrap > .example-line-numbers"), x => { + x.parentNode.removeChild(x); }); }; From f451a410e34c15befefdfed3195442f0de6ec052 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 21 Sep 2024 17:00:42 +0200 Subject: [PATCH 8/8] Add GUI regression test for non-rust code blocks line numbers --- .../docblock-code-block-line-number.goml | 67 +++++++++++++++++-- 1 file changed, 60 insertions(+), 7 deletions(-) diff --git a/tests/rustdoc-gui/docblock-code-block-line-number.goml b/tests/rustdoc-gui/docblock-code-block-line-number.goml index fed916ac24675..53f756dfcd64a 100644 --- a/tests/rustdoc-gui/docblock-code-block-line-number.goml +++ b/tests/rustdoc-gui/docblock-code-block-line-number.goml @@ -87,7 +87,7 @@ assert-css: ("#settings", {"display": "block"}) // Then, click the toggle button. click: "input#line-numbers" -wait-for: 100 // wait-for-false does not exist +wait-for: 100 // FIXME: `wait-for-false` does not exist assert-false: "pre.example-line-numbers" assert-local-storage: {"rustdoc-line-numbers": "false" } @@ -107,6 +107,8 @@ assert-css: ( click: "input#line-numbers" wait-for: "pre.example-line-numbers" assert-local-storage: {"rustdoc-line-numbers": "true" } +wait-for: 100 // FIXME: `wait-for-false` does not exist +assert: "pre.example-line-numbers" // Same check with scraped examples line numbers. go-to: "file://" + |DOC_PATH| + "/scrape_examples/fn.test_many.html" @@ -145,9 +147,6 @@ assert-css: ( ALL, ) -// Checking line numbers on scraped code examples. -go-to: "file://" + |DOC_PATH| + "/scrape_examples/fn.test_many.html" - define-function: ( "check-padding", [path, padding_bottom], @@ -157,19 +156,19 @@ define-function: ( "padding-bottom": "0px", "padding-left": "0px", "padding-right": "0px", - }) + }, ALL) assert-css: (|path| + " .src-line-numbers > pre", { "padding-top": "14px", "padding-bottom": |padding_bottom|, "padding-left": "0px", "padding-right": "0px", - }) + }, ALL) assert-css: (|path| + " .src-line-numbers > pre > span", { "padding-top": "0px", "padding-bottom": "0px", "padding-left": "8px", "padding-right": "8px", - }) + }, ALL) }, ) @@ -188,6 +187,35 @@ call-function: ("check-padding", { "padding_bottom": "14px", }) +define-function: ("check-line-numbers-existence", [], block { + assert-local-storage: {"rustdoc-line-numbers": "true" } + assert-false: ".example-line-numbers" + click: "#settings-menu" + wait-for: "#settings" + + // Then, click the toggle button. + click: "input#line-numbers" + wait-for: 100 // FIXME: `wait-for-false` does not exist + assert-local-storage-false: {"rustdoc-line-numbers": "true" } + assert-false: ".example-line-numbers" + // Line numbers should still be there. + assert: ".src-line-numbers" + // Now disabling the setting. + click: "input#line-numbers" + wait-for: 100 // FIXME: `wait-for-false` does not exist + assert-local-storage: {"rustdoc-line-numbers": "true" } + assert-false: ".example-line-numbers" + // Line numbers should still be there. + assert: ".src-line-numbers" + // Closing settings menu. + click: "#settings-menu" + wait-for-css: ("#settings", {"display": "none"}) +}) + +// Checking that turning off the line numbers setting won't remove line numbers from scraped +// examples. +call-function: ("check-line-numbers-existence", {}) + // Now checking the line numbers in the source code page. click: ".src" assert-css: (".src-line-numbers", { @@ -202,3 +230,28 @@ assert-css: (".src-line-numbers > a", { "padding-left": "8px", "padding-right": "8px", }) +// Checking that turning off the line numbers setting won't remove line numbers. +call-function: ("check-line-numbers-existence", {}) + +// Now checking that even non-rust code blocks have line numbers generated. +go-to: "file://" + |DOC_PATH| + "/lib2/sub_mod/struct.Foo.html" +assert-local-storage: {"rustdoc-line-numbers": "true" } +assert: ".example-wrap > pre.language-txt" +assert: ".example-wrap > pre.rust" +assert-count: (".example-wrap", 2) +assert-count: (".example-wrap > pre.example-line-numbers", 2) + +click: "#settings-menu" +wait-for: "#settings" + +// Then, click the toggle button. +click: "input#line-numbers" +wait-for: 100 // FIXME: `wait-for-false` does not exist +assert-local-storage-false: {"rustdoc-line-numbers": "true" } +assert-count: (".example-wrap > pre.example-line-numbers", 0) + +// Now turning off the setting. +click: "input#line-numbers" +wait-for: 100 // FIXME: `wait-for-false` does not exist +assert-local-storage: {"rustdoc-line-numbers": "true" } +assert-count: (".example-wrap > pre.example-line-numbers", 2)