Skip to content

Commit 34241d0

Browse files
committed
Check explicitly that tuple initializer is Sized.
1 parent 1ccc330 commit 34241d0

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
@@ -1095,6 +1095,9 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
10951095
ObligationCauseCode::AssignmentLhsSized => {
10961096
err.note("the left-hand-side of an assignment must have a statically known size");
10971097
}
1098+
ObligationCauseCode::TupleInitializerSized => {
1099+
err.note("tuples must have a statically known size to be initialized");
1100+
}
10981101
ObligationCauseCode::StructInitializerSized => {
10991102
err.note("structs must have a statically known size to be initialized");
11001103
}

src/librustc/traits/mod.rs

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

121121
/// Various cases where expressions must be sized/copy/etc:
122122
AssignmentLhsSized, // L = X implies that L is Sized
123+
TupleInitializerSized, // (x1, .., xn) must be Sized
123124
StructInitializerSized, // S { ... } must be Sized
124125
VariableType(ast::NodeId), // Type of each variable must be Sized
125126
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
@@ -3883,6 +3883,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
38833883
if tuple.references_error() {
38843884
tcx.types.err
38853885
} else {
3886+
self.require_type_is_sized(tuple, expr.span, traits::TupleInitializerSized);
38863887
tuple
38873888
}
38883889
}

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)