mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-24 13:43:17 +00:00
Format affected files
This commit is contained in:
parent
2e5e3560e9
commit
5dc54c6066
15 changed files with 104 additions and 80 deletions
|
@ -137,7 +137,7 @@ impl<'tcx> LateLintPass<'tcx> for LetUnderscore {
|
||||||
"non-binding let on a synchronization lock",
|
"non-binding let on a synchronization lock",
|
||||||
None,
|
None,
|
||||||
"consider using an underscore-prefixed named \
|
"consider using an underscore-prefixed named \
|
||||||
binding or dropping explicitly with `std::mem::drop`"
|
binding or dropping explicitly with `std::mem::drop`",
|
||||||
);
|
);
|
||||||
} else if init_ty.needs_drop(cx.tcx, cx.param_env) {
|
} else if init_ty.needs_drop(cx.tcx, cx.param_env) {
|
||||||
span_lint_and_help(
|
span_lint_and_help(
|
||||||
|
@ -147,7 +147,7 @@ impl<'tcx> LateLintPass<'tcx> for LetUnderscore {
|
||||||
"non-binding `let` on a type that implements `Drop`",
|
"non-binding `let` on a type that implements `Drop`",
|
||||||
None,
|
None,
|
||||||
"consider using an underscore-prefixed named \
|
"consider using an underscore-prefixed named \
|
||||||
binding or dropping explicitly with `std::mem::drop`"
|
binding or dropping explicitly with `std::mem::drop`",
|
||||||
);
|
);
|
||||||
} else if is_must_use_ty(cx, cx.typeck_results().expr_ty(init)) {
|
} else if is_must_use_ty(cx, cx.typeck_results().expr_ty(init)) {
|
||||||
span_lint_and_help(
|
span_lint_and_help(
|
||||||
|
@ -156,7 +156,7 @@ impl<'tcx> LateLintPass<'tcx> for LetUnderscore {
|
||||||
local.span,
|
local.span,
|
||||||
"non-binding let on an expression with `#[must_use]` type",
|
"non-binding let on an expression with `#[must_use]` type",
|
||||||
None,
|
None,
|
||||||
"consider explicitly using expression value"
|
"consider explicitly using expression value",
|
||||||
);
|
);
|
||||||
} else if is_must_use_func_call(cx, init) {
|
} else if is_must_use_func_call(cx, init) {
|
||||||
span_lint_and_help(
|
span_lint_and_help(
|
||||||
|
@ -165,7 +165,7 @@ impl<'tcx> LateLintPass<'tcx> for LetUnderscore {
|
||||||
local.span,
|
local.span,
|
||||||
"non-binding let on a result of a `#[must_use]` function",
|
"non-binding let on a result of a `#[must_use]` function",
|
||||||
None,
|
None,
|
||||||
"consider explicitly using function result"
|
"consider explicitly using function result",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -263,7 +263,8 @@ impl<'a, 'tcx> VarVisitor<'a, 'tcx> {
|
||||||
match res {
|
match res {
|
||||||
Res::Local(hir_id) => {
|
Res::Local(hir_id) => {
|
||||||
let parent_def_id = self.cx.tcx.hir().get_parent_item(expr.hir_id);
|
let parent_def_id = self.cx.tcx.hir().get_parent_item(expr.hir_id);
|
||||||
let extent = self.cx
|
let extent = self
|
||||||
|
.cx
|
||||||
.tcx
|
.tcx
|
||||||
.region_scope_tree(parent_def_id)
|
.region_scope_tree(parent_def_id)
|
||||||
.var_scope(hir_id.local_id)
|
.var_scope(hir_id.local_id)
|
||||||
|
@ -274,10 +275,11 @@ impl<'a, 'tcx> VarVisitor<'a, 'tcx> {
|
||||||
(Some(extent), self.cx.typeck_results().node_type(seqexpr.hir_id)),
|
(Some(extent), self.cx.typeck_results().node_type(seqexpr.hir_id)),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
self.indexed_indirectly.insert(seqvar.segments[0].ident.name, Some(extent));
|
self.indexed_indirectly
|
||||||
|
.insert(seqvar.segments[0].ident.name, Some(extent));
|
||||||
}
|
}
|
||||||
return false; // no need to walk further *on the variable*
|
return false; // no need to walk further *on the variable*
|
||||||
}
|
},
|
||||||
Res::Def(DefKind::Static(_) | DefKind::Const, ..) => {
|
Res::Def(DefKind::Static(_) | DefKind::Const, ..) => {
|
||||||
if index_used_directly {
|
if index_used_directly {
|
||||||
self.indexed_directly.insert(
|
self.indexed_directly.insert(
|
||||||
|
@ -288,7 +290,7 @@ impl<'a, 'tcx> VarVisitor<'a, 'tcx> {
|
||||||
self.indexed_indirectly.insert(seqvar.segments[0].ident.name, None);
|
self.indexed_indirectly.insert(seqvar.segments[0].ident.name, None);
|
||||||
}
|
}
|
||||||
return false; // no need to walk further *on the variable*
|
return false; // no need to walk further *on the variable*
|
||||||
}
|
},
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -310,14 +312,18 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> {
|
||||||
if (meth.ident.name == sym::index && self.cx.tcx.lang_items().index_trait() == Some(trait_id))
|
if (meth.ident.name == sym::index && self.cx.tcx.lang_items().index_trait() == Some(trait_id))
|
||||||
|| (meth.ident.name == sym::index_mut && self.cx.tcx.lang_items().index_mut_trait() == Some(trait_id));
|
|| (meth.ident.name == sym::index_mut && self.cx.tcx.lang_items().index_mut_trait() == Some(trait_id));
|
||||||
if !self.check(args_1, args_0, expr);
|
if !self.check(args_1, args_0, expr);
|
||||||
then { return }
|
then {
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if_chain! {
|
if_chain! {
|
||||||
// an index op
|
// an index op
|
||||||
if let ExprKind::Index(seqexpr, idx) = expr.kind;
|
if let ExprKind::Index(seqexpr, idx) = expr.kind;
|
||||||
if !self.check(idx, seqexpr, expr);
|
if !self.check(idx, seqexpr, expr);
|
||||||
then { return }
|
then {
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if_chain! {
|
if_chain! {
|
||||||
|
|
|
@ -141,7 +141,7 @@ fn future_output_ty<'tcx>(trait_ref: &'tcx TraitRef<'tcx>) -> Option<&'tcx Ty<'t
|
||||||
if binding.ident.name == sym::Output;
|
if binding.ident.name == sym::Output;
|
||||||
if let TypeBindingKind::Equality { term: Term::Ty(output) } = binding.kind;
|
if let TypeBindingKind::Equality { term: Term::Ty(output) } = binding.kind;
|
||||||
then {
|
then {
|
||||||
return Some(output)
|
return Some(output);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -180,7 +180,10 @@ fn desugared_async_block<'tcx>(cx: &LateContext<'tcx>, block: &'tcx Block<'tcx>)
|
||||||
.from_generator_fn()
|
.from_generator_fn()
|
||||||
.and_then(|def_id| match_function_call_with_def_id(cx, block_expr, def_id));
|
.and_then(|def_id| match_function_call_with_def_id(cx, block_expr, def_id));
|
||||||
if args.len() == 1;
|
if args.len() == 1;
|
||||||
if let Expr{kind: ExprKind::Closure(&Closure { body, .. }), ..} = args[0];
|
if let Expr {
|
||||||
|
kind: ExprKind::Closure(&Closure { body, .. }),
|
||||||
|
..
|
||||||
|
} = args[0];
|
||||||
let closure_body = cx.tcx.hir().body(body);
|
let closure_body = cx.tcx.hir().body(body);
|
||||||
if closure_body.generator_kind == Some(GeneratorKind::Async(AsyncGeneratorKind::Block));
|
if closure_body.generator_kind == Some(GeneratorKind::Async(AsyncGeneratorKind::Block));
|
||||||
then {
|
then {
|
||||||
|
|
|
@ -3370,7 +3370,9 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
|
||||||
then {
|
then {
|
||||||
let first_arg_span = first_arg_ty.span;
|
let first_arg_span = first_arg_ty.span;
|
||||||
let first_arg_ty = hir_ty_to_ty(cx.tcx, first_arg_ty);
|
let first_arg_ty = hir_ty_to_ty(cx.tcx, first_arg_ty);
|
||||||
let self_ty = TraitRef::identity(cx.tcx, item.def_id.to_def_id()).self_ty().skip_binder();
|
let self_ty = TraitRef::identity(cx.tcx, item.def_id.to_def_id())
|
||||||
|
.self_ty()
|
||||||
|
.skip_binder();
|
||||||
wrong_self_convention::check(
|
wrong_self_convention::check(
|
||||||
cx,
|
cx,
|
||||||
item.ident.name.as_str(),
|
item.ident.name.as_str(),
|
||||||
|
@ -3378,7 +3380,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
|
||||||
first_arg_ty,
|
first_arg_ty,
|
||||||
first_arg_span,
|
first_arg_span,
|
||||||
false,
|
false,
|
||||||
true
|
true,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3387,7 +3389,9 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
|
||||||
if item.ident.name == sym::new;
|
if item.ident.name == sym::new;
|
||||||
if let TraitItemKind::Fn(_, _) = item.kind;
|
if let TraitItemKind::Fn(_, _) = item.kind;
|
||||||
let ret_ty = return_ty(cx, item.hir_id());
|
let ret_ty = return_ty(cx, item.hir_id());
|
||||||
let self_ty = TraitRef::identity(cx.tcx, item.def_id.to_def_id()).self_ty().skip_binder();
|
let self_ty = TraitRef::identity(cx.tcx, item.def_id.to_def_id())
|
||||||
|
.self_ty()
|
||||||
|
.skip_binder();
|
||||||
if !ret_ty.contains(self_ty);
|
if !ret_ty.contains(self_ty);
|
||||||
|
|
||||||
then {
|
then {
|
||||||
|
|
|
@ -121,10 +121,9 @@ pub(super) fn check<'tcx>(
|
||||||
macro_expanded_snipped = snippet(cx, snippet_span, "..");
|
macro_expanded_snipped = snippet(cx, snippet_span, "..");
|
||||||
match macro_expanded_snipped.strip_prefix("$crate::vec::") {
|
match macro_expanded_snipped.strip_prefix("$crate::vec::") {
|
||||||
Some(stripped) => Cow::from(stripped),
|
Some(stripped) => Cow::from(stripped),
|
||||||
None => macro_expanded_snipped
|
None => macro_expanded_snipped,
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
not_macro_argument_snippet
|
not_macro_argument_snippet
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -47,14 +47,12 @@ declare_lint_pass!(NoNegCompOpForPartialOrd => [NEG_CMP_OP_ON_PARTIAL_ORD]);
|
||||||
impl<'tcx> LateLintPass<'tcx> for NoNegCompOpForPartialOrd {
|
impl<'tcx> LateLintPass<'tcx> for NoNegCompOpForPartialOrd {
|
||||||
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
|
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
|
||||||
if_chain! {
|
if_chain! {
|
||||||
|
|
||||||
if !in_external_macro(cx.sess(), expr.span);
|
if !in_external_macro(cx.sess(), expr.span);
|
||||||
if let ExprKind::Unary(UnOp::Not, inner) = expr.kind;
|
if let ExprKind::Unary(UnOp::Not, inner) = expr.kind;
|
||||||
if let ExprKind::Binary(ref op, left, _) = inner.kind;
|
if let ExprKind::Binary(ref op, left, _) = inner.kind;
|
||||||
if let BinOpKind::Le | BinOpKind::Ge | BinOpKind::Lt | BinOpKind::Gt = op.node;
|
if let BinOpKind::Le | BinOpKind::Ge | BinOpKind::Lt | BinOpKind::Gt = op.node;
|
||||||
|
|
||||||
then {
|
then {
|
||||||
|
|
||||||
let ty = cx.typeck_results().expr_ty(left);
|
let ty = cx.typeck_results().expr_ty(left);
|
||||||
|
|
||||||
let implements_ord = {
|
let implements_ord = {
|
||||||
|
@ -81,7 +79,7 @@ impl<'tcx> LateLintPass<'tcx> for NoNegCompOpForPartialOrd {
|
||||||
"the use of negated comparison operators on partially ordered \
|
"the use of negated comparison operators on partially ordered \
|
||||||
types produces code that is hard to read and refactor, please \
|
types produces code that is hard to read and refactor, please \
|
||||||
consider using the `partial_cmp` method instead, to make it \
|
consider using the `partial_cmp` method instead, to make it \
|
||||||
clear that the two values could be incomparable"
|
clear that the two values could be incomparable",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,11 +98,15 @@ fn get_args_to_check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> Ve
|
||||||
if trait_pred.self_ty() == inp;
|
if trait_pred.self_ty() == inp;
|
||||||
if let Some(return_ty_pred) = get_projection_pred(cx, generics, *trait_pred);
|
if let Some(return_ty_pred) = get_projection_pred(cx, generics, *trait_pred);
|
||||||
then {
|
then {
|
||||||
if ord_preds.iter().any(|ord| Some(ord.self_ty()) == return_ty_pred.term.ty()) {
|
if ord_preds
|
||||||
|
.iter()
|
||||||
|
.any(|ord| Some(ord.self_ty()) == return_ty_pred.term.ty())
|
||||||
|
{
|
||||||
args_to_check.push((i, "Ord".to_string()));
|
args_to_check.push((i, "Ord".to_string()));
|
||||||
} else if partial_ord_preds.iter().any(|pord| {
|
} else if partial_ord_preds
|
||||||
pord.self_ty() == return_ty_pred.term.ty().unwrap()
|
.iter()
|
||||||
}) {
|
.any(|pord| pord.self_ty() == return_ty_pred.term.ty().unwrap())
|
||||||
|
{
|
||||||
args_to_check.push((i, "PartialOrd".to_string()));
|
args_to_check.push((i, "PartialOrd".to_string()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,7 +92,12 @@ impl<'tcx> LateLintPass<'tcx> for CollapsibleCalls {
|
||||||
let mut sle = SpanlessEq::new(cx).deny_side_effects();
|
let mut sle = SpanlessEq::new(cx).deny_side_effects();
|
||||||
match ps.ident.as_str() {
|
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(&and_then_args[2], &span_call_args[0]) => {
|
||||||
suggest_suggestion(cx, expr, &and_then_snippets, &span_suggestion_snippets(cx, span_call_args));
|
suggest_suggestion(
|
||||||
|
cx,
|
||||||
|
expr,
|
||||||
|
&and_then_snippets,
|
||||||
|
&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(&and_then_args[2], &span_call_args[0]) => {
|
||||||
let help_snippet = snippet(cx, span_call_args[1].span, r#""...""#);
|
let help_snippet = snippet(cx, span_call_args[1].span, r#""...""#);
|
||||||
|
@ -105,11 +110,11 @@ impl<'tcx> LateLintPass<'tcx> for CollapsibleCalls {
|
||||||
"help" => {
|
"help" => {
|
||||||
let help_snippet = snippet(cx, span_call_args[0].span, r#""...""#);
|
let help_snippet = snippet(cx, span_call_args[0].span, r#""...""#);
|
||||||
suggest_help(cx, expr, &and_then_snippets, help_snippet.borrow(), false);
|
suggest_help(cx, expr, &and_then_snippets, help_snippet.borrow(), false);
|
||||||
}
|
},
|
||||||
"note" => {
|
"note" => {
|
||||||
let note_snippet = snippet(cx, span_call_args[0].span, r#""...""#);
|
let note_snippet = snippet(cx, span_call_args[0].span, r#""...""#);
|
||||||
suggest_note(cx, expr, &and_then_snippets, note_snippet.borrow(), false);
|
suggest_note(cx, expr, &and_then_snippets, note_snippet.borrow(), false);
|
||||||
}
|
},
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,8 +61,7 @@ impl<'tcx> LateLintPass<'tcx> for CompilerLintFunctions {
|
||||||
let fn_name = path.ident;
|
let fn_name = path.ident;
|
||||||
if let Some(sugg) = self.map.get(fn_name.as_str());
|
if let Some(sugg) = self.map.get(fn_name.as_str());
|
||||||
let ty = cx.typeck_results().expr_ty(self_arg).peel_refs();
|
let ty = cx.typeck_results().expr_ty(self_arg).peel_refs();
|
||||||
if match_type(cx, ty, &paths::EARLY_CONTEXT)
|
if match_type(cx, ty, &paths::EARLY_CONTEXT) || match_type(cx, ty, &paths::LATE_CONTEXT);
|
||||||
|| match_type(cx, ty, &paths::LATE_CONTEXT);
|
|
||||||
then {
|
then {
|
||||||
span_lint_and_help(
|
span_lint_and_help(
|
||||||
cx,
|
cx,
|
||||||
|
|
|
@ -94,7 +94,10 @@ fn check_nested_if_chains(
|
||||||
.iter()
|
.iter()
|
||||||
.all(|stmt| matches!(stmt.kind, StmtKind::Local(..)) && !sm.is_multiline(stmt.span));
|
.all(|stmt| matches!(stmt.kind, StmtKind::Local(..)) && !sm.is_multiline(stmt.span));
|
||||||
if if_chain_span.is_some() || !is_else_clause(cx.tcx, if_expr);
|
if if_chain_span.is_some() || !is_else_clause(cx.tcx, if_expr);
|
||||||
then {} else { return }
|
then {
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
let (span, msg) = match (if_chain_span, is_expn_of(tail.span, "if_chain")) {
|
let (span, msg) = match (if_chain_span, is_expn_of(tail.span, "if_chain")) {
|
||||||
(None, Some(_)) => (if_expr.span, "this `if` can be part of the inner `if_chain!`"),
|
(None, Some(_)) => (if_expr.span, "this `if` can be part of the inner `if_chain!`"),
|
||||||
|
|
|
@ -41,14 +41,17 @@ impl<'tcx> LateLintPass<'tcx> for InvalidPaths {
|
||||||
let body = cx.tcx.hir().body(body_id);
|
let body = cx.tcx.hir().body(body_id);
|
||||||
let typeck_results = cx.tcx.typeck_body(body_id);
|
let typeck_results = cx.tcx.typeck_body(body_id);
|
||||||
if let Some(Constant::Vec(path)) = constant_simple(cx, typeck_results, body.value);
|
if let Some(Constant::Vec(path)) = constant_simple(cx, typeck_results, body.value);
|
||||||
let path: Vec<&str> = path.iter().map(|x| {
|
let path: Vec<&str> = path
|
||||||
|
.iter()
|
||||||
|
.map(|x| {
|
||||||
if let Constant::Str(s) = x {
|
if let Constant::Str(s) = x {
|
||||||
s.as_str()
|
s.as_str()
|
||||||
} else {
|
} else {
|
||||||
// We checked the type of the constant above
|
// We checked the type of the constant above
|
||||||
unreachable!()
|
unreachable!()
|
||||||
}
|
}
|
||||||
}).collect();
|
})
|
||||||
|
.collect();
|
||||||
if !check_path(cx, &path[..]);
|
if !check_path(cx, &path[..]);
|
||||||
then {
|
then {
|
||||||
span_lint(cx, INVALID_PATHS, item.span, "invalid path");
|
span_lint(cx, INVALID_PATHS, item.span, "invalid path");
|
||||||
|
|
|
@ -317,11 +317,7 @@ pub(super) fn extract_clippy_version_value(cx: &LateContext<'_>, item: &'_ Item<
|
||||||
if tool_name.ident.name == sym::clippy;
|
if tool_name.ident.name == sym::clippy;
|
||||||
if attr_name.ident.name == sym::version;
|
if attr_name.ident.name == sym::version;
|
||||||
if let Some(version) = attr.value_str();
|
if let Some(version) = attr.value_str();
|
||||||
then {
|
then { Some(version) } else { None }
|
||||||
Some(version)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -532,7 +532,11 @@ fn parse_config_field_doc(doc_comment: &str) -> Option<(Vec<String>, String)> {
|
||||||
|
|
||||||
// Extract lints
|
// Extract lints
|
||||||
doc_comment.make_ascii_lowercase();
|
doc_comment.make_ascii_lowercase();
|
||||||
let lints: Vec<String> = doc_comment.split_off(DOC_START.len()).split(", ").map(str::to_string).collect();
|
let lints: Vec<String> = doc_comment
|
||||||
|
.split_off(DOC_START.len())
|
||||||
|
.split(", ")
|
||||||
|
.map(str::to_string)
|
||||||
|
.collect();
|
||||||
|
|
||||||
// Format documentation correctly
|
// Format documentation correctly
|
||||||
// split off leading `.` from lint name list and indent for correct formatting
|
// split off leading `.` from lint name list and indent for correct formatting
|
||||||
|
|
|
@ -113,6 +113,7 @@ impl UnnecessaryDefPath {
|
||||||
if let Some(def_id) = inherent_def_path_res(cx, &segments[..]);
|
if let Some(def_id) = inherent_def_path_res(cx, &segments[..]);
|
||||||
then {
|
then {
|
||||||
// Check if the target item is a diagnostic item or LangItem.
|
// Check if the target item is a diagnostic item or LangItem.
|
||||||
|
#[rustfmt::skip]
|
||||||
let (msg, item) = if let Some(item_name)
|
let (msg, item) = if let Some(item_name)
|
||||||
= cx.tcx.diagnostic_items(def_id.krate).id_to_name.get(&def_id)
|
= cx.tcx.diagnostic_items(def_id.krate).id_to_name.get(&def_id)
|
||||||
{
|
{
|
||||||
|
@ -133,11 +134,11 @@ impl UnnecessaryDefPath {
|
||||||
DefKind::Struct => {
|
DefKind::Struct => {
|
||||||
let variant = cx.tcx.adt_def(def_id).non_enum_variant();
|
let variant = cx.tcx.adt_def(def_id).non_enum_variant();
|
||||||
variant.ctor_def_id.is_some() && variant.fields.iter().all(|f| f.vis.is_public())
|
variant.ctor_def_id.is_some() && variant.fields.iter().all(|f| f.vis.is_public())
|
||||||
}
|
},
|
||||||
DefKind::Variant => {
|
DefKind::Variant => {
|
||||||
let variant = cx.tcx.adt_def(cx.tcx.parent(def_id)).variant_with_id(def_id);
|
let variant = cx.tcx.adt_def(cx.tcx.parent(def_id)).variant_with_id(def_id);
|
||||||
variant.ctor_def_id.is_some() && variant.fields.iter().all(|f| f.vis.is_public())
|
variant.ctor_def_id.is_some() && variant.fields.iter().all(|f| f.vis.is_public())
|
||||||
}
|
},
|
||||||
_ => false,
|
_ => false,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -146,35 +147,40 @@ impl UnnecessaryDefPath {
|
||||||
let def_snip = snippet_with_applicability(cx, def_arg.span, "..", &mut app);
|
let def_snip = snippet_with_applicability(cx, def_arg.span, "..", &mut app);
|
||||||
let (sugg, with_note) = match (which_path, item) {
|
let (sugg, with_note) = match (which_path, item) {
|
||||||
// match_def_path
|
// match_def_path
|
||||||
(0, Item::DiagnosticItem(item)) =>
|
(0, Item::DiagnosticItem(item)) => (
|
||||||
(format!("{cx_snip}.tcx.is_diagnostic_item(sym::{item}, {def_snip})"), has_ctor),
|
format!("{cx_snip}.tcx.is_diagnostic_item(sym::{item}, {def_snip})"),
|
||||||
|
has_ctor,
|
||||||
|
),
|
||||||
(0, Item::LangItem(item)) => (
|
(0, Item::LangItem(item)) => (
|
||||||
format!("{cx_snip}.tcx.lang_items().require(LangItem::{item}).ok() == Some({def_snip})"),
|
format!("{cx_snip}.tcx.lang_items().require(LangItem::{item}).ok() == Some({def_snip})"),
|
||||||
has_ctor
|
has_ctor,
|
||||||
),
|
),
|
||||||
// match_trait_method
|
// match_trait_method
|
||||||
(1, Item::DiagnosticItem(item)) =>
|
(1, Item::DiagnosticItem(item)) => {
|
||||||
(format!("is_trait_method({cx_snip}, {def_snip}, sym::{item})"), false),
|
(format!("is_trait_method({cx_snip}, {def_snip}, sym::{item})"), false)
|
||||||
|
},
|
||||||
// match_type
|
// match_type
|
||||||
(2, Item::DiagnosticItem(item)) =>
|
(2, Item::DiagnosticItem(item)) => (
|
||||||
(format!("is_type_diagnostic_item({cx_snip}, {def_snip}, sym::{item})"), false),
|
format!("is_type_diagnostic_item({cx_snip}, {def_snip}, sym::{item})"),
|
||||||
(2, Item::LangItem(item)) =>
|
false,
|
||||||
(format!("is_type_lang_item({cx_snip}, {def_snip}, LangItem::{item})"), false),
|
),
|
||||||
|
(2, Item::LangItem(item)) => (
|
||||||
|
format!("is_type_lang_item({cx_snip}, {def_snip}, LangItem::{item})"),
|
||||||
|
false,
|
||||||
|
),
|
||||||
// is_expr_path_def_path
|
// is_expr_path_def_path
|
||||||
(3, Item::DiagnosticItem(item)) if has_ctor => (
|
(3, Item::DiagnosticItem(item)) if has_ctor => (
|
||||||
format!(
|
format!("is_res_diag_ctor({cx_snip}, path_res({cx_snip}, {def_snip}), sym::{item})",),
|
||||||
"is_res_diag_ctor({cx_snip}, path_res({cx_snip}, {def_snip}), sym::{item})",
|
|
||||||
),
|
|
||||||
false,
|
false,
|
||||||
),
|
),
|
||||||
(3, Item::LangItem(item)) if has_ctor => (
|
(3, Item::LangItem(item)) if has_ctor => (
|
||||||
format!(
|
format!("is_res_lang_ctor({cx_snip}, path_res({cx_snip}, {def_snip}), LangItem::{item})",),
|
||||||
"is_res_lang_ctor({cx_snip}, path_res({cx_snip}, {def_snip}), LangItem::{item})",
|
false,
|
||||||
),
|
),
|
||||||
|
(3, Item::DiagnosticItem(item)) => (
|
||||||
|
format!("is_path_diagnostic_item({cx_snip}, {def_snip}, sym::{item})"),
|
||||||
false,
|
false,
|
||||||
),
|
),
|
||||||
(3, Item::DiagnosticItem(item)) =>
|
|
||||||
(format!("is_path_diagnostic_item({cx_snip}, {def_snip}, sym::{item})"), false),
|
|
||||||
(3, Item::LangItem(item)) => (
|
(3, Item::LangItem(item)) => (
|
||||||
format!(
|
format!(
|
||||||
"path_res({cx_snip}, {def_snip}).opt_def_id()\
|
"path_res({cx_snip}, {def_snip}).opt_def_id()\
|
||||||
|
@ -185,21 +191,15 @@ impl UnnecessaryDefPath {
|
||||||
_ => return,
|
_ => return,
|
||||||
};
|
};
|
||||||
|
|
||||||
span_lint_and_then(
|
span_lint_and_then(cx, UNNECESSARY_DEF_PATH, span, msg, |diag| {
|
||||||
cx,
|
|
||||||
UNNECESSARY_DEF_PATH,
|
|
||||||
span,
|
|
||||||
msg,
|
|
||||||
|diag| {
|
|
||||||
diag.span_suggestion(span, "try", sugg, app);
|
diag.span_suggestion(span, "try", sugg, app);
|
||||||
if with_note {
|
if with_note {
|
||||||
diag.help(
|
diag.help(
|
||||||
"if this `DefId` came from a constructor expression or pattern then the \
|
"if this `DefId` came from a constructor expression or pattern then the \
|
||||||
parent `DefId` should be used instead"
|
parent `DefId` should be used instead",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
},
|
});
|
||||||
);
|
|
||||||
|
|
||||||
self.linted_def_ids.insert(def_id);
|
self.linted_def_ids.insert(def_id);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue