From 847f1f71ab09c24fab8e088a1a3db0106288b671 Mon Sep 17 00:00:00 2001 From: Michal Fox Date: Tue, 29 Sep 2026 12:10:57 +0200 Subject: [PATCH] rustdoc: fix tooltip position of code examples inside warning blocks The tooltip of an `ignore`/`compile_fail`/`should_panic`/edition example is placed 25px to the left of the code block. Inside a `.warning` block that lands on top of the warning's own left border. --- src/librustdoc/html/static/css/rustdoc.css | 6 ++++++ tests/rustdoc-gui/src/test_docs/lib.rs | 8 ++++++++ tests/rustdoc-gui/warning-block.goml | 8 ++++++++ 3 files changed, 22 insertions(+) diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index 6e7a6da..27164c1 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -1818,6 +1818,12 @@ documentation. */ .top-doc > .docblock >.warning:first-child::before { top: 20px; } +.content .docblock .warning .example-wrap.compile_fail, +.content .docblock .warning .example-wrap.should_panic, +.content .docblock .warning .example-wrap.ignore, +.content .docblock .warning .example-wrap.edition { + margin-left: 25px; +} .example-wrap > a.test-arrow, .example-wrap .button-holder { visibility: hidden; diff --git a/tests/rustdoc-gui/src/test_docs/lib.rs b/tests/rustdoc-gui/src/test_docs/lib.rs index 54db340..b39c595 100644 --- a/tests/rustdoc-gui/src/test_docs/lib.rs +++ b/tests/rustdoc-gui/src/test_docs/lib.rs @@ -108,6 +108,14 @@ impl From for Foo { } ///
I have warnings!
+/// +///
+/// +/// ```ignore (it's a test) +/// let x = 12; +/// ``` +/// +///
pub struct WarningStruct; /// Just a normal enum. diff --git a/tests/rustdoc-gui/warning-block.goml b/tests/rustdoc-gui/warning-block.goml index 34207ed..b45c3ec 100644 --- a/tests/rustdoc-gui/warning-block.goml +++ b/tests/rustdoc-gui/warning-block.goml @@ -53,3 +53,11 @@ go-to: "file://" + |DOC_PATH| + "/test_docs/struct.WarningStruct.html" store-position: ("#doc-warning-0", {"y": warn_div_y}) store-position: ("#doc-warning-0::before", {"y": warn_y}) assert: |warn_y| == |warn_div_y| + |default_y_pos| + 15 + +// The tooltip of a code example inside a warning must not overlap the warning's left border. +store-position: ("#doc-warning-3", {"x": warn_x}) +store-position: ("#doc-warning-3 .example-wrap", {"x": code_x}) +store-position: ("#doc-warning-3 .example-wrap .tooltip", {"x": tooltip_x}) +store-size: ("#doc-warning-3 .example-wrap .tooltip", {"width": tooltip_width}) +assert: |tooltip_x| > |warn_x| + 2 +assert: |tooltip_x| + |tooltip_width| < |code_x|