diff options
Diffstat (limited to '')
25 files changed, 397 insertions, 0 deletions
diff --git a/src/test/ui/block-result/block-must-not-have-result-do.rs b/src/test/ui/block-result/block-must-not-have-result-do.rs new file mode 100644 index 000000000..4fdb69778 --- /dev/null +++ b/src/test/ui/block-result/block-must-not-have-result-do.rs @@ -0,0 +1,5 @@ +fn main() { + loop { + true //~ ERROR mismatched types + } +} diff --git a/src/test/ui/block-result/block-must-not-have-result-do.stderr b/src/test/ui/block-result/block-must-not-have-result-do.stderr new file mode 100644 index 000000000..914886f81 --- /dev/null +++ b/src/test/ui/block-result/block-must-not-have-result-do.stderr @@ -0,0 +1,9 @@ +error[E0308]: mismatched types + --> $DIR/block-must-not-have-result-do.rs:3:9 + | +LL | true + | ^^^^ expected `()`, found `bool` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/block-result/block-must-not-have-result-res.rs b/src/test/ui/block-result/block-must-not-have-result-res.rs new file mode 100644 index 000000000..7e86274a1 --- /dev/null +++ b/src/test/ui/block-result/block-must-not-have-result-res.rs @@ -0,0 +1,10 @@ +struct R; + +impl Drop for R { + fn drop(&mut self) { + true //~ ERROR mismatched types + } +} + +fn main() { +} diff --git a/src/test/ui/block-result/block-must-not-have-result-res.stderr b/src/test/ui/block-result/block-must-not-have-result-res.stderr new file mode 100644 index 000000000..0080d06dd --- /dev/null +++ b/src/test/ui/block-result/block-must-not-have-result-res.stderr @@ -0,0 +1,11 @@ +error[E0308]: mismatched types + --> $DIR/block-must-not-have-result-res.rs:5:9 + | +LL | fn drop(&mut self) { + | - expected `()` because of default return type +LL | true + | ^^^^ expected `()`, found `bool` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/block-result/block-must-not-have-result-while.rs b/src/test/ui/block-result/block-must-not-have-result-while.rs new file mode 100644 index 000000000..418059bf2 --- /dev/null +++ b/src/test/ui/block-result/block-must-not-have-result-while.rs @@ -0,0 +1,6 @@ +fn main() { + while true { //~ WARN denote infinite loops with + true //~ ERROR mismatched types + //~| expected `()`, found `bool` + } +} diff --git a/src/test/ui/block-result/block-must-not-have-result-while.stderr b/src/test/ui/block-result/block-must-not-have-result-while.stderr new file mode 100644 index 000000000..7f96aa289 --- /dev/null +++ b/src/test/ui/block-result/block-must-not-have-result-while.stderr @@ -0,0 +1,21 @@ +warning: denote infinite loops with `loop { ... }` + --> $DIR/block-must-not-have-result-while.rs:2:5 + | +LL | while true { + | ^^^^^^^^^^ help: use `loop` + | + = note: `#[warn(while_true)]` on by default + +error[E0308]: mismatched types + --> $DIR/block-must-not-have-result-while.rs:3:9 + | +LL | / while true { +LL | | true + | | ^^^^ expected `()`, found `bool` +LL | | +LL | | } + | |_____- expected this to be `()` + +error: aborting due to previous error; 1 warning emitted + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/block-result/consider-removing-last-semi.fixed b/src/test/ui/block-result/consider-removing-last-semi.fixed new file mode 100644 index 000000000..36a769fe5 --- /dev/null +++ b/src/test/ui/block-result/consider-removing-last-semi.fixed @@ -0,0 +1,20 @@ +// run-rustfix + +pub fn f() -> String { //~ ERROR mismatched types + 0u8; + "bla".to_string() +} + +pub fn g() -> String { //~ ERROR mismatched types + "this won't work".to_string(); + "removeme".to_string() +} + +pub fn macro_tests() -> u32 { //~ ERROR mismatched types + macro_rules! mac { + () => (1); + } + mac!() +} + +fn main() {} diff --git a/src/test/ui/block-result/consider-removing-last-semi.rs b/src/test/ui/block-result/consider-removing-last-semi.rs new file mode 100644 index 000000000..b9a731489 --- /dev/null +++ b/src/test/ui/block-result/consider-removing-last-semi.rs @@ -0,0 +1,20 @@ +// run-rustfix + +pub fn f() -> String { //~ ERROR mismatched types + 0u8; + "bla".to_string(); +} + +pub fn g() -> String { //~ ERROR mismatched types + "this won't work".to_string(); + "removeme".to_string(); +} + +pub fn macro_tests() -> u32 { //~ ERROR mismatched types + macro_rules! mac { + () => (1); + } + mac!(); +} + +fn main() {} diff --git a/src/test/ui/block-result/consider-removing-last-semi.stderr b/src/test/ui/block-result/consider-removing-last-semi.stderr new file mode 100644 index 000000000..2412dcd32 --- /dev/null +++ b/src/test/ui/block-result/consider-removing-last-semi.stderr @@ -0,0 +1,36 @@ +error[E0308]: mismatched types + --> $DIR/consider-removing-last-semi.rs:3:15 + | +LL | pub fn f() -> String { + | - ^^^^^^ expected struct `String`, found `()` + | | + | implicitly returns `()` as its body has no tail or `return` expression +LL | 0u8; +LL | "bla".to_string(); + | - help: remove this semicolon + +error[E0308]: mismatched types + --> $DIR/consider-removing-last-semi.rs:8:15 + | +LL | pub fn g() -> String { + | - ^^^^^^ expected struct `String`, found `()` + | | + | implicitly returns `()` as its body has no tail or `return` expression +LL | "this won't work".to_string(); +LL | "removeme".to_string(); + | - help: remove this semicolon + +error[E0308]: mismatched types + --> $DIR/consider-removing-last-semi.rs:13:25 + | +LL | pub fn macro_tests() -> u32 { + | ----------- ^^^ expected `u32`, found `()` + | | + | implicitly returns `()` as its body has no tail or `return` expression +... +LL | mac!(); + | - help: remove this semicolon + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/block-result/issue-11714.rs b/src/test/ui/block-result/issue-11714.rs new file mode 100644 index 000000000..3dda7e801 --- /dev/null +++ b/src/test/ui/block-result/issue-11714.rs @@ -0,0 +1,7 @@ +fn blah() -> i32 { //~ ERROR mismatched types + 1 + + ; +} + +fn main() { } diff --git a/src/test/ui/block-result/issue-11714.stderr b/src/test/ui/block-result/issue-11714.stderr new file mode 100644 index 000000000..5b8d96fd4 --- /dev/null +++ b/src/test/ui/block-result/issue-11714.stderr @@ -0,0 +1,14 @@ +error[E0308]: mismatched types + --> $DIR/issue-11714.rs:1:14 + | +LL | fn blah() -> i32 { + | ---- ^^^ expected `i32`, found `()` + | | + | implicitly returns `()` as its body has no tail or `return` expression +... +LL | ; + | - help: remove this semicolon + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/block-result/issue-13428.rs b/src/test/ui/block-result/issue-13428.rs new file mode 100644 index 000000000..ac8596435 --- /dev/null +++ b/src/test/ui/block-result/issue-13428.rs @@ -0,0 +1,16 @@ +// Regression test for #13428 + +fn foo() -> String { //~ ERROR mismatched types + format!("Hello {}", + "world") + // Put the trailing semicolon on its own line to test that the + // note message gets the offending semicolon exactly + ; +} + +fn bar() -> String { //~ ERROR mismatched types + "foobar".to_string() + ; +} + +pub fn main() {} diff --git a/src/test/ui/block-result/issue-13428.stderr b/src/test/ui/block-result/issue-13428.stderr new file mode 100644 index 000000000..a33448edf --- /dev/null +++ b/src/test/ui/block-result/issue-13428.stderr @@ -0,0 +1,22 @@ +error[E0308]: mismatched types + --> $DIR/issue-13428.rs:3:13 + | +LL | fn foo() -> String { + | --- ^^^^^^ expected struct `String`, found `()` + | | + | implicitly returns `()` as its body has no tail or `return` expression + +error[E0308]: mismatched types + --> $DIR/issue-13428.rs:11:13 + | +LL | fn bar() -> String { + | --- ^^^^^^ expected struct `String`, found `()` + | | + | implicitly returns `()` as its body has no tail or `return` expression +LL | "foobar".to_string() +LL | ; + | - help: remove this semicolon + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/block-result/issue-13624.rs b/src/test/ui/block-result/issue-13624.rs new file mode 100644 index 000000000..4d2844cc5 --- /dev/null +++ b/src/test/ui/block-result/issue-13624.rs @@ -0,0 +1,29 @@ +mod a { + pub enum Enum { + EnumStructVariant { x: u8, y: u8, z: u8 } + } + + pub fn get_enum_struct_variant() -> () { + Enum::EnumStructVariant { x: 1, y: 2, z: 3 } + //~^ ERROR mismatched types + //~| expected `()`, found enum `Enum` + } +} + +mod b { + mod test { + use a; + + fn test_enum_struct_variant() { + let enum_struct_variant = ::a::get_enum_struct_variant(); + match enum_struct_variant { + a::Enum::EnumStructVariant { x, y, z } => { + //~^ ERROR mismatched types + //~| expected `()`, found enum `Enum` + } + } + } + } +} + +fn main() {} diff --git a/src/test/ui/block-result/issue-13624.stderr b/src/test/ui/block-result/issue-13624.stderr new file mode 100644 index 000000000..13070b4e8 --- /dev/null +++ b/src/test/ui/block-result/issue-13624.stderr @@ -0,0 +1,19 @@ +error[E0308]: mismatched types + --> $DIR/issue-13624.rs:7:5 + | +LL | pub fn get_enum_struct_variant() -> () { + | -- expected `()` because of return type +LL | Enum::EnumStructVariant { x: 1, y: 2, z: 3 } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found enum `Enum` + +error[E0308]: mismatched types + --> $DIR/issue-13624.rs:20:9 + | +LL | match enum_struct_variant { + | ------------------- this expression has type `()` +LL | a::Enum::EnumStructVariant { x, y, z } => { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found enum `Enum` + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/block-result/issue-20862.rs b/src/test/ui/block-result/issue-20862.rs new file mode 100644 index 000000000..e435fd7ae --- /dev/null +++ b/src/test/ui/block-result/issue-20862.rs @@ -0,0 +1,9 @@ +fn foo(x: i32) { + |y| x + y +//~^ ERROR: mismatched types +} + +fn main() { + let x = foo(5)(2); +//~^ ERROR: expected function, found `()` +} diff --git a/src/test/ui/block-result/issue-20862.stderr b/src/test/ui/block-result/issue-20862.stderr new file mode 100644 index 000000000..37bad64c5 --- /dev/null +++ b/src/test/ui/block-result/issue-20862.stderr @@ -0,0 +1,26 @@ +error[E0308]: mismatched types + --> $DIR/issue-20862.rs:2:5 + | +LL | fn foo(x: i32) { + | - help: a return type might be missing here: `-> _` +LL | |y| x + y + | ^^^^^^^^^ expected `()`, found closure + | + = note: expected unit type `()` + found closure `[closure@$DIR/issue-20862.rs:2:5: 2:8]` + +error[E0618]: expected function, found `()` + --> $DIR/issue-20862.rs:7:13 + | +LL | fn foo(x: i32) { + | -------------- `foo` defined here returns `()` +... +LL | let x = foo(5)(2); + | ^^^^^^--- + | | + | call expression requires function + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0308, E0618. +For more information about an error, try `rustc --explain E0308`. diff --git a/src/test/ui/block-result/issue-22645.rs b/src/test/ui/block-result/issue-22645.rs new file mode 100644 index 000000000..5f7fb8dd3 --- /dev/null +++ b/src/test/ui/block-result/issue-22645.rs @@ -0,0 +1,17 @@ +use std::ops::Add; + +trait Scalar {} +impl Scalar for f64 {} + +struct Bob; + +impl<RHS: Scalar> Add <RHS> for Bob { + type Output = Bob; + fn add(self, rhs : RHS) -> Bob { Bob } +} + +fn main() { + let b = Bob + 3.5; + b + 3 //~ ERROR E0277 + //~^ ERROR: mismatched types +} diff --git a/src/test/ui/block-result/issue-22645.stderr b/src/test/ui/block-result/issue-22645.stderr new file mode 100644 index 000000000..31663e8e8 --- /dev/null +++ b/src/test/ui/block-result/issue-22645.stderr @@ -0,0 +1,26 @@ +error[E0277]: the trait bound `{integer}: Scalar` is not satisfied + --> $DIR/issue-22645.rs:15:5 + | +LL | b + 3 + | ^ the trait `Scalar` is not implemented for `{integer}` + | + = help: the trait `Scalar` is implemented for `f64` +note: required because of the requirements on the impl of `Add<{integer}>` for `Bob` + --> $DIR/issue-22645.rs:8:19 + | +LL | impl<RHS: Scalar> Add <RHS> for Bob { + | ^^^^^^^^^ ^^^ + +error[E0308]: mismatched types + --> $DIR/issue-22645.rs:15:3 + | +LL | fn main() { + | - expected `()` because of default return type +LL | let b = Bob + 3.5; +LL | b + 3 + | ^^^^^ expected `()`, found struct `Bob` + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0277, E0308. +For more information about an error, try `rustc --explain E0277`. diff --git a/src/test/ui/block-result/issue-3563.rs b/src/test/ui/block-result/issue-3563.rs new file mode 100644 index 000000000..0b652a1f5 --- /dev/null +++ b/src/test/ui/block-result/issue-3563.rs @@ -0,0 +1,7 @@ +trait A { + fn a(&self) { + || self.b() + //~^ ERROR no method named `b` found + } +} +fn main() {} diff --git a/src/test/ui/block-result/issue-3563.stderr b/src/test/ui/block-result/issue-3563.stderr new file mode 100644 index 000000000..5255e48be --- /dev/null +++ b/src/test/ui/block-result/issue-3563.stderr @@ -0,0 +1,9 @@ +error[E0599]: no method named `b` found for reference `&Self` in the current scope + --> $DIR/issue-3563.rs:3:17 + | +LL | || self.b() + | ^ help: there is an associated function with a similar name: `a` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0599`. diff --git a/src/test/ui/block-result/issue-5500.rs b/src/test/ui/block-result/issue-5500.rs new file mode 100644 index 000000000..577987a45 --- /dev/null +++ b/src/test/ui/block-result/issue-5500.rs @@ -0,0 +1,7 @@ +fn main() { + &panic!() + //~^ ERROR mismatched types + //~| expected unit type `()` + //~| found reference `&_` + //~| expected `()`, found reference +} diff --git a/src/test/ui/block-result/issue-5500.stderr b/src/test/ui/block-result/issue-5500.stderr new file mode 100644 index 000000000..211a60528 --- /dev/null +++ b/src/test/ui/block-result/issue-5500.stderr @@ -0,0 +1,19 @@ +error[E0308]: mismatched types + --> $DIR/issue-5500.rs:2:5 + | +LL | fn main() { + | - expected `()` because of default return type +LL | &panic!() + | ^^^^^^^^^ expected `()`, found reference + | + = note: expected unit type `()` + found reference `&_` +help: consider removing the borrow + | +LL - &panic!() +LL + panic!() + | + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/block-result/unexpected-return-on-unit.rs b/src/test/ui/block-result/unexpected-return-on-unit.rs new file mode 100644 index 000000000..2fcbfe8c0 --- /dev/null +++ b/src/test/ui/block-result/unexpected-return-on-unit.rs @@ -0,0 +1,14 @@ +// Test that we do some basic error correction in the tokeniser (and don't spew +// too many bogus errors). + +fn foo() -> usize { + 3 +} + +fn bar() { + foo() //~ ERROR mismatched types +} + +fn main() { + bar() +} diff --git a/src/test/ui/block-result/unexpected-return-on-unit.stderr b/src/test/ui/block-result/unexpected-return-on-unit.stderr new file mode 100644 index 000000000..4acb955a8 --- /dev/null +++ b/src/test/ui/block-result/unexpected-return-on-unit.stderr @@ -0,0 +1,18 @@ +error[E0308]: mismatched types + --> $DIR/unexpected-return-on-unit.rs:9:5 + | +LL | foo() + | ^^^^^ expected `()`, found `usize` + | +help: consider using a semicolon here + | +LL | foo(); + | + +help: try adding a return type + | +LL | fn bar() -> usize { + | ++++++++ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. |