@@ -7,13 +7,15 @@ use crate::clean::{
7
7
use crate :: core:: DocContext ;
8
8
use crate :: formats:: item_type:: ItemType ;
9
9
10
+ use rustc_ast:: tokenstream:: TokenTree ;
10
11
use rustc_hir as hir;
11
12
use rustc_hir:: def:: { DefKind , Res } ;
12
13
use rustc_hir:: def_id:: { DefId , LOCAL_CRATE } ;
13
14
use rustc_middle:: mir:: interpret:: ConstValue ;
14
15
use rustc_middle:: ty:: subst:: { GenericArgKind , SubstsRef } ;
15
16
use rustc_middle:: ty:: { self , DefIdTree , TyCtxt } ;
16
17
use rustc_span:: symbol:: { kw, sym, Symbol } ;
18
+ use std:: fmt:: Write as _;
17
19
use std:: mem;
18
20
19
21
#[ cfg( test) ]
@@ -248,22 +250,6 @@ crate fn build_deref_target_impls(cx: &mut DocContext<'_>, items: &[Item], ret:
248
250
}
249
251
}
250
252
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
-
267
253
crate fn name_from_pat ( p : & hir:: Pat < ' _ > ) -> Symbol {
268
254
use rustc_hir:: * ;
269
255
debug ! ( "trying to get a name from pattern: {:?}" , p) ;
@@ -572,3 +558,22 @@ crate fn has_doc_flag(attrs: ty::Attributes<'_>, flag: Symbol) -> bool {
572
558
///
573
559
/// Set by `bootstrap::Builder::doc_rust_lang_org_channel` in order to keep tests passing on beta/stable.
574
560
crate 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