// So a little bit of a funny story. Git on unix requires the pre-commit file
// to have the `execute` permission to be set. The Rust functions for modifying
- // these flags doesn't seem to work when executed with normal user permissions.
+ // these flags doesn't seem to work when executed with normal user permissions.
//
// However, there is a little hack that is also being used by Rust itself in their
// setup script. Git saves the `execute` flag when syncing files. This means
--- /dev/null
+use clippy_utils::diagnostics::span_lint_and_sugg;
+use clippy_utils::source::snippet_with_applicability;
+use clippy_utils::{path_to_local_id, peel_blocks, strip_pat_refs};
+use rustc_errors::Applicability;
+use rustc_hir::{ExprKind, Local, MatchSource, PatKind, QPath};
+use rustc_lint::LateContext;
+
+use super::INFALLIBLE_DESTRUCTURING_MATCH;
+
+pub(crate) fn check(cx: &LateContext<'_>, local: &Local<'_>) -> bool {
+ if_chain! {
+ if !local.span.from_expansion();
+ if let Some(expr) = local.init;
+ if let ExprKind::Match(target, arms, MatchSource::Normal) = expr.kind;
+ if arms.len() == 1 && arms[0].guard.is_none();
+ if let PatKind::TupleStruct(
+ QPath::Resolved(None, variant_name), args, _) = arms[0].pat.kind;
+ if args.len() == 1;
+ if let PatKind::Binding(_, arg, ..) = strip_pat_refs(&args[0]).kind;
+ let body = peel_blocks(arms[0].body);
+ if path_to_local_id(body, arg);
+
+ then {
+ let mut applicability = Applicability::MachineApplicable;
+ span_lint_and_sugg(
+ cx,
+ INFALLIBLE_DESTRUCTURING_MATCH,
+ local.span,
+ "you seem to be trying to use `match` to destructure a single infallible pattern. \
+ Consider using `let`",
+ "try this",
+ format!(
+ "let {}({}) = {};",
+ snippet_with_applicability(cx, variant_name.span, "..", &mut applicability),
+ snippet_with_applicability(cx, local.pat.span, "..", &mut applicability),
+ snippet_with_applicability(cx, target.span, "..", &mut applicability),
+ ),
+ applicability,
+ );
+ return true;
+ }
+ }
+ false
+}
+++ /dev/null
-use clippy_utils::diagnostics::span_lint_and_sugg;
-use clippy_utils::source::snippet_with_applicability;
-use clippy_utils::{path_to_local_id, peel_blocks, strip_pat_refs};
-use rustc_errors::Applicability;
-use rustc_hir::{ExprKind, Local, MatchSource, PatKind, QPath};
-use rustc_lint::LateContext;
-
-use super::INFALLIBLE_DESTRUCTURING_MATCH;
-
-pub(crate) fn check(cx: &LateContext<'_>, local: &Local<'_>) -> bool {
- if_chain! {
- if !local.span.from_expansion();
- if let Some(expr) = local.init;
- if let ExprKind::Match(target, arms, MatchSource::Normal) = expr.kind;
- if arms.len() == 1 && arms[0].guard.is_none();
- if let PatKind::TupleStruct(
- QPath::Resolved(None, variant_name), args, _) = arms[0].pat.kind;
- if args.len() == 1;
- if let PatKind::Binding(_, arg, ..) = strip_pat_refs(&args[0]).kind;
- let body = peel_blocks(arms[0].body);
- if path_to_local_id(body, arg);
-
- then {
- let mut applicability = Applicability::MachineApplicable;
- span_lint_and_sugg(
- cx,
- INFALLIBLE_DESTRUCTURING_MATCH,
- local.span,
- "you seem to be trying to use `match` to destructure a single infallible pattern. \
- Consider using `let`",
- "try this",
- format!(
- "let {}({}) = {};",
- snippet_with_applicability(cx, variant_name.span, "..", &mut applicability),
- snippet_with_applicability(cx, local.pat.span, "..", &mut applicability),
- snippet_with_applicability(cx, target.span, "..", &mut applicability),
- ),
- applicability,
- );
- return true;
- }
- }
- false
-}
fn check_fn_decl(&mut self, cx: &LateContext<'_>, decl: &FnDecl<'_>, context: CheckTyContext) {
// Ignore functions in trait implementations as they are usually forced by the trait definition.
//
- // FIXME: ideally we would like to warn *if the complicated type can be simplified*, but it's hard to
- // check.
+ // FIXME: ideally we would like to warn *if the complicated type can be simplified*, but it's hard
+ // to check.
if context.is_in_trait_impl {
return;
}
-error: unneeded late initalization
+error: unneeded late initialization
--> $DIR/needless_late_init.rs:5:5
|
LL | let a;
LL | };
| +
-error: unneeded late initalization
+error: unneeded late initialization
--> $DIR/needless_late_init.rs:14:5
|
LL | let b;
LL | };
| +
-error: unneeded late initalization
+error: unneeded late initialization
--> $DIR/needless_late_init.rs:21:5
|
LL | let c;
LL | };
| +
-error: unneeded late initalization
+error: unneeded late initialization
--> $DIR/needless_late_init.rs:28:5
|
LL | let d;
LL | };
| +
-error: unneeded late initalization
+error: unneeded late initialization
--> $DIR/needless_late_init.rs:36:5
|
LL | let e;
LL | };
| +
-error: unneeded late initalization
+error: unneeded late initialization
--> $DIR/needless_late_init.rs:43:5
|
LL | let f;
LL + 1 => "three",
|
-error: unneeded late initalization
+error: unneeded late initialization
--> $DIR/needless_late_init.rs:49:5
|
LL | let g: usize;
LL | };
| +
-error: unneeded late initalization
+error: unneeded late initialization
--> $DIR/needless_late_init.rs:64:5
|
LL | let a;
LL | };
| +
-error: unneeded late initalization
+error: unneeded late initialization
--> $DIR/needless_late_init.rs:81:5
|
LL | let a;
-error: unneeded late initalization
+error: unneeded late initialization
--> $DIR/needless_late_init_fixable.rs:6:5
|
LL | let a;
LL | let a = "zero";
| ~~~~~
-error: unneeded late initalization
+error: unneeded late initialization
--> $DIR/needless_late_init_fixable.rs:9:5
|
LL | let b;
LL | let b = 1;
| ~~~~~
-error: unneeded late initalization
+error: unneeded late initialization
--> $DIR/needless_late_init_fixable.rs:10:5
|
LL | let c;
LL | let c = 2;
| ~~~~~
-error: unneeded late initalization
+error: unneeded late initialization
--> $DIR/needless_late_init_fixable.rs:14:5
|
LL | let d: usize;
LL | let d: usize = 1;
| ~~~~~~~~~~~~
-error: unneeded late initalization
+error: unneeded late initialization
--> $DIR/needless_late_init_fixable.rs:17:5
|
LL | let mut e;
LL | let mut e = 1;
| ~~~~~~~~~
-error: unneeded late initalization
+error: unneeded late initialization
--> $DIR/needless_late_init_fixable.rs:21:5
|
LL | let h;