Skip to content

Commit fe307c5

Browse files
Rollup merge of #150816 - method-anchor, r=camelid
Fix trait method anchor disappearing before user can click on it A good example of this bug is going to https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir_analysis/collect/struct.ItemCtxt.html#impl-HirTyLowerer%3C'tcx%3E-for-ItemCtxt%3C'tcx%3E, and then try to click on the `§` anchor of the `tcx` method. The solution to this bug is to simply "glue" the anchor to the method, so when the mouse cursor moves to it, there is no gap between the two, preventing the anchor to disappear (hopefully this explanation doesn't make sense only to me ^^'). First commit fixes the bug by expanding the anchor size. Second commit is a small clean-up of the GUI test. Third commit actually adds the GUI regression test. cc @BoxyUwU r? @camelid
2 parents e99f5f6 + 16fbf6a commit fe307c5

4 files changed

Lines changed: 38 additions & 14 deletions

File tree

src/librustdoc/html/static/css/rustdoc.css

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1200,9 +1200,11 @@ nav.sub {
12001200
display: initial;
12011201
}
12021202
.anchor {
1203+
--anchor-link-shift: 0.5em;
12031204
display: none;
12041205
position: absolute;
1205-
left: -0.5em;
1206+
left: calc(var(--anchor-link-shift) * -1);
1207+
padding-right: var(--anchor-link-shift);
12061208
background: none !important;
12071209
}
12081210
.anchor.field {

tests/rustdoc-gui/anchor-navigable.goml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
go-to: "file://" + |DOC_PATH| + "/test_docs/struct.Foo.html"
88
// We check that ".item-info" is bigger than its content.
99
move-cursor-to: ".impl"
10-
assert-property: (".impl > a.anchor", {"offsetWidth": "8"})
10+
assert-property: (".impl > a.anchor", {"offsetWidth": "16"})
1111
assert-css: (".impl > a.anchor", {"left": "-8px"})

tests/rustdoc-gui/anchors.goml

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ define-function: (
1414
assert-css: ("#toggle-all-docs", {"color": |main_color|})
1515
assert-css: (".main-heading h1 span", {"color": |main_heading_type_color|})
1616
assert-css: (
17-
".rightside a.src",
18-
{"color": |src_link_color|, "text-decoration": "none"},
19-
ALL,
17+
".rightside a.src",
18+
{"color": |src_link_color|, "text-decoration": "none"},
19+
ALL,
2020
)
2121
compare-elements-css: (
2222
".rightside a.src",
@@ -31,25 +31,39 @@ define-function: (
3131

3232
move-cursor-to: ".main-heading a.src"
3333
assert-css: (
34-
".main-heading a.src",
35-
{"color": |src_link_color|, "text-decoration": "underline"},
34+
".main-heading a.src",
35+
{"color": |src_link_color|, "text-decoration": "underline"},
3636
)
3737
move-cursor-to: ".impl-items .rightside a.src"
3838
assert-css: (
39-
".impl-items .rightside a.src",
40-
{"color": |src_link_color|, "text-decoration": "none"},
39+
".impl-items .rightside a.src",
40+
{"color": |src_link_color|, "text-decoration": "none"},
4141
)
4242
move-cursor-to: ".impl-items a.rightside.src"
4343
assert-css: (
44-
".impl-items a.rightside.src",
45-
{"color": |src_link_color|, "text-decoration": "none"},
44+
".impl-items a.rightside.src",
45+
{"color": |src_link_color|, "text-decoration": "none"},
4646
)
4747

48+
// Now we ensure that the `§` anchor is "reachable" for users on trait methods.
49+
// To ensure the anchor is not hovered, we move the cursor to another item.
50+
move-cursor-to: "#search-button"
51+
// By default, the anchor is not displayed.
52+
wait-for-css: ("#method\.vroum .anchor", {"display": "none"})
53+
// Once we move the cursor to the method, the anchor should appear.
54+
move-cursor-to: "#method\.vroum .code-header"
55+
assert-css-false: ("#method\.vroum .anchor", {"display": "none"})
56+
// Now we move the cursor to the anchor to check there is no gap between the method and the
57+
// anchor, making the anchor disappear and preventing users to click on it.
58+
// To make it work, we need to first move it between the method and the anchor.
59+
store-position: ("#method\.vroum .code-header", {"x": method_x, "y": method_y})
60+
move-cursor-to: (|method_x| - 2, |method_y|)
61+
// Anchor should still be displayed.
62+
assert-css-false: ("#method\.vroum .anchor", {"display": "none"})
63+
4864
go-to: "file://" + |DOC_PATH| + "/test_docs/struct.HeavilyDocumentedStruct.html"
4965
// Since we changed page, we need to set the theme again.
50-
set-local-storage: {"rustdoc-theme": |theme|, "rustdoc-use-system-theme": "false"}
51-
// We reload the page so the local storage settings are being used.
52-
reload:
66+
call-function: ("switch-theme", {"theme": |theme|})
5367

5468
assert-css: ("#top-doc-prose-title", {"color": |title_color|})
5569

tests/rustdoc-gui/src/staged_api/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
#![stable(feature = "some_feature", since = "1.3.5")]
55
#![doc(rust_logo)]
66

7+
pub trait X {
8+
fn vroum();
9+
}
10+
711
#[stable(feature = "some_feature", since = "1.3.5")]
812
pub struct Foo {}
913

@@ -13,3 +17,7 @@ impl Foo {
1317
#[stable(feature = "some_other_feature", since = "1.3.6")]
1418
pub fn yo() {}
1519
}
20+
21+
impl X for Foo {
22+
fn vroum() {}
23+
}

0 commit comments

Comments
 (0)