1
1
use crate :: comment:: CommentStyle ;
2
2
use std:: fmt:: { self , Display } ;
3
- use syntax_pos:: symbol:: Symbol ;
4
3
4
+ #[ derive( new) ]
5
5
pub ( super ) struct DocCommentFormatter < ' a > {
6
- literal : & ' a Symbol ,
6
+ literal : & ' a str ,
7
7
style : CommentStyle < ' a > ,
8
8
}
9
9
10
- impl < ' a > DocCommentFormatter < ' a > {
11
- pub ( super ) fn new ( literal : & ' a Symbol , style : CommentStyle < ' a > ) -> Self {
12
- Self { literal, style }
13
- }
14
- }
15
-
16
10
impl Display for DocCommentFormatter < ' _ > {
17
11
fn fmt ( & self , formatter : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
18
12
let opener = self . style . opener ( ) . trim_end ( ) ;
19
- let literal_as_str = self . literal . as_str ( ) . get ( ) ;
20
-
21
- let mut lines = literal_as_str. lines ( ) . peekable ( ) ;
13
+ let mut lines = self . literal . lines ( ) . peekable ( ) ;
22
14
while let Some ( line) = lines. next ( ) {
23
15
let is_last_line = lines. peek ( ) . is_none ( ) ;
24
16
if is_last_line {
@@ -27,15 +19,13 @@ impl Display for DocCommentFormatter<'_> {
27
19
writeln ! ( formatter, "{}{}" , opener, line) ?;
28
20
}
29
21
}
30
-
31
22
Ok ( ( ) )
32
23
}
33
24
}
34
25
35
26
#[ cfg( test) ]
36
27
mod tests {
37
28
use super :: * ;
38
- use syntax_pos:: { Globals , GLOBALS } ;
39
29
40
30
#[ test]
41
31
fn literal_controls_leading_spaces ( ) {
@@ -78,13 +68,9 @@ mod tests {
78
68
expected_comment : & str ,
79
69
style : CommentStyle < ' _ > ,
80
70
) {
81
- GLOBALS . set ( & Globals :: new ( ) , || {
82
- let literal = Symbol :: gensym ( literal) ;
83
-
84
- assert_eq ! (
85
- expected_comment,
86
- format!( "{}" , DocCommentFormatter :: new( & literal, style) )
87
- ) ;
88
- } ) ;
71
+ assert_eq ! (
72
+ expected_comment,
73
+ format!( "{}" , DocCommentFormatter :: new( & literal, style) )
74
+ ) ;
89
75
}
90
76
}
0 commit comments