From 218caa410aa38c29984be31a5229b9fa717560ee Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:19:13 +0200 Subject: Merging upstream version 1.68.2+dfsg1. Signed-off-by: Daniel Baumann --- .../ui/type/type-check/assignment-expected-bool.rs | 34 +++++ .../type-check/assignment-expected-bool.stderr | 141 +++++++++++++++++++++ tests/ui/type/type-check/assignment-in-if.rs | 62 +++++++++ tests/ui/type/type-check/assignment-in-if.stderr | 130 +++++++++++++++++++ .../type/type-check/cannot_infer_local_or_array.rs | 3 + .../type-check/cannot_infer_local_or_array.stderr | 14 ++ .../type/type-check/cannot_infer_local_or_vec.rs | 4 + .../type-check/cannot_infer_local_or_vec.stderr | 14 ++ .../cannot_infer_local_or_vec_in_tuples.rs | 4 + .../cannot_infer_local_or_vec_in_tuples.stderr | 14 ++ tests/ui/type/type-check/issue-22897.rs | 5 + tests/ui/type/type-check/issue-22897.stderr | 9 ++ tests/ui/type/type-check/issue-40294.rs | 13 ++ tests/ui/type/type-check/issue-40294.stderr | 17 +++ tests/ui/type/type-check/issue-41314.rs | 10 ++ tests/ui/type/type-check/issue-41314.stderr | 14 ++ ...ssignment-match-prior-arm-bool-expected-unit.rs | 27 ++++ ...nment-match-prior-arm-bool-expected-unit.stderr | 22 ++++ ...8577-check-fn-with-more-than-65535-arguments.rs | 12 ++ ...-check-fn-with-more-than-65535-arguments.stderr | 13 ++ tests/ui/type/type-check/missing_trait_impl.rs | 16 +++ tests/ui/type/type-check/missing_trait_impl.stderr | 58 +++++++++ tests/ui/type/type-check/point-at-inference-2.rs | 13 ++ .../ui/type/type-check/point-at-inference-2.stderr | 51 ++++++++ .../ui/type/type-check/point-at-inference-3.fixed | 11 ++ tests/ui/type/type-check/point-at-inference-3.rs | 11 ++ .../ui/type/type-check/point-at-inference-3.stderr | 18 +++ tests/ui/type/type-check/point-at-inference.rs | 12 ++ tests/ui/type/type-check/point-at-inference.stderr | 19 +++ .../ui/type/type-check/unknown_type_for_closure.rs | 17 +++ .../type-check/unknown_type_for_closure.stderr | 37 ++++++ 31 files changed, 825 insertions(+) create mode 100644 tests/ui/type/type-check/assignment-expected-bool.rs create mode 100644 tests/ui/type/type-check/assignment-expected-bool.stderr create mode 100644 tests/ui/type/type-check/assignment-in-if.rs create mode 100644 tests/ui/type/type-check/assignment-in-if.stderr create mode 100644 tests/ui/type/type-check/cannot_infer_local_or_array.rs create mode 100644 tests/ui/type/type-check/cannot_infer_local_or_array.stderr create mode 100644 tests/ui/type/type-check/cannot_infer_local_or_vec.rs create mode 100644 tests/ui/type/type-check/cannot_infer_local_or_vec.stderr create mode 100644 tests/ui/type/type-check/cannot_infer_local_or_vec_in_tuples.rs create mode 100644 tests/ui/type/type-check/cannot_infer_local_or_vec_in_tuples.stderr create mode 100644 tests/ui/type/type-check/issue-22897.rs create mode 100644 tests/ui/type/type-check/issue-22897.stderr create mode 100644 tests/ui/type/type-check/issue-40294.rs create mode 100644 tests/ui/type/type-check/issue-40294.stderr create mode 100644 tests/ui/type/type-check/issue-41314.rs create mode 100644 tests/ui/type/type-check/issue-41314.stderr create mode 100644 tests/ui/type/type-check/issue-67273-assignment-match-prior-arm-bool-expected-unit.rs create mode 100644 tests/ui/type/type-check/issue-67273-assignment-match-prior-arm-bool-expected-unit.stderr create mode 100644 tests/ui/type/type-check/issue-88577-check-fn-with-more-than-65535-arguments.rs create mode 100644 tests/ui/type/type-check/issue-88577-check-fn-with-more-than-65535-arguments.stderr create mode 100644 tests/ui/type/type-check/missing_trait_impl.rs create mode 100644 tests/ui/type/type-check/missing_trait_impl.stderr create mode 100644 tests/ui/type/type-check/point-at-inference-2.rs create mode 100644 tests/ui/type/type-check/point-at-inference-2.stderr create mode 100644 tests/ui/type/type-check/point-at-inference-3.fixed create mode 100644 tests/ui/type/type-check/point-at-inference-3.rs create mode 100644 tests/ui/type/type-check/point-at-inference-3.stderr create mode 100644 tests/ui/type/type-check/point-at-inference.rs create mode 100644 tests/ui/type/type-check/point-at-inference.stderr create mode 100644 tests/ui/type/type-check/unknown_type_for_closure.rs create mode 100644 tests/ui/type/type-check/unknown_type_for_closure.stderr (limited to 'tests/ui/type/type-check') diff --git a/tests/ui/type/type-check/assignment-expected-bool.rs b/tests/ui/type/type-check/assignment-expected-bool.rs new file mode 100644 index 000000000..191939bdb --- /dev/null +++ b/tests/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/tests/ui/type/type-check/assignment-expected-bool.stderr b/tests/ui/type/type-check/assignment-expected-bool.stderr new file mode 100644 index 000000000..56494baff --- /dev/null +++ b/tests/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/tests/ui/type/type-check/assignment-in-if.rs b/tests/ui/type/type-check/assignment-in-if.rs new file mode 100644 index 000000000..ada250df2 --- /dev/null +++ b/tests/ui/type/type-check/assignment-in-if.rs @@ -0,0 +1,62 @@ +// 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); + } + + if x == x && x = x && x == x { + //~^ ERROR mismatched types + //~| ERROR mismatched types + //~| ERROR mismatched types + println!("{}", x); + } + + if x == x && x == x && x = x { + //~^ ERROR mismatched types + //~| ERROR mismatched types + println!("{}", x); + } + + if x = 1 && x == 1 { + //~^ ERROR mismatched types + //~| ERROR mismatched types + println!("{}", x); + } +} diff --git a/tests/ui/type/type-check/assignment-in-if.stderr b/tests/ui/type/type-check/assignment-in-if.stderr new file mode 100644 index 000000000..9f4558ada --- /dev/null +++ b/tests/ui/type/type-check/assignment-in-if.stderr @@ -0,0 +1,130 @@ +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[E0308]: mismatched types + --> $DIR/assignment-in-if.rs:44:18 + | +LL | if x == x && x = x && x == x { + | ------ ^ expected `bool`, found `usize` + | | + | expected because this is `bool` + +error[E0308]: mismatched types + --> $DIR/assignment-in-if.rs:44:22 + | +LL | if x == x && x = x && x == x { + | ^ expected `bool`, found `usize` + +error[E0308]: mismatched types + --> $DIR/assignment-in-if.rs:44:8 + | +LL | if x == x && x = x && x == x { + | ^^^^^^^^^^^^^^^^^^^^^^^^^ expected `bool`, found `()` + | +help: you might have meant to compare for equality + | +LL | if x == x && x == x && x == x { + | + + +error[E0308]: mismatched types + --> $DIR/assignment-in-if.rs:51:28 + | +LL | if x == x && x == x && x = x { + | ---------------- ^ expected `bool`, found `usize` + | | + | expected because this is `bool` + +error[E0308]: mismatched types + --> $DIR/assignment-in-if.rs:51:8 + | +LL | if x == x && x == x && x = x { + | ^^^^^^^^^^^^^^^^^^^^^^^^^ expected `bool`, found `()` + | +help: you might have meant to compare for equality + | +LL | if x == x && x == x && x == x { + | + + +error[E0308]: mismatched types + --> $DIR/assignment-in-if.rs:57:12 + | +LL | if x = 1 && x == 1 { + | ^ expected `bool`, found integer + +error[E0308]: mismatched types + --> $DIR/assignment-in-if.rs:57:8 + | +LL | if x = 1 && x == 1 { + | ^^^^^^^^^^^^^^^ expected `bool`, found `()` + | +help: you might have meant to compare for equality + | +LL | if x == 1 && x == 1 { + | + + +error: aborting due to 13 previous errors + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/type/type-check/cannot_infer_local_or_array.rs b/tests/ui/type/type-check/cannot_infer_local_or_array.rs new file mode 100644 index 000000000..af7552523 --- /dev/null +++ b/tests/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/tests/ui/type/type-check/cannot_infer_local_or_array.stderr b/tests/ui/type/type-check/cannot_infer_local_or_array.stderr new file mode 100644 index 000000000..e823bad26 --- /dev/null +++ b/tests/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/tests/ui/type/type-check/cannot_infer_local_or_vec.rs b/tests/ui/type/type-check/cannot_infer_local_or_vec.rs new file mode 100644 index 000000000..e72ddabf3 --- /dev/null +++ b/tests/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/tests/ui/type/type-check/cannot_infer_local_or_vec.stderr b/tests/ui/type/type-check/cannot_infer_local_or_vec.stderr new file mode 100644 index 000000000..b63d2a3b6 --- /dev/null +++ b/tests/ui/type/type-check/cannot_infer_local_or_vec.stderr @@ -0,0 +1,14 @@ +error[E0282]: type annotations needed for `Vec` + --> $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 = vec![]; + | ++++++++ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0282`. diff --git a/tests/ui/type/type-check/cannot_infer_local_or_vec_in_tuples.rs b/tests/ui/type/type-check/cannot_infer_local_or_vec_in_tuples.rs new file mode 100644 index 000000000..d21456439 --- /dev/null +++ b/tests/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/tests/ui/type/type-check/cannot_infer_local_or_vec_in_tuples.stderr b/tests/ui/type/type-check/cannot_infer_local_or_vec_in_tuples.stderr new file mode 100644 index 000000000..e544b3695 --- /dev/null +++ b/tests/ui/type/type-check/cannot_infer_local_or_vec_in_tuples.stderr @@ -0,0 +1,14 @@ +error[E0282]: type annotations needed for `(Vec,)` + --> $DIR/cannot_infer_local_or_vec_in_tuples.rs:2:9 + | +LL | let (x, ) = (vec![], ); + | ^^^^^ ---------- type must be known at this point + | +help: consider giving this pattern a type, where the type for type parameter `T` is specified + | +LL | let (x, ): (Vec,) = (vec![], ); + | +++++++++++ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0282`. diff --git a/tests/ui/type/type-check/issue-22897.rs b/tests/ui/type/type-check/issue-22897.rs new file mode 100644 index 000000000..8171a0ef1 --- /dev/null +++ b/tests/ui/type/type-check/issue-22897.rs @@ -0,0 +1,5 @@ +fn main() { } + +fn unconstrained_type() { + []; //~ ERROR type annotations needed +} diff --git a/tests/ui/type/type-check/issue-22897.stderr b/tests/ui/type/type-check/issue-22897.stderr new file mode 100644 index 000000000..fae7b7926 --- /dev/null +++ b/tests/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/tests/ui/type/type-check/issue-40294.rs b/tests/ui/type/type-check/issue-40294.rs new file mode 100644 index 000000000..5493a4e5f --- /dev/null +++ b/tests/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/tests/ui/type/type-check/issue-40294.stderr b/tests/ui/type/type-check/issue-40294.stderr new file mode 100644 index 000000000..d15fd2341 --- /dev/null +++ b/tests/ui/type/type-check/issue-40294.stderr @@ -0,0 +1,17 @@ +error[E0283]: type annotations needed: cannot satisfy `&'a T: Foo` + --> $DIR/issue-40294.rs:6:19 + | +LL | where &'a T : Foo, + | ^^^ + | +note: multiple `impl`s or `where` clauses satisfying `&'a T: Foo` found + --> $DIR/issue-40294.rs:6:19 + | +LL | where &'a T : Foo, + | ^^^ +LL | &'b T : Foo + | ^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0283`. diff --git a/tests/ui/type/type-check/issue-41314.rs b/tests/ui/type/type-check/issue-41314.rs new file mode 100644 index 000000000..cbd39f5f9 --- /dev/null +++ b/tests/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/tests/ui/type/type-check/issue-41314.stderr b/tests/ui/type/type-check/issue-41314.stderr new file mode 100644 index 000000000..4a9bf6106 --- /dev/null +++ b/tests/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/tests/ui/type/type-check/issue-67273-assignment-match-prior-arm-bool-expected-unit.rs b/tests/ui/type/type-check/issue-67273-assignment-match-prior-arm-bool-expected-unit.rs new file mode 100644 index 000000000..c39ab9544 --- /dev/null +++ b/tests/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/tests/ui/type/type-check/issue-67273-assignment-match-prior-arm-bool-expected-unit.stderr b/tests/ui/type/type-check/issue-67273-assignment-match-prior-arm-bool-expected-unit.stderr new file mode 100644 index 000000000..a431fe89c --- /dev/null +++ b/tests/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/tests/ui/type/type-check/issue-88577-check-fn-with-more-than-65535-arguments.rs b/tests/ui/type/type-check/issue-88577-check-fn-with-more-than-65535-arguments.rs new file mode 100644 index 000000000..e50cc5865 --- /dev/null +++ b/tests/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/tests/ui/type/type-check/issue-88577-check-fn-with-more-than-65535-arguments.stderr b/tests/ui/type/type-check/issue-88577-check-fn-with-more-than-65535-arguments.stderr new file mode 100644 index 000000000..847bc517e --- /dev/null +++ b/tests/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:22 + | +LL | fn _f($($t: ()),*) {} + | ^ +... +LL | many_args!{[_]########## ######} + | -------------------------------- in this macro invocation + | + = note: this error originates in the macro `many_args` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to previous error + diff --git a/tests/ui/type/type-check/missing_trait_impl.rs b/tests/ui/type/type-check/missing_trait_impl.rs new file mode 100644 index 000000000..0e3e703a2 --- /dev/null +++ b/tests/ui/type/type-check/missing_trait_impl.rs @@ -0,0 +1,16 @@ +fn main() { +} + +fn foo(x: T, y: T) { + let z = x + y; //~ ERROR cannot add `T` to `T` +} + +fn bar(x: T) { + x += x; //~ ERROR binary assignment operation `+=` cannot be applied to type `T` +} + +fn baz(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/tests/ui/type/type-check/missing_trait_impl.stderr b/tests/ui/type/type-check/missing_trait_impl.stderr new file mode 100644 index 000000000..2b58cd418 --- /dev/null +++ b/tests/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(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(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(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(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/tests/ui/type/type-check/point-at-inference-2.rs b/tests/ui/type/type-check/point-at-inference-2.rs new file mode 100644 index 000000000..6557d7fa1 --- /dev/null +++ b/tests/ui/type/type-check/point-at-inference-2.rs @@ -0,0 +1,13 @@ +fn bar(_: Vec) {} +fn baz(_: &Vec<&i32>) {} +fn main() { + let v = vec![&1]; + bar(v); //~ ERROR E0308 + let v = vec![]; + baz(&v); + baz(&v); + bar(v); //~ ERROR E0308 + let v = vec![]; + baz(&v); + bar(v); //~ ERROR E0308 +} diff --git a/tests/ui/type/type-check/point-at-inference-2.stderr b/tests/ui/type/type-check/point-at-inference-2.stderr new file mode 100644 index 000000000..1368aba0d --- /dev/null +++ b/tests/ui/type/type-check/point-at-inference-2.stderr @@ -0,0 +1,51 @@ +error[E0308]: mismatched types + --> $DIR/point-at-inference-2.rs:5:9 + | +LL | bar(v); + | --- ^ expected `i32`, found `&{integer}` + | | + | arguments to this function are incorrect + | + = note: expected struct `Vec` + found struct `Vec<&{integer}>` +note: function defined here + --> $DIR/point-at-inference-2.rs:1:4 + | +LL | fn bar(_: Vec) {} + | ^^^ ----------- + +error[E0308]: mismatched types + --> $DIR/point-at-inference-2.rs:9:9 + | +LL | bar(v); + | --- ^ expected `i32`, found `&i32` + | | + | arguments to this function are incorrect + | + = note: expected struct `Vec` + found struct `Vec<&i32>` +note: function defined here + --> $DIR/point-at-inference-2.rs:1:4 + | +LL | fn bar(_: Vec) {} + | ^^^ ----------- + +error[E0308]: mismatched types + --> $DIR/point-at-inference-2.rs:12:9 + | +LL | bar(v); + | --- ^ expected `i32`, found `&i32` + | | + | arguments to this function are incorrect + | + = note: expected struct `Vec` + found struct `Vec<&i32>` +note: function defined here + --> $DIR/point-at-inference-2.rs:1:4 + | +LL | fn bar(_: Vec) {} + | ^^^ ----------- + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/type/type-check/point-at-inference-3.fixed b/tests/ui/type/type-check/point-at-inference-3.fixed new file mode 100644 index 000000000..44c057c0d --- /dev/null +++ b/tests/ui/type/type-check/point-at-inference-3.fixed @@ -0,0 +1,11 @@ +// run-rustfix +fn main() { + let mut v = Vec::new(); + v.push(0i32); + v.push(0); + v.push(1i32); //~ ERROR mismatched types + //~^ NOTE expected `i32`, found `u32` + //~| NOTE arguments to this method are incorrect + //~| NOTE associated function defined here + //~| HELP change the type of the numeric literal from `u32` to `i32` +} diff --git a/tests/ui/type/type-check/point-at-inference-3.rs b/tests/ui/type/type-check/point-at-inference-3.rs new file mode 100644 index 000000000..e7ae54384 --- /dev/null +++ b/tests/ui/type/type-check/point-at-inference-3.rs @@ -0,0 +1,11 @@ +// run-rustfix +fn main() { + let mut v = Vec::new(); + v.push(0i32); + v.push(0); + v.push(1u32); //~ ERROR mismatched types + //~^ NOTE expected `i32`, found `u32` + //~| NOTE arguments to this method are incorrect + //~| NOTE associated function defined here + //~| HELP change the type of the numeric literal from `u32` to `i32` +} diff --git a/tests/ui/type/type-check/point-at-inference-3.stderr b/tests/ui/type/type-check/point-at-inference-3.stderr new file mode 100644 index 000000000..d7936e39c --- /dev/null +++ b/tests/ui/type/type-check/point-at-inference-3.stderr @@ -0,0 +1,18 @@ +error[E0308]: mismatched types + --> $DIR/point-at-inference-3.rs:6:12 + | +LL | v.push(1u32); + | ---- ^^^^ expected `i32`, found `u32` + | | + | arguments to this method are incorrect + | +note: associated function defined here + --> $SRC_DIR/alloc/src/vec/mod.rs:LL:COL +help: change the type of the numeric literal from `u32` to `i32` + | +LL | v.push(1i32); + | ~~~ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/type/type-check/point-at-inference.rs b/tests/ui/type/type-check/point-at-inference.rs new file mode 100644 index 000000000..5c46dd4ed --- /dev/null +++ b/tests/ui/type/type-check/point-at-inference.rs @@ -0,0 +1,12 @@ +fn bar(_: Vec) {} +fn baz(_: &impl std::any::Any) {} +fn main() { + let v = vec![1, 2, 3, 4, 5]; + let mut foo = vec![]; + baz(&foo); + for i in &v { + foo.push(i); + } + baz(&foo); + bar(foo); //~ ERROR E0308 +} diff --git a/tests/ui/type/type-check/point-at-inference.stderr b/tests/ui/type/type-check/point-at-inference.stderr new file mode 100644 index 000000000..2e17e5c5f --- /dev/null +++ b/tests/ui/type/type-check/point-at-inference.stderr @@ -0,0 +1,19 @@ +error[E0308]: mismatched types + --> $DIR/point-at-inference.rs:11:9 + | +LL | bar(foo); + | --- ^^^ expected `i32`, found `&{integer}` + | | + | arguments to this function are incorrect + | + = note: expected struct `Vec` + found struct `Vec<&{integer}>` +note: function defined here + --> $DIR/point-at-inference.rs:1:4 + | +LL | fn bar(_: Vec) {} + | ^^^ ----------- + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/type/type-check/unknown_type_for_closure.rs b/tests/ui/type/type-check/unknown_type_for_closure.rs new file mode 100644 index 000000000..167687c18 --- /dev/null +++ b/tests/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/tests/ui/type/type-check/unknown_type_for_closure.stderr b/tests/ui/type/type-check/unknown_type_for_closure.stderr new file mode 100644 index 000000000..e5e29aabf --- /dev/null +++ b/tests/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 = |_: /* Type */| {}; + | ++++++++++++ + +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::::new() }; + | +++++ + +error: aborting due to 4 previous errors + +For more information about this error, try `rustc --explain E0282`. -- cgit v1.2.3