Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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();
Comment on lines +657 to +658
Copy link
Contributor

@lcnr lcnr Sep 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, surprised we don't have a way to silence a lint by passing in an ErrorGuaranteed. We could then do

        if let InferSourceKind::ClosureArg { kind: PatKind::Err(guar), .. } = kind {
            err.silence_via_error_guaranteed(guar);
        }
}

though maybe even better... change this function to return Result<Diag, ErrorGuaranteed> and avoid creating a diagnostic at all edit: seems annoying to do 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the rationale for downgrade_to_delayed_bug itself not taking an ErrorGuarantee is because itself is kind of an error guarantee already :)

The guarantee is more critical for anything that could cause a binary to be emitted otherwise.

}
err
}
}
Expand All @@ -673,6 +677,7 @@ enum InferSourceKind<'tcx> {
ClosureArg {
insert_span: Span,
ty: Ty<'tcx>,
kind: PatKind<'tcx>,
},
GenericArg {
insert_span: Span,
Expand Down Expand Up @@ -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,
},
})
}
Expand Down
1 change: 0 additions & 1 deletion tests/ui/closures/varargs-in-closure-isnt-supported.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
14 changes: 1 addition & 13 deletions tests/ui/closures/varargs-in-closure-isnt-supported.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Loading