mirror of
https://github.com/rust-lang/rust.git
synced 2024-10-31 22:41:50 +00:00
auto merge of #19780 : jakub-/rust/e-needstest, r=alexcrichton
Closes #5988. Closes #10176. Closes #10456. Closes #12744. Closes #13264. Closes #13324. Closes #14182. Closes #15381. Closes #15444. Closes #15480. Closes #15756. Closes #16822. Closes #16966. Closes #17351. Closes #17503. Closes #17545. Closes #17771. Closes #17816. Closes #17897. Closes #17905. Closes #18188. Closes #18232. Closes #18345. Closes #18389. Closes #18400. Closes #18502. Closes #18611. Closes #18783. Closes #19009. Closes #19081. Closes #19098. Closes #19127. Closes #19135.
This commit is contained in:
commit
2a231594c4
30
src/test/auxiliary/issue-16822.rs
Normal file
30
src/test/auxiliary/issue-16822.rs
Normal file
@ -0,0 +1,30 @@
|
||||
// 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.
|
||||
|
||||
#![crate_type="lib"]
|
||||
|
||||
use std::cell::RefCell;
|
||||
|
||||
pub struct Window<Data>{
|
||||
pub data: RefCell<Data>
|
||||
}
|
||||
|
||||
impl<Data: Update> Window<Data> {
|
||||
pub fn update(&self, e: i32) {
|
||||
match e {
|
||||
1 => self.data.borrow_mut().update(),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub trait Update {
|
||||
fn update(&mut self);
|
||||
}
|
31
src/test/auxiliary/issue-18502.rs
Normal file
31
src/test/auxiliary/issue-18502.rs
Normal file
@ -0,0 +1,31 @@
|
||||
// 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.
|
||||
|
||||
#![crate_type="lib"]
|
||||
|
||||
struct Foo;
|
||||
// This is the ICE trigger
|
||||
struct Formatter;
|
||||
|
||||
trait Show {
|
||||
fn fmt(&self);
|
||||
}
|
||||
|
||||
impl Show for Foo {
|
||||
fn fmt(&self) {}
|
||||
}
|
||||
|
||||
fn bar<T>(f: extern "Rust" fn(&T), t: &T) { }
|
||||
|
||||
// ICE requirement: this has to be marked as inline
|
||||
#[inline]
|
||||
pub fn baz() {
|
||||
bar(Show::fmt, &Foo);
|
||||
}
|
16
src/test/compile-fail/issue-10176.rs
Normal file
16
src/test/compile-fail/issue-10176.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 f() -> int {
|
||||
(return 1, return 2)
|
||||
//~^ ERROR mismatched types: expected `int`, found `(_, _)` (expected int, found tuple)
|
||||
}
|
||||
|
||||
fn main() {}
|
25
src/test/compile-fail/issue-14182.rs
Normal file
25
src/test/compile-fail/issue-14182.rs
Normal file
@ -0,0 +1,25 @@
|
||||
// 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 Foo {
|
||||
f: for <'b> |&'b int|:
|
||||
'b -> &'b int //~ ERROR use of undeclared lifetime name `'b`
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut x: Vec< for <'a> ||
|
||||
:'a //~ ERROR use of undeclared lifetime name `'a`
|
||||
> = Vec::new();
|
||||
x.push(|| {});
|
||||
|
||||
let foo = Foo {
|
||||
f: |x| x
|
||||
};
|
||||
}
|
20
src/test/compile-fail/issue-15381.rs
Normal file
20
src/test/compile-fail/issue-15381.rs
Normal file
@ -0,0 +1,20 @@
|
||||
// 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 values: Vec<u8> = vec![1,2,3,4,5,6,7,8];
|
||||
|
||||
for
|
||||
[x,y,z]
|
||||
//~^ ERROR refutable pattern in `for` loop binding: `[]` not covered
|
||||
in values.as_slice().chunks(3).filter(|&xs| xs.len() == 3) {
|
||||
println!("y={}", y);
|
||||
}
|
||||
}
|
20
src/test/compile-fail/issue-15480.rs
Normal file
20
src/test/compile-fail/issue-15480.rs
Normal file
@ -0,0 +1,20 @@
|
||||
// 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 v = vec![
|
||||
&3i
|
||||
//~^ ERROR borrowed value does not live long enough
|
||||
];
|
||||
|
||||
for &&x in v.iter() {
|
||||
println!("{}", x + 3);
|
||||
}
|
||||
}
|
24
src/test/compile-fail/issue-15756.rs
Normal file
24
src/test/compile-fail/issue-15756.rs
Normal file
@ -0,0 +1,24 @@
|
||||
// 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::slice::Chunks;
|
||||
use std::slice::MutChunks;
|
||||
|
||||
fn dft_iter<'a, T>(arg1: Chunks<'a,T>, arg2: MutChunks<'a,T>)
|
||||
{
|
||||
for
|
||||
&something
|
||||
//~^ ERROR the trait `core::kinds::Sized` is not implemented for the type `[T]`
|
||||
in arg2
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
15
src/test/compile-fail/issue-16966.rs
Normal file
15
src/test/compile-fail/issue-16966.rs
Normal file
@ -0,0 +1,15 @@
|
||||
// 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 a type for this expression
|
||||
);
|
||||
}
|
18
src/test/compile-fail/issue-17545.rs
Normal file
18
src/test/compile-fail/issue-17545.rs
Normal file
@ -0,0 +1,18 @@
|
||||
// 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(unboxed_closures)]
|
||||
|
||||
pub fn foo<'a, F: Fn<(&'a (),), ()>>(bar: F) {
|
||||
bar.call((
|
||||
&(), //~ ERROR borrowed value does not live long enough
|
||||
));
|
||||
}
|
||||
fn main() {}
|
27
src/test/compile-fail/issue-17905.rs
Normal file
27
src/test/compile-fail/issue-17905.rs
Normal file
@ -0,0 +1,27 @@
|
||||
// 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)]
|
||||
struct Pair<T, V> (T, V);
|
||||
|
||||
impl Pair<
|
||||
&str, //~ ERROR missing lifetime specifier
|
||||
int
|
||||
> {
|
||||
fn say(self: &Pair<&str, int>) {
|
||||
//~^ ERROR mismatched types: expected `Pair<&'static str, int>`, found `Pair<&str, int>`
|
||||
println!("{}", self);
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let result = &Pair("shane", 1i);
|
||||
result.say();
|
||||
}
|
19
src/test/compile-fail/issue-18345.rs
Normal file
19
src/test/compile-fail/issue-18345.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.
|
||||
|
||||
type Step<'s, R, T> = |R, T|: 's -> R;
|
||||
type Transducer<'t, R, T, U> = |Step<'t, R, U>|: 't -> Step<'t, R, T>;
|
||||
|
||||
fn mapping<'f, R, T, U>(f: |T|: 'f -> U) -> &'f Transducer<'f, R, T, U> {
|
||||
|step| |r, x|
|
||||
step(r, f(x)) //~ ERROR the type of this value must be known in this context
|
||||
}
|
||||
|
||||
fn main() {}
|
34
src/test/compile-fail/issue-18389.rs
Normal file
34
src/test/compile-fail/issue-18389.rs
Normal file
@ -0,0 +1,34 @@
|
||||
// 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(unboxed_closures)]
|
||||
#![feature(associated_types)]
|
||||
|
||||
use std::any::Any;
|
||||
use std::intrinsics::TypeId;
|
||||
|
||||
pub trait Pt {}
|
||||
pub trait Rt {}
|
||||
|
||||
trait Private<P: Pt, R: Rt> {
|
||||
fn call(&self, p: P, r: R);
|
||||
}
|
||||
pub trait Public: Private<
|
||||
<Self as Public>::P,
|
||||
//~^ ERROR illegal recursive type; insert an enum or struct in the cycle, if this is desired
|
||||
<Self as Public>::R
|
||||
> {
|
||||
type P;
|
||||
type R;
|
||||
|
||||
fn call_inner(&self);
|
||||
}
|
||||
|
||||
fn main() {}
|
36
src/test/compile-fail/issue-18400.rs
Normal file
36
src/test/compile-fail/issue-18400.rs
Normal file
@ -0,0 +1,36 @@
|
||||
// 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.
|
||||
|
||||
trait Set<T> {
|
||||
fn contains(&self, T) -> bool;
|
||||
fn set(&mut self, T);
|
||||
}
|
||||
|
||||
impl<'a, T, S> Set<&'a [T]> for S where
|
||||
T: Copy,
|
||||
S: Set<T>,
|
||||
{
|
||||
fn contains(&self, bits: &[T]) -> bool {
|
||||
bits.iter().all(|&bit| self.contains(bit))
|
||||
}
|
||||
|
||||
fn set(&mut self, bits: &[T]) {
|
||||
for &bit in bits.iter() {
|
||||
self.set(bit)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let bits: &[_] = &[0, 1];
|
||||
|
||||
0.contains(bits);
|
||||
//~^ ERROR the trait `Set<_>` is not implemented for the type `_`
|
||||
}
|
22
src/test/compile-fail/issue-18611.rs
Normal file
22
src/test/compile-fail/issue-18611.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.
|
||||
|
||||
#![feature(associated_types)]
|
||||
|
||||
fn add_state(op:
|
||||
<int as HasState>::State
|
||||
//~^ ERROR it is currently unsupported to access associated types except through a type parameter
|
||||
) {}
|
||||
|
||||
trait HasState {
|
||||
type State;
|
||||
}
|
||||
|
||||
fn main() {}
|
37
src/test/compile-fail/issue-18783.rs
Normal file
37
src/test/compile-fail/issue-18783.rs
Normal file
@ -0,0 +1,37 @@
|
||||
// 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::cell::RefCell;
|
||||
|
||||
fn main() {
|
||||
let c = RefCell::new(vec![]);
|
||||
let mut y = 1u;
|
||||
c.push(|| y = 0);
|
||||
c.push(|| y = 0);
|
||||
//~^ ERROR cannot borrow `y` as mutable more than once at a time
|
||||
}
|
||||
|
||||
fn ufcs() {
|
||||
let c = RefCell::new(vec![]);
|
||||
let mut y = 1u;
|
||||
|
||||
Push::push(&c, || y = 0);
|
||||
Push::push(&c, || y = 0);
|
||||
}
|
||||
|
||||
trait Push<'c> {
|
||||
fn push<'f: 'c>(&self, push: ||:'f -> ());
|
||||
}
|
||||
|
||||
impl<'c> Push<'c> for RefCell<Vec<||:'c>> {
|
||||
fn push<'f: 'c>(&self, fun: ||:'f -> ()) {
|
||||
self.borrow_mut().push(fun)
|
||||
}
|
||||
}
|
19
src/test/compile-fail/issue-19009.rs
Normal file
19
src/test/compile-fail/issue-19009.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.
|
||||
|
||||
#![feature(lang_items)]
|
||||
#![no_std]
|
||||
#![crate_type="rlib"]
|
||||
#[lang="sized"] pub trait Sized for Sized? {}
|
||||
|
||||
fn ice(f: for <'s> ||
|
||||
:'s //~ ERROR use of undeclared lifetime name `'s`
|
||||
) {}
|
||||
fn main() { ice(||{}) }
|
25
src/test/compile-fail/issue-19081.rs
Normal file
25
src/test/compile-fail/issue-19081.rs
Normal file
@ -0,0 +1,25 @@
|
||||
// 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(associated_types)]
|
||||
|
||||
pub trait Hasher{
|
||||
type State;
|
||||
|
||||
fn hash<T: Hash<
|
||||
<Self as Hasher>::State //~ ERROR no suitable bound on `Self`
|
||||
>>(&self, value: &T) -> u64;
|
||||
}
|
||||
|
||||
trait Hash<S> {
|
||||
fn hash(&self, state: &mut S);
|
||||
}
|
||||
|
||||
fn main() {}
|
31
src/test/run-pass-fulldeps/issue-16822.rs
Normal file
31
src/test/run-pass-fulldeps/issue-16822.rs
Normal file
@ -0,0 +1,31 @@
|
||||
// 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.
|
||||
|
||||
// aux-build:issue-16822.rs
|
||||
|
||||
extern crate "issue-16822" as lib;
|
||||
|
||||
use std::cell::RefCell;
|
||||
|
||||
struct App {
|
||||
i: int
|
||||
}
|
||||
|
||||
impl lib::Update for App {
|
||||
fn update(&mut self) {
|
||||
self.i += 1;
|
||||
}
|
||||
}
|
||||
|
||||
fn main(){
|
||||
let app = App { i: 5 };
|
||||
let window = lib::Window { data: RefCell::new(app) };
|
||||
window.update(1);
|
||||
}
|
17
src/test/run-pass-fulldeps/issue-18502.rs
Normal file
17
src/test/run-pass-fulldeps/issue-18502.rs
Normal file
@ -0,0 +1,17 @@
|
||||
// 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.
|
||||
|
||||
// aux-build:issue-18502.rs
|
||||
|
||||
extern crate "issue-18502" as fmt;
|
||||
|
||||
fn main() {
|
||||
::fmt::baz();
|
||||
}
|
30
src/test/run-pass/issue-10456.rs
Normal file
30
src/test/run-pass/issue-10456.rs
Normal file
@ -0,0 +1,30 @@
|
||||
// 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 struct Foo;
|
||||
|
||||
pub trait Bar {
|
||||
fn bar(&self);
|
||||
}
|
||||
|
||||
pub trait Baz {}
|
||||
|
||||
impl<T: Baz> Bar for T {
|
||||
fn bar(&self) {}
|
||||
}
|
||||
|
||||
impl Baz for Foo {}
|
||||
|
||||
pub fn foo(t: Box<Foo>) {
|
||||
t.bar(); // ~Foo doesn't implement Baz
|
||||
(*t).bar(); // ok b/c Foo implements Baz
|
||||
}
|
||||
|
||||
fn main() {}
|
14
src/test/run-pass/issue-12744.rs
Normal file
14
src/test/run-pass/issue-12744.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.
|
||||
|
||||
fn main() {
|
||||
fn test() -> Box<std::any::Any + 'static> { box 1i }
|
||||
println!("{}", test())
|
||||
}
|
74
src/test/run-pass/issue-13264.rs
Normal file
74
src/test/run-pass/issue-13264.rs
Normal file
@ -0,0 +1,74 @@
|
||||
// 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 Root {
|
||||
jsref: JSRef
|
||||
}
|
||||
|
||||
impl Deref<JSRef> for Root {
|
||||
fn deref<'a>(&'a self) -> &'a JSRef {
|
||||
&self.jsref
|
||||
}
|
||||
}
|
||||
|
||||
#[deriving(Copy)]
|
||||
struct JSRef {
|
||||
node: *const Node
|
||||
}
|
||||
|
||||
impl Deref<Node> for JSRef {
|
||||
fn deref<'a>(&'a self) -> &'a Node {
|
||||
self.get()
|
||||
}
|
||||
}
|
||||
|
||||
trait INode {
|
||||
fn RemoveChild(&self);
|
||||
}
|
||||
|
||||
impl INode for JSRef {
|
||||
fn RemoveChild(&self) {
|
||||
self.get().RemoveChild(0)
|
||||
}
|
||||
}
|
||||
|
||||
impl JSRef {
|
||||
fn AddChild(&self) {
|
||||
self.get().AddChild(0);
|
||||
}
|
||||
|
||||
fn get<'a>(&'a self) -> &'a Node {
|
||||
unsafe {
|
||||
&*self.node
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct Node;
|
||||
|
||||
impl Node {
|
||||
fn RemoveChild(&self, _a: uint) {
|
||||
}
|
||||
|
||||
fn AddChild(&self, _a: uint) {
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let n = Node;
|
||||
let jsref = JSRef { node: &n };
|
||||
let root = Root { jsref: jsref };
|
||||
|
||||
root.AddChild();
|
||||
jsref.AddChild();
|
||||
|
||||
root.RemoveChild();
|
||||
jsref.RemoveChild();
|
||||
}
|
66
src/test/run-pass/issue-13323.rs
Normal file
66
src/test/run-pass/issue-13323.rs
Normal file
@ -0,0 +1,66 @@
|
||||
// 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 StrWrap {
|
||||
s: String
|
||||
}
|
||||
|
||||
impl StrWrap {
|
||||
fn new(s: &str) -> StrWrap {
|
||||
StrWrap { s: s.into_string() }
|
||||
}
|
||||
|
||||
fn get_s<'a>(&'a self) -> &'a str {
|
||||
self.s.as_slice()
|
||||
}
|
||||
}
|
||||
|
||||
struct MyStruct {
|
||||
s: StrWrap
|
||||
}
|
||||
|
||||
impl MyStruct {
|
||||
fn new(s: &str) -> MyStruct {
|
||||
MyStruct { s: StrWrap::new(s) }
|
||||
}
|
||||
|
||||
fn get_str_wrap<'a>(&'a self) -> &'a StrWrap {
|
||||
&self.s
|
||||
}
|
||||
}
|
||||
|
||||
trait Matcher<T> {
|
||||
fn matches(&self, actual: T) -> bool;
|
||||
}
|
||||
|
||||
fn assert_that<T, U: Matcher<T>>(actual: T, matcher: &U) {
|
||||
assert!(matcher.matches(actual));
|
||||
}
|
||||
|
||||
struct EqualTo<T> {
|
||||
expected: T
|
||||
}
|
||||
|
||||
impl<T: Eq> Matcher<T> for EqualTo<T> {
|
||||
fn matches(&self, actual: T) -> bool {
|
||||
self.expected.eq(&actual)
|
||||
}
|
||||
}
|
||||
|
||||
fn equal_to<T: Eq>(expected: T) -> Box<EqualTo<T>> {
|
||||
box EqualTo { expected: expected }
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
let my_struct = MyStruct::new("zomg");
|
||||
let s = my_struct.get_str_wrap();
|
||||
|
||||
assert_that(s.get_s(), &*equal_to("zomg"));
|
||||
}
|
29
src/test/run-pass/issue-15444.rs
Normal file
29
src/test/run-pass/issue-15444.rs
Normal file
@ -0,0 +1,29 @@
|
||||
// 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.
|
||||
|
||||
trait MyTrait {
|
||||
fn foo(&self);
|
||||
}
|
||||
|
||||
impl<A, B, C> MyTrait for fn(A, B) -> C {
|
||||
fn foo(&self) {}
|
||||
}
|
||||
|
||||
fn bar<T: MyTrait>(t: &T) {
|
||||
t.foo()
|
||||
}
|
||||
|
||||
fn thing(a: int, b: int) -> int {
|
||||
a + b
|
||||
}
|
||||
|
||||
fn main() {
|
||||
bar(&thing);
|
||||
}
|
13
src/test/run-pass/issue-17351.rs
Normal file
13
src/test/run-pass/issue-17351.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() {
|
||||
let _: &Str = &"x";
|
||||
}
|
21
src/test/run-pass/issue-17503.rs
Normal file
21
src/test/run-pass/issue-17503.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.
|
||||
|
||||
#![feature(slicing_syntax)]
|
||||
|
||||
fn main() {
|
||||
let s: &[int] = &[0, 1, 2, 3, 4];
|
||||
let ss: &&[int] = &s;
|
||||
let sss: &&&[int] = &ss;
|
||||
|
||||
println!("{}", s[..3]);
|
||||
println!("{}", ss[3..]);
|
||||
println!("{}", sss[2..4]);
|
||||
}
|
27
src/test/run-pass/issue-17771.rs
Normal file
27
src/test/run-pass/issue-17771.rs
Normal file
@ -0,0 +1,27 @@
|
||||
// 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.
|
||||
|
||||
trait Aaa {}
|
||||
|
||||
impl<'a> Aaa for &'a mut (Aaa + 'a) {}
|
||||
|
||||
struct Bar<'a> {
|
||||
writer: &'a mut (Aaa + 'a),
|
||||
}
|
||||
|
||||
fn baz(_: &mut Aaa) {
|
||||
}
|
||||
|
||||
fn foo<'a>(mut bar: Bar<'a>) {
|
||||
baz(&mut bar.writer);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
}
|
18
src/test/run-pass/issue-17816.rs
Normal file
18
src/test/run-pass/issue-17816.rs
Normal file
@ -0,0 +1,18 @@
|
||||
// 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(unboxed_closures)]
|
||||
|
||||
fn main() {
|
||||
struct Symbol<'a, F: Fn(Vec<&'a str>) -> &'a str> { function: F }
|
||||
let f = |&: x: Vec<&str>| -> &str "foobar";
|
||||
let sym = Symbol { function: f };
|
||||
(sym.function)(vec![]);
|
||||
}
|
21
src/test/run-pass/issue-17897.rs
Normal file
21
src/test/run-pass/issue-17897.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.
|
||||
|
||||
#![feature(default_type_params, unboxed_closures)]
|
||||
|
||||
use std::thunk::Thunk;
|
||||
|
||||
fn action(cb: Thunk<uint, uint>) -> uint {
|
||||
cb.invoke(1)
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
println!("num: {}", action(Thunk::with_arg(move |:u| u)));
|
||||
}
|
31
src/test/run-pass/issue-18188.rs
Normal file
31
src/test/run-pass/issue-18188.rs
Normal file
@ -0,0 +1,31 @@
|
||||
// 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(default_type_params, unboxed_closures)]
|
||||
|
||||
use std::thunk::Thunk;
|
||||
|
||||
pub trait Promisable: Send + Sync {}
|
||||
impl<T: Send + Sync> Promisable for T {}
|
||||
pub fn propagate<T, E, F, G>(action: F) -> Thunk<Result<T, E>, Result<T, E>>
|
||||
where
|
||||
T: Promisable + Clone,
|
||||
E: Promisable + Clone,
|
||||
F: FnOnce(&T) -> Result<T, E> + Send,
|
||||
G: FnOnce(Result<T, E>) -> Result<T, E> {
|
||||
Thunk::with_arg(move |: result: Result<T, E>| {
|
||||
match result {
|
||||
Ok(ref t) => action(t),
|
||||
Err(ref e) => Err(e.clone()),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn main() {}
|
29
src/test/run-pass/issue-18232.rs
Normal file
29
src/test/run-pass/issue-18232.rs
Normal file
@ -0,0 +1,29 @@
|
||||
// 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 Cursor<'a>;
|
||||
|
||||
trait CursorNavigator {
|
||||
fn init_cursor<'a, 'b:'a>(&'a self, cursor: &mut Cursor<'b>) -> bool;
|
||||
}
|
||||
|
||||
struct SimpleNavigator;
|
||||
|
||||
impl CursorNavigator for SimpleNavigator {
|
||||
fn init_cursor<'a, 'b: 'a>(&'a self, _cursor: &mut Cursor<'b>) -> bool {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut c = Cursor;
|
||||
let n = SimpleNavigator;
|
||||
n.init_cursor(&mut c);
|
||||
}
|
24
src/test/run-pass/issue-19098.rs
Normal file
24
src/test/run-pass/issue-19098.rs
Normal file
@ -0,0 +1,24 @@
|
||||
// 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(unboxed_closures)]
|
||||
|
||||
pub trait Handler {
|
||||
fn handle(&self, &mut String);
|
||||
}
|
||||
|
||||
impl<F> Handler for F
|
||||
where F: for<'a, 'b> Fn(&'a mut String) {
|
||||
fn handle(&self, st: &mut String) {
|
||||
self.call((st,))
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
18
src/test/run-pass/issue-19127.rs
Normal file
18
src/test/run-pass/issue-19127.rs
Normal file
@ -0,0 +1,18 @@
|
||||
// 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(unboxed_closures)]
|
||||
|
||||
fn foo<T, F: FnOnce(T) -> T>(f: F) {}
|
||||
fn id<'a>(input: &'a u8) -> &'a u8 { input }
|
||||
|
||||
fn main() {
|
||||
foo(id);
|
||||
}
|
22
src/test/run-pass/issue-19135.rs
Normal file
22
src/test/run-pass/issue-19135.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.
|
||||
|
||||
#![feature(unboxed_closures)]
|
||||
|
||||
#[deriving(Show)]
|
||||
struct LifetimeStruct<'a>;
|
||||
|
||||
fn main() {
|
||||
takes_hrtb_closure(|&mut: lts| println!("{}", lts));
|
||||
}
|
||||
|
||||
fn takes_hrtb_closure<F: for<'a>FnMut(LifetimeStruct<'a>)>(mut f: F) {
|
||||
f(LifetimeStruct);
|
||||
}
|
32
src/test/run-pass/issue-5988.rs
Normal file
32
src/test/run-pass/issue-5988.rs
Normal file
@ -0,0 +1,32 @@
|
||||
// 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::io;
|
||||
trait B {
|
||||
fn f(&self);
|
||||
}
|
||||
|
||||
trait T : B {
|
||||
}
|
||||
|
||||
struct A;
|
||||
|
||||
impl<U: T> B for U {
|
||||
fn f(&self) { io::println("Hey, I'm a T!"); }
|
||||
}
|
||||
|
||||
impl T for A {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let a = A;
|
||||
let br = &a as &B;
|
||||
br.f();
|
||||
}
|
Loading…
Reference in New Issue
Block a user