Rollup merge of #23201 - pnkfelix:fsk-struct-ooe-23112, r=nikomatsakis
For FRU, eval field exprs (into scratch temps) before base expr Fix #23112.
This commit is contained in:
commit
a49b6f8bd3
5 changed files with 138 additions and 27 deletions
|
|
@ -12,11 +12,12 @@ struct S { f0: String, f1: int }
|
|||
|
||||
pub fn main() {
|
||||
let s = "Hello, world!".to_string();
|
||||
let _s = S {
|
||||
let s = S {
|
||||
f0: s.to_string(),
|
||||
..S {
|
||||
f0: s,
|
||||
f1: 23
|
||||
}
|
||||
};
|
||||
assert_eq!(s.f0, "Hello, world!");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,8 +15,9 @@ struct S {
|
|||
|
||||
pub fn main() {
|
||||
let s = "Hello, world!".to_string();
|
||||
let _s = S {
|
||||
let s = S {
|
||||
f1: s.to_string(),
|
||||
f0: s
|
||||
};
|
||||
assert_eq!(s.f0, "Hello, world!");
|
||||
}
|
||||
|
|
|
|||
46
src/test/run-pass/struct-order-of-eval-3.rs
Normal file
46
src/test/run-pass/struct-order-of-eval-3.rs
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// Checks that functional-record-update order-of-eval is as expected
|
||||
// even when no Drop-implementations are involved.
|
||||
|
||||
use std::sync::atomic::{Ordering, AtomicUsize, ATOMIC_USIZE_INIT};
|
||||
|
||||
struct W { wrapped: u32 }
|
||||
struct S { f0: W, _f1: i32 }
|
||||
|
||||
pub fn main() {
|
||||
const VAL: u32 = 0x89AB_CDEF;
|
||||
let w = W { wrapped: VAL };
|
||||
let s = S {
|
||||
f0: { event(0x01); W { wrapped: w.wrapped + 1 } },
|
||||
..S {
|
||||
f0: { event(0x02); w},
|
||||
_f1: 23
|
||||
}
|
||||
};
|
||||
assert_eq!(s.f0.wrapped, VAL + 1);
|
||||
let actual = event_log();
|
||||
let expect = 0x01_02;
|
||||
assert!(expect == actual,
|
||||
"expect: 0x{:x} actual: 0x{:x}", expect, actual);
|
||||
}
|
||||
|
||||
static LOG: AtomicUsize = ATOMIC_USIZE_INIT;
|
||||
|
||||
fn event_log() -> usize {
|
||||
LOG.load(Ordering::SeqCst)
|
||||
}
|
||||
|
||||
fn event(tag: u8) {
|
||||
let old_log = LOG.load(Ordering::SeqCst);
|
||||
let new_log = (old_log << 8) + tag as usize;
|
||||
LOG.store(new_log, Ordering::SeqCst);
|
||||
}
|
||||
43
src/test/run-pass/struct-order-of-eval-4.rs
Normal file
43
src/test/run-pass/struct-order-of-eval-4.rs
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// Checks that struct-literal expression order-of-eval is as expected
|
||||
// even when no Drop-implementations are involved.
|
||||
|
||||
use std::sync::atomic::{Ordering, AtomicUsize, ATOMIC_USIZE_INIT};
|
||||
|
||||
struct W { wrapped: u32 }
|
||||
struct S { f0: W, _f1: i32 }
|
||||
|
||||
pub fn main() {
|
||||
const VAL: u32 = 0x89AB_CDEF;
|
||||
let w = W { wrapped: VAL };
|
||||
let s = S {
|
||||
_f1: { event(0x01); 23 },
|
||||
f0: { event(0x02); w },
|
||||
};
|
||||
assert_eq!(s.f0.wrapped, VAL);
|
||||
let actual = event_log();
|
||||
let expect = 0x01_02;
|
||||
assert!(expect == actual,
|
||||
"expect: 0x{:x} actual: 0x{:x}", expect, actual);
|
||||
}
|
||||
|
||||
static LOG: AtomicUsize = ATOMIC_USIZE_INIT;
|
||||
|
||||
fn event_log() -> usize {
|
||||
LOG.load(Ordering::SeqCst)
|
||||
}
|
||||
|
||||
fn event(tag: u8) {
|
||||
let old_log = LOG.load(Ordering::SeqCst);
|
||||
let new_log = (old_log << 8) + tag as usize;
|
||||
LOG.store(new_log, Ordering::SeqCst);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue