Skip to content

Commit

Permalink
Tests for fixed issues.
Browse files Browse the repository at this point in the history
Closes #3794.
Closes #4025.
Closes #5688.
Closes #5708.
Closes #7012.
Closes #7327.
  • Loading branch information
huonw committed Sep 3, 2013
1 parent 364beaa commit 12099ce
Show file tree
Hide file tree
Showing 6 changed files with 171 additions and 1 deletion.
26 changes: 26 additions & 0 deletions src/test/compile-fail/functional-struct-update-noncopyable.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2012 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.

// issue 7327

// xfail-fast #7103
extern mod extra;
use extra::arc::*;

struct A { y: Arc<int>, x: Arc<int> }

impl Drop for A {
fn drop(&self) { println(fmt!("x=%?", self.x.get())); }
}
fn main() {
let a = A { y: Arc::new(1), x: Arc::new(2) };
let _b = A { y: Arc::new(3), ..a };
let _c = a; //~ ERROR use of moved value
}
1 change: 0 additions & 1 deletion src/test/run-pass/issue-3794.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// xfail-test
trait T {
fn print(&self);
}
Expand Down
32 changes: 32 additions & 0 deletions src/test/run-pass/issue-4025.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright 2013 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.

/*
# if b { x } else { y } requires identical types for x and y
*/

fn print1(b: bool, s1: &str, s2: &str) {
println(if b { s1 } else { s2 });
}
fn print2<'a, 'b>(b: bool, s1: &'a str, s2: &'b str) {
println(if b { s1 } else { s2 });
}
fn print3(b: bool, s1: &str, s2: &str) {
let mut s: &str;
if b { s = s1; } else { s = s2; }
println(s);
}
fn print4<'a, 'b>(b: bool, s1: &'a str, s2: &'b str) {
let mut s: &str;
if b { s = s1; } else { s = s2; }
println(s);
}

pub fn main() {}
26 changes: 26 additions & 0 deletions src/test/run-pass/issue-5688.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2013 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.

/*
# Corrupted initialization in the static struct
...should print &[1, 2, 3] but instead prints something like
&[4492532864, 24]. It is pretty evident that the compiler messed up
with the representation of [int, ..n] and [int] somehow, or at least
failed to typecheck correctly.
*/

struct X { vec: &'static [int] }
static V: &'static [X] = &[X { vec: &[1, 2, 3] }];
fn main() {
for &v in V.iter() {
println(fmt!("%?", v.vec));
}
}
60 changes: 60 additions & 0 deletions src/test/run-pass/issue-5708.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright 2013 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.

/*
# ICE when returning struct with borrowed pointer to trait
A function which takes a borrowed pointer to a trait and returns a
struct with that borrowed pointer results in an ICE.
This does not occur with concrete types, only with borrowed pointers
to traits.
*/

// original
trait Inner {
fn print(&self);
}

impl Inner for int {
fn print(&self) { print(fmt!("Inner: %d\n", *self)); }
}

struct Outer<'self> {
inner: &'self Inner
}

impl<'self> Outer<'self> {
fn new<'r>(inner: &'r Inner) -> Outer<'r> {
Outer {
inner: inner
}
}
}

fn main() {
let inner = 5;
let outer = Outer::new(&inner as &Inner);
outer.inner.print();
}


// minimal
trait MyTrait<T> { }

pub struct MyContainer<'self, T> {
foos: ~[&'self MyTrait<T>],
}

impl<'self, T> MyContainer<'self, T> {
pub fn add (&mut self, foo: &'self MyTrait<T>) {
self.foos.push(foo);
}
}
27 changes: 27 additions & 0 deletions src/test/run-pass/issue-7012.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2013 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.

/*
# Comparison of static arrays
The expected behaviour would be that test==test1, therefore 'true'
would be printed, however the below prints false.
*/

struct signature<'self> { pattern : &'self [u32] }

static test1: signature<'static> = signature {
pattern: &[0x243f6a88u32,0x85a308d3u32,0x13198a2eu32,0x03707344u32,0xa4093822u32,0x299f31d0u32]
};

fn main() {
let test = &[0x243f6a88u32,0x85a308d3u32,0x13198a2eu32,0x03707344u32,0xa4093822u32,0x299f31d0u32];
println(fmt!("%b",test==test1.pattern));
}

4 comments on commit 12099ce

@bors
Copy link
Contributor

@bors bors commented on 12099ce Sep 3, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from thestinger
at huonw@12099ce

@bors
Copy link
Contributor

@bors bors commented on 12099ce Sep 3, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging huonw/rust/closed-issues = 12099ce into auto

@bors
Copy link
Contributor

@bors bors commented on 12099ce Sep 3, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

huonw/rust/closed-issues = 12099ce merged ok, testing candidate = b0d069bb

Please sign in to comment.