Merge commit 'd5e2a7aca5' into clippyup
This commit is contained in:
parent
58eb9964cc
commit
8df896c076
184 changed files with 3000 additions and 1635 deletions
|
|
@ -1,6 +1,6 @@
|
|||
use super::{contains_return, BIND_INSTEAD_OF_MAP};
|
||||
use clippy_utils::diagnostics::{multispan_sugg_with_applicability, span_lint_and_sugg, span_lint_and_then};
|
||||
use clippy_utils::source::{snippet, snippet_with_macro_callsite};
|
||||
use clippy_utils::source::{snippet, snippet_with_context};
|
||||
use clippy_utils::{peel_blocks, visitors::find_all_ret_expressions};
|
||||
use if_chain::if_chain;
|
||||
use rustc_errors::Applicability;
|
||||
|
|
@ -76,11 +76,8 @@ pub(crate) trait BindInsteadOfMap {
|
|||
if !contains_return(inner_expr);
|
||||
if let Some(msg) = Self::lint_msg(cx);
|
||||
then {
|
||||
let some_inner_snip = if inner_expr.span.from_expansion() {
|
||||
snippet_with_macro_callsite(cx, inner_expr.span, "_")
|
||||
} else {
|
||||
snippet(cx, inner_expr.span, "_")
|
||||
};
|
||||
let mut app = Applicability::MachineApplicable;
|
||||
let some_inner_snip = snippet_with_context(cx, inner_expr.span, closure_expr.span.ctxt(), "_", &mut app).0;
|
||||
|
||||
let closure_args_snip = snippet(cx, closure_args_span, "..");
|
||||
let option_snip = snippet(cx, recv.span, "..");
|
||||
|
|
@ -92,7 +89,7 @@ pub(crate) trait BindInsteadOfMap {
|
|||
&msg,
|
||||
"try this",
|
||||
note,
|
||||
Applicability::MachineApplicable,
|
||||
app,
|
||||
);
|
||||
true
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use clippy_utils::diagnostics::span_lint_and_sugg;
|
||||
use clippy_utils::paths;
|
||||
use clippy_utils::source::snippet_with_macro_callsite;
|
||||
use clippy_utils::source::snippet_with_context;
|
||||
use clippy_utils::ty::{is_type_diagnostic_item, match_type};
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_hir as hir;
|
||||
|
|
@ -33,7 +33,9 @@ pub(super) fn check(
|
|||
return;
|
||||
};
|
||||
|
||||
let snippet = snippet_with_macro_callsite(cx, receiver.span, "..");
|
||||
// Sometimes unnecessary ::<_> after Rc/Arc/Weak
|
||||
let mut app = Applicability::Unspecified;
|
||||
let snippet = snippet_with_context(cx, receiver.span, expr.span.ctxt(), "..", &mut app).0;
|
||||
|
||||
span_lint_and_sugg(
|
||||
cx,
|
||||
|
|
@ -42,7 +44,7 @@ pub(super) fn check(
|
|||
"using `.clone()` on a ref-counted pointer",
|
||||
"try this",
|
||||
format!("{caller_type}::<{}>::clone(&{snippet})", subst.type_at(0)),
|
||||
Applicability::Unspecified, // Sometimes unnecessary ::<_> after Rc/Arc/Weak
|
||||
app,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use clippy_utils::diagnostics::span_lint_and_sugg;
|
||||
use clippy_utils::eager_or_lazy::switch_to_lazy_eval;
|
||||
use clippy_utils::source::{snippet, snippet_with_macro_callsite};
|
||||
use clippy_utils::source::snippet_with_context;
|
||||
use clippy_utils::ty::{implements_trait, is_type_diagnostic_item};
|
||||
use clippy_utils::{contains_return, is_trait_item, last_path_segment};
|
||||
use if_chain::if_chain;
|
||||
|
|
@ -9,7 +9,6 @@ use rustc_hir as hir;
|
|||
use rustc_lint::LateContext;
|
||||
use rustc_span::source_map::Span;
|
||||
use rustc_span::symbol::{kw, sym, Symbol};
|
||||
use std::borrow::Cow;
|
||||
|
||||
use super::OR_FUN_CALL;
|
||||
|
||||
|
|
@ -111,37 +110,24 @@ pub(super) fn check<'tcx>(
|
|||
if poss.contains(&name);
|
||||
|
||||
then {
|
||||
let ctxt = span.ctxt();
|
||||
let mut app = Applicability::HasPlaceholders;
|
||||
let sugg = {
|
||||
let (snippet_span, use_lambda) = match (fn_has_arguments, fun_span) {
|
||||
(false, Some(fun_span)) => (fun_span, false),
|
||||
_ => (arg.span, true),
|
||||
};
|
||||
|
||||
let format_span = |span: Span| {
|
||||
let not_macro_argument_snippet = snippet_with_macro_callsite(cx, span, "..");
|
||||
let snip = if not_macro_argument_snippet == "vec![]" {
|
||||
let macro_expanded_snipped = snippet(cx, snippet_span, "..");
|
||||
match macro_expanded_snipped.strip_prefix("$crate::vec::") {
|
||||
Some(stripped) => Cow::Owned(stripped.to_owned()),
|
||||
None => macro_expanded_snipped,
|
||||
}
|
||||
} else {
|
||||
not_macro_argument_snippet
|
||||
};
|
||||
|
||||
snip.to_string()
|
||||
};
|
||||
|
||||
let snip = format_span(snippet_span);
|
||||
let snip = snippet_with_context(cx, snippet_span, ctxt, "..", &mut app).0;
|
||||
let snip = if use_lambda {
|
||||
let l_arg = if fn_has_arguments { "_" } else { "" };
|
||||
format!("|{l_arg}| {snip}")
|
||||
} else {
|
||||
snip
|
||||
snip.into_owned()
|
||||
};
|
||||
|
||||
if let Some(f) = second_arg {
|
||||
let f = format_span(f.span);
|
||||
let f = snippet_with_context(cx, f.span, ctxt, "..", &mut app).0;
|
||||
format!("{snip}, {f}")
|
||||
} else {
|
||||
snip
|
||||
|
|
@ -155,7 +141,7 @@ pub(super) fn check<'tcx>(
|
|||
&format!("use of `{name}` followed by a function call"),
|
||||
"try this",
|
||||
format!("{name}_{suffix}({sugg})"),
|
||||
Applicability::HasPlaceholders,
|
||||
app,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue