Skip to content

Commit d6ebe12

Browse files
committed
Check explicitly that tuple initializer is Sized.
1 parent 76242ae commit d6ebe12

File tree

5 files changed

+9
-0
lines changed

5 files changed

+9
-0
lines changed

src/librustc/traits/error_reporting.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,6 +1133,9 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
11331133
ObligationCauseCode::AssignmentLhsSized => {
11341134
err.note("the left-hand-side of an assignment must have a statically known size");
11351135
}
1136+
ObligationCauseCode::TupleInitializerSized => {
1137+
err.note("tuples must have a statically known size to be initialized");
1138+
}
11361139
ObligationCauseCode::StructInitializerSized => {
11371140
err.note("structs must have a statically known size to be initialized");
11381141
}

src/librustc/traits/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ pub enum ObligationCauseCode<'tcx> {
121121

122122
/// Various cases where expressions must be sized/copy/etc:
123123
AssignmentLhsSized, // L = X implies that L is Sized
124+
TupleInitializerSized, // (x1, .., xn) must be Sized
124125
StructInitializerSized, // S { ... } must be Sized
125126
VariableType(ast::NodeId), // Type of each variable must be Sized
126127
ReturnType, // Return type must be Sized

src/librustc/traits/structural_impls.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ impl<'a, 'tcx> Lift<'tcx> for traits::ObligationCauseCode<'a> {
189189
tcx.lift(&ty).map(super::ObjectCastObligation)
190190
}
191191
super::AssignmentLhsSized => Some(super::AssignmentLhsSized),
192+
super::TupleInitializerSized => Some(super::TupleInitializerSized),
192193
super::StructInitializerSized => Some(super::StructInitializerSized),
193194
super::VariableType(id) => Some(super::VariableType(id)),
194195
super::ReturnType => Some(super::ReturnType),
@@ -490,6 +491,7 @@ impl<'tcx> TypeFoldable<'tcx> for traits::ObligationCauseCode<'tcx> {
490491
super::TupleElem |
491492
super::ItemObligation(_) |
492493
super::AssignmentLhsSized |
494+
super::TupleInitializerSized |
493495
super::StructInitializerSized |
494496
super::VariableType(_) |
495497
super::ReturnType |
@@ -535,6 +537,7 @@ impl<'tcx> TypeFoldable<'tcx> for traits::ObligationCauseCode<'tcx> {
535537
super::TupleElem |
536538
super::ItemObligation(_) |
537539
super::AssignmentLhsSized |
540+
super::TupleInitializerSized |
538541
super::StructInitializerSized |
539542
super::VariableType(_) |
540543
super::ReturnType |

src/librustc_typeck/check/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3838,6 +3838,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
38383838
if tuple.references_error() {
38393839
tcx.types.err
38403840
} else {
3841+
self.require_type_is_sized(tuple, expr.span, traits::TupleInitializerSized);
38413842
tuple
38423843
}
38433844
}

src/test/compile-fail/unsized3.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ fn f9<X: ?Sized>(x1: Box<S<X>>) {
5454
fn f10<X: ?Sized>(x1: Box<S<X>>) {
5555
f5(&(32, *x1));
5656
//~^ ERROR `X: std::marker::Sized` is not satisfied
57+
//~| ERROR `X: std::marker::Sized` is not satisfied
5758
}
5859

5960
pub fn main() {

0 commit comments

Comments
 (0)