]> git.proxmox.com Git - rustc.git/blame - src/test/compile-fail/move-fragments-6.rs
New upstream version 1.18.0+dfsg1
[rustc.git] / src / test / compile-fail / move-fragments-6.rs
CommitLineData
1a4d82fc
JJ
1// Copyright 2014 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// Test that we correctly compute the move fragments for a fn.
12//
13// Note that the code below is not actually incorrect; the
14// `rustc_move_fragments` attribute is a hack that uses the error
15// reporting mechanisms as a channel for communicating from the
16// internals of the compiler.
17
18// Test that moving into a field (i.e. overwriting it) fragments the
19// receiver.
20
85aaf69f
SL
21#![feature(rustc_attrs)]
22
1a4d82fc
JJ
23use std::mem::drop;
24
25pub struct Pair<X,Y> { x: X, y: Y }
26
27#[rustc_move_fragments]
28pub fn test_overwrite_uninit_field<Z>(z: Z) {
29 //~^ ERROR parent_of_fragments: `$(local mut p)`
30 //~| ERROR assigned_leaf_path: `$(local z)`
31 //~| ERROR moved_leaf_path: `$(local z)`
32 //~| ERROR assigned_leaf_path: `$(local mut p).x`
33 //~| ERROR unmoved_fragment: `$(local mut p).y`
34
35 let mut p: Pair<Z,Z>;
36 p.x = z;
37}
38
39#[rustc_move_fragments]
40pub fn test_overwrite_moved_field<Z>(mut p: Pair<Z,Z>, z: Z) {
41 //~^ ERROR parent_of_fragments: `$(local mut p)`
42 //~| ERROR assigned_leaf_path: `$(local z)`
43 //~| ERROR moved_leaf_path: `$(local z)`
44 //~| ERROR assigned_leaf_path: `$(local mut p).y`
45 //~| ERROR unmoved_fragment: `$(local mut p).x`
46
47 drop(p);
48 p.y = z;
49}
50
51#[rustc_move_fragments]
52pub fn test_overwrite_same_field<Z>(mut p: Pair<Z,Z>) {
53 //~^ ERROR parent_of_fragments: `$(local mut p)`
54 //~| ERROR moved_leaf_path: `$(local mut p).x`
55 //~| ERROR assigned_leaf_path: `$(local mut p).x`
56 //~| ERROR unmoved_fragment: `$(local mut p).y`
57
58 p.x = p.x;
59}
60
61pub fn main() { }