Skip to content

Commit d82f912

Browse files
committed
Fallout from this change.
1 parent 58dc3bb commit d82f912

15 files changed

+220
-54
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Check that we get an error when you use `<Self as Get>::Value` in
12+
// the trait definition but `Self` does not, in fact, implement `Get`.
13+
//
14+
// See also associated-types-no-suitable-supertrait.rs, which checks
15+
// that we see the same error when making this mistake on an impl
16+
// rather than the default method impl.
17+
//
18+
// See also run-pass/associated-types-projection-to-unrelated-trait.rs,
19+
// which checks that the trait interface itself is not considered an
20+
// error as long as all impls satisfy the constraint.
21+
22+
trait Get : ::std::marker::MarkerTrait {
23+
type Value;
24+
}
25+
26+
trait Other {
27+
fn uhoh<U:Get>(&self, foo: U, bar: <Self as Get>::Value) {}
28+
//~^ ERROR the trait `Get` is not implemented for the type `Self`
29+
}
30+
31+
fn main() { }

src/test/compile-fail/associated-types-no-suitable-supertrait.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,30 @@
1010

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

1422
trait Get : ::std::marker::MarkerTrait {
1523
type Value;
1624
}
1725

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

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

2939
fn main() { }
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Tests that enum-to-float casts are disallowed.
12+
13+
enum E {
14+
L0 = -1,
15+
H0 = 1
16+
}
17+
18+
enum F {
19+
L1 = 1,
20+
H1 = 0xFFFFFFFFFFFFFFFF
21+
}
22+
23+
pub fn main() {
24+
let a = E::L0 as f32; //~ ERROR illegal cast
25+
let c = F::H1 as f32; //~ ERROR illegal cast
26+
assert_eq!(a, -1.0f32);
27+
assert_eq!(c, -1.0f32);
28+
}

src/test/compile-fail/enum-to-float-cast.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,8 @@ static C0: f32 = E::L0 as f32; //~ ERROR illegal cast
2424
static C1: f32 = F::H1 as f32; //~ ERROR illegal cast
2525

2626
pub fn main() {
27-
let a = E::L0 as f32; //~ ERROR illegal cast
2827
let b = C0;
29-
let c = F::H1 as f32; //~ ERROR illegal cast
3028
let d = C1;
31-
assert_eq!(a, -1.0f32);
3229
assert_eq!(b, -1.0f32);
33-
assert_eq!(c, -1.0f32);
3430
assert_eq!(d, -1.0f32);
3531
}

src/test/compile-fail/issue-16048.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ impl<'a> Test<'a> for Foo<'a> {
2929
impl<'a> NoLifetime for Foo<'a> {
3030
fn get<'p, T : Test<'a>>(&self) -> T {
3131
//~^ ERROR lifetime parameters or bounds on method `get` do not match the trait declaration
32-
return *self as T; //~ ERROR non-scalar cast: `Foo<'a>` as `T`
32+
return *self as T;
3333
}
3434
}
3535

src/test/compile-fail/issue-19244-1.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,5 @@ const TUP: (usize,) = (42,);
1212

1313
fn main() {
1414
let a: [isize; TUP.1];
15-
//~^ ERROR array length constant evaluation error: tuple index out of bounds
16-
//~| ERROR attempted out-of-bounds tuple index
17-
//~| ERROR attempted out-of-bounds tuple index
15+
//~^ ERROR attempted out-of-bounds tuple index
1816
}

src/test/compile-fail/issue-19244-2.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,5 @@ const STRUCT: MyStruct = MyStruct { field: 42 };
1313

1414
fn main() {
1515
let a: [isize; STRUCT.nonexistent_field];
16-
//~^ ERROR array length constant evaluation error: nonexistent struct field
17-
//~| ERROR attempted access of field `nonexistent_field`
18-
//~| ERROR attempted access of field `nonexistent_field`
16+
//~^ ERROR attempted access of field `nonexistent_field`
1917
}

src/test/compile-fail/issue-2063.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ impl to_str_2 for t {
2828
}
2929

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

3437
fn main() {

src/test/compile-fail/non-constant-expr-for-fixed-len-vec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212

1313
fn main() {
1414
fn bar(n: isize) {
15+
// FIXME (#24414): This error message needs improvement.
1516
let _x: [isize; n];
1617
//~^ ERROR no type for local variable
17-
//~| ERROR array length constant evaluation error: non-constant path in constant expr
1818
}
1919
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Check that `base` in `Fru { field: expr, ..base }` must have right type.
12+
//
13+
// See also struct-base-wrong-type.rs, which tests same condition
14+
// within a const expression.
15+
16+
struct Foo { a: isize, b: isize }
17+
struct Bar { x: isize }
18+
19+
fn main() {
20+
let b = Bar { x: 5 };
21+
let f = Foo { a: 2, ..b }; //~ ERROR mismatched types
22+
//~| expected `Foo`
23+
//~| found `Bar`
24+
//~| expected struct `Foo`
25+
//~| found struct `Bar`
26+
let f__isize = Foo { a: 2, ..4 }; //~ ERROR mismatched types
27+
//~| expected `Foo`
28+
//~| found `_`
29+
//~| expected struct `Foo`
30+
//~| found integral variable
31+
}

src/test/compile-fail/struct-base-wrong-type.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// Check that `base` in `Fru { field: expr, ..base }` must have right type.
12+
//
13+
// See also struct-base-wrong-type-2.rs, which tests same condition
14+
// within a function body.
15+
1116
struct Foo { a: isize, b: isize }
1217
struct Bar { x: isize }
1318

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

2631
fn main() {
2732
let b = Bar { x: 5 };
28-
let f = Foo { a: 2, ..b }; //~ ERROR mismatched types
29-
//~| expected `Foo`
30-
//~| found `Bar`
31-
//~| expected struct `Foo`
32-
//~| found struct `Bar`
33-
let f__isize = Foo { a: 2, ..4 }; //~ ERROR mismatched types
34-
//~| expected `Foo`
35-
//~| found `_`
36-
//~| expected struct `Foo`
37-
//~| found integral variable
33+
// errors below are no longer caught since error above causes
34+
// compilation to abort before we bother checking function bodies.
35+
// See also struct-base-wrong-type-2.rs, which checks that we
36+
// would catch these errors eventually.
37+
let f = Foo { a: 2, ..b };
38+
let f__isize = Foo { a: 2, ..4 };
3839
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
extern {
12+
fn foo(f: isize, x: u8, ...);
13+
}
14+
15+
extern "C" fn bar(f: isize, x: u8) {}
16+
17+
fn main() {
18+
unsafe {
19+
foo(); //~ ERROR: this function takes at least 2 parameters but 0 parameters were supplied
20+
foo(1); //~ ERROR: this function takes at least 2 parameters but 1 parameter was supplied
21+
22+
let x: unsafe extern "C" fn(f: isize, x: u8) = foo;
23+
//~^ ERROR: mismatched types
24+
//~| expected `unsafe extern "C" fn(isize, u8)`
25+
//~| found `unsafe extern "C" fn(isize, u8, ...)`
26+
//~| expected non-variadic fn
27+
//~| found variadic function
28+
29+
let y: extern "C" fn(f: isize, x: u8, ...) = bar;
30+
//~^ ERROR: mismatched types
31+
//~| expected `extern "C" fn(isize, u8, ...)`
32+
//~| found `extern "C" fn(isize, u8) {bar}`
33+
//~| expected variadic fn
34+
//~| found non-variadic function
35+
36+
foo(1, 2, 3f32); //~ ERROR: can't pass an f32 to variadic function, cast to c_double
37+
foo(1, 2, true); //~ ERROR: can't pass bool to variadic function, cast to c_int
38+
foo(1, 2, 1i8); //~ ERROR: can't pass i8 to variadic function, cast to c_int
39+
foo(1, 2, 1u8); //~ ERROR: can't pass u8 to variadic function, cast to c_uint
40+
foo(1, 2, 1i16); //~ ERROR: can't pass i16 to variadic function, cast to c_int
41+
foo(1, 2, 1u16); //~ ERROR: can't pass u16 to variadic function, cast to c_uint
42+
}
43+
}

src/test/compile-fail/variadic-ffi.rs

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,20 @@ extern {
1919
extern "C" fn bar(f: isize, x: u8) {}
2020

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

2628
let x: unsafe extern "C" fn(f: isize, x: u8) = foo;
27-
//~^ ERROR: mismatched types
28-
//~| expected `unsafe extern "C" fn(isize, u8)`
29-
//~| found `unsafe extern "C" fn(isize, u8, ...)`
30-
//~| expected non-variadic fn
31-
//~| found variadic function
32-
3329
let y: extern "C" fn(f: isize, x: u8, ...) = bar;
34-
//~^ ERROR: mismatched types
35-
//~| expected `extern "C" fn(isize, u8, ...)`
36-
//~| found `extern "C" fn(isize, u8) {bar}`
37-
//~| expected variadic fn
38-
//~| found non-variadic function
3930

40-
foo(1, 2, 3f32); //~ ERROR: can't pass an f32 to variadic function, cast to c_double
41-
foo(1, 2, true); //~ ERROR: can't pass bool to variadic function, cast to c_int
42-
foo(1, 2, 1i8); //~ ERROR: can't pass i8 to variadic function, cast to c_int
43-
foo(1, 2, 1u8); //~ ERROR: can't pass u8 to variadic function, cast to c_uint
44-
foo(1, 2, 1i16); //~ ERROR: can't pass i16 to variadic function, cast to c_int
45-
foo(1, 2, 1u16); //~ ERROR: can't pass u16 to variadic function, cast to c_uint
31+
foo(1, 2, 3f32);
32+
foo(1, 2, true);
33+
foo(1, 2, 1i8);
34+
foo(1, 2, 1u8);
35+
foo(1, 2, 1i16);
36+
foo(1, 2, 1u16);
4637
}
4738
}

src/test/compile-fail/wrong-mul-method-signature.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,9 @@ pub fn main() {
7171
let x: Vec1 = Vec1 { x: 1.0 } * 2.0; // this is OK
7272

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

8578
let x: i32 = Vec3 { x: 1.0, y: 2.0, z: 3.0 } * 2.0;
8679
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Check that we do not get an error when you use `<Self as Get>::Value` in
12+
// the trait definition if there is no default method and for every impl,
13+
// `Self` does implement `Get`.
14+
//
15+
// See also compile-fail tests associated-types-no-suitable-supertrait
16+
// and associated-types-no-suitable-supertrait-2, which show how small
17+
// variants of the code below can fail.
18+
19+
trait Get {
20+
type Value;
21+
}
22+
23+
trait Other {
24+
fn okay<U:Get>(&self, foo: U, bar: <Self as Get>::Value);
25+
}
26+
27+
impl Get for () {
28+
type Value = f32;
29+
}
30+
31+
impl Get for f64 {
32+
type Value = u32;
33+
}
34+
35+
impl Other for () {
36+
fn okay<U:Get>(&self, _foo: U, _bar: <Self as Get>::Value) { }
37+
}
38+
39+
impl Other for f64 {
40+
fn okay<U:Get>(&self, _foo: U, _bar: <Self as Get>::Value) { }
41+
}
42+
43+
fn main() { }

0 commit comments

Comments
 (0)