Skip to content

Commit 30ed45b

Browse files
refactor: apply AST doc comment updates
Implements changes required post rust-lang/rust#65750
1 parent 6064ab5 commit 30ed45b

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
lines changed

rustfmt-core/rustfmt-lib/src/attr.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ fn rewrite_initial_doc_comments(
167167
return Some((0, None));
168168
}
169169
// Rewrite doc comments
170-
let sugared_docs = take_while_with_pred(context, attrs, |a| a.is_sugared_doc);
170+
let sugared_docs = take_while_with_pred(context, attrs, |a| a.is_doc_comment());
171171
if !sugared_docs.is_empty() {
172172
let snippet = sugared_docs
173173
.iter()
@@ -315,7 +315,7 @@ where
315315
impl Rewrite for ast::Attribute {
316316
fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
317317
let snippet = context.snippet(self.span);
318-
if self.is_sugared_doc {
318+
if self.is_doc_comment() {
319319
rewrite_doc_comment(snippet, shape.comment(context.config), context.config)
320320
} else {
321321
let should_skip = self
@@ -437,7 +437,7 @@ impl<'a> Rewrite for [ast::Attribute] {
437437
)?;
438438
result.push_str(&comment);
439439
if let Some(next) = attrs.get(derives.len()) {
440-
if next.is_sugared_doc {
440+
if next.is_doc_comment() {
441441
let snippet = context.snippet(missing_span);
442442
let (_, mlb) = has_newlines_before_after_comment(snippet);
443443
result.push_str(&mlb);
@@ -470,7 +470,7 @@ impl<'a> Rewrite for [ast::Attribute] {
470470
)?;
471471
result.push_str(&comment);
472472
if let Some(next) = attrs.get(1) {
473-
if next.is_sugared_doc {
473+
if next.is_doc_comment() {
474474
let snippet = context.snippet(missing_span);
475475
let (_, mlb) = has_newlines_before_after_comment(snippet);
476476
result.push_str(&mlb);

rustfmt-core/rustfmt-lib/src/imports.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ impl UseTree {
248248

249249
let allow_extend = if attrs.len() == 1 {
250250
let line_len = attr_str.len() + 1 + use_str.len();
251-
!attrs.first().unwrap().is_sugared_doc
251+
!attrs.first().unwrap().is_doc_comment()
252252
&& context.config.inline_attribute_width() >= line_len
253253
} else {
254254
false

rustfmt-core/rustfmt-lib/src/items.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3139,7 +3139,7 @@ fn rewrite_attrs(
31393139

31403140
let allow_extend = if attrs.len() == 1 {
31413141
let line_len = attrs_str.len() + 1 + item_str.len();
3142-
!attrs.first().unwrap().is_sugared_doc
3142+
!attrs.first().unwrap().is_doc_comment()
31433143
&& context.config.inline_attribute_width() >= line_len
31443144
} else {
31453145
false

rustfmt-core/rustfmt-lib/src/syntux/parser.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,11 @@ impl<'a> Parser<'a> {
151151
}
152152
TokenKind::DocComment(s) => {
153153
// we need to get the position of this token before we bump.
154-
let attr = syntax::attr::mk_sugared_doc_attr(s, parser.token.span);
154+
let attr = syntax::attr::mk_doc_comment(
155+
syntax::util::comments::doc_comment_style(&s.as_str()),
156+
s,
157+
parser.token.span,
158+
);
155159
if attr.style == ast::AttrStyle::Inner {
156160
attrs.push(attr);
157161
parser.bump();

0 commit comments

Comments
 (0)