Skip to content

Commit

Permalink
Fallout from this change.
Browse files Browse the repository at this point in the history
  • Loading branch information
pnkfelix committed Apr 14, 2015
1 parent 58dc3bb commit d82f912
Show file tree
Hide file tree
Showing 15 changed files with 220 additions and 54 deletions.
31 changes: 31 additions & 0 deletions src/test/compile-fail/associated-types-no-suitable-supertrait-2.rs
Original file line number Diff line number Diff line change
@@ -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.

// Check that we get an error when you use `<Self as Get>::Value` in
// the trait definition but `Self` does not, in fact, implement `Get`.
//
// See also associated-types-no-suitable-supertrait.rs, which checks
// that we see the same error when making this mistake on an impl
// rather than the default method impl.
//
// See also run-pass/associated-types-projection-to-unrelated-trait.rs,
// which checks that the trait interface itself is not considered an
// error as long as all impls satisfy the constraint.

trait Get : ::std::marker::MarkerTrait {
type Value;
}

trait Other {
fn uhoh<U:Get>(&self, foo: U, bar: <Self as Get>::Value) {}
//~^ ERROR the trait `Get` is not implemented for the type `Self`
}

fn main() { }
14 changes: 12 additions & 2 deletions src/test/compile-fail/associated-types-no-suitable-supertrait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,30 @@

// Check that we get an error when you use `<Self as Get>::Value` in
// the trait definition but `Self` does not, in fact, implement `Get`.
//
// See also associated-types-no-suitable-supertrait-2.rs, which checks
// that we see the same error if we get around to checking the default
// method body.
//
// See also run-pass/associated-types-projection-to-unrelated-trait.rs,
// which checks that the trait interface itself is not considered an
// error as long as all impls satisfy the constraint.

trait Get : ::std::marker::MarkerTrait {
type Value;
}

trait Other {
fn uhoh<U:Get>(&self, foo: U, bar: <Self as Get>::Value) {}
//~^ ERROR the trait `Get` is not implemented for the type `Self`
// (note that we no longer catch the error here, since the
// error below aborts compilation.
// See also associated-types-no-suitable-supertrait-2.rs
// which checks that this error would be caught eventually.)
}

impl<T:Get> Other for T {
fn uhoh<U:Get>(&self, foo: U, bar: <(T, U) as Get>::Value) {}
//~^ ERROR the trait `Get` is not implemented for the type `(T, U)`
//~| ERROR the trait `Get` is not implemented for the type `(T, U)`
}

fn main() { }
28 changes: 28 additions & 0 deletions src/test/compile-fail/enum-to-float-cast-2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// Tests that enum-to-float casts are disallowed.

enum E {
L0 = -1,
H0 = 1
}

enum F {
L1 = 1,
H1 = 0xFFFFFFFFFFFFFFFF
}

pub fn main() {
let a = E::L0 as f32; //~ ERROR illegal cast
let c = F::H1 as f32; //~ ERROR illegal cast
assert_eq!(a, -1.0f32);
assert_eq!(c, -1.0f32);
}
4 changes: 0 additions & 4 deletions src/test/compile-fail/enum-to-float-cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,8 @@ static C0: f32 = E::L0 as f32; //~ ERROR illegal cast
static C1: f32 = F::H1 as f32; //~ ERROR illegal cast

pub fn main() {
let a = E::L0 as f32; //~ ERROR illegal cast
let b = C0;
let c = F::H1 as f32; //~ ERROR illegal cast
let d = C1;
assert_eq!(a, -1.0f32);
assert_eq!(b, -1.0f32);
assert_eq!(c, -1.0f32);
assert_eq!(d, -1.0f32);
}
2 changes: 1 addition & 1 deletion src/test/compile-fail/issue-16048.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl<'a> Test<'a> for Foo<'a> {
impl<'a> NoLifetime for Foo<'a> {
fn get<'p, T : Test<'a>>(&self) -> T {
//~^ ERROR lifetime parameters or bounds on method `get` do not match the trait declaration
return *self as T; //~ ERROR non-scalar cast: `Foo<'a>` as `T`
return *self as T;
}
}

Expand Down
4 changes: 1 addition & 3 deletions src/test/compile-fail/issue-19244-1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,5 @@ const TUP: (usize,) = (42,);

