Skip to content

Commit 00bd370

Browse files
committed
---
yaml --- r: 64818 b: refs/heads/snap-stage3 c: 1493141 h: refs/heads/master v: v3
1 parent 8bed96d commit 00bd370

File tree

7 files changed

+43
-30
lines changed

7 files changed

+43
-30
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 2d28d645422c1617be58c8ca7ad9a457264ca850
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 52dbe138cfd462f443fe209bcab12de418786e45
4+
refs/heads/snap-stage3: 1493141bfdb478c42fb073ef6872540de3b125f0
55
refs/heads/try: 7b78b52e602bb3ea8174f9b2006bff3315f03ef9
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/librustc/middle/check_const.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ pub fn check_expr(sess: Session,
160160
expr_field(*) |
161161
expr_index(*) |
162162
expr_tup(*) |
163-
expr_struct(_, _, None) => { }
163+
expr_struct(*) => { }
164164
expr_addr_of(*) => {
165165
sess.span_err(
166166
e.span,

branches/snap-stage3/src/librustc/middle/trans/consts.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -485,20 +485,30 @@ fn const_expr_unadjusted(cx: @mut CrateContext, e: &ast::expr) -> ValueRef {
485485
let vals = es.map(|&e| const_expr(cx, e));
486486
adt::trans_const(cx, repr, 0, vals)
487487
}
488-
ast::expr_struct(_, ref fs, None) => {
488+
ast::expr_struct(_, ref fs, ref base_opt) => {
489489
let ety = ty::expr_ty(cx.tcx, e);
490490
let repr = adt::represent_type(cx, ety);
491491
let tcx = cx.tcx;
492+
493+
let base_val = match *base_opt {
494+
Some(base) => Some(const_expr(cx, base)),
495+
None => None
496+
};
497+
492498
do expr::with_field_tys(tcx, ety, Some(e.id))
493499
|discr, field_tys| {
494-
let cs = field_tys.map(|field_ty| {
500+
let cs: ~[ValueRef] = field_tys.iter().enumerate()
501+
.transform(|(ix, &field_ty)| {
495502
match fs.iter().find_(|f| field_ty.ident == f.ident) {
496503
Some(f) => const_expr(cx, (*f).expr),
497504
None => {
498-
cx.tcx.sess.span_bug(e.span, "missing struct field");
505+
match base_val {
506+
Some(bv) => adt::const_get_field(cx, repr, bv, discr, ix),
507+
None => cx.tcx.sess.span_bug(e.span, "missing struct field")
508+
}
499509
}
500510
}
501-
});
511+
}).collect();
502512
adt::trans_const(cx, repr, discr, cs)
503513
}
504514
}

branches/snap-stage3/src/libstd/str.rs

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use char::Char;
2323
use clone::Clone;
2424
use container::{Container, Mutable};
2525
use iter::Times;
26-
use iterator::{Iterator, FromIterator, IteratorUtil, FilterIterator, AdditiveIterator, MapIterator};
26+
use iterator::{Iterator, IteratorUtil, FilterIterator, AdditiveIterator, MapIterator};
2727
use libc;
2828
use num::Zero;
2929
use option::{None, Option, Some};
@@ -2319,18 +2319,6 @@ impl<'self> Iterator<u8> for BytesRevIterator<'self> {
23192319
}
23202320
}
23212321
2322-
impl<T: Iterator<char>> FromIterator<char, T> for ~str {
2323-
#[inline]
2324-
fn from_iterator(iterator: &mut T) -> ~str {
2325-
let (lower, _) = iterator.size_hint();
2326-
let mut buf = with_capacity(lower);
2327-
for iterator.advance |ch| {
2328-
buf.push_char(ch)
2329-
}
2330-
buf
2331-
}
2332-
}
2333-
23342322
// This works because every lifetime is a sub-lifetime of 'static
23352323
impl<'self> Zero for &'self str {
23362324
fn zero() -> &'self str { "" }
@@ -2494,16 +2482,6 @@ mod tests {
24942482
assert_eq!(~"华ประเทศไทย中", data);
24952483
}
24962484
2497-
#[test]
2498-
fn test_collect() {
2499-
let empty = "";
2500-
let s: ~str = empty.iter().collect();
2501-
assert_eq!(empty, s.as_slice());
2502-
let data = "ประเทศไทย中";
2503-
let s: ~str = data.iter().collect();
2504-
assert_eq!(data, s.as_slice());
2505-
}
2506-
25072485
#[test]
25082486
fn test_clear() {
25092487
let mut empty = ~"";

branches/snap-stage3/src/libsyntax/ast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ pub enum expr_ {
498498
expr_mac(mac),
499499

500500
// A struct literal expression.
501-
expr_struct(Path, ~[Field], Option<@expr>),
501+
expr_struct(Path, ~[Field], Option<@expr> /* base */),
502502

503503
// A vector literal constructed from one repeated element.
504504
expr_repeat(@expr /* element */, @expr /* count */, mutability),
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
struct Foo { a: int, b: int }
12+
struct Bar { x: int }
13+
14+
static bar: Bar = Bar { x: 5 };
15+
static foo: Foo = Foo { a: 2, ..bar }; //~ ERROR mismatched types: expected `Foo` but found `Bar`
16+
static foo_i: Foo = Foo { a: 2, ..4 }; //~ ERROR mismatched types: expected `Foo`
17+
18+
fn main() {
19+
let b = Bar { x: 5 };
20+
let f = Foo { a: 2, ..b }; //~ ERROR mismatched types: expected `Foo` but found `Bar`
21+
let f_i = Foo { a: 2, ..4 }; //~ ERROR mismatched types: expected `Foo`
22+
}

branches/snap-stage3/src/test/run-pass/const-struct.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,14 @@ impl cmp::Eq for foo {
2525
static x : foo = foo { a:1, b:2, c: 3 };
2626
static y : foo = foo { b:2, c:3, a: 1 };
2727
static z : &'static foo = &foo { a: 10, b: 22, c: 12 };
28+
static w : foo = foo { a:5, ..x };
2829

2930
pub fn main() {
3031
assert_eq!(x.b, 2);
3132
assert_eq!(x, y);
3233
assert_eq!(z.b, 22);
34+
assert_eq!(w.a, 5);
35+
assert_eq!(w.c, 3);
3336
printfln!("0x%x", x.b as uint);
3437
printfln!("0x%x", z.c as uint);
3538
}

0 commit comments

Comments
 (0)