6
6
//! Use the `render_with_highlighting` to highlight some rust code.
7
7
8
8
use std:: collections:: VecDeque ;
9
- use std:: fmt:: { Display , Write } ;
9
+ use std:: fmt:: { self , Display , Write } ;
10
10
11
11
use rustc_data_structures:: fx:: FxIndexMap ;
12
12
use rustc_lexer:: { Cursor , FrontmatterAllowed , LiteralKind , TokenKind } ;
@@ -36,9 +36,10 @@ pub(crate) struct HrefContext<'a, 'tcx> {
36
36
#[ derive( Default ) ]
37
37
pub ( crate ) struct DecorationInfo ( pub ( crate ) FxIndexMap < & ' static str , Vec < ( u32 , u32 ) > > ) ;
38
38
39
- #[ derive( Eq , PartialEq , Clone , Copy ) ]
39
+ #[ derive( Eq , PartialEq , Clone ) ]
40
40
pub ( crate ) enum Tooltip {
41
- Ignore ,
41
+ IgnoreAll ,
42
+ IgnoreSome ( Vec < String > ) ,
42
43
CompileFail ,
43
44
ShouldPanic ,
44
45
Edition ( Edition ) ,
@@ -70,7 +71,7 @@ fn write_header(
70
71
format_args ! (
71
72
"<div class=\" example-wrap{}\" >" ,
72
73
match tooltip {
73
- Tooltip :: Ignore => " ignore" ,
74
+ Tooltip :: IgnoreAll | Tooltip :: IgnoreSome ( _ ) => " ignore" ,
74
75
Tooltip :: CompileFail => " compile_fail" ,
75
76
Tooltip :: ShouldPanic => " should_panic" ,
76
77
Tooltip :: Edition ( _) => " edition" ,
@@ -80,18 +81,46 @@ fn write_header(
80
81
) ;
81
82
82
83
if tooltip != Tooltip :: None {
83
- let edition_code;
84
+ // variable for extending lifetimes of temporaries
85
+ let tmp;
84
86
write_str (
85
87
out,
86
88
format_args ! (
87
89
"<a href=\" #\" class=\" tooltip\" title=\" {}\" >ⓘ</a>" ,
88
90
match tooltip {
89
- Tooltip :: Ignore => "This example is not tested" ,
91
+ Tooltip :: IgnoreAll => "This example is not tested" ,
92
+ Tooltip :: IgnoreSome ( platforms) => {
93
+ tmp = format!(
94
+ "This example is not tested on {}" ,
95
+ fmt:: from_fn( |f| {
96
+ match platforms. len( ) {
97
+ 0 => unreachable!( ) ,
98
+ 1 => f. write_str( & platforms[ 0 ] ) ,
99
+ 2 => write!( f, "{} or {}" , & platforms[ 0 ] , & platforms[ 1 ] ) ,
100
+ _ => {
101
+ for ( i, plat) in platforms. iter( ) . enumerate( ) {
102
+ match ( platforms. len( ) - 2 ) . cmp( & i) {
103
+ std:: cmp:: Ordering :: Greater => {
104
+ write!( f, "{}, " , plat) ?
105
+ }
106
+ std:: cmp:: Ordering :: Equal => {
107
+ write!( f, "{}, or " , plat) ?
108
+ }
109
+ std:: cmp:: Ordering :: Less => f. write_str( & plat) ?,
110
+ }
111
+ }
112
+ Ok ( ( ) )
113
+ }
114
+ }
115
+ } )
116
+ ) ;
117
+ & tmp
118
+ }
90
119
Tooltip :: CompileFail => "This example deliberately fails to compile" ,
91
120
Tooltip :: ShouldPanic => "This example panics" ,
92
121
Tooltip :: Edition ( edition) => {
93
- edition_code = format!( "This example runs with edition {edition}" ) ;
94
- & edition_code
122
+ tmp = format!( "This example runs with edition {edition}" ) ;
123
+ & tmp
95
124
}
96
125
Tooltip :: None => unreachable!( ) ,
97
126
}
0 commit comments