Skip to content

Commit 9d966ae

Browse files
committed
auto merge of #6134 : jld/rust/issue-6117, r=catamorphism
Cases like `Either<@int,()>` have a null case with at most one value but a nonzero number of fields; if we misreport this, then bad things can happen inside of, for example, pattern matching. Closes #6117.
2 parents 9b54fbd + 8408012 commit 9d966ae

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/librustc/middle/trans/adt.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -409,8 +409,8 @@ pub fn num_args(r: &Repr, discr: int) -> uint {
409409
st.fields.len() - (if dtor { 1 } else { 0 })
410410
}
411411
General(ref cases) => cases[discr as uint].fields.len() - 1,
412-
NullablePointer{ nonnull: ref nonnull, nndiscr, _ } => {
413-
if discr == nndiscr { nonnull.fields.len() } else { 0 }
412+
NullablePointer{ nonnull: ref nonnull, nndiscr, nullfields: ref nullfields, _ } => {
413+
if discr == nndiscr { nonnull.fields.len() } else { nullfields.len() }
414414
}
415415
}
416416
}

src/test/run-pass/issue-6117.rs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
pub fn main() {
12+
match Left(@17) {
13+
Right(()) => {}
14+
_ => {}
15+
}
16+
}

0 commit comments

Comments
 (0)