Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions clippy_lints/src/doc/doc_suspicious_footnotes.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use clippy_utils::diagnostics::span_lint_and_then;
use rustc_ast::attr::AttributeExt as _;
use rustc_ast::token::CommentKind;
use rustc_errors::Applicability;
use rustc_hir::{AttrStyle, Attribute};
Expand All @@ -8,7 +7,7 @@ use rustc_resolve::rustdoc::DocFragmentKind;

use std::ops::Range;

use super::{DOC_SUSPICIOUS_FOOTNOTES, Fragments};
use super::{DOC_SUSPICIOUS_FOOTNOTES, Fragments, find_doc_attr_by_span};

pub fn check(cx: &LateContext<'_>, doc: &str, range: Range<usize>, fragments: &Fragments<'_>, attrs: &[Attribute]) {
for i in doc[range.clone()]
Expand Down Expand Up @@ -44,14 +43,8 @@ pub fn check(cx: &LateContext<'_>, doc: &str, range: Range<usize>, fragments: &F
"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
.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()?))
})
.unwrap();
let (doc_attr, doc_attr_comment_kind, attr_style) =
find_doc_attr_by_span(attrs, this_fragment.span).unwrap();
let (to_add, terminator) = match (doc_attr_comment_kind, attr_style) {
(CommentKind::Line, AttrStyle::Outer) => ("\n///\n/// ", ""),
(CommentKind::Line, AttrStyle::Inner) => ("\n//!\n//! ", ""),
Expand Down
10 changes: 1 addition & 9 deletions clippy_lints/src/doc/lazy_continuation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,6 @@ use std::ops::Range;

use super::{DOC_LAZY_CONTINUATION, DOC_OVERINDENTED_LIST_ITEMS, Fragments};

fn map_container_to_text(c: &super::Container) -> &'static str {
match c {
super::Container::Blockquote => "> ",
// numbered list can have up to nine digits, plus the dot, plus four spaces on either side
super::Container::List(indent) => &" "[0..*indent],
}
}

pub(super) fn check(
cx: &LateContext<'_>,
doc: &str,
Expand All @@ -41,7 +33,7 @@ pub(super) fn check(
let mut doc_start_range = &doc[cooked_range];
let mut suggested = String::new();
for c in containers {
let text = map_container_to_text(c);
let text = c.map_to_text();
if doc_start_range.starts_with(text) {
doc_start_range = &doc_start_range[text.len()..];
span = span.with_lo(
Expand Down
25 changes: 13 additions & 12 deletions clippy_lints/src/doc/missing_headers.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::{DocHeaders, MISSING_ERRORS_DOC, MISSING_PANICS_DOC, MISSING_SAFETY_DOC, UNNECESSARY_SAFETY_DOC};
use clippy_utils::diagnostics::{span_lint, span_lint_and_note};
use clippy_utils::diagnostics::span_lint;
use clippy_utils::macros::{is_panic, root_macro_call_first_node};
use clippy_utils::ty::{get_type_diagnostic_name, implements_trait_with_env, is_type_diagnostic_item};
use clippy_utils::visitors::for_each_expr;
Expand All @@ -14,7 +14,7 @@ pub fn check(
cx: &LateContext<'_>,
owner_id: OwnerId,
sig: FnSig<'_>,
headers: DocHeaders,
headers: &DocHeaders,
body_id: Option<BodyId>,
check_private_items: bool,
) {
Expand All @@ -33,37 +33,38 @@ pub fn check(
}

let span = cx.tcx.def_span(owner_id);
match (headers.safety, sig.header.safety()) {
(false, Safety::Unsafe) => span_lint(
match (headers.safety.is_missing(), sig.header.safety()) {
(true, Safety::Unsafe) => headers.safety.lint(
cx,
MISSING_SAFETY_DOC,
span,
"unsafe function's docs are missing a `# Safety` section",
),
(true, Safety::Safe) => span_lint(
(false, Safety::Safe) => span_lint(
cx,
UNNECESSARY_SAFETY_DOC,
span,
"safe function's docs have unnecessary `# Safety` section",
),
_ => (),
}
if !headers.panics
if headers.panics.is_missing()
&& let Some(body_id) = body_id
&& let Some(panic_span) = find_panic(cx, body_id)
{
span_lint_and_note(
headers.panics.lint_and_then(
cx,
MISSING_PANICS_DOC,
span,
"docs for function which may panic missing `# Panics` section",
Some(panic_span),
"first possible panic found here",
|diag| {
diag.span_note(panic_span, "first possible panic found here");
},
);
}
if !headers.errors {
if headers.errors.is_missing() {
if is_type_diagnostic_item(cx, return_ty(cx, owner_id), sym::Result) {
span_lint(
headers.errors.lint(
cx,
MISSING_ERRORS_DOC,
span,
Expand All @@ -85,7 +86,7 @@ pub fn check(
&& let ty::Coroutine(_, subs) = ret_ty.kind()
&& is_type_diagnostic_item(cx, subs.as_coroutine().return_ty(), sym::Result)
{
span_lint(
headers.errors.lint(
cx,
MISSING_ERRORS_DOC,
span,
Expand Down
Loading
Loading