@@ -14,7 +14,7 @@ use rustc_span::edition::Edition;
1414use rustc_span:: symbol:: Symbol ;
1515use rustc_span:: { BytePos , DUMMY_SP , Span } ;
1616
17- use super :: format:: { self , Buffer } ;
17+ use super :: format:: { self , write_str } ;
1818use crate :: clean:: PrimitiveType ;
1919use crate :: html:: escape:: EscapeBodyText ;
2020use crate :: html:: render:: { Context , LinkFromSrc } ;
@@ -48,7 +48,7 @@ pub(crate) enum Tooltip {
4848/// Highlights `src` as an inline example, returning the HTML output.
4949pub ( crate ) fn render_example_with_highlighting (
5050 src : & str ,
51- out : & mut Buffer ,
51+ out : & mut String ,
5252 tooltip : Tooltip ,
5353 playground_button : Option < & str > ,
5454 extra_classes : & [ String ] ,
@@ -59,61 +59,69 @@ pub(crate) fn render_example_with_highlighting(
5959}
6060
6161fn write_header (
62- out : & mut Buffer ,
62+ out : & mut String ,
6363 class : & str ,
64- extra_content : Option < Buffer > ,
64+ extra_content : Option < & str > ,
6565 tooltip : Tooltip ,
6666 extra_classes : & [ String ] ,
6767) {
68- write ! (
68+ write_str (
6969 out,
70- "<div class=\" example-wrap{}\" >" ,
71- match tooltip {
72- Tooltip :: Ignore => " ignore" ,
73- Tooltip :: CompileFail => " compile_fail" ,
74- Tooltip :: ShouldPanic => " should_panic" ,
75- Tooltip :: Edition ( _) => " edition" ,
76- Tooltip :: None => "" ,
77- } ,
70+ format_args ! (
71+ "<div class=\" example-wrap{}\" >" ,
72+ match tooltip {
73+ Tooltip :: Ignore => " ignore" ,
74+ Tooltip :: CompileFail => " compile_fail" ,
75+ Tooltip :: ShouldPanic => " should_panic" ,
76+ Tooltip :: Edition ( _) => " edition" ,
77+ Tooltip :: None => "" ,
78+ }
79+ ) ,
7880 ) ;
7981
8082 if tooltip != Tooltip :: None {
8183 let edition_code;
82- write ! (
84+ write_str (
8385 out,
84- "<a href=\" #\" class=\" tooltip\" title=\" {}\" >ⓘ</a>" ,
85- match tooltip {
86- Tooltip :: Ignore => "This example is not tested" ,
87- Tooltip :: CompileFail => "This example deliberately fails to compile" ,
88- Tooltip :: ShouldPanic => "This example panics" ,
89- Tooltip :: Edition ( edition) => {
90- edition_code = format!( "This example runs with edition {edition}" ) ;
91- & edition_code
86+ format_args ! (
87+ "<a href=\" #\" class=\" tooltip\" title=\" {}\" >ⓘ</a>" ,
88+ match tooltip {
89+ Tooltip :: Ignore => "This example is not tested" ,
90+ Tooltip :: CompileFail => "This example deliberately fails to compile" ,
91+ Tooltip :: ShouldPanic => "This example panics" ,
92+ Tooltip :: Edition ( edition) => {
93+ edition_code = format!( "This example runs with edition {edition}" ) ;
94+ & edition_code
95+ }
96+ Tooltip :: None => unreachable!( ) ,
9297 }
93- Tooltip :: None => unreachable!( ) ,
94- } ,
98+ ) ,
9599 ) ;
96100 }
97101
98102 if let Some ( extra) = extra_content {
99- out. push_buffer ( extra) ;
103+ out. push_str ( & extra) ;
100104 }
101105 if class. is_empty ( ) {
102- write ! (
106+ write_str (
103107 out,
104- "<pre class=\" rust{}{}\" >" ,
105- if extra_classes. is_empty( ) { "" } else { " " } ,
106- extra_classes. join( " " ) ,
108+ format_args ! (
109+ "<pre class=\" rust{}{}\" >" ,
110+ if extra_classes. is_empty( ) { "" } else { " " } ,
111+ extra_classes. join( " " )
112+ ) ,
107113 ) ;
108114 } else {
109- write ! (
115+ write_str (
110116 out,
111- "<pre class=\" rust {class}{}{}\" >" ,
112- if extra_classes. is_empty( ) { "" } else { " " } ,
113- extra_classes. join( " " ) ,
117+ format_args ! (
118+ "<pre class=\" rust {class}{}{}\" >" ,
119+ if extra_classes. is_empty( ) { "" } else { " " } ,
120+ extra_classes. join( " " )
121+ ) ,
114122 ) ;
115123 }
116- write ! ( out, "<code>" ) ;
124+ write_str ( out, format_args ! ( "<code>" ) ) ;
117125}
118126
119127/// Check if two `Class` can be merged together. In the following rules, "unclassified" means `None`
@@ -398,8 +406,8 @@ pub(super) fn write_code(
398406 } ) ;
399407}
400408
401- fn write_footer ( out : & mut Buffer , playground_button : Option < & str > ) {
402- writeln ! ( out, "</code></pre>{}</div>" , playground_button. unwrap_or_default( ) ) ;
409+ fn write_footer ( out : & mut String , playground_button : Option < & str > ) {
410+ write_str ( out, format_args_nl ! ( "</code></pre>{}</div>" , playground_button. unwrap_or_default( ) ) ) ;
403411}
404412
405413/// How a span of text is classified. Mostly corresponds to token kinds.
0 commit comments