Merge remote-tracking branch 'origin/master' into proc_macro_api

This commit is contained in:
Alex Crichton 2017-07-05 08:42:13 -07:00
commit fd95db25b3
605 changed files with 6469 additions and 3681 deletions

View file

@ -0,0 +1,13 @@
// Copyright 2017 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() {
1u32 as char; //~ ERROR E0604
}

View file

@ -0,0 +1,19 @@
// Copyright 2017 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 = 0u8;
x as Vec<u8>; //~ ERROR E0605
//~| NOTE an `as` expression can only be used to convert between primitive types
let v = 0 as *const u8;
v as &u8; //~ ERROR E0605
//~| NOTE an `as` expression can only be used to convert between primitive types
}

View file

@ -0,0 +1,13 @@
// Copyright 2017 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() {
&0u8 as u8; //~ ERROR E0606
}

View file

@ -0,0 +1,14 @@
// Copyright 2017 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 = 0 as *const u8;
v as *const [u8]; //~ ERROR E0607
}

View file

@ -0,0 +1,19 @@
// Copyright 2017 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;
match x {
(..) => {} //~ ERROR E0619
_ => {}
}
}

View file

@ -0,0 +1,13 @@
// Copyright 2017 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 _foo = &[1_usize, 2] as [usize]; //~ ERROR E0620
}

View file

@ -0,0 +1,28 @@
// Copyright 2016 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.
// Test that we give the generic E0495 when one of the free regions is
// bound in a closure (rather than suggesting a change to the signature
// of the closure, which is not specified in `foo` but rather in `invoke`).
// FIXME - This might be better as a UI test, but the finer details
// of the error seem to vary on different machines.
fn invoke<'a, F>(x: &'a i32, f: F) -> &'a i32
where F: FnOnce(&'a i32, &i32) -> &'a i32
{
let y = 22;
f(x, &y)
}
fn foo<'a>(x: &'a i32) {
invoke(&x, |a, b| if a > b { a } else { b }); //~ ERROR E0495
}
fn main() {}

View file

@ -11,6 +11,6 @@
#![feature(intrinsics)]
extern "rust-intrinsic" {
pub static breakpoint : unsafe extern "rust-intrinsic" fn();
//~^ ERROR intrinsic has wrong type
//~^ ERROR intrinsic must be a function [E0622]
}
fn main() { unsafe { breakpoint(); } }
fn main() { unsafe { breakpoint(); } }

View file

