Update clippy code to new doc attribute API
This commit is contained in:
parent
8cc9c5ebb1
commit
e013f772da
3 changed files with 13 additions and 9 deletions
|
|
@ -1,10 +1,9 @@
|
|||
use clippy_utils::diagnostics::span_lint_and_then;
|
||||
use rustc_ast::attr::AttributeExt as _;
|
||||
use rustc_ast::token::CommentKind;
|
||||
use rustc_ast::token::{CommentKind, DocFragmentKind};
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_hir::{AttrStyle, Attribute};
|
||||
use rustc_lint::{LateContext, LintContext};
|
||||
use rustc_resolve::rustdoc::DocFragmentKind;
|
||||
|
||||
use std::ops::Range;
|
||||
|
||||
|
|
@ -43,13 +42,18 @@ pub fn check(cx: &LateContext<'_>, doc: &str, range: Range<usize>, fragments: &F
|
|||
span,
|
||||
"looks like a footnote ref, but has no matching footnote",
|
||||
|diag| {
|
||||
if this_fragment.kind == DocFragmentKind::SugaredDoc {
|
||||
let (doc_attr, (_, doc_attr_comment_kind), attr_style) = attrs
|
||||
if let DocFragmentKind::Sugared(_) = this_fragment.kind {
|
||||
let (doc_attr, doc_attr_comment_kind, attr_style) = attrs
|
||||
.iter()
|
||||
.filter(|attr| attr.span().overlaps(this_fragment.span))
|
||||
.rev()
|
||||
.find_map(|attr| {
|
||||
Some((attr, attr.doc_str_and_comment_kind()?, attr.doc_resolution_scope()?))
|
||||
let (_, fragment) = attr.doc_str_and_fragment_kind()?;
|
||||
let fragment = match fragment {
|
||||
DocFragmentKind::Sugared(kind) => kind,
|
||||
DocFragmentKind::Raw(_) => CommentKind::Line,
|
||||
};
|
||||
Some((attr, fragment, attr.doc_resolution_scope()?))
|
||||
})
|
||||
.unwrap();
|
||||
let (to_add, terminator) = match (doc_attr_comment_kind, attr_style) {
|
||||
|
|
|
|||
|
|
@ -861,7 +861,7 @@ fn check_attrs(cx: &LateContext<'_>, valid_idents: &FxHashSet<String>, attrs: &[
|
|||
|
||||
let (fragments, _) = attrs_to_doc_fragments(
|
||||
attrs.iter().filter_map(|attr| {
|
||||
if attr.doc_str_and_comment_kind().is_none() || attr.span().in_external_macro(cx.sess().source_map()) {
|
||||
if attr.doc_str_and_fragment_kind().is_none() || attr.span().in_external_macro(cx.sess().source_map()) {
|
||||
None
|
||||
} else {
|
||||
Some((attr, None))
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use clippy_utils::diagnostics::span_lint_and_then;
|
||||
use rustc_ast::AttrStyle;
|
||||
use rustc_ast::token::CommentKind;
|
||||
use rustc_ast::token::{CommentKind, DocFragmentKind};
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_hir::Attribute;
|
||||
use rustc_hir::attrs::AttributeKind;
|
||||
|
|
@ -46,8 +46,8 @@ fn collect_doc_replacements(attrs: &[Attribute]) -> Vec<(Span, String)> {
|
|||
&& let Some(com) = comment.as_str().strip_prefix('!')
|
||||
{
|
||||
let sugg = match kind {
|
||||
CommentKind::Line => format!("//!{com}"),
|
||||
CommentKind::Block => format!("/*!{com}*/"),
|
||||
DocFragmentKind::Sugared(CommentKind::Block) => format!("/*!{com}*/"),
|
||||
DocFragmentKind::Sugared(CommentKind::Line) | DocFragmentKind::Raw(_) => format!("//!{com}"),
|
||||
};
|
||||
Some((attr.span(), sugg))
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue