Skip to content

Commit 0e290e4

Browse files
committed
Silence inference error on PatKind::Err
1 parent 9405e76 commit 0e290e4

File tree

3 files changed

+9
-16
lines changed

3 files changed

+9
-16
lines changed

compiler/rustc_trait_selection/src/error_reporting/infer/need_type_info.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::path::PathBuf;
44

55
use rustc_errors::codes::*;
66
use rustc_errors::{Diag, IntoDiagArg};
7-
use rustc_hir as hir;
7+
use rustc_hir::{self as hir, PatKind};
88
use rustc_hir::def::{CtorOf, DefKind, Namespace, Res};
99
use rustc_hir::def_id::{DefId, LocalDefId};
1010
use rustc_hir::intravisit::{self, Visitor};
@@ -512,7 +512,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
512512
type_name: ty_to_string(self, ty, def_id),
513513
});
514514
}
515-
InferSourceKind::ClosureArg { insert_span, ty } => {
515+
InferSourceKind::ClosureArg { insert_span, ty, .. } => {
516516
infer_subdiags.push(SourceKindSubdiag::LetLike {
517517
span: insert_span,
518518
name: String::new(),
@@ -652,6 +652,10 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
652652
}),
653653
};
654654
*err.long_ty_path() = long_ty_path;
655+
if let InferSourceKind::ClosureArg { kind: PatKind::Err(_), .. } = kind {
656+
// We will have already emitted an error about this pattern.
657+
err.downgrade_to_delayed_bug();
658+
}
655659
err
656660
}
657661
}
@@ -673,6 +677,7 @@ enum InferSourceKind<'tcx> {
673677
ClosureArg {
674678
insert_span: Span,
675679
ty: Ty<'tcx>,
680+
kind: PatKind<'tcx>,
676681
},
677682
GenericArg {
678683
insert_span: Span,
@@ -1197,6 +1202,7 @@ impl<'a, 'tcx> Visitor<'tcx> for FindInferSourceVisitor<'a, 'tcx> {
11971202
kind: InferSourceKind::ClosureArg {
11981203
insert_span: param.pat.span.shrink_to_hi(),
11991204
ty: param_ty,
1205+
kind: param.pat.kind,
12001206
},
12011207
})
12021208
}

tests/ui/closures/varargs-in-closure-isnt-supported.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
unsafe extern "C" fn thats_not_a_pattern(mut ap: ...) -> u32 {
55
let mut lol = |...| (); //~ ERROR: unexpected `...`
66
unsafe { ap.arg::<u32>() } //~^ NOTE: C-variadic type `...` is not allowed here
7-
//~| ERROR: type annotations needed
87
//~| NOTE: not a valid pattern
98
}
109

tests/ui/closures/varargs-in-closure-isnt-supported.stderr

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,5 @@ LL | let mut lol = |...| ();
66
|
77
= note: C-variadic type `...` is not allowed here
88

9-
error[E0282]: type annotations needed
10-
--> $DIR/varargs-in-closure-isnt-supported.rs:5:20
11-
|
12-
LL | let mut lol = |...| ();
13-
| ^^^
14-
|
15-
help: consider giving this closure parameter an explicit type
16-
|
17-
LL | let mut lol = |...: /* Type */| ();
18-
| ++++++++++++
19-
20-
error: aborting due to 2 previous errors
9+
error: aborting due to 1 previous error
2110

22-
For more information about this error, try `rustc --explain E0282`.

0 commit comments

Comments
 (0)