Skip to content

Commit 17fca8b

Browse files
committed
Check explicitly that tuple initializer is Sized.
1 parent 7acce37 commit 17fca8b

File tree

5 files changed

+10
-0
lines changed

5 files changed

+10
-0
lines changed

src/librustc/traits/error_reporting.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,6 +1097,9 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
10971097
ObligationCauseCode::AssignmentLhsSized => {
10981098
err.note("the left-hand-side of an assignment must have a statically known size");
10991099
}
1100+
ObligationCauseCode::TupleInitializerSized => {
1101+
err.note("tuples must have a statically known size to be initialized");
1102+
}
11001103
ObligationCauseCode::StructInitializerSized => {
11011104
err.note("structs must have a statically known size to be initialized");
11021105
}

src/librustc/traits/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ pub enum ObligationCauseCode<'tcx> {
121121
// Various cases where expressions must be sized/copy/etc:
122122
/// L = X implies that L is Sized
123123
AssignmentLhsSized,
124+
/// (x1, .., xn) must be Sized
125+
TupleInitializerSized,
124126
/// S { ... } must be Sized
125127
StructInitializerSized,
126128
/// Type of each variable 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(id) => Some(super::ReturnType(id)),
@@ -476,6 +477,7 @@ impl<'tcx> TypeFoldable<'tcx> for traits::ObligationCauseCode<'tcx> {
476477
super::TupleElem |
477478
super::ItemObligation(_) |
478479
super::AssignmentLhsSized |
480+
super::TupleInitializerSized |
479481
super::StructInitializerSized |
480482
super::VariableType(_) |
481483
super::ReturnType(_) |
@@ -523,6 +525,7 @@ impl<'tcx> TypeFoldable<'tcx> for traits::ObligationCauseCode<'tcx> {
523525
super::TupleElem |
524526
super::ItemObligation(_) |
525527
super::AssignmentLhsSized |
528+
super::TupleInitializerSized |
526529
super::StructInitializerSized |
527530
super::VariableType(_) |
528531
super::ReturnType(_) |

src/librustc_typeck/check/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3854,6 +3854,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
38543854
if tuple.references_error() {
38553855
tcx.types.err
38563856
} else {
3857+
self.require_type_is_sized(tuple, expr.span, traits::TupleInitializerSized);
38573858
tuple
38583859
}
38593860
}

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)