mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 07:14:28 +00:00
Add support for #[rustc_must_implement_one_of]
to rustdoc
This commit is contained in:
parent
35a0617248
commit
3da2553f2f
@ -1991,6 +1991,7 @@ fn clean_maybe_renamed_item<'tcx>(
|
|||||||
ItemKind::Trait(_, _, generics, bounds, item_ids) => {
|
ItemKind::Trait(_, _, generics, bounds, item_ids) => {
|
||||||
let items =
|
let items =
|
||||||
item_ids.iter().map(|ti| cx.tcx.hir().trait_item(ti.id).clean(cx)).collect();
|
item_ids.iter().map(|ti| cx.tcx.hir().trait_item(ti.id).clean(cx)).collect();
|
||||||
|
|
||||||
TraitItem(Trait {
|
TraitItem(Trait {
|
||||||
def_id,
|
def_id,
|
||||||
items,
|
items,
|
||||||
|
@ -1,9 +1,5 @@
|
|||||||
use clean::AttributesExt;
|
use clean::AttributesExt;
|
||||||
|
|
||||||
use std::cmp::Ordering;
|
|
||||||
use std::fmt;
|
|
||||||
use std::rc::Rc;
|
|
||||||
|
|
||||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def::CtorKind;
|
use rustc_hir::def::CtorKind;
|
||||||
@ -15,6 +11,9 @@ use rustc_middle::ty::{Adt, TyCtxt};
|
|||||||
use rustc_span::hygiene::MacroKind;
|
use rustc_span::hygiene::MacroKind;
|
||||||
use rustc_span::symbol::{kw, sym, Symbol};
|
use rustc_span::symbol::{kw, sym, Symbol};
|
||||||
use rustc_target::abi::{Layout, Primitive, TagEncoding, Variants};
|
use rustc_target::abi::{Layout, Primitive, TagEncoding, Variants};
|
||||||
|
use std::cmp::Ordering;
|
||||||
|
use std::fmt;
|
||||||
|
use std::rc::Rc;
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
collect_paths_for_type, document, ensure_trailing_slash, item_ty_to_section,
|
collect_paths_for_type, document, ensure_trailing_slash, item_ty_to_section,
|
||||||
@ -37,6 +36,7 @@ use crate::html::markdown::{HeadingOffset, MarkdownSummaryLine};
|
|||||||
use crate::html::url_parts_builder::UrlPartsBuilder;
|
use crate::html::url_parts_builder::UrlPartsBuilder;
|
||||||
|
|
||||||
use askama::Template;
|
use askama::Template;
|
||||||
|
use itertools::Itertools;
|
||||||
|
|
||||||
const ITEM_TABLE_OPEN: &str = "<div class=\"item-table\">";
|
const ITEM_TABLE_OPEN: &str = "<div class=\"item-table\">";
|
||||||
const ITEM_TABLE_CLOSE: &str = "</div>";
|
const ITEM_TABLE_CLOSE: &str = "</div>";
|
||||||
@ -539,6 +539,8 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean:
|
|||||||
let count_types = required_types.len() + provided_types.len();
|
let count_types = required_types.len() + provided_types.len();
|
||||||
let count_consts = required_consts.len() + provided_consts.len();
|
let count_consts = required_consts.len() + provided_consts.len();
|
||||||
let count_methods = required_methods.len() + provided_methods.len();
|
let count_methods = required_methods.len() + provided_methods.len();
|
||||||
|
let must_implement_one_of_functions =
|
||||||
|
cx.tcx().trait_def(t.def_id).must_implement_one_of.clone();
|
||||||
|
|
||||||
// Output the trait definition
|
// Output the trait definition
|
||||||
wrap_into_docblock(w, |w| {
|
wrap_into_docblock(w, |w| {
|
||||||
@ -784,13 +786,22 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Output the documentation for each function individually
|
// Output the documentation for each function individually
|
||||||
if !required_methods.is_empty() {
|
if !required_methods.is_empty() || must_implement_one_of_functions.is_some() {
|
||||||
write_small_section_header(
|
write_small_section_header(
|
||||||
w,
|
w,
|
||||||
"required-methods",
|
"required-methods",
|
||||||
"Required Methods",
|
"Required Methods",
|
||||||
"<div class=\"methods\">",
|
"<div class=\"methods\">",
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if let Some(list) = must_implement_one_of_functions.as_deref() {
|
||||||
|
write!(
|
||||||
|
w,
|
||||||
|
"<div class=\"stab must_implement\">At least one of {} methods is required.</div>",
|
||||||
|
list.iter().join(", ")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
for m in required_methods {
|
for m in required_methods {
|
||||||
trait_item(w, cx, m, it);
|
trait_item(w, cx, m, it);
|
||||||
}
|
}
|
||||||
|
@ -1110,7 +1110,7 @@ table,
|
|||||||
padding: 0 20px 20px 17px;
|
padding: 0 20px 20px 17px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.item-info .stab {
|
.item-info,.methods .stab {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
}
|
}
|
||||||
.stab {
|
.stab {
|
||||||
|
@ -209,7 +209,8 @@ details.rustdoc-toggle > summary::before {
|
|||||||
.stab.unstable,
|
.stab.unstable,
|
||||||
.stab.deprecated,
|
.stab.deprecated,
|
||||||
.stab.portability,
|
.stab.portability,
|
||||||
.stab.empty-impl {
|
.stab.empty-impl,
|
||||||
|
.stab.must_implement {
|
||||||
color: #c5c5c5;
|
color: #c5c5c5;
|
||||||
background: #314559 !important;
|
background: #314559 !important;
|
||||||
border-style: none !important;
|
border-style: none !important;
|
||||||
|
@ -180,6 +180,7 @@ details.rustdoc-toggle > summary::before {
|
|||||||
.stab.empty-impl { background: #FFF5D6; border-color: #FFC600; color: #2f2f2f; }
|
.stab.empty-impl { background: #FFF5D6; border-color: #FFC600; color: #2f2f2f; }
|
||||||
.stab.unstable { background: #FFF5D6; border-color: #FFC600; color: #2f2f2f; }
|
.stab.unstable { background: #FFF5D6; border-color: #FFC600; color: #2f2f2f; }
|
||||||
.stab.deprecated { background: #ffc4c4; border-color: #db7b7b; color: #2f2f2f; }
|
.stab.deprecated { background: #ffc4c4; border-color: #db7b7b; color: #2f2f2f; }
|
||||||
|
.stab.must_implement { background: #F3DFFF; border-color: #b07bdb; color: #2f2f2f; }
|
||||||
.stab.portability { background: #F3DFFF; border-color: #b07bdb; color: #2f2f2f; }
|
.stab.portability { background: #F3DFFF; border-color: #b07bdb; color: #2f2f2f; }
|
||||||
.stab.portability > code { background: none; }
|
.stab.portability > code { background: none; }
|
||||||
|
|
||||||
|
@ -163,6 +163,7 @@ details.rustdoc-toggle > summary::before {
|
|||||||
.stab.empty-impl { background: #FFF5D6; border-color: #FFC600; }
|
.stab.empty-impl { background: #FFF5D6; border-color: #FFC600; }
|
||||||
.stab.unstable { background: #FFF5D6; border-color: #FFC600; }
|
.stab.unstable { background: #FFF5D6; border-color: #FFC600; }
|
||||||
.stab.deprecated { background: #ffc4c4; border-color: #db7b7b; }
|
.stab.deprecated { background: #ffc4c4; border-color: #db7b7b; }
|
||||||
|
.stab.must_implement { background: #F3DFFF; border-color: #b07bdb; }
|
||||||
.stab.portability { background: #F3DFFF; border-color: #b07bdb; }
|
.stab.portability { background: #F3DFFF; border-color: #b07bdb; }
|
||||||
.stab.portability > code { background: none; }
|
.stab.portability > code { background: none; }
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user