Skip to content

Commit 572dfd3

Browse files
committed
Merge method and tymethod URL fragments and sections
This change was discussed on Zulip [here][1]. Here is an excerpt of my proposal, explaining my rationale: They add needless complexity to the intra-doc links code (e.g., [whether an associated item is an impl vs a prototype has to be hardcoded in some circumstances][2]) and elsewhere in rustdoc. I don't think there's any need to distinguish between these two kinds. For example, associated constant prototypes in traits vs definitions in traits, trait impls, and inherent impls both use `associatedconstant`. [1]: https://rust-lang.zulipchat.com/#narrow/stream/266220-rustdoc/topic/.5Bproposal.5D.20merge.20tymethod.20and.20method [2]: https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/trait.20assoc.20item.20-.3E.20impl.20assoc.20item
1 parent 427eba2 commit 572dfd3

File tree

7 files changed

+12
-28
lines changed

7 files changed

+12
-28
lines changed

src/librustdoc/formats/item_type.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,7 @@ impl ItemType {
160160
ItemType::Static => "static",
161161
ItemType::Trait => "trait",
162162
ItemType::Impl => "impl",
163-
ItemType::TyMethod => "tymethod",
164-
ItemType::Method => "method",
163+
ItemType::Method | ItemType::TyMethod => "method",
165164
ItemType::StructField => "structfield",
166165
ItemType::Variant => "variant",
167166
ItemType::Macro => "macro",

src/librustdoc/html/render/mod.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -2276,7 +2276,7 @@ fn sidebar_trait(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, t: &clean
22762276
"<h3 class=\"sidebar-title\"><a href=\"#required-methods\">\
22772277
Required Methods</a></h3><div class=\"sidebar-links\">",
22782278
|m| m.is_ty_method(),
2279-
|out, sym| write!(out, "<a href=\"#tymethod.{0}\">{0}</a>", sym),
2279+
|out, sym| write!(out, "<a href=\"#method.{0}\">{0}</a>", sym),
22802280
"</div>",
22812281
);
22822282

@@ -2422,8 +2422,7 @@ fn item_ty_to_strs(ty: ItemType) -> (&'static str, &'static str) {
24222422
ItemType::Constant => ("constants", "Constants"),
24232423
ItemType::Trait => ("traits", "Traits"),
24242424
ItemType::Impl => ("impls", "Implementations"),
2425-
ItemType::TyMethod => ("tymethods", "Type Methods"),
2426-
ItemType::Method => ("methods", "Methods"),
2425+
ItemType::Method | ItemType::TyMethod => ("methods", "Methods"),
24272426
ItemType::StructField => ("fields", "Struct Fields"),
24282427
ItemType::Variant => ("variants", "Variants"),
24292428
ItemType::Macro => ("macros", "Macros"),

src/librustdoc/html/static/css/themes/ayu.css

+5-6
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,8 @@ pre, .rustdoc.source .example-wrap {
182182
.content a.associatedtype,
183183
.block a.current.associatedtype { color: #39AFD7; }
184184
.content span.fn, .content a.fn, .content span.method,
185-
.content a.method, .content span.tymethod,
186-
.content a.tymethod, .content .fnname {
185+
.content a.method,
186+
.content .fnname {
187187
color: #fdd687;
188188
}
189189
.content span.attr, .content a.attr, .content span.derive,
@@ -442,15 +442,15 @@ above the `@media (max-width: 700px)` rules due to a bug in the css checker */
442442
pre.rust .lifetime {}
443443
.stab.unstable {}
444444
h2,
445-
h3:not(.impl):not(.method):not(.type):not(.tymethod), h4:not(.method):not(.type):not(.tymethod) {}
445+
h3:not(.impl):not(.method):not(.type), h4:not(.method):not(.type) {}
446446
.content span.enum,.content a.enum,.block a.current.enum {}
447447
.content span.constant,.content a.constant,.block a.current.constant,.content span.static,
448448
.content a.static, .block a.current.static {}
449449
.content span.keyword,.content a.keyword,.block a.current.keyword {}
450450
pre.rust .comment {}
451451
.content span.traitalias,.content a.traitalias,.block a.current.traitalias {}
452452
.content span.fn,.content a.fn,.block a.current.fn,.content span.method,.content a.method,
453-
.block a.current.method,.content span.tymethod,.content a.tymethod,.block a.current.tymethod,
453+
.block a.current.method,
454454
.content .fnname {}
455455
pre.rust .kw {}
456456
pre.rust .self,pre.rust .bool-val,pre.rust .prelude-val,pre.rust .attribute,
@@ -476,8 +476,7 @@ a.result-enum:focus {}
476476
a.result-struct:focus {}
477477
a.result-union:focus {}
478478
a.result-fn:focus,
479-
a.result-method:focus,
480-
a.result-tymethod:focus {}
479+
a.result-method:focus {}
481480
a.result-type:focus {}
482481
a.result-associatedtype:focus {}
483482
a.result-foreigntype:focus {}

src/librustdoc/html/static/css/themes/dark.css

+1-3
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,7 @@ a.result-enum:focus { background-color: #194e9f; }
109109
a.result-struct:focus { background-color: #194e9f; }
110110
a.result-union:focus { background-color: #194e9f; }
111111
a.result-fn:focus,
112-
a.result-method:focus,
113-
a.result-tymethod:focus { background-color: #4950ed; }
112+
a.result-method:focus { background-color: #4950ed; }
114113
a.result-type:focus { background-color: #194e9f; }
115114
a.result-associatedtype:focus { background-color: #884719; }
116115
a.result-foreigntype:focus { background-color: #194e9f; }
@@ -144,7 +143,6 @@ a.result-keyword:focus { background-color: #884719; }
144143
.content span.traitalias, .content a.traitalias, .block a.current.traitalias { color: #b78cf2; }
145144
.content span.fn, .content a.fn, .block a.current.fn,
146145
.content span.method, .content a.method, .block a.current.method,
147-
.content span.tymethod, .content a.tymethod, .block a.current.tymethod,
148146
.content .fnname{ color: #2BAB63; }
149147
.content span.keyword, .content a.keyword, .block a.current.keyword { color: #D2991D; }
150148

src/librustdoc/html/static/css/themes/light.css

+1-3
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,7 @@ a.result-enum:focus { background-color: #e7b1a0; }
109109
a.result-struct:focus { background-color: #e7b1a0; }
110110
a.result-union:focus { background-color: #e7b1a0; }
111111
a.result-fn:focus,
112-
a.result-method:focus,
113-
a.result-tymethod:focus { background-color: #c6afb3; }
112+
a.result-method:focus { background-color: #c6afb3; }
114113
a.result-type:focus { background-color: #e7b1a0; }
115114
a.result-associatedtype:focus { background-color: #afc6e4; }
116115
a.result-foreigntype:focus { background-color: #e7b1a0; }
@@ -144,7 +143,6 @@ a.result-keyword:focus { background-color: #afc6e4; }
144143
.content span.traitalias, .content a.traitalias, .block a.current.traitalias { color: #5137AD; }
145144
.content span.fn, .content a.fn, .block a.current.fn,
146145
.content span.method, .content a.method, .block a.current.method,
147-
.content span.tymethod, .content a.tymethod, .block a.current.tymethod,
148146
.content .fnname { color: #AD7C37; }
149147
.content span.keyword, .content a.keyword, .block a.current.keyword { color: #3873AD; }
150148

src/librustdoc/html/static/js/search.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ var itemTypes = [
1515
"static",
1616
"trait",
1717
"impl",
18-
"tymethod",
1918
"method",
2019
"structfield",
2120
"variant",
@@ -566,7 +565,7 @@ window.initSearch = function(rawSearchIndex) {
566565
case "constant":
567566
return name === "associatedconstant";
568567
case "fn":
569-
return name === "method" || name === "tymethod";
568+
return name === "method";
570569
case "type":
571570
return name === "primitive" || name === "associatedtype";
572571
case "trait":

src/librustdoc/passes/collect_intra_doc_links.rs

+1-9
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,6 @@ crate struct ItemFragment(FragmentKind, DefId);
294294
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
295295
crate enum FragmentKind {
296296
Method,
297-
TyMethod,
298297
AssociatedConstant,
299298
AssociatedType,
300299

@@ -309,13 +308,7 @@ impl ItemFragment {
309308
fn from_assoc_item(item: &ty::AssocItem) -> Self {
310309
let def_id = item.def_id;
311310
match item.kind {
312-
ty::AssocKind::Fn => {
313-
if item.defaultness.has_value() {
314-
ItemFragment(FragmentKind::Method, def_id)
315-
} else {
316-
ItemFragment(FragmentKind::TyMethod, def_id)
317-
}
318-
}
311+
ty::AssocKind::Fn => ItemFragment(FragmentKind::Method, def_id),
319312
ty::AssocKind::Const => ItemFragment(FragmentKind::AssociatedConstant, def_id),
320313
ty::AssocKind::Type => ItemFragment(FragmentKind::AssociatedType, def_id),
321314
}
@@ -329,7 +322,6 @@ impl ItemFragment {
329322
let name = tcx.item_name(def_id);
330323
match kind {
331324
FragmentKind::Method => write!(s, "method.{}", name),
332-
FragmentKind::TyMethod => write!(s, "tymethod.{}", name),
333325
FragmentKind::AssociatedConstant => write!(s, "associatedconstant.{}", name),
334326
FragmentKind::AssociatedType => write!(s, "associatedtype.{}", name),
335327
FragmentKind::StructField => write!(s, "structfield.{}", name),

0 commit comments

Comments
 (0)