fn main() {
let a: [isize; TUP.1];
//~^ ERROR array length constant evaluation error: tuple index out of bounds
//~| ERROR attempted out-of-bounds tuple index
//~| ERROR attempted out-of-bounds tuple index
//~^ ERROR attempted out-of-bounds tuple index
}
4 changes: 1 addition & 3 deletions src/test/compile-fail/issue-19244-2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,5 @@ const STRUCT: MyStruct = MyStruct { field: 42 };

fn main() {
let a: [isize; STRUCT.nonexistent_field];
//~^ ERROR array length constant evaluation error: nonexistent struct field
//~| ERROR attempted access of field `nonexistent_field`
//~| ERROR attempted access of field `nonexistent_field`
//~^ ERROR attempted access of field `nonexistent_field`
}
5 changes: 4 additions & 1 deletion src/test/compile-fail/issue-2063.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ impl to_str_2 for t {
}

fn new_t(x: t) {
x.my_to_string(); //~ ERROR does not implement
x.my_to_string();
// (there used to be an error emitted right here as well. It was
// spurious, at best; if `t` did exist as a type, it clearly would
// have an impl of the `to_str_2` trait.)
}

fn main() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

fn main() {
fn bar(n: isize) {
// FIXME (#24414): This error message needs improvement.
let _x: [isize; n];
//~^ ERROR no type for local variable
//~| ERROR array length constant evaluation error: non-constant path in constant expr
}
}
31 changes: 31 additions & 0 deletions src/test/compile-fail/struct-base-wrong-type-2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// Check that `base` in `Fru { field: expr, ..base }` must have right type.
//
// See also struct-base-wrong-type.rs, which tests same condition
// within a const expression.

struct Foo { a: isize, b: isize }
struct Bar { x: isize }

fn main() {
let b = Bar { x: 5 };
let f = Foo { a: 2, ..b }; //~ ERROR mismatched types
//~| expected `Foo`
//~| found `Bar`
//~| expected struct `Foo`
//~| found struct `Bar`
let f__isize = Foo { a: 2, ..4 }; //~ ERROR mismatched types
//~| expected `Foo`
//~| found `_`
//~| expected struct `Foo`
//~| found integral variable
}
21 changes: 11 additions & 10 deletions src/test/compile-fail/struct-base-wrong-type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// Check that `base` in `Fru { field: expr, ..base }` must have right type.
//
// See also struct-base-wrong-type-2.rs, which tests same condition
// within a function body.

struct Foo { a: isize, b: isize }
struct Bar { x: isize }

Expand All @@ -25,14 +30,10 @@ static foo_i: Foo = Foo { a: 2, ..4 }; //~ ERROR mismatched types

fn main() {
let b = Bar { x: 5 };
let f = Foo { a: 2, ..b }; //~ ERROR mismatched types
//~| expected `Foo`
//~| found `Bar`
//~| expected struct `Foo`
//~| found struct `Bar`
let f__isize = Foo { a: 2, ..4 }; //~ ERROR mismatched types
//~| expected `Foo`
//~| found `_`
//~| expected struct `Foo`
//~| found integral variable
// errors below are no longer caught since error above causes
// compilation to abort before we bother checking function bodies.
// See also struct-base-wrong-type-2.rs, which checks that we
// would catch these errors eventually.
let f = Foo { a: 2, ..b };
let f__isize = Foo { a: 2, ..4 };
}
43 changes: 43 additions & 0 deletions src/test/compile-fail/variadic-ffi-3.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

extern {
fn foo(f: isize, x: u8, ...);
}

extern "C" fn bar(f: isize, x: u8) {}

fn main() {
unsafe {
foo(); //~ ERROR: this function takes at least 2 parameters but 0 parameters were supplied
foo(1); //~ ERROR: this function takes at least 2 parameters but 1 parameter was supplied

let x: unsafe extern "C" fn(f: isize, x: u8) = foo;
//~^ ERROR: mismatched types
//~| expected `unsafe extern "C" fn(isize, u8)`
//~| found `unsafe extern "C" fn(isize, u8, ...)`
//~| expected non-variadic fn
//~| found variadic function

let y: extern "C" fn(f: isize, x: u8, ...) = bar;
//~^ ERROR: mismatched types
//~| expected `extern "C" fn(isize, u8, ...)`
//~| found `extern "C" fn(isize, u8) {bar}`
//~| expected variadic fn
//~| found non-variadic function

foo(1, 2, 3f32); //~ ERROR: can't pass an f32 to variadic function, cast to c_double
foo(1, 2, true); //~ ERROR: can't pass bool to variadic function, cast to c_int
foo(1, 2, 1i8); //~ ERROR: can't pass i8 to variadic function, cast to c_int
foo(1, 2, 1u8); //~ ERROR: can't pass u8 to variadic function, cast to c_uint
foo(1, 2, 1i16); //~ ERROR: can't pass i16 to variadic function, cast to c_int
foo(1, 2, 1u16); //~ ERROR: can't pass u16 to variadic function, cast to c_uint
}
}
29 changes: 10 additions & 19 deletions src/test/compile-fail/variadic-ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,20 @@ extern {
extern "C" fn bar(f: isize, x: u8) {}

fn main() {
// errors below are no longer checked because error above aborts
// compilation; see variadic-ffi-3.rs for corresponding test.
unsafe {
foo(); //~ ERROR: this function takes at least 2 parameters but 0 parameters were supplied
foo(1); //~ ERROR: this function takes at least 2 parameters but 1 parameter was supplied
foo();
foo(1);

let x: unsafe extern "C" fn(f: isize, x: u8) = foo;
//~^ ERROR: mismatched types
//~| expected `unsafe extern "C" fn(isize, u8)`
//~| found `unsafe extern "C" fn(isize, u8, ...)`
//~| expected non-variadic fn
//~| found variadic function

let y: extern "C" fn(f: isize, x: u8, ...) = bar;
//~^ ERROR: mismatched types
//~| expected `extern "C" fn(isize, u8, ...)`
//~| found `extern "C" fn(isize, u8) {bar}`
//~| expected variadic fn
//~| found non-variadic function

foo(1, 2, 3f32); //~ ERROR: can't pass an f32 to variadic function, cast to c_double
foo(1, 2, true); //~ ERROR: can't pass bool to variadic function, cast to c_int
foo(1, 2, 1i8); //~ ERROR: can't pass i8 to variadic function, cast to c_int
foo(1, 2, 1u8); //~ ERROR: can't pass u8 to variadic function, cast to c_uint
foo(1, 2, 1i16); //~ ERROR: can't pass i16 to variadic function, cast to c_int
foo(1, 2, 1u16); //~ ERROR: can't pass u16 to variadic function, cast to c_uint
foo(1, 2, 3f32);
foo(1, 2, true);
foo(1, 2, 1i8);
foo(1, 2, 1u8);
foo(1, 2, 1i16);
foo(1, 2, 1u16);
}
}
13 changes: 3 additions & 10 deletions src/test/compile-fail/wrong-mul-method-signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,9 @@ pub fn main() {
let x: Vec1 = Vec1 { x: 1.0 } * 2.0; // this is OK

let x: Vec2 = Vec2 { x: 1.0, y: 2.0 } * 2.0; // trait had reversed order
//~^ ERROR mismatched types
//~| expected `Vec2`
//~| found `_`
//~| expected struct `Vec2`
//~| found floating-point variable
//~| ERROR mismatched types
//~| expected `Vec2`
//~| found `f64`
//~| expected struct `Vec2`
//~| found f64
// (we no longer signal a compile error here, since the
// error in the trait signature will cause compilation to
// abort before we bother looking at function bodies.)

let x: i32 = Vec3 { x: 1.0, y: 2.0, z: 3.0 } * 2.0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// 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 we do not get an error when you use `<Self as Get>::Value` in
// the trait definition if there is no default method and for every impl,
// `Self` does implement `Get`.
//
// See also compile-fail tests associated-types-no-suitable-supertrait
// and associated-types-no-suitable-supertrait-2, which show how small
// variants of the code below can fail.

trait Get {
type Value;
}

trait Other {
fn okay<U:Get>(&self, foo: U, bar: <Self as Get>::Value);
}

impl Get for () {
type Value = f32;
}

impl Get for f64 {
type Value = u32;
}

impl Other for () {
fn okay<U:Get>(&self, _foo: U, _bar: <Self as Get>::Value) { }
}

impl Other for f64 {
fn okay<U:Get>(&self, _foo: U, _bar: <Self as Get>::Value) { }
}

fn main() { }

0 comments on commit d82f912

Please sign in to comment.