@ -38,11 +38,13 @@ pub fn f1_int_uint() {
pub fn f1_uint_uint() {
f1(2u32, 4u32);
//~^ ERROR `u32: Foo` is not satisfied
//~| ERROR `u32: Foo` is not satisfied
}
pub fn f1_uint_int() {
f1(2u32, 4i32);
//~^ ERROR `u32: Foo` is not satisfied
//~| ERROR `u32: Foo` is not satisfied
}
pub fn f2_int() {

View file

@ -8,5 +8,5 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// error-pattern: non-scalar cast: `()` as `u32`
// error-pattern: non-primitive cast: `()` as `u32`
fn main() { let u = (assert!(true) as u32); }

View file

@ -13,8 +13,8 @@ fn foo(_x: isize) { }
fn main() {
let v: u64 = 5;
let x = foo as extern "C" fn() -> isize;
//~^ ERROR non-scalar cast
//~^ ERROR non-primitive cast
let y = v as extern "Rust" fn(isize) -> (isize, isize);
//~^ ERROR non-scalar cast
//~^ ERROR non-primitive cast
y(x());
}

View file

@ -8,5 +8,5 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// error-pattern: non-scalar cast: `u32` as `()`
// error-pattern: non-primitive cast: `u32` as `()`
fn main() { let u = 0u32 as (); }

View file

@ -14,5 +14,5 @@
fn main() {
let b = 0u8;
let baz: fn() -> u8 = (|| { b }) as fn() -> u8;
//~^ ERROR non-scalar cast
//~^ ERROR non-primitive cast
}

View file

@ -17,7 +17,7 @@ fn cast_a() {
}
fn cast_b() {
let y = 22 as !; //~ ERROR non-scalar cast
let y = 22 as !; //~ ERROR non-primitive cast
}
fn main() { }

View file

@ -0,0 +1,23 @@
// Copyright 2017 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.
mod a {}
macro_rules! m {
() => {
use a::$crate; //~ ERROR unresolved import `a::$crate`
use a::$crate::b; //~ ERROR unresolved import `a::$crate::b`
type A = a::$crate; //~ ERROR cannot find type `$crate` in module `a`
}
}
m!();
fn main() {}

View file

@ -0,0 +1,24 @@
// Copyright 2017 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.
macro_rules! m {
() => {
struct $crate {} //~ ERROR expected identifier, found reserved identifier `$crate`
use $crate; // OK
//~^ WARN `$crate` may not be imported
use $crate as $crate; //~ ERROR expected identifier, found reserved identifier `$crate`
//~^ WARN `$crate` may not be imported
}
}
m!();
fn main() {}

View 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.
// Forbid assignment into a dynamically sized type.
#![feature(unsized_tuple_coercion)]
type Fat<T: ?Sized> = (isize, &'static str, T);
//~^ WARNING trait bounds are not (yet) enforced
#[derive(PartialEq,Eq)]
struct Bar;
#[derive(PartialEq,Eq)]
struct Bar1 {
f: isize
}
trait ToBar {
fn to_bar(&self) -> Bar;
fn to_val(&self) -> isize;
}
impl ToBar for Bar1 {
fn to_bar(&self) -> Bar {
Bar
}
fn to_val(&self) -> isize {
self.f
}
}
pub fn main() {
// Assignment.
let f5: &mut Fat<ToBar> = &mut (5, "some str", Bar1 {f :42});
let z: Box<ToBar> = Box::new(Bar1 {f: 36});
f5.2 = Bar1 {f: 36};
//~^ ERROR mismatched types
//~| expected type `ToBar`
//~| found type `Bar1`
//~| expected trait ToBar, found struct `Bar1`
//~| ERROR `ToBar: std::marker::Sized` is not satisfied
}

View file

@ -10,6 +10,8 @@
// Attempt to change the type as well as unsizing.
#![feature(unsized_tuple_coercion)]
struct Fat<T: ?Sized> {
ptr: T
}
@ -29,4 +31,16 @@ pub fn main() {
let f2: &Fat<Foo> = &f1;
let f3: &Fat<Bar> = f2;
//~^ ERROR `Foo: Bar` is not satisfied
// Tuple with a vec of isize.
let f1 = ([1, 2, 3],);
let f2: &([isize; 3],) = &f1;
let f3: &([usize],) = f2;
//~^ ERROR mismatched types
// Tuple with a trait.
let f1 = (Foo,);
let f2: &(Foo,) = &f1;
let f3: &(Bar,) = f2;
//~^ ERROR `Foo: Bar` is not satisfied
}

View file

@ -28,4 +28,14 @@ pub fn main() {
let f1 = Fat { ptr: Foo };
let f2: &Fat<Foo> = &f1;
let f3: &mut Fat<Bar> = f2; //~ ERROR mismatched types
// Tuple with a vec of ints.
let f1 = ([1, 2, 3],);
let f2: &([isize; 3],) = &f1;
let f3: &mut ([isize],) = f2; //~ ERROR mismatched types
// Tuple with a trait.
let f1 = (Foo,);
let f2: &(Foo,) = &f1;
let f3: &mut (Bar,) = f2; //~ ERROR mismatched types
}

View file

@ -10,6 +10,8 @@
// Attempt to extend the lifetime as well as unsizing.
#![feature(unsized_tuple_coercion)]
struct Fat<T: ?Sized> {
ptr: T
}
@ -28,6 +30,16 @@ fn baz<'a>() {
let f1 = Fat { ptr: Foo };
let f2: &Fat<Foo> = &f1; //~ ERROR `f1` does not live long enough
let f3: &'a Fat<Bar> = f2;
// Tuple with a vec of ints.
let f1 = ([1, 2, 3],);
let f2: &([isize; 3],) = &f1; //~ ERROR `f1` does not live long enough
let f3: &'a ([isize],) = f2;
// Tuple with a trait.
let f1 = (Foo,);
let f2: &(Foo,) = &f1; //~ ERROR `f1` does not live long enough
let f3: &'a (Bar,) = f2;
}
pub fn main() {

View file

@ -10,6 +10,8 @@
// Attempt to coerce from unsized to sized.
#![feature(unsized_tuple_coercion)]
struct Fat<T: ?Sized> {
ptr: T
}
@ -22,4 +24,12 @@ pub fn main() {
//~| expected type `&Fat<[isize; 3]>`
//~| found type `&Fat<[isize]>`
//~| expected array of 3 elements, found slice
// Tuple with a vec of isizes.
let f1: &([isize],) = &([1, 2, 3],);
let f2: &([isize; 3],) = f1;
//~^ ERROR mismatched types
//~| expected type `&([isize; 3],)`
//~| found type `&([isize],)`
//~| expected array of 3 elements, found slice
}

View file

@ -0,0 +1,23 @@
// 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.
// Try to initialise a DST struct where the lost information is deeply nested.
// This is an error because it requires an unsized rvalue. This is a problem
// because it would require stack allocation of an unsized temporary (*g in the
// test).
#![feature(unsized_tuple_coercion)]
pub fn main() {
let f: ([isize; 3],) = ([5, 6, 7],);
let g: &([isize],) = &f;
let h: &(([isize],),) = &(*g,);
//~^ ERROR `[isize]: std::marker::Sized` is not satisfied
}

View file

@ -22,7 +22,7 @@ fn main() {
a as isize; //~ ERROR casting
a as i16; //~ ERROR casting `&[i32]` as `i16` is invalid
a as u32; //~ ERROR casting `&[i32]` as `u32` is invalid
b as usize; //~ ERROR non-scalar cast
b as usize; //~ ERROR non-primitive cast
p as usize;
//~^ ERROR casting
//~^^ HELP cast through a thin pointer

View file

@ -0,0 +1,17 @@
// 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.
// check that #[allow_fail] is feature-gated
#[allow_fail] //~ ERROR allow_fail attribute is currently unstable
fn ok_to_fail() {
assert!(false);
}

View file

@ -0,0 +1,14 @@
// Copyright 2017 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 _ : &(Send,) = &((),);
//~^ ERROR Unsized tuple coercion is not stable enough
}

View file

@ -10,5 +10,5 @@
fn main() {
let nil = ();
let _t = nil as usize; //~ ERROR: non-scalar cast: `()` as `usize`
let _t = nil as usize; //~ ERROR: non-primitive cast: `()` as `usize`
}

View file

@ -9,5 +9,5 @@
// except according to those terms.
fn main() {
0 as &std::any::Any; //~ ERROR non-scalar cast
0 as &std::any::Any; //~ ERROR non-primitive cast
}

View file

@ -19,7 +19,7 @@ pub trait Array2D: Index<usize> {
}
let i = y * self.columns() + x;
let indexer = &(*self as &Index<usize, Output = <Self as Index<usize>>::Output>);
//~^ERROR non-scalar cast
//~^ERROR non-primitive cast
Some(indexer.index(i))
}
}

View file

@ -24,7 +24,7 @@ pub fn let_<'var, VAR, F: for<'v: 'var> Fn(Expr<'v, VAR>) -> Expr<'v, VAR>>
}
fn main() {
let ex = |x| {
let_(add(x,x), |y| { //~ ERROR type annotations needed
let ex = |x| { //~ ERROR type annotations needed
let_(add(x,x), |y| {
let_(add(x, x), |x|x)})};
}

View file

@ -9,7 +9,7 @@
// except according to those terms.
fn bad (p: *const isize) {
let _q: &isize = p as &isize; //~ ERROR non-scalar cast
let _q: &isize = p as &isize; //~ ERROR non-primitive cast
}
fn main() { }

View file

@ -8,9 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(rustc_attrs)]
fn _test(ref _p: str) {}
//~^ ERROR the trait bound `str: std::marker::Sized` is not satisfied [E0277]
#[rustc_error]
fn main() { } //~ ERROR compilation successful
fn main() { }

View file

@ -0,0 +1,21 @@
// Copyright 2017 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::ops::Deref;
pub trait Foo {
fn baz(_: Self::Target) where Self: Deref {}
//~^ ERROR `<Self as std::ops::Deref>::Target: std::marker::Sized` is not satisfied
}
pub fn f(_: ToString) {}
//~^ ERROR the trait bound `std::string::ToString + 'static: std::marker::Sized` is not satisfied
fn main() { }

View file

@ -0,0 +1,18 @@
// Copyright 2017 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 Value = String;
fn main() {
let f = |&Value::String(_)| (); //~ ERROR no associated item named
let vec: Vec<Value> = Vec::new();
vec.last().map(f);
}

View file

@ -8,13 +8,11 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// error-pattern:non-scalar cast
#[derive(Debug)]
struct foo {
x: isize
}
fn main() {
println!("{}", foo{ x: 1 } as isize);
println!("{}", foo{ x: 1 } as isize); //~ non-primitive cast: `foo` as `isize` [E0605]
}

View file

@ -44,12 +44,18 @@ fn main() {
//~^ ERROR E0277
//~| NOTE trait message
//~| NOTE required by
//~| ERROR E0277
//~| NOTE trait message
Index::index(&[] as &[i32], Foo(2u32));
//~^ ERROR E0277
//~| NOTE on impl for Foo
//~| NOTE required by
//~| ERROR E0277
//~| NOTE on impl for Foo
Index::index(&[] as &[i32], Bar(2u32));
//~^ ERROR E0277
//~| NOTE on impl for Bar
//~| NOTE required by
//~| ERROR E0277
//~| NOTE on impl for Bar
}

View file

@ -33,4 +33,6 @@ fn main() {
//~^ ERROR E0277
//~| NOTE a usize is required
//~| NOTE required by
//~| ERROR E0277
//~| NOTE a usize is required
}

View file

@ -0,0 +1,36 @@
// Copyright 2017 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.
macro_rules! enum_number {
($name:ident { $($variant:ident = $value:expr, )* }) => {
enum $name {
$($variant = $value,)*
}
fn foo(value: i32) -> Option<$name> {
match value {
$( $value => Some($name::$variant), )* // PatKind::Lit
$( $value ... 42 => Some($name::$variant), )* // PatKind::Range
_ => None
}
}
}
}
enum_number!(Change {
Pos = 1,
Neg = -1,
Arith = 1 + 1, //~ ERROR arbitrary expressions aren't allowed in patterns
//~^ ERROR arbitrary expressions aren't allowed in patterns
//~^^ ERROR only char and numeric types are allowed in range patterns
});
fn main() {}

View file

@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
//error-pattern: non-scalar cast
enum non_nullary {
nullary,
other(isize),
@ -17,5 +15,5 @@ enum non_nullary {
fn main() {
let v = non_nullary::nullary;
let val = v as isize;
let val = v as isize; //~ ERROR non-primitive cast: `non_nullary` as `isize` [E0605]
}

View file

@ -11,7 +11,7 @@
enum E {}
fn f(e: E) {
println!("{}", (e as isize).to_string()); //~ ERROR non-scalar cast
println!("{}", (e as isize).to_string()); //~ ERROR non-primitive cast
}
fn main() {}

View file

@ -54,6 +54,7 @@ fn f9<X: ?Sized>(x1: Box<S<X>>) {
fn f10<X: ?Sized>(x1: Box<S<X>>) {
f5(&(32, *x1));
//~^ ERROR `X: std::marker::Sized` is not satisfied
//~| ERROR `X: std::marker::Sized` is not satisfied
}
pub fn main() {

View file

@ -0,0 +1,21 @@
// Copyright 2017 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 S;
impl S {
fn f() {}
fn g() {
use Self::f; //~ ERROR unresolved import
pub(in Self::f) struct Z; //~ ERROR Use of undeclared type or module `Self`
}
}
fn main() {}

View file

@ -14,13 +14,11 @@
// Check that bounds on type parameters (other than `Self`) do not
// influence variance.
#[rustc_variance]
trait Getter<T> { //~ ERROR [o, o]
trait Getter<T> {
fn get(&self) -> T;
}
#[rustc_variance]
trait Setter<T> { //~ ERROR [o, o]
trait Setter<T> {
fn get(&self, T);
}
@ -34,20 +32,6 @@ enum TestEnum<U,T:Setter<U>> { //~ ERROR [*, +]
Foo(T)
}
#[rustc_variance]
trait TestTrait<U,T:Setter<U>> { //~ ERROR [o, o, o]
fn getter(&self, u: U) -> T;
}
#[rustc_variance]
trait TestTrait2<U> : Getter<U> { //~ ERROR [o, o]
}
#[rustc_variance]
trait TestTrait3<U> { //~ ERROR [o, o]
fn getter<T:Getter<U>>(&self);
}
#[rustc_variance]
struct TestContraStruct<U,T:Setter<U>> { //~ ERROR [*, +]
t: T

View file

@ -36,37 +36,14 @@ struct TestIndirect2<A:'static, B:'static> { //~ ERROR [o, o]
m: TestMut<B, A>
}
#[rustc_variance]
trait Getter<A> { //~ ERROR [o, o]
trait Getter<A> {
fn get(&self) -> A;
}
#[rustc_variance]
trait Setter<A> { //~ ERROR [o, o]
trait Setter<A> {
fn set(&mut self, a: A);
}
#[rustc_variance]
trait GetterSetter<A> { //~ ERROR [o, o]
fn get(&self) -> A;
fn set(&mut self, a: A);
}
#[rustc_variance]
trait GetterInTypeBound<A> { //~ ERROR [o, o]
// Here, the use of `A` in the method bound *does* affect
// variance. Think of it as if the method requested a dictionary
// for `T:Getter<A>`. Since this dictionary is an input, it is
// contravariant, and the Getter is covariant w/r/t A, yielding an
// overall contravariant result.
fn do_it<T:Getter<A>>(&self);
}
#[rustc_variance]
trait SetterInTypeBound<A> { //~ ERROR [o, o]
fn do_it<T:Setter<A>>(&self);
}
#[rustc_variance]
struct TestObject<A, R> { //~ ERROR [o, o]
n: Box<Setter<A>+Send>,

View file

@ -10,7 +10,7 @@
// compile-flags: -Z parse-only
fn macro() { //~ ERROR `macro` is a reserved keyword
fn macro() { //~ ERROR expected identifier, found reserved keyword `macro`
}
pub fn main() {

View file

@ -85,6 +85,6 @@ fn main() {
let (result, _) = rustc_driver::run_compiler(
&args, &mut JitCalls, Some(box JitLoader), None);
if let Err(n) = result {
panic!("Error {}", n);
panic!("Error {:?}", n);
}
}

View 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.
// no-prefer-dynamic
#![feature(unsized_tuple_coercion)]
static mut DROP_RAN: bool = false;
struct Foo;
impl Drop for Foo {
fn drop(&mut self) {
unsafe { DROP_RAN = true; }
}
}
trait Trait { fn dummy(&self) { } }
impl Trait for Foo {}
pub fn main() {
{
let _x: Box<(i32, Trait)> = Box::<(i32, Foo)>::new((42, Foo));
}
unsafe {
assert!(DROP_RAN);
}
}

View 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.
// no-prefer-dynamic
#![feature(unsized_tuple_coercion)]
static mut DROP_RAN: isize = 0;
struct Foo;
impl Drop for Foo {
fn drop(&mut self) {
unsafe { DROP_RAN += 1; }
}
}
pub fn main() {
{
let _x: Box<(i32, [Foo])> = Box::<(i32, [Foo; 3])>::new((42, [Foo, Foo, Foo]));
}
unsafe {
assert_eq!(DROP_RAN, 3);
}
}

View file

@ -0,0 +1,27 @@
// Copyright 2017 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(alloc, allocator_api, heap_api, unique)]
extern crate alloc;
use alloc::heap::HeapAlloc;
use alloc::allocator::Alloc;
fn main() {
unsafe {
let ptr = HeapAlloc.alloc_one::<i32>().unwrap_or_else(|e| {
HeapAlloc.oom(e)
});
*ptr.as_ptr() = 4;
assert_eq!(*ptr.as_ptr(), 4);
HeapAlloc.dealloc_one(ptr);
}
}

View file

@ -15,8 +15,6 @@ use std::ops::Deref;
pub trait Foo {
type A;
fn boo(&self) -> Self::A;
fn baz(_: Self::Target) where Self: Deref {}
}
impl Foo for isize {

View file

@ -45,8 +45,8 @@ impl<'a> Hasher for FakeHasher<'a> {
}
}
fn fake_hash(v: &mut Vec<u8>, e: E) {
e.hash(&mut FakeHasher(v));
fn fake_hash<A: Hash>(v: &mut Vec<u8>, a: A) {
a.hash(&mut FakeHasher(v));
}
fn main() {
@ -69,4 +69,13 @@ fn main() {
fake_hash(&mut va, E::A);
fake_hash(&mut vb, E::B);
assert!(va != vb);
// issue #39137: single variant enum hash should not hash discriminant
#[derive(Hash)]
enum SingleVariantEnum {
A(u8),
}
let mut v = vec![];
fake_hash(&mut v, SingleVariantEnum::A(17));
assert_eq!(vec![17], v);
}

View file

@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(unsized_tuple_coercion)]
struct Test<T: ?Sized>(T);
fn main() {
@ -21,4 +23,14 @@ fn main() {
let slice = &[1,2,3];
let x = Test(&slice);
let Test(&_slice) = x;
let x = (10, [1,2,3]);
let x : &(i32, [i32]) = &x;
let & ref _y = x;
let slice = &[1,2,3];
let x = (10, &slice);
let (_, &_slice) = x;
}

View file

@ -11,6 +11,8 @@
// Test DST raw pointers
#![feature(unsized_tuple_coercion)]
trait Trait {
fn foo(&self) -> isize;
}
@ -45,6 +47,14 @@ pub fn main() {
};
assert_eq!(r, 42);
// raw DST tuple
let p = (A { f: 42 },);
let o: *const (Trait,) = &p;
let r = unsafe {
(&*o).0.foo()
};
assert_eq!(r, 42);
// raw slice
let a: *const [_] = &[1, 2, 3];
unsafe {
@ -72,6 +82,15 @@ pub fn main() {
assert_eq!(len, 3);
}
// raw DST tuple with slice
let c: *const ([_],) = &([1, 2, 3],);
unsafe {
let b = (&*c).0[0];
assert_eq!(b, 1);
let len = (&*c).0.len();
assert_eq!(len, 3);
}
// all of the above with *mut
let mut x = A { f: 42 };
let z: *mut Trait = &mut x;
@ -87,6 +106,13 @@ pub fn main() {
};
assert_eq!(r, 42);
let mut p = (A { f: 42 },);
let o: *mut (Trait,) = &mut p;
let r = unsafe {
(&*o).0.foo()
};
assert_eq!(r, 42);
let a: *mut [_] = &mut [1, 2, 3];
unsafe {
let b = (*a)[2];
@ -110,4 +136,12 @@ pub fn main() {
let len = (&*c).f.len();
assert_eq!(len, 3);
}
let c: *mut ([_],) = &mut ([1, 2, 3],);
unsafe {
let b = (&*c).0[0];
assert_eq!(b, 1);
let len = (&*c).0.len();
assert_eq!(len, 3);
}
}

View file

@ -0,0 +1,111 @@
// 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.
#![allow(unused_features)]
#![feature(box_syntax)]
#![feature(unsized_tuple_coercion)]
type Fat<T: ?Sized> = (isize, &'static str, T);
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
struct Bar;
#[derive(Copy, Clone, PartialEq, Eq)]
struct Bar1 {
f: isize
}
trait ToBar {
fn to_bar(&self) -> Bar;
fn to_val(&self) -> isize;
}
impl ToBar for Bar {
fn to_bar(&self) -> Bar {
*self
}
fn to_val(&self) -> isize {
0
}
}
impl ToBar for Bar1 {
fn to_bar(&self) -> Bar {
Bar
}
fn to_val(&self) -> isize {
self.f
}
}
// x is a fat pointer
fn foo(x: &Fat<ToBar>) {
assert_eq!(x.0, 5);
assert_eq!(x.1, "some str");
assert_eq!(x.2.to_bar(), Bar);
assert_eq!(x.2.to_val(), 42);
let y = &x.2;
assert_eq!(y.to_bar(), Bar);
assert_eq!(y.to_val(), 42);
}
fn bar(x: &ToBar) {
assert_eq!(x.to_bar(), Bar);
assert_eq!(x.to_val(), 42);
}
fn baz(x: &Fat<Fat<ToBar>>) {
assert_eq!(x.0, 5);
assert_eq!(x.1, "some str");
assert_eq!((x.2).0, 8);
assert_eq!((x.2).1, "deep str");
assert_eq!((x.2).2.to_bar(), Bar);
assert_eq!((x.2).2.to_val(), 42);
let y = &(x.2).2;
assert_eq!(y.to_bar(), Bar);
assert_eq!(y.to_val(), 42);
}
pub fn main() {
let f1 = (5, "some str", Bar1 {f :42});
foo(&f1);
let f2 = &f1;
foo(f2);
let f3: &Fat<ToBar> = f2;
foo(f3);
let f4: &Fat<ToBar> = &f1;
foo(f4);
let f5: &Fat<ToBar> = &(5, "some str", Bar1 {f :42});
foo(f5);
// Zero size object.
let f6: &Fat<ToBar> = &(5, "some str", Bar);
assert_eq!(f6.2.to_bar(), Bar);
// &*
//
let f7: Box<ToBar> = Box::new(Bar1 {f :42});
bar(&*f7);
// Deep nesting
let f1 = (5, "some str", (8, "deep str", Bar1 {f :42}));
baz(&f1);
let f2 = &f1;
baz(f2);
let f3: &Fat<Fat<ToBar>> = f2;
baz(f3);
let f4: &Fat<Fat<ToBar>> = &f1;
baz(f4);
let f5: &Fat<Fat<ToBar>> = &(5, "some str", (8, "deep str", Bar1 {f :42}));
baz(f5);
}

View file

@ -0,0 +1,85 @@
// 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.
// As dst-tuple.rs, but the unsized field is the only field in the tuple.
#![feature(unsized_tuple_coercion)]
type Fat<T: ?Sized> = (T,);
// x is a fat pointer
fn foo(x: &Fat<[isize]>) {
let y = &x.0;
assert_eq!(x.0.len(), 3);
assert_eq!(y[0], 1);
assert_eq!(x.0[1], 2);
}
fn foo2<T:ToBar>(x: &Fat<[T]>) {
let y = &x.0;
let bar = Bar;
assert_eq!(x.0.len(), 3);
assert_eq!(y[0].to_bar(), bar);
assert_eq!(x.0[1].to_bar(), bar);
}
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
struct Bar;
trait ToBar {
fn to_bar(&self) -> Bar;
}
impl ToBar for Bar {
fn to_bar(&self) -> Bar {
*self
}
}
pub fn main() {
// With a vec of ints.
let f1 = ([1, 2, 3],);
foo(&f1);
let f2 = &f1;
foo(f2);
let f3: &Fat<[isize]> = f2;
foo(f3);
let f4: &Fat<[isize]> = &f1;
foo(f4);
let f5: &Fat<[isize]> = &([1, 2, 3],);
foo(f5);
// With a vec of Bars.
let bar = Bar;
let f1 = ([bar, bar, bar],);
foo2(&f1);
let f2 = &f1;
foo2(f2);
let f3: &Fat<[Bar]> = f2;
foo2(f3);
let f4: &Fat<[Bar]> = &f1;
foo2(f4);
let f5: &Fat<[Bar]> = &([bar, bar, bar],);
foo2(f5);
// Assignment.
let f5: &mut Fat<[isize]> = &mut ([1, 2, 3],);
f5.0[1] = 34;
assert_eq!(f5.0[0], 1);
assert_eq!(f5.0[1], 34);
assert_eq!(f5.0[2], 3);
// Zero size vec.
let f5: &Fat<[isize]> = &([],);
assert!(f5.0.is_empty());
let f5: &Fat<[Bar]> = &([],);
assert!(f5.0.is_empty());
}

View file

@ -0,0 +1,129 @@
// 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.
#![allow(unknown_features)]
#![feature(box_syntax)]
#![feature(unsized_tuple_coercion)]
type Fat<T: ?Sized> = (isize, &'static str, T);
// x is a fat pointer
fn foo(x: &Fat<[isize]>) {
let y = &x.2;
assert_eq!(x.2.len(), 3);
assert_eq!(y[0], 1);
assert_eq!(x.2[1], 2);
assert_eq!(x.0, 5);
assert_eq!(x.1, "some str");
}
fn foo2<T:ToBar>(x: &Fat<[T]>) {
let y = &x.2;
let bar = Bar;
assert_eq!(x.2.len(), 3);
assert_eq!(y[0].to_bar(), bar);
assert_eq!(x.2[1].to_bar(), bar);
assert_eq!(x.0, 5);
assert_eq!(x.1, "some str");
}
fn foo3(x: &Fat<Fat<[isize]>>) {
let y = &(x.2).2;
assert_eq!(x.0, 5);
assert_eq!(x.1, "some str");
assert_eq!((x.2).0, 8);
assert_eq!((x.2).1, "deep str");
assert_eq!((x.2).2.len(), 3);
assert_eq!(y[0], 1);
assert_eq!((x.2).2[1], 2);
}
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
struct Bar;
trait ToBar {
fn to_bar(&self) -> Bar;
}
impl ToBar for Bar {
fn to_bar(&self) -> Bar {
*self
}
}
pub fn main() {
// With a vec of ints.
let f1 = (5, "some str", [1, 2, 3]);
foo(&f1);
let f2 = &f1;
foo(f2);
let f3: &Fat<[isize]> = f2;
foo(f3);
let f4: &Fat<[isize]> = &f1;
foo(f4);
let f5: &Fat<[isize]> = &(5, "some str", [1, 2, 3]);
foo(f5);
// With a vec of Bars.
let bar = Bar;
let f1 = (5, "some str", [bar, bar, bar]);
foo2(&f1);
let f2 = &f1;
foo2(f2);
let f3: &Fat<[Bar]> = f2;
foo2(f3);
let f4: &Fat<[Bar]> = &f1;
foo2(f4);
let f5: &Fat<[Bar]> = &(5, "some str", [bar, bar, bar]);
foo2(f5);
// Assignment.
let f5: &mut Fat<[isize]> = &mut (5, "some str", [1, 2, 3]);
f5.2[1] = 34;
assert_eq!(f5.2[0], 1);
assert_eq!(f5.2[1], 34);
assert_eq!(f5.2[2], 3);
// Zero size vec.
let f5: &Fat<[isize]> = &(5, "some str", []);
assert!(f5.2.is_empty());
let f5: &Fat<[Bar]> = &(5, "some str", []);
assert!(f5.2.is_empty());
// Deeply nested.
let f1 = (5, "some str", (8, "deep str", [1, 2, 3]));
foo3(&f1);
let f2 = &f1;
foo3(f2);
let f3: &Fat<Fat<[isize]>> = f2;
foo3(f3);
let f4: &Fat<Fat<[isize]>> = &f1;
foo3(f4);
let f5: &Fat<Fat<[isize]>> = &(5, "some str", (8, "deep str", [1, 2, 3]));
foo3(f5);
// Box.
let f1 = Box::new([1, 2, 3]);
assert_eq!((*f1)[1], 2);
let f2: Box<[isize]> = f1;
assert_eq!((*f2)[1], 2);
// Nested Box.
let f1 : Box<Fat<[isize; 3]>> = box (5, "some str", [1, 2, 3]);
foo(&*f1);
let f2 : Box<Fat<[isize]>> = f1;
foo(&*f2);
let f3 : Box<Fat<[isize]>> =
Box::<Fat<[_; 3]>>::new((5, "some str", [1, 2, 3]));
foo(&*f3);
}

View file

@ -106,6 +106,18 @@ fn struct_dynamic_drop(a: &Allocator, c0: bool, c1: bool, c: bool) {
}
}
fn field_assignment(a: &Allocator, c0: bool) {
let mut x = (TwoPtrs(a.alloc(), a.alloc()), a.alloc());
x.1 = a.alloc();
x.1 = a.alloc();
let f = (x.0).0;
if c0 {
(x.0).0 = f;
}
}
fn assignment2(a: &Allocator, c0: bool, c1: bool) {
let mut _v = a.alloc();
let mut _w = a.alloc();
@ -207,5 +219,8 @@ fn main() {
run_test(|a| struct_dynamic_drop(a, true, true, false));
run_test(|a| struct_dynamic_drop(a, true, true, true));
run_test(|a| field_assignment(a, false));
run_test(|a| field_assignment(a, true));
run_test_nopanic(|a| union1(a));
}

98
src/test/run-pass/env.rs Normal file
View file

@ -0,0 +1,98 @@
// Copyright 2017 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.
// compile-flags: --test
#![feature(rand, std_panic)]
use std::env::*;
use std::__rand as rand;
use std::__rand::Rng;
use std::iter::repeat;
use std::ffi::{OsString, OsStr};
fn make_rand_name() -> OsString {
let mut rng = rand::thread_rng();
let n = format!("TEST{}", rng.gen_ascii_chars().take(10)
.collect::<String>());
let n = OsString::from(n);
assert!(var_os(&n).is_none());
n
}
fn eq(a: Option<OsString>, b: Option<&str>) {
assert_eq!(a.as_ref().map(|s| &**s), b.map(OsStr::new).map(|s| &*s));
}
#[test]
fn test_set_var() {
let n = make_rand_name();
set_var(&n, "VALUE");
eq(var_os(&n), Some("VALUE"));
}
#[test]
fn test_remove_var() {
let n = make_rand_name();
set_var(&n, "VALUE");
remove_var(&n);
eq(var_os(&n), None);
}
#[test]
fn test_set_var_overwrite() {
let n = make_rand_name();
set_var(&n, "1");
set_var(&n, "2");
eq(var_os(&n), Some("2"));
set_var(&n, "");
eq(var_os(&n), Some(""));
}
#[test]
#[cfg_attr(target_os = "emscripten", ignore)]
fn test_var_big() {
let mut s = "".to_string();
let mut i = 0;
while i < 100 {
s.push_str("aaaaaaaaaa");
i += 1;
}
let n = make_rand_name();
set_var(&n, &s);
eq(var_os(&n), Some(&s));
}
#[test]
#[cfg_attr(target_os = "emscripten", ignore)]
fn test_env_set_get_huge() {
let n = make_rand_name();
let s = repeat("x").take(10000).collect::<String>();
set_var(&n, &s);
eq(var_os(&n), Some(&s));
remove_var(&n);
eq(var_os(&n), None);
}
#[test]
fn test_env_set_var() {
let n = make_rand_name();
let mut e = vars_os();
set_var(&n, "VALUE");
assert!(!e.any(|(k, v)| {
&*k == &*n && &*v == "VALUE"
}));
assert!(vars_os().any(|(k, v)| {
&*k == &*n && &*v == "VALUE"
}));
}

View file

@ -12,9 +12,12 @@ pub struct Struct<K: 'static> {
pub field: K,
}
// Partial fix for #31260, doesn't work without {...}.
static STRUCT: Struct<&'static [u8]> = Struct {
field: {&[1]}
};
static STRUCT2: Struct<&'static [u8]> = Struct {
field: &[1]
};
fn main() {}

View file

@ -0,0 +1,14 @@
// Copyright 2016 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 fn foo<'a>(s: &'a mut ()) where &'a mut (): Clone {
s.clone();
}
fn main() {}

View file

@ -0,0 +1,35 @@
// Copyright 2017 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.
macro_rules! enum_number {
($name:ident { $($variant:ident = $value:expr, )* }) => {
enum $name {
$($variant = $value,)*
}
fn foo(value: i32) -> Option<$name> {
match value {
$( $value => Some($name::$variant), )*
_ => None
}
}
}
}
enum_number!(Change {
Down = -1,
None = 0,
Up = 1,
});
fn main() {
if let Some(Change::Down) = foo(-1) {} else { panic!() }
}

View file

@ -10,8 +10,6 @@
// ignore-emscripten
#![feature(command_envs)]
use std::process::Command;
use std::env;
use std::collections::HashMap;

View file

@ -10,7 +10,7 @@
// Test inclusive range syntax.
#![feature(inclusive_range_syntax, inclusive_range, step_by)]
#![feature(inclusive_range_syntax, inclusive_range, iterator_step_by)]
use std::ops::{RangeInclusive, RangeToInclusive};

View file

@ -14,7 +14,7 @@
#![feature(iter_empty)]
#![feature(iter_once)]
#![feature(iter_unfold)]
#![feature(step_by)]
#![feature(iterator_step_by)]
#![feature(str_escape)]
use std::iter::{empty, once, repeat};

View file

@ -0,0 +1,24 @@
// Copyright 2016 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.
// compile-flags: --test
#![feature(allow_fail)]
#[test]
#[allow_fail]
fn test1() {
panic!();
}
#[test]
#[allow_fail]
fn test2() {
assert!(true);
}

View file

@ -10,14 +10,17 @@
// ignore-emscripten no threads support
#![feature(rand)]
#![feature(const_fn)]
#![feature(rand)]
#![feature(sort_unstable)]
use std::__rand::{thread_rng, Rng};
use std::panic;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::thread;
use std::cell::Cell;
use std::cmp::Ordering;
use std::panic;
use std::sync::atomic::{ATOMIC_USIZE_INIT, AtomicUsize};
use std::sync::atomic::Ordering::Relaxed;
use std::thread;
const MAX_LEN: usize = 80;
@ -45,54 +48,85 @@ static DROP_COUNTS: [AtomicUsize; MAX_LEN] = [
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
];
#[derive(Clone, PartialEq, PartialOrd, Eq, Ord)]
static VERSIONS: AtomicUsize = ATOMIC_USIZE_INIT;
#[derive(Clone, Eq)]
struct DropCounter {
x: u32,
id: usize,
version: Cell<usize>,
}
impl PartialEq for DropCounter {
fn eq(&self, other: &Self) -> bool {
self.partial_cmp(other) == Some(Ordering::Equal)
}
}
impl PartialOrd for DropCounter {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
self.version.set(self.version.get() + 1);
other.version.set(other.version.get() + 1);
VERSIONS.fetch_add(2, Relaxed);
self.x.partial_cmp(&other.x)
}
}
impl Ord for DropCounter {
fn cmp(&self, other: &Self) -> Ordering {
self.partial_cmp(other).unwrap()
}
}
impl Drop for DropCounter {
fn drop(&mut self) {
DROP_COUNTS[self.id].fetch_add(1, Ordering::Relaxed);
DROP_COUNTS[self.id].fetch_add(1, Relaxed);
VERSIONS.fetch_sub(self.version.get(), Relaxed);
}
}
fn test(input: &[DropCounter]) {
let len = input.len();
macro_rules! test {
($input:ident, $func:ident) => {
let len = $input.len();
// Work out the total number of comparisons required to sort
// this array...
let mut count = 0usize;
input.to_owned().sort_by(|a, b| { count += 1; a.cmp(b) });
// Work out the total number of comparisons required to sort
// this array...
let mut count = 0usize;
$input.to_owned().$func(|a, b| { count += 1; a.cmp(b) });
// ... and then panic on each and every single one.
for panic_countdown in 0..count {
// Refresh the counters.
for i in 0..len {
DROP_COUNTS[i].store(0, Ordering::Relaxed);
}
// ... and then panic on each and every single one.
for panic_countdown in 0..count {
// Refresh the counters.
VERSIONS.store(0, Relaxed);
for i in 0..len {
DROP_COUNTS[i].store(0, Relaxed);
}
let v = input.to_owned();
let _ = thread::spawn(move || {
let mut v = v;
let mut panic_countdown = panic_countdown;
v.sort_by(|a, b| {
if panic_countdown == 0 {
SILENCE_PANIC.with(|s| s.set(true));
panic!();
}
panic_countdown -= 1;
a.cmp(b)
})
}).join();
let v = $input.to_owned();
let _ = thread::spawn(move || {
let mut v = v;
let mut panic_countdown = panic_countdown;
v.$func(|a, b| {
if panic_countdown == 0 {
SILENCE_PANIC.with(|s| s.set(true));
panic!();
}
panic_countdown -= 1;
a.cmp(b)
})
}).join();
// Check that the number of things dropped is exactly
// what we expect (i.e. the contents of `v`).
for (i, c) in DROP_COUNTS.iter().enumerate().take(len) {
let count = c.load(Ordering::Relaxed);
assert!(count == 1,
"found drop count == {} for i == {}, len == {}",
count, i, len);
// Check that the number of things dropped is exactly
// what we expect (i.e. the contents of `v`).
for (i, c) in DROP_COUNTS.iter().enumerate().take(len) {
let count = c.load(Relaxed);
assert!(count == 1,
"found drop count == {} for i == {}, len == {}",
count, i, len);
}
// Check that the most recent versions of values were dropped.
assert_eq!(VERSIONS.load(Relaxed), 0);
}
}
}
@ -106,33 +140,41 @@ fn main() {
prev(info);
}
}));
let mut rng = thread_rng();
for len in (1..20).chain(70..MAX_LEN) {
// Test on a random array.
let mut rng = thread_rng();
let input = (0..len).map(|id| {
DropCounter {
x: rng.next_u32(),
id: id,
}
}).collect::<Vec<_>>();
test(&input);
for &modulus in &[5, 20, 50] {
for &has_runs in &[false, true] {
let mut input = (0..len)
.map(|id| {
DropCounter {
x: rng.next_u32() % modulus,
id: id,
version: Cell::new(0),
}
})
.collect::<Vec<_>>();
// Test on a sorted array with two elements randomly swapped, creating several natural
// runs of random lengths. Such arrays have very high chances of hitting all code paths in
// the merge procedure.
for _ in 0..5 {
let mut input = (0..len).map(|i|
DropCounter {
x: i as u32,
id: i,
if has_runs {
for c in &mut input {
c.x = c.id as u32;
}
for _ in 0..5 {
let a = rng.gen::<usize>() % len;
let b = rng.gen::<usize>() % len;
if a < b {
input[a..b].reverse();
} else {
input.swap(a, b);
}
}
}
).collect::<Vec<_>>();
let a = rng.gen::<usize>() % len;
let b = rng.gen::<usize>() % len;
input.swap(a, b);
test(&input);
test!(input, sort_by);
test!(input, sort_unstable_by);
}
}
}
}

View file

@ -0,0 +1,23 @@
// Copyright 2017 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.
// compile-flags: --no-defaults
#![crate_name = "foo"]
// @has foo/a/index.html '//code' 'use *;'
mod a {
use *;
}
// @has foo/b/index.html '//code' 'pub use *;'
pub mod b {
pub use *;
}

View file

@ -0,0 +1,11 @@
error[E0308]: mismatched types
--> $DIR/block-must-not-have-result-do.rs:13:9
|
13 | true //~ ERROR mismatched types
| ^^^^ expected (), found bool
|
= note: expected type `()`
found type `bool`
error: aborting due to previous error

View file

@ -0,0 +1,11 @@
error[E0308]: mismatched types
--> $DIR/block-must-not-have-result-res.rs:15:9
|
15 | true //~ ERROR mismatched types
| ^^^^ expected (), found bool
|
= note: expected type `()`
found type `bool`
error: aborting due to previous error

View file

@ -0,0 +1,11 @@
error[E0308]: mismatched types
--> $DIR/block-must-not-have-result-while.rs:13:9
|
13 | true //~ ERROR mismatched types
| ^^^^ expected (), found bool
|
= note: expected type `()`
found type `bool`
error: aborting due to previous error

View file

@ -0,0 +1,30 @@
error[E0308]: mismatched types
--> $DIR/consider-removing-last-semi.rs:11:18
|
11 | fn f() -> String { //~ ERROR mismatched types
| __________________^
12 | | 0u8;
13 | | "bla".to_string(); //~ HELP consider removing this semicolon
| | - help: consider removing this semicolon
14 | | }
| |_^ expected struct `std::string::String`, found ()
|
= note: expected type `std::string::String`
found type `()`
error[E0308]: mismatched types
--> $DIR/consider-removing-last-semi.rs:16:18
|
16 | fn g() -> String { //~ ERROR mismatched types
| __________________^
17 | | "this won't work".to_string();
18 | | "removeme".to_string(); //~ HELP consider removing this semicolon
| | - help: consider removing this semicolon
19 | | }
| |_^ expected struct `std::string::String`, found ()
|
= note: expected type `std::string::String`
found type `()`
error: aborting due to 2 previous errors

View file

@ -0,0 +1,17 @@
error[E0308]: mismatched types
--> $DIR/issue-11714.rs:11:18
|
11 | fn blah() -> i32 { //~ ERROR mismatched types
| __________________^
12 | | 1
13 | |
14 | | ; //~ HELP consider removing this semicolon:
| | - help: consider removing this semicolon
15 | | }
| |_^ expected i32, found ()
|
= note: expected type `i32`
found type `()`
error: aborting due to previous error

View file

@ -0,0 +1,33 @@
error[E0308]: mismatched types
--> $DIR/issue-13428.rs:13:20
|
13 | fn foo() -> String { //~ ERROR mismatched types
| ____________________^
14 | | format!("Hello {}",
15 | | "world")
16 | | // Put the trailing semicolon on its own line to test that the
17 | | // note message gets the offending semicolon exactly
18 | | ; //~ HELP consider removing this semicolon
| | - help: consider removing this semicolon
19 | | }
| |_^ expected struct `std::string::String`, found ()
|
= note: expected type `std::string::String`
found type `()`
error[E0308]: mismatched types
--> $DIR/issue-13428.rs:21:20
|
21 | fn bar() -> String { //~ ERROR mismatched types
| ____________________^
22 | | "foobar".to_string()
23 | | ; //~ HELP consider removing this semicolon
| | - help: consider removing this semicolon
24 | | }
| |_^ expected struct `std::string::String`, found ()
|
= note: expected type `std::string::String`
found type `()`
error: aborting due to 2 previous errors

View file

@ -0,0 +1,20 @@
error[E0308]: mismatched types
--> $DIR/issue-13624.rs:17:5
|
17 | Enum::EnumStructVariant { x: 1, y: 2, z: 3 }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected (), found enum `a::Enum`
|
= note: expected type `()`
found type `a::Enum`
error[E0308]: mismatched types
--> $DIR/issue-13624.rs:32:9
|
32 | a::Enum::EnumStructVariant { x, y, z } => {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected (), found enum `a::Enum`
|
= note: expected type `()`
found type `a::Enum`
error: aborting due to 2 previous errors

View file

@ -0,0 +1,19 @@
error[E0308]: mismatched types
--> $DIR/issue-20862.rs:12:5
|
11 | fn foo(x: i32) {
| - possibly return type missing here?
12 | |y| x + y
| ^^^^^^^^^ expected (), found closure
|
= note: expected type `()`
found type `[closure@$DIR/issue-20862.rs:12:5: 12:14 x:_]`
error[E0618]: expected function, found `()`
--> $DIR/issue-20862.rs:17:13
|
17 | let x = foo(5)(2);
| ^^^^^^^^^
error: aborting due to 2 previous errors

View file

@ -0,0 +1,21 @@
error[E0277]: the trait bound `{integer}: Scalar` is not satisfied
--> $DIR/issue-22645.rs:25:5
|
25 | b + 3 //~ ERROR E0277
| ^ the trait `Scalar` is not implemented for `{integer}`
|
= help: the following implementations were found:
<f64 as Scalar>
= note: required because of the requirements on the impl of `std::ops::Add<{integer}>` for `Bob`
error[E0308]: mismatched types
--> $DIR/issue-22645.rs:25:3
|
25 | b + 3 //~ ERROR E0277
| ^^^^^ expected (), found struct `Bob`
|
= note: expected type `()`
found type `Bob`
error: aborting due to 2 previous errors

View file

@ -0,0 +1,19 @@
error[E0599]: no method named `b` found for type `&Self` in the current scope
--> $DIR/issue-3563.rs:13:17
|
13 | || self.b()
| ^
error[E0308]: mismatched types
--> $DIR/issue-3563.rs:13:9
|
12 | fn a(&self) {
| - possibly return type missing here?
13 | || self.b()
| ^^^^^^^^^^^ expected (), found closure
|
= note: expected type `()`
found type `[closure@$DIR/issue-3563.rs:13:9: 13:20 self:_]`
error: aborting due to 2 previous errors

View file

@ -0,0 +1,11 @@
error[E0308]: mismatched types
--> $DIR/issue-5500.rs:12:5
|
12 | &panic!()
| ^^^^^^^^^ expected (), found reference
|
= note: expected type `()`
found type `&_`
error: aborting due to previous error

View file

@ -0,0 +1,24 @@
// Copyright 2017 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.
// Test that we do some basic error correcton in the tokeniser (and don't spew
// too many bogus errors).
fn foo() -> usize {
3
}
fn bar() {
foo()
}
fn main() {
bar()
}

View file

@ -0,0 +1,15 @@
error[E0308]: mismatched types
--> $DIR/unexpected-return-on-unit.rs:19:5
|
19 | foo()
| ^^^^^ expected (), found usize
|
= note: expected type `()`
found type `usize`
help: did you mean to add a semicolon here?
| foo();
help: possibly return type missing here?
| fn bar() -> usize {
error: aborting due to previous error

View file

@ -6,5 +6,5 @@ error[E0507]: cannot move out of captured outer variable in an `Fn` closure
15 | Box::new(|| x) //~ ERROR cannot move out of captured outer variable
| ^ cannot move out of captured outer variable in an `Fn` closure
error: aborting due to previous error(s)
error: aborting due to previous error

View file

@ -7,5 +7,5 @@ error[E0507]: cannot move out of captured outer variable in an `Fn` closure
21 | y.into_iter();
| ^ cannot move out of captured outer variable in an `Fn` closure
error: aborting due to previous error(s)
error: aborting due to previous error

View file

@ -46,5 +46,5 @@ error[E0004]: non-exhaustive patterns: `Some(B)`, `Some(C)`, `Some(D)` and 2 mor
49 | match Some(A) {
| ^^^^^^^ patterns `Some(B)`, `Some(C)`, `Some(D)` and 2 more not covered
error: aborting due to previous error(s)
error: aborting due to 8 previous errors

View file

@ -16,5 +16,5 @@ note: closure is `FnMut` because it mutates the variable `num` here
15 | num += 1;
| ^^^
error: aborting due to previous error(s)
error: aborting due to previous error

View file

@ -16,5 +16,5 @@ note: closure is `FnOnce` because it moves the variable `vec` out of its environ
15 | vec
| ^^^
error: aborting due to previous error(s)
error: aborting due to previous error

View file

@ -12,5 +12,5 @@ note: closure cannot be invoked more than once because it moves the variable `di
16 | for (key, value) in dict {
| ^^^^
error: aborting due to previous error(s)
error: aborting due to previous error

View file

@ -22,5 +22,5 @@ error: expected token: `,`
|
= note: this error originates in a macro outside of the current crate
error: aborting due to previous error(s)
error: aborting due to 3 previous errors

View file

@ -6,5 +6,5 @@ error[E0592]: duplicate definitions with name `f`
15 | impl C { fn f() {} }
| --------- other definition for `f`
error: aborting due to previous error(s)
error: aborting due to previous error

View file

@ -4,5 +4,5 @@ error[E0321]: cross-crate traits with a default impl, like `std::marker::Send`,
17 | unsafe impl Send for &'static Foo { }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to previous error(s)
error: aborting due to previous error

View file

@ -7,5 +7,5 @@ error[E0596]: cannot borrow immutable local variable `x` as mutable
100 | let y = &mut x;
| ^ cannot borrow mutably
error: aborting due to previous error(s)
error: aborting due to previous error

Some files were not shown because too many files have changed in this diff Show more