diff options
Diffstat (limited to '')
26 files changed, 712 insertions, 0 deletions
diff --git a/src/test/ui/type/type-check-defaults.rs b/src/test/ui/type/type-check-defaults.rs new file mode 100644 index 000000000..6a0a7ed33 --- /dev/null +++ b/src/test/ui/type/type-check-defaults.rs @@ -0,0 +1,27 @@ +use std::iter::FromIterator; +use std::vec::IntoIter; +use std::ops::Add; + +struct Foo<T, U: FromIterator<T>>(T, U); +struct WellFormed<Z = Foo<i32, i32>>(Z); +//~^ ERROR a value of type `i32` cannot be built from an iterator over elements of type `i32` +struct WellFormedNoBounds<Z:?Sized = Foo<i32, i32>>(Z); +//~^ ERROR a value of type `i32` cannot be built from an iterator over elements of type `i32` + +struct Bounds<T:Copy=String>(T); +//~^ ERROR the trait bound `String: Copy` is not satisfied [E0277] + +struct WhereClause<T=String>(T) where T: Copy; +//~^ ERROR the trait bound `String: Copy` is not satisfied [E0277] + +trait TraitBound<T:Copy=String> {} +//~^ ERROR the trait bound `String: Copy` is not satisfied [E0277] + +trait Super<T: Copy> { } +trait Base<T = String>: Super<T> { } +//~^ ERROR the trait bound `T: Copy` is not satisfied [E0277] + +trait ProjectionPred<T:Iterator = IntoIter<i32>> where T::Item : Add<u8> {} +//~^ ERROR cannot add `u8` to `i32` [E0277] + +fn main() { } diff --git a/src/test/ui/type/type-check-defaults.stderr b/src/test/ui/type/type-check-defaults.stderr new file mode 100644 index 000000000..56a9b5317 --- /dev/null +++ b/src/test/ui/type/type-check-defaults.stderr @@ -0,0 +1,81 @@ +error[E0277]: a value of type `i32` cannot be built from an iterator over elements of type `i32` + --> $DIR/type-check-defaults.rs:6:19 + | +LL | struct WellFormed<Z = Foo<i32, i32>>(Z); + | ^^^^^^^^^^^^^^^^^ value of type `i32` cannot be built from `std::iter::Iterator<Item=i32>` + | + = help: the trait `FromIterator<i32>` is not implemented for `i32` +note: required by a bound in `Foo` + --> $DIR/type-check-defaults.rs:5:18 + | +LL | struct Foo<T, U: FromIterator<T>>(T, U); + | ^^^^^^^^^^^^^^^ required by this bound in `Foo` + +error[E0277]: a value of type `i32` cannot be built from an iterator over elements of type `i32` + --> $DIR/type-check-defaults.rs:8:27 + | +LL | struct WellFormedNoBounds<Z:?Sized = Foo<i32, i32>>(Z); + | ^^^^^^^^^^^^^^^^^^^^^^^^ value of type `i32` cannot be built from `std::iter::Iterator<Item=i32>` + | + = help: the trait `FromIterator<i32>` is not implemented for `i32` +note: required by a bound in `Foo` + --> $DIR/type-check-defaults.rs:5:18 + | +LL | struct Foo<T, U: FromIterator<T>>(T, U); + | ^^^^^^^^^^^^^^^ required by this bound in `Foo` + +error[E0277]: the trait bound `String: Copy` is not satisfied + --> $DIR/type-check-defaults.rs:11:17 + | +LL | struct Bounds<T:Copy=String>(T); + | ^^^^ the trait `Copy` is not implemented for `String` + +error[E0277]: the trait bound `String: Copy` is not satisfied + --> $DIR/type-check-defaults.rs:14:42 + | +LL | struct WhereClause<T=String>(T) where T: Copy; + | ^^^^ the trait `Copy` is not implemented for `String` + +error[E0277]: the trait bound `String: Copy` is not satisfied + --> $DIR/type-check-defaults.rs:17:20 + | +LL | trait TraitBound<T:Copy=String> {} + | ^^^^ the trait `Copy` is not implemented for `String` + +error[E0277]: the trait bound `T: Copy` is not satisfied + --> $DIR/type-check-defaults.rs:21:25 + | +LL | trait Base<T = String>: Super<T> { } + | ^^^^^^^^ the trait `Copy` is not implemented for `T` + | +note: required by a bound in `Super` + --> $DIR/type-check-defaults.rs:20:16 + | +LL | trait Super<T: Copy> { } + | ^^^^ required by this bound in `Super` +help: consider further restricting type parameter `T` + | +LL | trait Base<T = String>: Super<T> where T: std::marker::Copy { } + | ++++++++++++++++++++++++++ + +error[E0277]: cannot add `u8` to `i32` + --> $DIR/type-check-defaults.rs:24:66 + | +LL | trait ProjectionPred<T:Iterator = IntoIter<i32>> where T::Item : Add<u8> {} + | ^^^^^^^ no implementation for `i32 + u8` + | + = help: the trait `Add<u8>` is not implemented for `i32` + = help: the following other types implement trait `Add<Rhs>`: + <&'a f32 as Add<f32>> + <&'a f64 as Add<f64>> + <&'a i128 as Add<i128>> + <&'a i16 as Add<i16>> + <&'a i32 as Add<i32>> + <&'a i64 as Add<i64>> + <&'a i8 as Add<i8>> + <&'a isize as Add<isize>> + and 48 others + +error: aborting due to 7 previous errors + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/type/type-check/assignment-expected-bool.rs b/src/test/ui/type/type-check/assignment-expected-bool.rs new file mode 100644 index 000000000..191939bdb --- /dev/null +++ b/src/test/ui/type/type-check/assignment-expected-bool.rs @@ -0,0 +1,34 @@ +// The purpose of this text is to ensure that we get good +// diagnostics when a `bool` is expected but that due to +// an assignment expression `x = y` the type is `()`. + +fn main() { + let _: bool = 0 = 0; //~ ERROR mismatched types [E0308] + + let _: bool = match 0 { + 0 => 0 = 0, //~ ERROR mismatched types [E0308] + _ => 0 = 0, //~ ERROR mismatched types [E0308] + }; + + let _: bool = match true { + true => 0 = 0, //~ ERROR mismatched types [E0308] + _ => (), + }; + + if 0 = 0 {} //~ ERROR mismatched types [E0308] + + let _: bool = if { 0 = 0 } { //~ ERROR mismatched types [E0308] + 0 = 0 //~ ERROR mismatched types [E0308] + } else { + 0 = 0 //~ ERROR mismatched types [E0308] + }; + + let _ = (0 = 0) //~ ERROR mismatched types [E0308] + && { 0 = 0 } //~ ERROR mismatched types [E0308] + || (0 = 0); //~ ERROR mismatched types [E0308] + + // A test to check that not expecting `bool` behaves well: + let _: usize = 0 = 0; + //~^ ERROR mismatched types [E0308] + //~| ERROR invalid left-hand side of assignment [E0070] +} diff --git a/src/test/ui/type/type-check/assignment-expected-bool.stderr b/src/test/ui/type/type-check/assignment-expected-bool.stderr new file mode 100644 index 000000000..e2b821f7b --- /dev/null +++ b/src/test/ui/type/type-check/assignment-expected-bool.stderr @@ -0,0 +1,141 @@ +error[E0308]: mismatched types + --> $DIR/assignment-expected-bool.rs:6:19 + | +LL | let _: bool = 0 = 0; + | ^^^^^ expected `bool`, found `()` + | +help: you might have meant to compare for equality + | +LL | let _: bool = 0 == 0; + | ~~ + +error[E0308]: mismatched types + --> $DIR/assignment-expected-bool.rs:9:14 + | +LL | 0 => 0 = 0, + | ^^^^^ expected `bool`, found `()` + | +help: you might have meant to compare for equality + | +LL | 0 => 0 == 0, + | ~~ + +error[E0308]: mismatched types + --> $DIR/assignment-expected-bool.rs:10:14 + | +LL | _ => 0 = 0, + | ^^^^^ expected `bool`, found `()` + | +help: you might have meant to compare for equality + | +LL | _ => 0 == 0, + | ~~ + +error[E0308]: mismatched types + --> $DIR/assignment-expected-bool.rs:14:17 + | +LL | true => 0 = 0, + | ^^^^^ expected `bool`, found `()` + | +help: you might have meant to compare for equality + | +LL | true => 0 == 0, + | ~~ + +error[E0308]: mismatched types + --> $DIR/assignment-expected-bool.rs:18:8 + | +LL | if 0 = 0 {} + | ^^^^^ expected `bool`, found `()` + | +help: you might have meant to compare for equality + | +LL | if 0 == 0 {} + | ~~ + +error[E0308]: mismatched types + --> $DIR/assignment-expected-bool.rs:20:24 + | +LL | let _: bool = if { 0 = 0 } { + | ^^^^^ expected `bool`, found `()` + | +help: you might have meant to compare for equality + | +LL | let _: bool = if { 0 == 0 } { + | ~~ + +error[E0308]: mismatched types + --> $DIR/assignment-expected-bool.rs:21:9 + | +LL | 0 = 0 + | ^^^^^ expected `bool`, found `()` + | +help: you might have meant to compare for equality + | +LL | 0 == 0 + | ~~ + +error[E0308]: mismatched types + --> $DIR/assignment-expected-bool.rs:23:9 + | +LL | 0 = 0 + | ^^^^^ expected `bool`, found `()` + | +help: you might have meant to compare for equality + | +LL | 0 == 0 + | ~~ + +error[E0308]: mismatched types + --> $DIR/assignment-expected-bool.rs:26:13 + | +LL | let _ = (0 = 0) + | ^^^^^^^ expected `bool`, found `()` + | +help: you might have meant to compare for equality + | +LL | let _ = (0 == 0) + | ~~ + +error[E0308]: mismatched types + --> $DIR/assignment-expected-bool.rs:27:14 + | +LL | && { 0 = 0 } + | ^^^^^ expected `bool`, found `()` + | +help: you might have meant to compare for equality + | +LL | && { 0 == 0 } + | ~~ + +error[E0308]: mismatched types + --> $DIR/assignment-expected-bool.rs:28:12 + | +LL | || (0 = 0); + | ^^^^^^^ expected `bool`, found `()` + | +help: you might have meant to compare for equality + | +LL | || (0 == 0); + | ~~ + +error[E0070]: invalid left-hand side of assignment + --> $DIR/assignment-expected-bool.rs:31:22 + | +LL | let _: usize = 0 = 0; + | - ^ + | | + | cannot assign to this expression + +error[E0308]: mismatched types + --> $DIR/assignment-expected-bool.rs:31:20 + | +LL | let _: usize = 0 = 0; + | ----- ^^^^^ expected `usize`, found `()` + | | + | expected due to this + +error: aborting due to 13 previous errors + +Some errors have detailed explanations: E0070, E0308. +For more information about an error, try `rustc --explain E0070`. diff --git a/src/test/ui/type/type-check/assignment-in-if.rs b/src/test/ui/type/type-check/assignment-in-if.rs new file mode 100644 index 000000000..8da7b32b4 --- /dev/null +++ b/src/test/ui/type/type-check/assignment-in-if.rs @@ -0,0 +1,43 @@ +// Test that the parser does not attempt to parse struct literals +// within assignments in if expressions. + +#![allow(unused_parens)] + +struct Foo { + foo: usize +} + +fn main() { + let x = 1; + let y: Foo; + + // `x { ... }` should not be interpreted as a struct literal here + if x = x { + //~^ ERROR mismatched types + println!("{}", x); + } + // Explicit parentheses on the left should match behavior of above + if (x = x) { + //~^ ERROR mismatched types + println!("{}", x); + } + // The struct literal interpretation is fine with explicit parentheses on the right + if y = (Foo { foo: x }) { + //~^ ERROR mismatched types + println!("{}", x); + } + // "invalid left-hand side of assignment" error is suppresed + if 3 = x { + //~^ ERROR mismatched types + println!("{}", x); + } + if ( + if true { + x = 4 //~ ERROR mismatched types + } else { + x = 5 //~ ERROR mismatched types + } + ) { + println!("{}", x); + } +} diff --git a/src/test/ui/type/type-check/assignment-in-if.stderr b/src/test/ui/type/type-check/assignment-in-if.stderr new file mode 100644 index 000000000..f4ef44e24 --- /dev/null +++ b/src/test/ui/type/type-check/assignment-in-if.stderr @@ -0,0 +1,69 @@ +error[E0308]: mismatched types + --> $DIR/assignment-in-if.rs:15:8 + | +LL | if x = x { + | ^^^^^ expected `bool`, found `()` + | +help: you might have meant to compare for equality + | +LL | if x == x { + | ~~ + +error[E0308]: mismatched types + --> $DIR/assignment-in-if.rs:20:8 + | +LL | if (x = x) { + | ^^^^^^^ expected `bool`, found `()` + | +help: you might have meant to compare for equality + | +LL | if (x == x) { + | ~~ + +error[E0308]: mismatched types + --> $DIR/assignment-in-if.rs:25:8 + | +LL | if y = (Foo { foo: x }) { + | ^^^^^^^^^^^^^^^^^^^^ expected `bool`, found `()` + | +help: you might have meant to compare for equality + | +LL | if y == (Foo { foo: x }) { + | ~~ + +error[E0308]: mismatched types + --> $DIR/assignment-in-if.rs:30:8 + | +LL | if 3 = x { + | ^^^^^ expected `bool`, found `()` + | +help: you might have meant to compare for equality + | +LL | if 3 == x { + | ~~ + +error[E0308]: mismatched types + --> $DIR/assignment-in-if.rs:36:13 + | +LL | x = 4 + | ^^^^^ expected `bool`, found `()` + | +help: you might have meant to compare for equality + | +LL | x == 4 + | ~~ + +error[E0308]: mismatched types + --> $DIR/assignment-in-if.rs:38:13 + | +LL | x = 5 + | ^^^^^ expected `bool`, found `()` + | +help: you might have meant to compare for equality + | +LL | x == 5 + | ~~ + +error: aborting due to 6 previous errors + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/type/type-check/cannot_infer_local_or_array.rs b/src/test/ui/type/type-check/cannot_infer_local_or_array.rs new file mode 100644 index 000000000..af7552523 --- /dev/null +++ b/src/test/ui/type/type-check/cannot_infer_local_or_array.rs @@ -0,0 +1,3 @@ +fn main() { + let x = []; //~ ERROR type annotations needed +} diff --git a/src/test/ui/type/type-check/cannot_infer_local_or_array.stderr b/src/test/ui/type/type-check/cannot_infer_local_or_array.stderr new file mode 100644 index 000000000..e823bad26 --- /dev/null +++ b/src/test/ui/type/type-check/cannot_infer_local_or_array.stderr @@ -0,0 +1,14 @@ +error[E0282]: type annotations needed for `[_; 0]` + --> $DIR/cannot_infer_local_or_array.rs:2:9 + | +LL | let x = []; + | ^ -- type must be known at this point + | +help: consider giving `x` an explicit type, where the placeholders `_` are specified + | +LL | let x: [_; 0] = []; + | ++++++++ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0282`. diff --git a/src/test/ui/type/type-check/cannot_infer_local_or_vec.rs b/src/test/ui/type/type-check/cannot_infer_local_or_vec.rs new file mode 100644 index 000000000..e72ddabf3 --- /dev/null +++ b/src/test/ui/type/type-check/cannot_infer_local_or_vec.rs @@ -0,0 +1,4 @@ +fn main() { + let x = vec![]; + //~^ ERROR type annotations needed +} diff --git a/src/test/ui/type/type-check/cannot_infer_local_or_vec.stderr b/src/test/ui/type/type-check/cannot_infer_local_or_vec.stderr new file mode 100644 index 000000000..b63d2a3b6 --- /dev/null +++ b/src/test/ui/type/type-check/cannot_infer_local_or_vec.stderr @@ -0,0 +1,14 @@ +error[E0282]: type annotations needed for `Vec<T>` + --> $DIR/cannot_infer_local_or_vec.rs:2:9 + | +LL | let x = vec![]; + | ^ + | +help: consider giving `x` an explicit type, where the type for type parameter `T` is specified + | +LL | let x: Vec<T> = vec![]; + | ++++++++ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0282`. diff --git a/src/test/ui/type/type-check/cannot_infer_local_or_vec_in_tuples.rs b/src/test/ui/type/type-check/cannot_infer_local_or_vec_in_tuples.rs new file mode 100644 index 000000000..d21456439 --- /dev/null +++ b/src/test/ui/type/type-check/cannot_infer_local_or_vec_in_tuples.rs @@ -0,0 +1,4 @@ +fn main() { + let (x, ) = (vec![], ); + //~^ ERROR type annotations needed +} diff --git a/src/test/ui/type/type-check/cannot_infer_local_or_vec_in_tuples.stderr b/src/test/ui/type/type-check/cannot_infer_local_or_vec_in_tuples.stderr new file mode 100644 index 000000000..be60cda68 --- /dev/null +++ b/src/test/ui/type/type-check/cannot_infer_local_or_vec_in_tuples.stderr @@ -0,0 +1,14 @@ +error[E0282]: type annotations needed for `(Vec<T>,)` + --> $DIR/cannot_infer_local_or_vec_in_tuples.rs:2:9 + | +LL | let (x, ) = (vec![], ); + | ^^^^^ + | +help: consider giving this pattern a type, where the type for type parameter `T` is specified + | +LL | let (x, ): (Vec<T>,) = (vec![], ); + | +++++++++++ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0282`. diff --git a/src/test/ui/type/type-check/issue-22897.rs b/src/test/ui/type/type-check/issue-22897.rs new file mode 100644 index 000000000..8171a0ef1 --- /dev/null +++ b/src/test/ui/type/type-check/issue-22897.rs @@ -0,0 +1,5 @@ +fn main() { } + +fn unconstrained_type() { + []; //~ ERROR type annotations needed +} diff --git a/src/test/ui/type/type-check/issue-22897.stderr b/src/test/ui/type/type-check/issue-22897.stderr new file mode 100644 index 000000000..fae7b7926 --- /dev/null +++ b/src/test/ui/type/type-check/issue-22897.stderr @@ -0,0 +1,9 @@ +error[E0282]: type annotations needed + --> $DIR/issue-22897.rs:4:5 + | +LL | []; + | ^^ cannot infer type for array `[_; 0]` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0282`. diff --git a/src/test/ui/type/type-check/issue-40294.rs b/src/test/ui/type/type-check/issue-40294.rs new file mode 100644 index 000000000..5493a4e5f --- /dev/null +++ b/src/test/ui/type/type-check/issue-40294.rs @@ -0,0 +1,13 @@ +trait Foo: Sized { + fn foo(self); +} + +fn foo<'a,'b,T>(x: &'a T, y: &'b T) + where &'a T : Foo, //~ ERROR type annotations needed + &'b T : Foo +{ + x.foo(); + y.foo(); +} + +fn main() { } diff --git a/src/test/ui/type/type-check/issue-40294.stderr b/src/test/ui/type/type-check/issue-40294.stderr new file mode 100644 index 000000000..75feb5698 --- /dev/null +++ b/src/test/ui/type/type-check/issue-40294.stderr @@ -0,0 +1,11 @@ +error[E0283]: type annotations needed: cannot satisfy `&'a T: Foo` + --> $DIR/issue-40294.rs:6:19 + | +LL | where &'a T : Foo, + | ^^^ + | + = note: cannot satisfy `&'a T: Foo` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0283`. diff --git a/src/test/ui/type/type-check/issue-41314.rs b/src/test/ui/type/type-check/issue-41314.rs new file mode 100644 index 000000000..cbd39f5f9 --- /dev/null +++ b/src/test/ui/type/type-check/issue-41314.rs @@ -0,0 +1,10 @@ +enum X { + Y(u32) +} + +fn main() { + match X::Y(0) { + X::Y { number } => {} + //~^ ERROR tuple variant `X::Y` written as struct variant + } +} diff --git a/src/test/ui/type/type-check/issue-41314.stderr b/src/test/ui/type/type-check/issue-41314.stderr new file mode 100644 index 000000000..4a9bf6106 --- /dev/null +++ b/src/test/ui/type/type-check/issue-41314.stderr @@ -0,0 +1,14 @@ +error[E0769]: tuple variant `X::Y` written as struct variant + --> $DIR/issue-41314.rs:7:9 + | +LL | X::Y { number } => {} + | ^^^^^^^^^^^^^^^ + | +help: use the tuple variant pattern syntax instead + | +LL | X::Y(number) => {} + | ~~~~~~~~ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0769`. diff --git a/src/test/ui/type/type-check/issue-67273-assignment-match-prior-arm-bool-expected-unit.rs b/src/test/ui/type/type-check/issue-67273-assignment-match-prior-arm-bool-expected-unit.rs new file mode 100644 index 000000000..c39ab9544 --- /dev/null +++ b/src/test/ui/type/type-check/issue-67273-assignment-match-prior-arm-bool-expected-unit.rs @@ -0,0 +1,27 @@ +fn main() { + let mut i: i64; + // Expected type is an inference variable `?T` + // because the `match` is used as a statement. + // This is the "initial" type of the `coercion`. + match i { + // Add `bool` to the overall `coercion`. + 0 => true, + + // Necessary to cause the ICE: + 1 => true, + + // Suppose that we had `let _: bool = match i { ... }`. + // In that case, as the expected type would be `bool`, + // we would suggest `i == 1` as a fix. + // + // However, no type error happens when checking `i = 1` because `expected == ?T`, + // which will unify with `typeof(i = 1) == ()`. + // + // However, in #67273, we would delay the unification of this arm with the above + // because we used the hitherto accumulated coercion as opposed to the "initial" type. + 2 => i = 1, + //~^ ERROR `match` arms have incompatible types + + _ => (), + } +} diff --git a/src/test/ui/type/type-check/issue-67273-assignment-match-prior-arm-bool-expected-unit.stderr b/src/test/ui/type/type-check/issue-67273-assignment-match-prior-arm-bool-expected-unit.stderr new file mode 100644 index 000000000..a431fe89c --- /dev/null +++ b/src/test/ui/type/type-check/issue-67273-assignment-match-prior-arm-bool-expected-unit.stderr @@ -0,0 +1,22 @@ +error[E0308]: `match` arms have incompatible types + --> $DIR/issue-67273-assignment-match-prior-arm-bool-expected-unit.rs:22:14 + | +LL | / match i { +LL | | // Add `bool` to the overall `coercion`. +LL | | 0 => true, + | | ---- this is found to be of type `bool` +LL | | +LL | | // Necessary to cause the ICE: +LL | | 1 => true, + | | ---- this is found to be of type `bool` +... | +LL | | 2 => i = 1, + | | ^^^^^ expected `bool`, found `()` +... | +LL | | _ => (), +LL | | } + | |_____- `match` arms have incompatible types + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/type/type-check/issue-88577-check-fn-with-more-than-65535-arguments.rs b/src/test/ui/type/type-check/issue-88577-check-fn-with-more-than-65535-arguments.rs new file mode 100644 index 000000000..e50cc5865 --- /dev/null +++ b/src/test/ui/type/type-check/issue-88577-check-fn-with-more-than-65535-arguments.rs @@ -0,0 +1,12 @@ +macro_rules! many_args { + ([$($t:tt)*]#$($h:tt)*) => { + many_args!{[$($t)*$($t)*]$($h)*} + }; + ([$($t:tt)*]) => { + fn _f($($t: ()),*) {} //~ ERROR function can not have more than 65535 arguments + } +} + +many_args!{[_]########## ######} + +fn main() {} diff --git a/src/test/ui/type/type-check/issue-88577-check-fn-with-more-than-65535-arguments.stderr b/src/test/ui/type/type-check/issue-88577-check-fn-with-more-than-65535-arguments.stderr new file mode 100644 index 000000000..615fd2ccb --- /dev/null +++ b/src/test/ui/type/type-check/issue-88577-check-fn-with-more-than-65535-arguments.stderr @@ -0,0 +1,13 @@ +error: function can not have more than 65535 arguments + --> $DIR/issue-88577-check-fn-with-more-than-65535-arguments.rs:6:24 + | +LL | fn _f($($t: ()),*) {} + | ________________________^ +LL | | } +LL | | } +LL | | +LL | | many_args!{[_]########## ######} + | |____________^ + +error: aborting due to previous error + diff --git a/src/test/ui/type/type-check/missing_trait_impl.rs b/src/test/ui/type/type-check/missing_trait_impl.rs new file mode 100644 index 000000000..0e3e703a2 --- /dev/null +++ b/src/test/ui/type/type-check/missing_trait_impl.rs @@ -0,0 +1,16 @@ +fn main() { +} + +fn foo<T>(x: T, y: T) { + let z = x + y; //~ ERROR cannot add `T` to `T` +} + +fn bar<T>(x: T) { + x += x; //~ ERROR binary assignment operation `+=` cannot be applied to type `T` +} + +fn baz<T>(x: T) { + let y = -x; //~ ERROR cannot apply unary operator `-` to type `T` + let y = !x; //~ ERROR cannot apply unary operator `!` to type `T` + let y = *x; //~ ERROR type `T` cannot be dereferenced +} diff --git a/src/test/ui/type/type-check/missing_trait_impl.stderr b/src/test/ui/type/type-check/missing_trait_impl.stderr new file mode 100644 index 000000000..2b58cd418 --- /dev/null +++ b/src/test/ui/type/type-check/missing_trait_impl.stderr @@ -0,0 +1,58 @@ +error[E0369]: cannot add `T` to `T` + --> $DIR/missing_trait_impl.rs:5:15 + | +LL | let z = x + y; + | - ^ - T + | | + | T + | +help: consider restricting type parameter `T` + | +LL | fn foo<T: std::ops::Add>(x: T, y: T) { + | +++++++++++++++ + +error[E0368]: binary assignment operation `+=` cannot be applied to type `T` + --> $DIR/missing_trait_impl.rs:9:5 + | +LL | x += x; + | -^^^^^ + | | + | cannot use `+=` on type `T` + | +help: consider restricting type parameter `T` + | +LL | fn bar<T: std::ops::AddAssign>(x: T) { + | +++++++++++++++++++++ + +error[E0600]: cannot apply unary operator `-` to type `T` + --> $DIR/missing_trait_impl.rs:13:13 + | +LL | let y = -x; + | ^^ cannot apply unary operator `-` + | +help: consider restricting type parameter `T` + | +LL | fn baz<T: std::ops::Neg>(x: T) { + | +++++++++++++++ + +error[E0600]: cannot apply unary operator `!` to type `T` + --> $DIR/missing_trait_impl.rs:14:13 + | +LL | let y = !x; + | ^^ cannot apply unary operator `!` + | +help: consider restricting type parameter `T` + | +LL | fn baz<T: std::ops::Not>(x: T) { + | +++++++++++++++ + +error[E0614]: type `T` cannot be dereferenced + --> $DIR/missing_trait_impl.rs:15:13 + | +LL | let y = *x; + | ^^ + +error: aborting due to 5 previous errors + +Some errors have detailed explanations: E0368, E0369, E0600, E0614. +For more information about an error, try `rustc --explain E0368`. diff --git a/src/test/ui/type/type-check/unknown_type_for_closure.rs b/src/test/ui/type/type-check/unknown_type_for_closure.rs new file mode 100644 index 000000000..167687c18 --- /dev/null +++ b/src/test/ui/type/type-check/unknown_type_for_closure.rs @@ -0,0 +1,17 @@ +fn infer_in_arg() { + let x = |b: Vec<_>| {}; //~ ERROR E0282 +} + +fn empty_pattern() { + let x = |_| {}; //~ ERROR type annotations needed +} + +fn infer_ty() { + let x = |k: _| {}; //~ ERROR type annotations needed +} + +fn ambig_return() { + let x = || -> Vec<_> { Vec::new() }; //~ ERROR type annotations needed +} + +fn main() {} diff --git a/src/test/ui/type/type-check/unknown_type_for_closure.stderr b/src/test/ui/type/type-check/unknown_type_for_closure.stderr new file mode 100644 index 000000000..9ae97f390 --- /dev/null +++ b/src/test/ui/type/type-check/unknown_type_for_closure.stderr @@ -0,0 +1,37 @@ +error[E0282]: type annotations needed + --> $DIR/unknown_type_for_closure.rs:2:13 + | +LL | let x = |b: Vec<_>| {}; + | ^^^^^^^^^^^^^^ cannot infer type for struct `Vec<_>` + +error[E0282]: type annotations needed + --> $DIR/unknown_type_for_closure.rs:6:14 + | +LL | let x = |_| {}; + | ^ + | +help: consider giving this closure parameter an explicit type + | +LL | let x = |_: _| {}; + | +++ + +error[E0282]: type annotations needed + --> $DIR/unknown_type_for_closure.rs:10:14 + | +LL | let x = |k: _| {}; + | ^ cannot infer type + +error[E0282]: type annotations needed + --> $DIR/unknown_type_for_closure.rs:14:28 + | +LL | let x = || -> Vec<_> { Vec::new() }; + | ^^^^^^^^ cannot infer type of the type parameter `T` declared on the struct `Vec` + | +help: consider specifying the generic argument + | +LL | let x = || -> Vec<_> { Vec::<T>::new() }; + | +++++ + +error: aborting due to 4 previous errors + +For more information about this error, try `rustc --explain E0282`. |