mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-18 09:53:26 +00:00
Check explicitly that tuple initializer is Sized.
This commit is contained in:
parent
7acce3724d
commit
17fca8b460
@ -1097,6 +1097,9 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
|||||||
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");
|
||||||
}
|
}
|
||||||
|
ObligationCauseCode::TupleInitializerSized => {
|
||||||
|
err.note("tuples must have a statically known size to be initialized");
|
||||||
|
}
|
||||||
ObligationCauseCode::StructInitializerSized => {
|
ObligationCauseCode::StructInitializerSized => {
|
||||||
err.note("structs must have a statically known size to be initialized");
|
err.note("structs must have a statically known size to be initialized");
|
||||||
}
|
}
|
||||||
|
@ -121,6 +121,8 @@ pub enum ObligationCauseCode<'tcx> {
|
|||||||
// Various cases where expressions must be sized/copy/etc:
|
// Various cases where expressions must be sized/copy/etc:
|
||||||
/// L = X implies that L is Sized
|
/// L = X implies that L is Sized
|
||||||
AssignmentLhsSized,
|
AssignmentLhsSized,
|
||||||
|
/// (x1, .., xn) must be Sized
|
||||||
|
TupleInitializerSized,
|
||||||
/// S { ... } must be Sized
|
/// S { ... } must be Sized
|
||||||
StructInitializerSized,
|
StructInitializerSized,
|
||||||
/// Type of each variable must be Sized
|
/// Type of each variable must be Sized
|
||||||
|
@ -189,6 +189,7 @@ impl<'a, 'tcx> Lift<'tcx> for traits::ObligationCauseCode<'a> {
|
|||||||
tcx.lift(&ty).map(super::ObjectCastObligation)
|
tcx.lift(&ty).map(super::ObjectCastObligation)
|
||||||
}
|
}
|
||||||
super::AssignmentLhsSized => Some(super::AssignmentLhsSized),
|
super::AssignmentLhsSized => Some(super::AssignmentLhsSized),
|
||||||
|
super::TupleInitializerSized => Some(super::TupleInitializerSized),
|
||||||
super::StructInitializerSized => Some(super::StructInitializerSized),
|
super::StructInitializerSized => Some(super::StructInitializerSized),
|
||||||
super::VariableType(id) => Some(super::VariableType(id)),
|
super::VariableType(id) => Some(super::VariableType(id)),
|
||||||
super::ReturnType(id) => Some(super::ReturnType(id)),
|
super::ReturnType(id) => Some(super::ReturnType(id)),
|
||||||
@ -476,6 +477,7 @@ impl<'tcx> TypeFoldable<'tcx> for traits::ObligationCauseCode<'tcx> {
|
|||||||
super::TupleElem |
|
super::TupleElem |
|
||||||
super::ItemObligation(_) |
|
super::ItemObligation(_) |
|
||||||
super::AssignmentLhsSized |
|
super::AssignmentLhsSized |
|
||||||
|
super::TupleInitializerSized |
|
||||||
super::StructInitializerSized |
|
super::StructInitializerSized |
|
||||||
super::VariableType(_) |
|
super::VariableType(_) |
|
||||||
super::ReturnType(_) |
|
super::ReturnType(_) |
|
||||||
@ -523,6 +525,7 @@ impl<'tcx> TypeFoldable<'tcx> for traits::ObligationCauseCode<'tcx> {
|
|||||||
super::TupleElem |
|
super::TupleElem |
|
||||||
super::ItemObligation(_) |
|
super::ItemObligation(_) |
|
||||||
super::AssignmentLhsSized |
|
super::AssignmentLhsSized |
|
||||||
|
super::TupleInitializerSized |
|
||||||
super::StructInitializerSized |
|
super::StructInitializerSized |
|
||||||
super::VariableType(_) |
|
super::VariableType(_) |
|
||||||
super::ReturnType(_) |
|
super::ReturnType(_) |
|
||||||
|
@ -3854,6 +3854,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
|||||||
if tuple.references_error() {
|
if tuple.references_error() {
|
||||||
tcx.types.err
|
tcx.types.err
|
||||||
} else {
|
} else {
|
||||||
|
self.require_type_is_sized(tuple, expr.span, traits::TupleInitializerSized);
|
||||||
tuple
|
tuple
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -54,6 +54,7 @@ fn f9<X: ?Sized>(x1: Box<S<X>>) {
|
|||||||
fn f10<X: ?Sized>(x1: Box<S<X>>) {
|
fn f10<X: ?Sized>(x1: Box<S<X>>) {
|
||||||
f5(&(32, *x1));
|
f5(&(32, *x1));
|
||||||
//~^ ERROR `X: std::marker::Sized` is not satisfied
|
//~^ ERROR `X: std::marker::Sized` is not satisfied
|
||||||
|
//~| ERROR `X: std::marker::Sized` is not satisfied
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
|
Loading…
Reference in New Issue
Block a user