Merge commit 'a109190d70' into clippy-subtree-update
This commit is contained in:
parent
c512a221c2
commit
fea5e77da1
179 changed files with 4032 additions and 1752 deletions
|
|
@ -5,6 +5,7 @@ use rustc_errors::Applicability;
|
|||
use rustc_hir::{Closure, Expr, ExprKind};
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
use rustc_session::declare_lint_pass;
|
||||
use rustc_span::Span;
|
||||
|
||||
use std::borrow::{Borrow, Cow};
|
||||
|
||||
|
|
@ -76,19 +77,19 @@ impl<'tcx> LateLintPass<'tcx> for CollapsibleCalls {
|
|||
return;
|
||||
}
|
||||
|
||||
if let ExprKind::Call(func, and_then_args) = expr.kind
|
||||
if let ExprKind::Call(func, [call_cx, call_lint, call_sp, call_msg, call_f]) = expr.kind
|
||||
&& is_expr_path_def_path(cx, func, &["clippy_utils", "diagnostics", "span_lint_and_then"])
|
||||
&& and_then_args.len() == 5
|
||||
&& let ExprKind::Closure(&Closure { body, .. }) = &and_then_args[4].kind
|
||||
&& let ExprKind::Closure(&Closure { body, .. }) = &call_f.kind
|
||||
&& let body = cx.tcx.hir().body(body)
|
||||
&& let only_expr = peel_blocks_with_stmt(body.value)
|
||||
&& let ExprKind::MethodCall(ps, recv, span_call_args, _) = &only_expr.kind
|
||||
&& let ExprKind::Path(..) = recv.kind
|
||||
{
|
||||
let and_then_snippets = get_and_then_snippets(cx, and_then_args);
|
||||
let and_then_snippets =
|
||||
get_and_then_snippets(cx, call_cx.span, call_lint.span, call_sp.span, call_msg.span);
|
||||
let mut sle = SpanlessEq::new(cx).deny_side_effects();
|
||||
match ps.ident.as_str() {
|
||||
"span_suggestion" if sle.eq_expr(&and_then_args[2], &span_call_args[0]) => {
|
||||
"span_suggestion" if sle.eq_expr(call_sp, &span_call_args[0]) => {
|
||||
suggest_suggestion(
|
||||
cx,
|
||||
expr,
|
||||
|
|
@ -96,11 +97,11 @@ impl<'tcx> LateLintPass<'tcx> for CollapsibleCalls {
|
|||
&span_suggestion_snippets(cx, span_call_args),
|
||||
);
|
||||
},
|
||||
"span_help" if sle.eq_expr(&and_then_args[2], &span_call_args[0]) => {
|
||||
"span_help" if sle.eq_expr(call_sp, &span_call_args[0]) => {
|
||||
let help_snippet = snippet(cx, span_call_args[1].span, r#""...""#);
|
||||
suggest_help(cx, expr, &and_then_snippets, help_snippet.borrow(), true);
|
||||
},
|
||||
"span_note" if sle.eq_expr(&and_then_args[2], &span_call_args[0]) => {
|
||||
"span_note" if sle.eq_expr(call_sp, &span_call_args[0]) => {
|
||||
let note_snippet = snippet(cx, span_call_args[1].span, r#""...""#);
|
||||
suggest_note(cx, expr, &and_then_snippets, note_snippet.borrow(), true);
|
||||
},
|
||||
|
|
@ -125,11 +126,17 @@ struct AndThenSnippets<'a> {
|
|||
msg: Cow<'a, str>,
|
||||
}
|
||||
|
||||
fn get_and_then_snippets<'a, 'hir>(cx: &LateContext<'_>, and_then_snippets: &'hir [Expr<'hir>]) -> AndThenSnippets<'a> {
|
||||
let cx_snippet = snippet(cx, and_then_snippets[0].span, "cx");
|
||||
let lint_snippet = snippet(cx, and_then_snippets[1].span, "..");
|
||||
let span_snippet = snippet(cx, and_then_snippets[2].span, "span");
|
||||
let msg_snippet = snippet(cx, and_then_snippets[3].span, r#""...""#);
|
||||
fn get_and_then_snippets(
|
||||
cx: &LateContext<'_>,
|
||||
cx_span: Span,
|
||||
lint_span: Span,
|
||||
span_span: Span,
|
||||
msg_span: Span,
|
||||
) -> AndThenSnippets<'static> {
|
||||
let cx_snippet = snippet(cx, cx_span, "cx");
|
||||
let lint_snippet = snippet(cx, lint_span, "..");
|
||||
let span_snippet = snippet(cx, span_span, "span");
|
||||
let msg_snippet = snippet(cx, msg_span, r#""...""#);
|
||||
|
||||
AndThenSnippets {
|
||||
cx: cx_snippet,
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use clippy_utils::diagnostics::{span_lint, span_lint_and_help};
|
|||
use clippy_utils::macros::root_macro_call_first_node;
|
||||
use clippy_utils::{is_lint_allowed, match_def_path, paths};
|
||||
use rustc_ast::ast::LitKind;
|
||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
|
||||
use rustc_hir::def::{DefKind, Res};
|
||||
use rustc_hir::hir_id::CRATE_HIR_ID;
|
||||
use rustc_hir::intravisit::Visitor;
|
||||
|
|
@ -87,8 +87,8 @@ declare_clippy_lint! {
|
|||
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub struct LintWithoutLintPass {
|
||||
declared_lints: FxHashMap<Symbol, Span>,
|
||||
registered_lints: FxHashSet<Symbol>,
|
||||
declared_lints: FxIndexMap<Symbol, Span>,
|
||||
registered_lints: FxIndexSet<Symbol>,
|
||||
}
|
||||
|
||||
impl_lint_pass!(LintWithoutLintPass => [
|
||||
|
|
@ -266,7 +266,7 @@ pub(super) fn extract_clippy_version_value(cx: &LateContext<'_>, item: &'_ Item<
|
|||
}
|
||||
|
||||
struct LintCollector<'a, 'tcx> {
|
||||
output: &'a mut FxHashSet<Symbol>,
|
||||
output: &'a mut FxIndexSet<Symbol>,
|
||||
cx: &'a LateContext<'tcx>,
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue