Skip to content

Commit

Permalink
refactor: apply AST doc comment updates
Browse files Browse the repository at this point in the history
Implements changes required post
rust-lang/rust#65750
  • Loading branch information
calebcartwright committed Jan 15, 2020
1 parent 6064ab5 commit 30ed45b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
8 changes: 4 additions & 4 deletions rustfmt-core/rustfmt-lib/src/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ fn rewrite_initial_doc_comments(
return Some((0, None));
}
// Rewrite doc comments
let sugared_docs = take_while_with_pred(context, attrs, |a| a.is_sugared_doc);
let sugared_docs = take_while_with_pred(context, attrs, |a| a.is_doc_comment());
if !sugared_docs.is_empty() {
let snippet = sugared_docs
.iter()
Expand Down Expand Up @@ -315,7 +315,7 @@ where
impl Rewrite for ast::Attribute {
fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
let snippet = context.snippet(self.span);
if self.is_sugared_doc {
if self.is_doc_comment() {
rewrite_doc_comment(snippet, shape.comment(context.config), context.config)
} else {
let should_skip = self
Expand Down Expand Up @@ -437,7 +437,7 @@ impl<'a> Rewrite for [ast::Attribute] {
)?;
result.push_str(&comment);
if let Some(next) = attrs.get(derives.len()) {
if next.is_sugared_doc {
if next.is_doc_comment() {
let snippet = context.snippet(missing_span);
let (_, mlb) = has_newlines_before_after_comment(snippet);
result.push_str(&mlb);
Expand Down Expand Up @@ -470,7 +470,7 @@ impl<'a> Rewrite for [ast::Attribute] {
)?;
result.push_str(&comment);
if let Some(next) = attrs.get(1) {
if next.is_sugared_doc {
if next.is_doc_comment() {
let snippet = context.snippet(missing_span);
let (_, mlb) = has_newlines_before_after_comment(snippet);
result.push_str(&mlb);
Expand Down
2 changes: 1 addition & 1 deletion rustfmt-core/rustfmt-lib/src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ impl UseTree {

let allow_extend = if attrs.len() == 1 {
let line_len = attr_str.len() + 1 + use_str.len();
!attrs.first().unwrap().is_sugared_doc
!attrs.first().unwrap().is_doc_comment()
&& context.config.inline_attribute_width() >= line_len
} else {
false
Expand Down
2 changes: 1 addition & 1 deletion rustfmt-core/rustfmt-lib/src/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3139,7 +3139,7 @@ fn rewrite_attrs(

let allow_extend = if attrs.len() == 1 {
let line_len = attrs_str.len() + 1 + item_str.len();
!attrs.first().unwrap().is_sugared_doc
!attrs.first().unwrap().is_doc_comment()
&& context.config.inline_attribute_width() >= line_len
} else {
false
Expand Down
6 changes: 5 additions & 1 deletion rustfmt-core/rustfmt-lib/src/syntux/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,11 @@ impl<'a> Parser<'a> {
}
TokenKind::DocComment(s) => {
// we need to get the position of this token before we bump.
let attr = syntax::attr::mk_sugared_doc_attr(s, parser.token.span);
let attr = syntax::attr::mk_doc_comment(
syntax::util::comments::doc_comment_style(&s.as_str()),
s,
parser.token.span,
);
if attr.style == ast::AttrStyle::Inner {
attrs.push(attr);
parser.bump();
Expand Down

0 comments on commit 30ed45b

Please sign in to comment.