Skip to content

Commit 3da2553

Browse files
committed
Add support for #[rustc_must_implement_one_of] to rustdoc
1 parent 35a0617 commit 3da2553

File tree

6 files changed

+22
-7
lines changed

6 files changed

+22
-7
lines changed

src/librustdoc/clean/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1991,6 +1991,7 @@ fn clean_maybe_renamed_item<'tcx>(
19911991
ItemKind::Trait(_, _, generics, bounds, item_ids) => {
19921992
let items =
19931993
item_ids.iter().map(|ti| cx.tcx.hir().trait_item(ti.id).clean(cx)).collect();
1994+
19941995
TraitItem(Trait {
19951996
def_id,
19961997
items,

src/librustdoc/html/render/print_item.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
use clean::AttributesExt;
22

3-
use std::cmp::Ordering;
4-
use std::fmt;
5-
use std::rc::Rc;
6-
73
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
84
use rustc_hir as hir;
95
use rustc_hir::def::CtorKind;
@@ -15,6 +11,9 @@ use rustc_middle::ty::{Adt, TyCtxt};
1511
use rustc_span::hygiene::MacroKind;
1612
use rustc_span::symbol::{kw, sym, Symbol};
1713
use rustc_target::abi::{Layout, Primitive, TagEncoding, Variants};
14+
use std::cmp::Ordering;
15+
use std::fmt;
16+
use std::rc::Rc;
1817

1918
use super::{
2019
collect_paths_for_type, document, ensure_trailing_slash, item_ty_to_section,
@@ -37,6 +36,7 @@ use crate::html::markdown::{HeadingOffset, MarkdownSummaryLine};
3736
use crate::html::url_parts_builder::UrlPartsBuilder;
3837

3938
use askama::Template;
39+
use itertools::Itertools;
4040

4141
const ITEM_TABLE_OPEN: &str = "<div class=\"item-table\">";
4242
const ITEM_TABLE_CLOSE: &str = "</div>";
@@ -539,6 +539,8 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean:
539539
let count_types = required_types.len() + provided_types.len();
540540
let count_consts = required_consts.len() + provided_consts.len();
541541
let count_methods = required_methods.len() + provided_methods.len();
542+
let must_implement_one_of_functions =
543+
cx.tcx().trait_def(t.def_id).must_implement_one_of.clone();
542544

543545
// Output the trait definition
544546
wrap_into_docblock(w, |w| {
@@ -784,13 +786,22 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean:
784786
}
785787

786788
// Output the documentation for each function individually
787-
if !required_methods.is_empty() {
789+
if !required_methods.is_empty() || must_implement_one_of_functions.is_some() {
788790
write_small_section_header(
789791
w,
790792
"required-methods",
791793
"Required Methods",
792794
"<div class=\"methods\">",
793795
);
796+
797+
if let Some(list) = must_implement_one_of_functions.as_deref() {
798+
write!(
799+
w,
800+
"<div class=\"stab must_implement\">At least one of {} methods is required.</div>",
801+
list.iter().join(", ")
802+
);
803+
}
804+
794805
for m in required_methods {
795806
trait_item(w, cx, m, it);
796807
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1110,7 +1110,7 @@ table,
11101110
padding: 0 20px 20px 17px;
11111111
}
11121112

1113-
.item-info .stab {
1113+
.item-info,.methods .stab {
11141114
display: inline-block;
11151115
}
11161116
.stab {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,8 @@ details.rustdoc-toggle > summary::before {
209209
.stab.unstable,
210210
.stab.deprecated,
211211
.stab.portability,
212-
.stab.empty-impl {
212+
.stab.empty-impl,
213+
.stab.must_implement {
213214
color: #c5c5c5;
214215
background: #314559 !important;
215216
border-style: none !important;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ details.rustdoc-toggle > summary::before {
180180
.stab.empty-impl { background: #FFF5D6; border-color: #FFC600; color: #2f2f2f; }
181181
.stab.unstable { background: #FFF5D6; border-color: #FFC600; color: #2f2f2f; }
182182
.stab.deprecated { background: #ffc4c4; border-color: #db7b7b; color: #2f2f2f; }
183+
.stab.must_implement { background: #F3DFFF; border-color: #b07bdb; color: #2f2f2f; }
183184
.stab.portability { background: #F3DFFF; border-color: #b07bdb; color: #2f2f2f; }
184185
.stab.portability > code { background: none; }
185186

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ details.rustdoc-toggle > summary::before {
163163
.stab.empty-impl { background: #FFF5D6; border-color: #FFC600; }
164164
.stab.unstable { background: #FFF5D6; border-color: #FFC600; }
165165
.stab.deprecated { background: #ffc4c4; border-color: #db7b7b; }
166+
.stab.must_implement { background: #F3DFFF; border-color: #b07bdb; }
166167
.stab.portability { background: #F3DFFF; border-color: #b07bdb; }
167168
.stab.portability > code { background: none; }
168169

0 commit comments

Comments
 (0)