about summary refs log tree commit diff
path: root/clippy_lints
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2021-12-15 01:28:04 +0100
committerGitHub <noreply@github.com>2021-12-15 01:28:04 +0100
commitb166642c353ea19c02c4bdb7494c1c2f19868ad4 (patch)
treeba3317f58cb5b376c1ee142f8ed0c7cf390cf5dd /clippy_lints
parent6b6cc5d5764e83a122f24d966a59a60cee871633 (diff)
parentc5287b37fa048e83374afa274168f184a4479013 (diff)
Rollup merge of #90939 - estebank:wg-af-polish, r=tmandry
Tweak errors coming from `for`-loop, `?` and `.await` desugaring

 * Suggest removal of `.await` on non-`Future` expression
 * Keep track of obligations introduced by desugaring
 * Remove span pointing at method for obligation errors coming from desugaring
 * Point at called local sync `fn` and suggest making it `async`

```
error[E0277]: `()` is not a future
  --> $DIR/unnecessary-await.rs:9:10
   |
LL |     boo().await;
   |     -----^^^^^^ `()` is not a future
   |     |
   |     this call returns `()`
   |
   = help: the trait `Future` is not implemented for `()`
help: do not `.await` the expression
   |
LL -     boo().await;
LL +     boo();
   |
help: alternatively, consider making `fn boo` asynchronous
   |
LL | async fn boo () {}
   | +++++
```

