Skip to content

Commit 3a69d06

Browse files
Update clippy code to new doc attribute API
1 parent 1e85502 commit 3a69d06

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

src/tools/clippy/clippy_lints/src/doc/doc_suspicious_footnotes.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
use clippy_utils::diagnostics::span_lint_and_then;
22
use rustc_ast::attr::AttributeExt as _;
3-
use rustc_ast::token::CommentKind;
3+
use rustc_ast::token::{CommentKind, DocFragmentKind};
44
use rustc_errors::Applicability;
55
use rustc_hir::{AttrStyle, Attribute};
66
use rustc_lint::{LateContext, LintContext};
7-
use rustc_resolve::rustdoc::DocFragmentKind;
87

98
use std::ops::Range;
109

@@ -43,13 +42,18 @@ pub fn check(cx: &LateContext<'_>, doc: &str, range: Range<usize>, fragments: &F
4342
span,
4443
"looks like a footnote ref, but has no matching footnote",
4544
|diag| {
46-
if this_fragment.kind == DocFragmentKind::SugaredDoc {
47-
let (doc_attr, (_, doc_attr_comment_kind), attr_style) = attrs
45+
if let DocFragmentKind::Sugared(_) = this_fragment.kind {
46+
let (doc_attr, doc_attr_comment_kind, attr_style) = attrs
4847
.iter()
4948
.filter(|attr| attr.span().overlaps(this_fragment.span))
5049
.rev()
5150
.find_map(|attr| {
52-
Some((attr, attr.doc_str_and_comment_kind()?, attr.doc_resolution_scope()?))
51+
let (_, fragment) = attr.doc_str_and_fragment_kind()?;
52+
let fragment = match fragment {
53+
DocFragmentKind::Sugared(kind) => kind,
54+
DocFragmentKind::Raw(_) => CommentKind::Line,
55+
};
56+
Some((attr, fragment, attr.doc_resolution_scope()?))
5357
})
5458
.unwrap();
5559
let (to_add, terminator) = match (doc_attr_comment_kind, attr_style) {

src/tools/clippy/clippy_lints/src/doc/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,7 @@ fn check_attrs(cx: &LateContext<'_>, valid_idents: &FxHashSet<String>, attrs: &[
861861

862862
let (fragments, _) = attrs_to_doc_fragments(
863863
attrs.iter().filter_map(|attr| {
864-
if attr.doc_str_and_comment_kind().is_none() || attr.span().in_external_macro(cx.sess().source_map()) {
864+
if attr.doc_str_and_fragment_kind().is_none() || attr.span().in_external_macro(cx.sess().source_map()) {
865865
None
866866
} else {
867867
Some((attr, None))

src/tools/clippy/clippy_lints/src/doc/suspicious_doc_comments.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use clippy_utils::diagnostics::span_lint_and_then;
22
use rustc_ast::AttrStyle;
3-
use rustc_ast::token::CommentKind;
3+
use rustc_ast::token::{CommentKind, DocFragmentKind};
44
use rustc_errors::Applicability;
55
use rustc_hir::Attribute;
66
use rustc_hir::attrs::AttributeKind;
@@ -46,8 +46,8 @@ fn collect_doc_replacements(attrs: &[Attribute]) -> Vec<(Span, String)> {
4646
&& let Some(com) = comment.as_str().strip_prefix('!')
4747
{
4848
let sugg = match kind {
49-
CommentKind::Line => format!("//!{com}"),
50-
CommentKind::Block => format!("/*!{com}*/"),
49+
DocFragmentKind::Sugared(CommentKind::Block) => format!("/*!{com}*/"),
50+
DocFragmentKind::Sugared(CommentKind::Line) | DocFragmentKind::Raw(_) => format!("//!{com}"),
5151
};
5252
Some((attr.span(), sugg))
5353
} else {

0 commit comments

Comments
 (0)