Require a box expression's type to be Sized
This commit is contained in:
parent
ba83b39d4e
commit
b8fff95961
4 changed files with 7 additions and 3 deletions
|
@ -225,6 +225,8 @@ pub enum ObligationCauseCode<'tcx> {
|
||||||
SizedReturnType,
|
SizedReturnType,
|
||||||
/// Yield type must be `Sized`.
|
/// Yield type must be `Sized`.
|
||||||
SizedYieldType,
|
SizedYieldType,
|
||||||
|
/// Box expression result type must be `Sized`.
|
||||||
|
SizedBoxType,
|
||||||
/// Inline asm operand type must be `Sized`.
|
/// Inline asm operand type must be `Sized`.
|
||||||
InlineAsmSized,
|
InlineAsmSized,
|
||||||
/// `[T, ..n]` implies that `T` must be `Copy`.
|
/// `[T, ..n]` implies that `T` must be `Copy`.
|
||||||
|
|
|
@ -1893,9 +1893,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||||
|
|
||||||
// While this is located in `nll::typeck` this error is not
|
// While this is located in `nll::typeck` this error is not
|
||||||
// an NLL error, it's a required check to prevent creation
|
// an NLL error, it's a required check to prevent creation
|
||||||
// of unsized rvalues in certain cases:
|
// of unsized rvalues in a call expression.
|
||||||
// * operand of a box expression
|
|
||||||
// * callee in a call expression
|
|
||||||
diag.emit();
|
diag.emit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2072,6 +2072,9 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||||
ObligationCauseCode::SizedYieldType => {
|
ObligationCauseCode::SizedYieldType => {
|
||||||
err.note("the yield type of a generator must have a statically known size");
|
err.note("the yield type of a generator must have a statically known size");
|
||||||
}
|
}
|
||||||
|
ObligationCauseCode::SizedBoxType => {
|
||||||
|
err.note("the type of a box expression must have a statically known size");
|
||||||
|
}
|
||||||
ObligationCauseCode::AssignmentLhsSized => {
|
ObligationCauseCode::AssignmentLhsSized => {
|
||||||
err.note("the left-hand-side of an assignment must have a statically known size");
|
err.note("the left-hand-side of an assignment must have a statically known size");
|
||||||
}
|
}
|
||||||
|
|
|
@ -313,6 +313,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
_ => NoExpectation,
|
_ => NoExpectation,
|
||||||
});
|
});
|
||||||
let referent_ty = self.check_expr_with_expectation(expr, expected_inner);
|
let referent_ty = self.check_expr_with_expectation(expr, expected_inner);
|
||||||
|
self.require_type_is_sized(referent_ty, expr.span, traits::SizedBoxType);
|
||||||
self.tcx.mk_box(referent_ty)
|
self.tcx.mk_box(referent_ty)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue