1
1
use clean:: AttributesExt ;
2
2
3
- use std:: cmp:: Ordering ;
4
- use std:: fmt;
5
- use std:: rc:: Rc ;
6
-
7
3
use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
8
4
use rustc_hir as hir;
9
5
use rustc_hir:: def:: CtorKind ;
@@ -15,6 +11,9 @@ use rustc_middle::ty::{Adt, TyCtxt};
15
11
use rustc_span:: hygiene:: MacroKind ;
16
12
use rustc_span:: symbol:: { kw, sym, Symbol } ;
17
13
use rustc_target:: abi:: { Layout , Primitive , TagEncoding , Variants } ;
14
+ use std:: cmp:: Ordering ;
15
+ use std:: fmt;
16
+ use std:: rc:: Rc ;
18
17
19
18
use super :: {
20
19
collect_paths_for_type, document, ensure_trailing_slash, item_ty_to_section,
@@ -37,6 +36,7 @@ use crate::html::markdown::{HeadingOffset, MarkdownSummaryLine};
37
36
use crate :: html:: url_parts_builder:: UrlPartsBuilder ;
38
37
39
38
use askama:: Template ;
39
+ use itertools:: Itertools ;
40
40
41
41
const ITEM_TABLE_OPEN : & str = "<div class=\" item-table\" >" ;
42
42
const ITEM_TABLE_CLOSE : & str = "</div>" ;
@@ -539,6 +539,8 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean:
539
539
let count_types = required_types. len ( ) + provided_types. len ( ) ;
540
540
let count_consts = required_consts. len ( ) + provided_consts. len ( ) ;
541
541
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 ( ) ;
542
544
543
545
// Output the trait definition
544
546
wrap_into_docblock ( w, |w| {
@@ -784,13 +786,22 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean:
784
786
}
785
787
786
788
// 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 ( ) {
788
790
write_small_section_header (
789
791
w,
790
792
"required-methods" ,
791
793
"Required Methods" ,
792
794
"<div class=\" methods\" >" ,
793
795
) ;
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
+
794
805
for m in required_methods {
795
806
trait_item ( w, cx, m, it) ;
796
807
}
0 commit comments