@@ -7,13 +7,15 @@ use crate::clean::{
77use crate :: core:: DocContext ;
88use crate :: formats:: item_type:: ItemType ;
99
10+ use rustc_ast:: tokenstream:: TokenTree ;
1011use rustc_hir as hir;
1112use rustc_hir:: def:: { DefKind , Res } ;
1213use rustc_hir:: def_id:: { DefId , LOCAL_CRATE } ;
1314use rustc_middle:: mir:: interpret:: ConstValue ;
1415use rustc_middle:: ty:: subst:: { GenericArgKind , SubstsRef } ;
1516use rustc_middle:: ty:: { self , DefIdTree , TyCtxt } ;
1617use rustc_span:: symbol:: { kw, sym, Symbol } ;
18+ use std:: fmt:: Write as _;
1719use std:: mem;
1820
1921#[ cfg( test) ]
@@ -248,22 +250,6 @@ crate fn build_deref_target_impls(cx: &mut DocContext<'_>, items: &[Item], ret:
248250 }
249251}
250252
251- crate trait ToSource {
252- fn to_src ( & self , cx : & DocContext < ' _ > ) -> String ;
253- }
254-
255- impl ToSource for rustc_span:: Span {
256- fn to_src ( & self , cx : & DocContext < ' _ > ) -> String {
257- debug ! ( "converting span {:?} to snippet" , self ) ;
258- let sn = match cx. sess ( ) . source_map ( ) . span_to_snippet ( * self ) {
259- Ok ( x) => x,
260- Err ( _) => String :: new ( ) ,
261- } ;
262- debug ! ( "got snippet {}" , sn) ;
263- sn
264- }
265- }
266-
267253crate fn name_from_pat ( p : & hir:: Pat < ' _ > ) -> Symbol {
268254 use rustc_hir:: * ;
269255 debug ! ( "trying to get a name from pattern: {:?}" , p) ;
@@ -572,3 +558,22 @@ crate fn has_doc_flag(attrs: ty::Attributes<'_>, flag: Symbol) -> bool {
572558///
573559/// Set by `bootstrap::Builder::doc_rust_lang_org_channel` in order to keep tests passing on beta/stable.
574560crate const DOC_RUST_LANG_ORG_CHANNEL : & ' static str = env ! ( "DOC_RUST_LANG_ORG_CHANNEL" ) ;
561+
562+ /// Render a sequence of macro arms in a format suitable for displaying to the user
563+ /// as part of an item declaration.
564+ pub ( super ) fn render_macro_arms < ' a > (
565+ matchers : impl Iterator < Item = & ' a TokenTree > ,
566+ arm_delim : & str ,
567+ ) -> String {
568+ let mut out = String :: new ( ) ;
569+ for matcher in matchers {
570+ writeln ! ( out, " {} => {{ ... }}{}" , render_macro_matcher( matcher) , arm_delim) . unwrap ( ) ;
571+ }
572+ out
573+ }
574+
575+ /// Render a macro matcher in a format suitable for displaying to the user
576+ /// as part of an item declaration.
577+ pub ( super ) fn render_macro_matcher ( matcher : & TokenTree ) -> String {
578+ rustc_ast_pretty:: pprust:: tt_to_string ( matcher)
579+ }
0 commit comments