Fix #66731.
Diffstat (limited to 'clippy_lints')
-rw-r--r--clippy_lints/src/methods/str_splitn.rs2
-rw-r--r--clippy_lints/src/needless_late_init.rs11
-rw-r--r--clippy_lints/src/needless_question_mark.rs2
-rw-r--r--clippy_lints/src/strings.rs2
-rw-r--r--clippy_lints/src/try_err.rs2
-rw-r--r--clippy_lints/src/unused_io_amount.rs2
-rw-r--r--clippy_lints/src/utils/author.rs2
7 files changed, 14 insertions, 9 deletions
diff --git a/clippy_lints/src/methods/str_splitn.rs b/clippy_lints/src/methods/str_splitn.rs
index 2595f734f11..e5fafdb075c 100644
--- a/clippy_lints/src/methods/str_splitn.rs
+++ b/clippy_lints/src/methods/str_splitn.rs
@@ -204,7 +204,7 @@ fn parse_iter_usage(
         match e.kind {
             ExprKind::Call(
                 Expr {
-                    kind: ExprKind::Path(QPath::LangItem(LangItem::TryTraitBranch, _)),
+                    kind: ExprKind::Path(QPath::LangItem(LangItem::TryTraitBranch, ..)),
                     ..
                 },
                 _,
diff --git a/clippy_lints/src/needless_late_init.rs b/clippy_lints/src/needless_late_init.rs
index e0522f3fe0b..5b098659377 100644
--- a/clippy_lints/src/needless_late_init.rs
+++ b/clippy_lints/src/needless_late_init.rs
@@ -73,7 +73,7 @@ fn contains_assign_expr<'tcx>(cx: &LateContext<'tcx>, stmt: &'tcx Stmt<'tcx>) ->
     seen
 }
 
-#[derive(Debug)]
+#[derive(Debug, Clone)]
 struct LocalAssign {
     lhs_id: HirId,
     lhs_span: Span,
@@ -154,9 +154,14 @@ fn assignment_suggestions<'tcx>(
         assignments.push(assign);
     }
 
-    let suggestions = assignments
+    let suggestions = assignments.clone()
         .into_iter()
-        .map(|assignment| Some((assignment.span, snippet_opt(cx, assignment.rhs_span)?)))
+        .map(|assignment| Some((assignment.span.until(assignment.rhs_span), String::new())))
+        .chain(
+            assignments
+                .into_iter()
+                .map(|assignment| Some((assignment.rhs_span.shrink_to_hi().with_hi(assignment.span.hi()), String::new())))
+        )
         .collect::<Option<Vec<(Span, String)>>>()?;
 
     let applicability = if suggestions.len() > 1 {
diff --git a/clippy_lints/src/needless_question_mark.rs b/clippy_lints/src/needless_question_mark.rs
index 1ffed6a0524..0e7ae43ce2d 100644
--- a/clippy_lints/src/needless_question_mark.rs
+++ b/clippy_lints/src/needless_question_mark.rs
@@ -105,7 +105,7 @@ fn check(cx: &LateContext<'_>, expr: &Expr<'_>) {
         };
         if let ExprKind::Match(inner_expr_with_q, _, MatchSource::TryDesugar) = &arg.kind;
         if let ExprKind::Call(called, [inner_expr]) = &inner_expr_with_q.kind;
-        if let ExprKind::Path(QPath::LangItem(LangItem::TryTraitBranch, _)) = &called.kind;
+        if let ExprKind::Path(QPath::LangItem(LangItem::TryTraitBranch, ..)) = &called.kind;
         if expr.span.ctxt() == inner_expr.span.ctxt();
         let expr_ty = cx.typeck_results().expr_ty(expr);
         let inner_ty = cx.typeck_results().expr_ty(inner_expr);
diff --git a/clippy_lints/src/strings.rs b/clippy_lints/src/strings.rs
index 368274440d5..c2163a24b7f 100644
--- a/clippy_lints/src/strings.rs
+++ b/clippy_lints/src/strings.rs
@@ -260,7 +260,7 @@ impl<'tcx> LateLintPass<'tcx> for StringLitAsBytes {
             if method_names[0] == sym!(as_bytes);
 
             // Check for slicer
-            if let ExprKind::Struct(QPath::LangItem(LangItem::Range, _), _, _) = right.kind;
+            if let ExprKind::Struct(QPath::LangItem(LangItem::Range, ..), _, _) = right.kind;
 
             then {
                 let mut applicability = Applicability::MachineApplicable;
diff --git a/clippy_lints/src/try_err.rs b/clippy_lints/src/try_err.rs
index e0e7ec9a452..4da32c52e75 100644
--- a/clippy_lints/src/try_err.rs
+++ b/clippy_lints/src/try_err.rs
@@ -65,7 +65,7 @@ impl<'tcx> LateLintPass<'tcx> for TryErr {
             if let ExprKind::Match(match_arg, _, MatchSource::TryDesugar) = expr.kind;
             if let ExprKind::Call(match_fun, try_args) = match_arg.kind;
             if let ExprKind::Path(ref match_fun_path) = match_fun.kind;
-            if matches!(match_fun_path, QPath::LangItem(LangItem::TryTraitBranch, _));
+            if matches!(match_fun_path, QPath::LangItem(LangItem::TryTraitBranch, ..));
             if let Some(try_arg) = try_args.get(0);
             if let ExprKind::Call(err_fun, err_args) = try_arg.kind;
             if let Some(err_arg) = err_args.get(0);
diff --git a/clippy_lints/src/unused_io_amount.rs b/clippy_lints/src/unused_io_amount.rs
index d4b5c9770a2..111413e5193 100644
--- a/clippy_lints/src/unused_io_amount.rs
+++ b/clippy_lints/src/unused_io_amount.rs
@@ -49,7 +49,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedIoAmount {
                 if let hir::ExprKind::Call(func, [ref arg_0, ..]) = res.kind {
                     if matches!(
                         func.kind,
-                        hir::ExprKind::Path(hir::QPath::LangItem(hir::LangItem::TryTraitBranch, _))
+                        hir::ExprKind::Path(hir::QPath::LangItem(hir::LangItem::TryTraitBranch, ..))
                     ) {
                         check_map_error(cx, arg_0, expr);
                     }
diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs
index d20bf341318..f186e1f05a0 100644
--- a/clippy_lints/src/utils/author.rs
+++ b/clippy_lints/src/utils/author.rs
@@ -260,7 +260,7 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
     }
 
     fn qpath(&self, qpath: &Binding<&QPath<'_>>) {
-        if let QPath::LangItem(lang_item, _) = *qpath.value {
+        if let QPath::LangItem(lang_item, ..) = *qpath.value {
             out!("if matches!({qpath}, QPath::LangItem(LangItem::{lang_item:?}, _));");
         } else {
             out!("if match_qpath({qpath}, &[{}]);", path_to_string(qpath.value));