Skip to content

Commit bbcb641

Browse files
committed
fix doc comments, use optional snippets
1 parent 266d5fb commit bbcb641

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

clippy_lints/src/doc/doc_comment_double_space_linebreak.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use clippy_utils::diagnostics::span_lint_and_then;
2-
use clippy_utils::source::snippet;
2+
use clippy_utils::source::snippet_opt;
33
use rustc_errors::Applicability;
44
use rustc_lint::LateContext;
55
use rustc_span::Span;
@@ -30,7 +30,8 @@ fn collect_doc_replacements(cx: &LateContext<'_>, spans: &[Span]) -> Vec<(Span,
3030
spans
3131
.iter()
3232
.map(|span| {
33-
let s = snippet(cx, *span, "..");
33+
// we already made sure the snippet exists when collecting spans
34+
let s = snippet_opt(cx, *span).expect("snippet was already validated to exist");
3435
let after_newline = s.trim_start_matches(' ');
3536

3637
let new_comment = format!("\\{after_newline}");

clippy_lints/src/doc/mod.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use clippy_config::Conf;
77
use clippy_utils::attrs::is_doc_hidden;
88
use clippy_utils::diagnostics::{span_lint, span_lint_and_help, span_lint_and_then};
99
use clippy_utils::macros::{is_panic, root_macro_call_first_node};
10-
use clippy_utils::source::snippet;
10+
use clippy_utils::source::snippet_opt;
1111
use clippy_utils::ty::is_type_diagnostic_item;
1212
use clippy_utils::visitors::Visitable;
1313
use clippy_utils::{is_entrypoint_fn, is_trait_impl_item, method_chain_args};
@@ -626,11 +626,11 @@ declare_clippy_lint! {
626626
}
627627

628628
declare_clippy_lint! {
629-
/// Detects doc comment linebreaks that use double spaces to separate lines, instead of back-slash (\).
629+
/// Detects doc comment linebreaks that use double spaces to separate lines, instead of back-slash (`\`).
630630
///
631631
/// ### Why is this bad?
632632
/// Double spaces, when used as doc comment linebreaks, can be difficult to see, and may
633-
/// accidentally be removed during automatic formatting or manual refactoring. The use of a back-slash (\)
633+
/// accidentally be removed during automatic formatting or manual refactoring. The use of a back-slash (`\`)
634634
/// is clearer in this regard.
635635
///
636636
/// ### Example
@@ -909,6 +909,7 @@ fn check_doc<'a, Events: Iterator<Item = (pulldown_cmark::Event<'a>, Range<usize
909909
let mut code_level = 0;
910910
let mut blockquote_level = 0;
911911
let mut collected_breaks: Vec<Span> = Vec::new();
912+
let mut is_first_paragraph = true;
912913

913914
let mut containers = Vec::new();
914915

@@ -1085,7 +1086,7 @@ fn check_doc<'a, Events: Iterator<Item = (pulldown_cmark::Event<'a>, Range<usize
10851086

10861087
if let Some(span) = fragments.span(cx, range.clone())
10871088
&& !span.from_expansion()
1088-
&& let snippet = snippet(cx, span, "..")
1089+
&& let Some(snippet) = snippet_opt(cx, span)
10891090
&& !snippet.trim().starts_with('\\')
10901091
&& event == HardBreak {
10911092
collected_breaks.push(span);

0 commit comments

Comments
 (0)