mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 15:23:46 +00:00
Add tests for E-needstest issues
This commit is contained in:
parent
3327ecca42
commit
69988539da
16
src/test/compile-fail/issue-11382.rs
Normal file
16
src/test/compile-fail/issue-11382.rs
Normal file
@ -0,0 +1,16 @@
|
||||
// Copyright 2014 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.
|
||||
|
||||
fn main() {
|
||||
panic!(
|
||||
1.2
|
||||
//~^ ERROR cannot determine the type of this number; add a suffix to specify the type explicitly
|
||||
);
|
||||
}
|
21
src/test/compile-fail/issue-11771.rs
Normal file
21
src/test/compile-fail/issue-11771.rs
Normal file
@ -0,0 +1,21 @@
|
||||
// Copyright 2014 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.
|
||||
|
||||
fn main() {
|
||||
let x = ();
|
||||
1 +
|
||||
x //~ ERROR mismatched types: expected `_`, found `()` (expected integral variable, found ())
|
||||
;
|
||||
|
||||
let x: () = ();
|
||||
1 +
|
||||
x //~ ERROR mismatched types: expected `_`, found `()` (expected integral variable, found ())
|
||||
;
|
||||
}
|
39
src/test/compile-fail/issue-13058.rs
Normal file
39
src/test/compile-fail/issue-13058.rs
Normal file
@ -0,0 +1,39 @@
|
||||
// Copyright 2014 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.
|
||||
|
||||
use std::iter::{Range,range};
|
||||
|
||||
trait Itble<'r, T, I: Iterator<T>> { fn iter(&'r self) -> I; }
|
||||
|
||||
impl<'r> Itble<'r, uint, Range<uint>> for (uint, uint) {
|
||||
fn iter(&'r self) -> Range<uint> {
|
||||
let &(min, max) = self;
|
||||
range(min, max)
|
||||
}
|
||||
}
|
||||
|
||||
fn check<'r, I: Iterator<uint>, T: Itble<'r, uint, I>>(cont: &T) -> bool
|
||||
//~^ HELP as shown: fn check<'r, I: Iterator<uint>, T: Itble<'r, uint, I>>(cont: &'r T) -> bool
|
||||
{
|
||||
let cont_iter = cont.iter();
|
||||
//~^ ERROR cannot infer an appropriate lifetime for autoref due to conflicting requirements
|
||||
let result = cont_iter.fold(Some(0u16), |state, val| {
|
||||
state.map_or(None, |mask| {
|
||||
let bit = 1 << val;
|
||||
if mask & bit == 0 {Some(mask|bit)} else {None}
|
||||
})
|
||||
});
|
||||
result.is_some()
|
||||
}
|
||||
|
||||
fn main() {
|
||||
check((3u, 5u));
|
||||
//~^ ERROR mismatched types: expected `&_`, found `(uint, uint)` (expected &-ptr, found tuple)
|
||||
}
|
@ -8,18 +8,15 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// ignore-test
|
||||
|
||||
pub struct send_packet<T> {
|
||||
p: T
|
||||
p: T
|
||||
}
|
||||
|
||||
|
||||
mod pingpong {
|
||||
use send_packet;
|
||||
pub type ping = send_packet<pong>;
|
||||
pub struct pong(send_packet<ping>);
|
||||
//~^ ERROR illegal recursive enum type; wrap the inner value in a box to make it representable
|
||||
//~^ ERROR illegal recursive struct type; wrap the inner value in a box to make it representable
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
22
src/test/run-pass/issue-10396.rs
Normal file
22
src/test/run-pass/issue-10396.rs
Normal file
@ -0,0 +1,22 @@
|
||||
// Copyright 2014 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.
|
||||
|
||||
#[deriving(Show)]
|
||||
enum Foo<'s> {
|
||||
V(&'s str)
|
||||
}
|
||||
|
||||
fn f(arr: &[&Foo]) {
|
||||
for &f in arr.iter() {
|
||||
println!("{}", f);
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
14
src/test/run-pass/issue-10501.rs
Normal file
14
src/test/run-pass/issue-10501.rs
Normal file
@ -0,0 +1,14 @@
|
||||
// Copyright 2014 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.
|
||||
|
||||
pub type Foo = fn(&int) -> ();
|
||||
#[deriving(Clone)]
|
||||
enum Baz { Bar(Foo) }
|
||||
fn main() {}
|
35
src/test/run-pass/issue-12741.rs
Normal file
35
src/test/run-pass/issue-12741.rs
Normal file
@ -0,0 +1,35 @@
|
||||
// Copyright 2014 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.
|
||||
|
||||
#[deriving(Clone)]
|
||||
pub struct Foo {
|
||||
f: fn(char, |char| -> char) -> char
|
||||
}
|
||||
|
||||
impl Foo {
|
||||
fn bar(&self) -> char {
|
||||
((*self).f)('a', |c: char| c)
|
||||
}
|
||||
}
|
||||
|
||||
fn bla(c: char, cb: |char| -> char) -> char {
|
||||
cb(c)
|
||||
}
|
||||
|
||||
pub fn make_foo() -> Foo {
|
||||
Foo {
|
||||
f: bla
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let a = make_foo();
|
||||
assert_eq!(a.bar(), 'a');
|
||||
}
|
19
src/test/run-pass/issue-15063.rs
Normal file
19
src/test/run-pass/issue-15063.rs
Normal file
@ -0,0 +1,19 @@
|
||||
// Copyright 2014 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.
|
||||
|
||||
enum Two { A, B}
|
||||
impl Drop for Two {
|
||||
fn drop(&mut self) {
|
||||
println!("Dropping!");
|
||||
}
|
||||
}
|
||||
fn main() {
|
||||
let k = A;
|
||||
}
|
56
src/test/run-pass/issue-15734.rs
Normal file
56
src/test/run-pass/issue-15734.rs
Normal file
@ -0,0 +1,56 @@
|
||||
// Copyright 2014 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.
|
||||
|
||||
struct Mat<T> { data: Vec<T>, cols: uint, }
|
||||
|
||||
impl<T> Mat<T> {
|
||||
fn new(data: Vec<T>, cols: uint) -> Mat<T> {
|
||||
Mat { data: data, cols: cols }
|
||||
}
|
||||
fn row<'a>(&'a self, row: uint) -> Row<&'a Mat<T>> {
|
||||
Row { mat: self, row: row, }
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Index<(uint, uint), T> for Mat<T> {
|
||||
fn index<'a>(&'a self, &(row, col): &(uint, uint)) -> &'a T {
|
||||
&self.data[row * self.cols + col]
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T> Index<(uint, uint), T> for &'a Mat<T> {
|
||||
fn index<'b>(&'b self, index: &(uint, uint)) -> &'b T {
|
||||
(*self).index(index)
|
||||
}
|
||||
}
|
||||
|
||||
struct Row<M> { mat: M, row: uint, }
|
||||
|
||||
impl<T, M: Index<(uint, uint), T>> Index<uint, T> for Row<M> {
|
||||
fn index<'a>(&'a self, col: &uint) -> &'a T {
|
||||
&self.mat[(self.row, *col)]
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let m = Mat::new(vec!(1u, 2, 3, 4, 5, 6), 3);
|
||||
let r = m.row(1);
|
||||
|
||||
assert!(r.index(&2) == &6);
|
||||
assert!(r[2] == 6);
|
||||
assert!(r[2u] == 6u);
|
||||
assert!(6 == r[2]);
|
||||
|
||||
let e = r[2];
|
||||
assert!(e == 6);
|
||||
|
||||
let e: uint = r[2];
|
||||
assert!(e == 6);
|
||||
}
|
50
src/test/run-pass/issue-16774.rs
Normal file
50
src/test/run-pass/issue-16774.rs
Normal file
@ -0,0 +1,50 @@
|
||||
// Copyright 2014 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.
|
||||
|
||||
#![feature(overloaded_calls, unboxed_closures)]
|
||||
|
||||
struct X(Box<int>);
|
||||
|
||||
static mut DESTRUCTOR_RAN: bool = false;
|
||||
|
||||
impl Drop for X {
|
||||
fn drop(&mut self) {
|
||||
unsafe {
|
||||
assert!(!DESTRUCTOR_RAN);
|
||||
DESTRUCTOR_RAN = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref<int> for X {
|
||||
fn deref(&self) -> &int {
|
||||
let &X(box ref x) = self;
|
||||
x
|
||||
}
|
||||
}
|
||||
|
||||
impl DerefMut<int> for X {
|
||||
fn deref_mut(&mut self) -> &mut int {
|
||||
let &X(box ref mut x) = self;
|
||||
x
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
{
|
||||
let mut test = X(box 5i);
|
||||
{
|
||||
let mut change = |&mut:| { *test = 10 };
|
||||
change();
|
||||
}
|
||||
assert_eq!(*test, 10);
|
||||
}
|
||||
assert!(unsafe { DESTRUCTOR_RAN });
|
||||
}
|
13
src/test/run-pass/issue-18110.rs
Normal file
13
src/test/run-pass/issue-18110.rs
Normal file
@ -0,0 +1,13 @@
|
||||
// Copyright 2014 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.
|
||||
|
||||
fn main() {
|
||||
({return},);
|
||||
}
|
16
src/test/run-pass/issue-7268.rs
Normal file
16
src/test/run-pass/issue-7268.rs
Normal file
@ -0,0 +1,16 @@
|
||||
// Copyright 2014 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.
|
||||
|
||||
fn foo<T: 'static>(_: T) {}
|
||||
|
||||
fn bar<T>(x: &'static T) {
|
||||
foo(x);
|
||||
}
|
||||
fn main() {}
|
Loading…
Reference in New Issue
Block a user