about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEsteban Küber <esteban@osdyne.com>2025-09-15 03:06:16 -0700
committerEsteban Küber <esteban@osdyne.com>2025-09-15 03:06:16 -0700
commit0e290e4228e90720b4b3e263f95250db7046cdd2 (patch)
tree9c6fdbe2c98a56da370a53cd695fe7aa2eeedb12
parent9405e76431374e25077b374ed0cd9c920a1c0f4f (diff)
downloadrust-0e290e4228e90720b4b3e263f95250db7046cdd2.tar.gz
rust-0e290e4228e90720b4b3e263f95250db7046cdd2.zip
Silence inference error on `PatKind::Err`
-rw-r--r--compiler/rustc_trait_selection/src/error_reporting/infer/need_type_info.rs10
-rw-r--r--tests/ui/closures/varargs-in-closure-isnt-supported.rs1
-rw-r--r--tests/ui/closures/varargs-in-closure-isnt-supported.stderr14
3 files changed, 9 insertions, 16 deletions
diff --git a/compiler/rustc_trait_selection/src/error_reporting/infer/need_type_info.rs b/compiler/rustc_trait_selection/src/error_reporting/infer/need_type_info.rs
index edab530590b..94772be16be 100644
--- a/compiler/rustc_trait_selection/src/error_reporting/infer/need_type_info.rs
+++ b/compiler/rustc_trait_selection/src/error_reporting/infer/need_type_info.rs
@@ -4,7 +4,7 @@ use std::path::PathBuf;
 
 use rustc_errors::codes::*;
 use rustc_errors::{Diag, IntoDiagArg};
-use rustc_hir as hir;
+use rustc_hir::{self as hir, PatKind};
 use rustc_hir::def::{CtorOf, DefKind, Namespace, Res};
 use rustc_hir::def_id::{DefId, LocalDefId};
 use rustc_hir::intravisit::{self, Visitor};
@@ -512,7 +512,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
                     type_name: ty_to_string(self, ty, def_id),
                 });
             }
-            InferSourceKind::ClosureArg { insert_span, ty } => {
+            InferSourceKind::ClosureArg { insert_span, ty, .. } => {
                 infer_subdiags.push(SourceKindSubdiag::LetLike {
                     span: insert_span,
                     name: String::new(),
@@ -652,6 +652,10 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
             }),
         };
         *err.long_ty_path() = long_ty_path;
+        if let InferSourceKind::ClosureArg { kind: PatKind::Err(_), .. } = kind {
+            // We will have already emitted an error about this pattern.
+            err.downgrade_to_delayed_bug();
+        }
         err
     }
 }
@@ -673,6 +677,7 @@ enum InferSourceKind<'tcx> {
     ClosureArg {
         insert_span: Span,
         ty: Ty<'tcx>,
+        kind: PatKind<'tcx>,
     },
     GenericArg {
         insert_span: Span,
@@ -1197,6 +1202,7 @@ impl<'a, 'tcx> Visitor<'tcx> for FindInferSourceVisitor<'a, 'tcx> {
                     kind: InferSourceKind::ClosureArg {
                         insert_span: param.pat.span.shrink_to_hi(),
                         ty: param_ty,
+                        kind: param.pat.kind,
                     },
                 })
             }
diff --git a/tests/ui/closures/varargs-in-closure-isnt-supported.rs b/tests/ui/closures/varargs-in-closure-isnt-supported.rs
index 5dff69194f9..4de78bef14d 100644
--- a/tests/ui/closures/varargs-in-closure-isnt-supported.rs
+++ b/tests/ui/closures/varargs-in-closure-isnt-supported.rs
@@ -4,7 +4,6 @@
 unsafe extern "C" fn thats_not_a_pattern(mut ap: ...) -> u32 {
     let mut lol = |...| (); //~ ERROR: unexpected `...`
     unsafe { ap.arg::<u32>() } //~^ NOTE: C-variadic type `...` is not allowed here
-    //~| ERROR: type annotations needed
     //~| NOTE: not a valid pattern
 }
 
diff --git a/tests/ui/closures/varargs-in-closure-isnt-supported.stderr b/tests/ui/closures/varargs-in-closure-isnt-supported.stderr
index 4f66ff59af1..a645741a527 100644
--- a/tests/ui/closures/varargs-in-closure-isnt-supported.stderr
+++ b/tests/ui/closures/varargs-in-closure-isnt-supported.stderr
@@ -6,17 +6,5 @@ LL |     let mut lol = |...| ();
    |
    = note: C-variadic type `...` is not allowed here
 
-error[E0282]: type annotations needed
-  --> $DIR/varargs-in-closure-isnt-supported.rs:5:20
-   |
-LL |     let mut lol = |...| ();
-   |                    ^^^
-   |
-help: consider giving this closure parameter an explicit type
-   |
-LL |     let mut lol = |...: /* Type */| ();
-   |                       ++++++++++++
-
-error: aborting due to 2 previous errors
+error: aborting due to 1 previous error
 
-For more information about this error, try `rustc --explain E0282`.