From 11a68d313ad351907acd68da3e4a683f7c30d94f Mon Sep 17 00:00:00 2001 From: Ruben Schmidmeister Date: Sat, 18 May 2019 11:47:54 +0200 Subject: [PATCH] Pass string instead of Symbol to DocCommentFormatter --- src/attr.rs | 2 +- src/attr/doc_comment.rs | 28 +++++++--------------------- 2 files changed, 8 insertions(+), 22 deletions(-) diff --git a/src/attr.rs b/src/attr.rs index 961b6031c935..1fb4ef407eb0 100644 --- a/src/attr.rs +++ b/src/attr.rs @@ -334,7 +334,7 @@ impl Rewrite for ast::Attribute { }; let doc_comment_formatter = - DocCommentFormatter::new(literal, comment_style); + DocCommentFormatter::new(literal.as_str().get(), comment_style); let doc_comment = format!("{}", doc_comment_formatter); return rewrite_doc_comment( &doc_comment, diff --git a/src/attr/doc_comment.rs b/src/attr/doc_comment.rs index 1affc7bc910d..c2ae16d1c914 100644 --- a/src/attr/doc_comment.rs +++ b/src/attr/doc_comment.rs @@ -1,24 +1,16 @@ use crate::comment::CommentStyle; use std::fmt::{self, Display}; -use syntax_pos::symbol::Symbol; +#[derive(new)] pub(super) struct DocCommentFormatter<'a> { - literal: &'a Symbol, + literal: &'a str, style: CommentStyle<'a>, } -impl<'a> DocCommentFormatter<'a> { - pub(super) fn new(literal: &'a Symbol, style: CommentStyle<'a>) -> Self { - Self { literal, style } - } -} - impl Display for DocCommentFormatter<'_> { fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { let opener = self.style.opener().trim_end(); - let literal_as_str = self.literal.as_str().get(); - - let mut lines = literal_as_str.lines().peekable(); + let mut lines = self.literal.lines().peekable(); while let Some(line) = lines.next() { let is_last_line = lines.peek().is_none(); if is_last_line { @@ -27,7 +19,6 @@ impl Display for DocCommentFormatter<'_> { writeln!(formatter, "{}{}", opener, line)?; } } - Ok(()) } } @@ -35,7 +26,6 @@ impl Display for DocCommentFormatter<'_> { #[cfg(test)] mod tests { use super::*; - use syntax_pos::{Globals, GLOBALS}; #[test] fn literal_controls_leading_spaces() { @@ -78,13 +68,9 @@ mod tests { expected_comment: &str, style: CommentStyle<'_>, ) { - GLOBALS.set(&Globals::new(), || { - let literal = Symbol::gensym(literal); - - assert_eq!( - expected_comment, - format!("{}", DocCommentFormatter::new(&literal, style)) - ); - }); + assert_eq!( + expected_comment, + format!("{}", DocCommentFormatter::new(&literal, style)) + ); } }