Skip to content

Commit

Permalink
Auto merge of rust-lang#8011 - birkenfeld:double_backticks, r=xFrednet
Browse files Browse the repository at this point in the history
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`
  • Loading branch information
bors committed Nov 20, 2021
2 parents 827fd50 + 0c4055c commit 32048eb
Show file tree
Hide file tree
Showing 3 changed files with 212 additions and 39 deletions.
21 changes: 15 additions & 6 deletions clippy_lints/src/doc.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use clippy_utils::attrs::is_doc_hidden;
use clippy_utils::diagnostics::{span_lint, span_lint_and_help, span_lint_and_note, span_lint_and_sugg};
use clippy_utils::diagnostics::{span_lint, span_lint_and_help, span_lint_and_note, span_lint_and_then};
use clippy_utils::source::{first_line_of_span, snippet_with_applicability};
use clippy_utils::ty::{implements_trait, is_type_diagnostic_item};
use clippy_utils::{is_entrypoint_fn, is_expn_of, match_panic_def_id, method_chain_args, return_ty};
Expand All @@ -10,7 +10,7 @@ use rustc_ast::token::CommentKind;
use rustc_data_structures::fx::FxHashSet;
use rustc_data_structures::sync::Lrc;
use rustc_errors::emitter::EmitterWriter;
use rustc_errors::{Applicability, Handler};
use rustc_errors::{Applicability, Handler, SuggestionStyle};
use rustc_hir as hir;
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
use rustc_hir::{AnonConst, Expr, ExprKind, QPath};
Expand Down Expand Up @@ -770,14 +770,23 @@ fn check_word(cx: &LateContext<'_>, word: &str, span: Span) {
if has_underscore(word) || word.contains("::") || is_camel_case(word) {
let mut applicability = Applicability::MachineApplicable;

span_lint_and_sugg(
span_lint_and_then(
cx,
DOC_MARKDOWN,
span,
"item in documentation is missing backticks",
"try",
format!("`{}`", snippet_with_applicability(cx, span, "..", &mut applicability)),
applicability,
|diag| {
let snippet = snippet_with_applicability(cx, span, "..", &mut applicability);
diag.span_suggestion_with_style(
span,
"try",
format!("`{}`", snippet),
applicability,
// always show the suggestion in a separate line, since the
// inline presentation adds another pair of backticks
SuggestionStyle::ShowAlways,
);
},
);
}
}
Expand Down
Loading

0 comments on commit 32048eb

Please sign in to comment.