Check that closure's by-value captures are sized
This commit is contained in:
parent
2d08657901
commit
c21867f9f6
6 changed files with 62 additions and 0 deletions
|
@ -3007,6 +3007,17 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
ObligationCauseCode::InlineAsmSized => {
|
||||
err.note("all inline asm arguments must have a statically known size");
|
||||
}
|
||||
ObligationCauseCode::SizedClosureCapture(closure_def_id) => {
|
||||
err.note("all values captured by value by a closure must have a statically known size");
|
||||
let hir::ExprKind::Closure(closure) = self.tcx.hir().get_by_def_id(closure_def_id).expect_expr().kind else {
|
||||
bug!("expected closure in SizedClosureCapture obligation");
|
||||
};
|
||||
if let hir::CaptureBy::Value = closure.capture_clause
|
||||
&& let Some(span) = closure.fn_arg_span
|
||||
{
|
||||
err.span_label(span, "this closure captures all values by move");
|
||||
}
|
||||
}
|
||||
ObligationCauseCode::ConstPatternStructural => {
|
||||
err.note("constants used for pattern-matching must derive `PartialEq` and `Eq`");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue