mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-29 20:46:07 +03:00
Update clippy code
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
use rustc_ast::attr::AttributeExt as _;
|
||||
use rustc_ast::token::{CommentKind, DocFragmentKind};
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_hir::attrs::AttributeKind;
|
||||
use rustc_hir::{AttrStyle, Attribute};
|
||||
use rustc_lint::{LateContext, LintContext};
|
||||
|
||||
@@ -45,7 +46,13 @@ pub fn check(cx: &LateContext<'_>, doc: &str, range: Range<usize>, fragments: &F
|
||||
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))
|
||||
.filter(|attr| {
|
||||
matches!(
|
||||
attr,
|
||||
Attribute::Parsed(AttributeKind::DocComment { span, .. })
|
||||
if span.overlaps(this_fragment.span),
|
||||
)
|
||||
})
|
||||
.rev()
|
||||
.find_map(|attr| {
|
||||
let (_, fragment) = attr.doc_str_and_fragment_kind()?;
|
||||
|
||||
@@ -39,15 +39,15 @@ fn collect_doc_replacements(attrs: &[Attribute]) -> Vec<(Span, String)> {
|
||||
.filter_map(|attr| {
|
||||
if let Attribute::Parsed(AttributeKind::DocComment {
|
||||
style: AttrStyle::Outer,
|
||||
kind,
|
||||
kind: DocFragmentKind::Sugared(comment_kind),
|
||||
comment,
|
||||
..
|
||||
}) = attr
|
||||
&& let Some(com) = comment.as_str().strip_prefix('!')
|
||||
{
|
||||
let sugg = match kind {
|
||||
DocFragmentKind::Sugared(CommentKind::Block) => format!("/*!{com}*/"),
|
||||
DocFragmentKind::Sugared(CommentKind::Line) | DocFragmentKind::Raw(_) => format!("//!{com}"),
|
||||
let sugg = match comment_kind {
|
||||
CommentKind::Block => format!("/*!{com}*/"),
|
||||
CommentKind::Line => format!("//!{com}"),
|
||||
};
|
||||
Some((attr.span(), sugg))
|
||||
} else {
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
use crate::source::SpanRangeExt;
|
||||
use crate::{sym, tokenize_with_text};
|
||||
use rustc_ast::attr;
|
||||
use rustc_ast::attr::AttributeExt;
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_hir::attrs::AttributeKind;
|
||||
@@ -87,11 +86,7 @@ pub fn is_proc_macro(attrs: &[impl AttributeExt]) -> bool {
|
||||
|
||||
/// Checks whether `attrs` contain `#[doc(hidden)]`
|
||||
pub fn is_doc_hidden(attrs: &[impl AttributeExt]) -> bool {
|
||||
attrs
|
||||
.iter()
|
||||
.filter(|attr| attr.has_name(sym::doc))
|
||||
.filter_map(AttributeExt::meta_item_list)
|
||||
.any(|l| attr::list_contains_name(&l, sym::hidden))
|
||||
attrs.iter().any(|attr| attr.is_doc_hidden())
|
||||
}
|
||||
|
||||
/// Checks whether the given ADT, or any of its fields/variants, are marked as `#[non_exhaustive]`
|
||||
|
||||
Reference in New Issue
Block a user