Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 11a68d3

Browse files
author
Ruben Schmidmeister
committed
Pass string instead of Symbol to DocCommentFormatter
1 parent 8d4cb6e commit 11a68d3

File tree

2 files changed

+8
-22
lines changed

2 files changed

+8
-22
lines changed

src/attr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ impl Rewrite for ast::Attribute {
334334
};
335335

336336
let doc_comment_formatter =
337-
DocCommentFormatter::new(literal, comment_style);
337+
DocCommentFormatter::new(literal.as_str().get(), comment_style);
338338
let doc_comment = format!("{}", doc_comment_formatter);
339339
return rewrite_doc_comment(
340340
&doc_comment,

src/attr/doc_comment.rs

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,16 @@
11
use crate::comment::CommentStyle;
22
use std::fmt::{self, Display};
3-
use syntax_pos::symbol::Symbol;
43

4+
#[derive(new)]
55
pub(super) struct DocCommentFormatter<'a> {
6-
literal: &'a Symbol,
6+
literal: &'a str,
77
style: CommentStyle<'a>,
88
}
99

10-
impl<'a> DocCommentFormatter<'a> {
11-
pub(super) fn new(literal: &'a Symbol, style: CommentStyle<'a>) -> Self {
12-
Self { literal, style }
13-
}
14-
}
15-
1610
impl Display for DocCommentFormatter<'_> {
1711
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
1812
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();
2214
while let Some(line) = lines.next() {
2315
let is_last_line = lines.peek().is_none();
2416
if is_last_line {
@@ -27,15 +19,13 @@ impl Display for DocCommentFormatter<'_> {
2719
writeln!(formatter, "{}{}", opener, line)?;
2820
}
2921
}
30-
3122
Ok(())
3223
}
3324
}
3425

3526
#[cfg(test)]
3627
mod tests {
3728
use super::*;
38-
use syntax_pos::{Globals, GLOBALS};
3929

4030
#[test]
4131
fn literal_controls_leading_spaces() {
@@ -78,13 +68,9 @@ mod tests {
7868
expected_comment: &str,
7969
style: CommentStyle<'_>,
8070
) {
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+
);
8975
}
9076
}

0 commit comments

Comments
 (0)