Skip to content

Commit 32048eb

Browse files
committed
Auto merge of rust-lang#8011 - birkenfeld:double_backticks, r=xFrednet
Avoid inline hints with double backticks for `doc-markdown` The easiest route here was to ensure that the suggestion is always shown on its own line, where no additional backticks are added by the diagnostic formatter. Fixes rust-lang#8002 --- *Please write a short comment explaining your change (or "none" for internal only changes)* changelog: Avoid inline hints with double backticks for `doc-markdown`
2 parents 827fd50 + 0c4055c commit 32048eb

File tree

3 files changed

+212
-39
lines changed

3 files changed

+212
-39
lines changed

clippy_lints/src/doc.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use clippy_utils::attrs::is_doc_hidden;
2-
use clippy_utils::diagnostics::{span_lint, span_lint_and_help, span_lint_and_note, span_lint_and_sugg};
2+
use clippy_utils::diagnostics::{span_lint, span_lint_and_help, span_lint_and_note, span_lint_and_then};
33
use clippy_utils::source::{first_line_of_span, snippet_with_applicability};
44
use clippy_utils::ty::{implements_trait, is_type_diagnostic_item};
55
use clippy_utils::{is_entrypoint_fn, is_expn_of, match_panic_def_id, method_chain_args, return_ty};
@@ -10,7 +10,7 @@ use rustc_ast::token::CommentKind;
1010
use rustc_data_structures::fx::FxHashSet;
1111
use rustc_data_structures::sync::Lrc;
1212
use rustc_errors::emitter::EmitterWriter;
13-
use rustc_errors::{Applicability, Handler};
13+
use rustc_errors::{Applicability, Handler, SuggestionStyle};
1414
use rustc_hir as hir;
1515
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
1616
use rustc_hir::{AnonConst, Expr, ExprKind, QPath};
@@ -770,14 +770,23 @@ fn check_word(cx: &LateContext<'_>, word: &str, span: Span) {
770770
if has_underscore(word) || word.contains("::") || is_camel_case(word) {
771771
let mut applicability = Applicability::MachineApplicable;
772772

773-
span_lint_and_sugg(
773+
span_lint_and_then(
774774
cx,
775775
DOC_MARKDOWN,
776776
span,
777777
"item in documentation is missing backticks",
778-
"try",
779-
format!("`{}`", snippet_with_applicability(cx, span, "..", &mut applicability)),
780-
applicability,
778+
|diag| {
779+
let snippet = snippet_with_applicability(cx, span, "..", &mut applicability);
780+
diag.span_suggestion_with_style(
781+
span,
782+
"try",
783+
format!("`{}`", snippet),
784+
applicability,
785+
// always show the suggestion in a separate line, since the
786+
// inline presentation adds another pair of backticks
787+
SuggestionStyle::ShowAlways,
788+
);
789+
},
781790
);
782791
}
783792
}

0 commit comments

Comments
 (0)