From 30ed45bee48e00477c0de590fbb25c6ee9985659 Mon Sep 17 00:00:00 2001 From: Caleb Cartwright Date: Tue, 14 Jan 2020 20:30:07 -0600 Subject: [PATCH] refactor: apply AST doc comment updates Implements changes required post https://github.com/rust-lang/rust/pull/65750 --- rustfmt-core/rustfmt-lib/src/attr.rs | 8 ++++---- rustfmt-core/rustfmt-lib/src/imports.rs | 2 +- rustfmt-core/rustfmt-lib/src/items.rs | 2 +- rustfmt-core/rustfmt-lib/src/syntux/parser.rs | 6 +++++- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/rustfmt-core/rustfmt-lib/src/attr.rs b/rustfmt-core/rustfmt-lib/src/attr.rs index 4b11e5ea329..9872d190139 100644 --- a/rustfmt-core/rustfmt-lib/src/attr.rs +++ b/rustfmt-core/rustfmt-lib/src/attr.rs @@ -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() @@ -315,7 +315,7 @@ where impl Rewrite for ast::Attribute { fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option { 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 @@ -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); @@ -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); diff --git a/rustfmt-core/rustfmt-lib/src/imports.rs b/rustfmt-core/rustfmt-lib/src/imports.rs index 3b6354575da..9a193113799 100644 --- a/rustfmt-core/rustfmt-lib/src/imports.rs +++ b/rustfmt-core/rustfmt-lib/src/imports.rs @@ -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 diff --git a/rustfmt-core/rustfmt-lib/src/items.rs b/rustfmt-core/rustfmt-lib/src/items.rs index be99d81b752..e1b2b7860fe 100644 --- a/rustfmt-core/rustfmt-lib/src/items.rs +++ b/rustfmt-core/rustfmt-lib/src/items.rs @@ -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 diff --git a/rustfmt-core/rustfmt-lib/src/syntux/parser.rs b/rustfmt-core/rustfmt-lib/src/syntux/parser.rs index 9a5bab17795..8cae3315976 100644 --- a/rustfmt-core/rustfmt-lib/src/syntux/parser.rs +++ b/rustfmt-core/rustfmt-lib/src/syntux/parser.rs @@ -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();