summaryrefslogtreecommitdiffstats
path: root/tests/ui/block-result
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:13 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:13 +0000
commit218caa410aa38c29984be31a5229b9fa717560ee (patch)
treec54bd55eeb6e4c508940a30e94c0032fbd45d677 /tests/ui/block-result
parentReleasing progress-linux version 1.67.1+dfsg1-1~progress7.99u1. (diff)
downloadrustc-218caa410aa38c29984be31a5229b9fa717560ee.tar.xz
rustc-218caa410aa38c29984be31a5229b9fa717560ee.zip
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/block-result')
-rw-r--r--tests/ui/block-result/block-must-not-have-result-do.rs5
-rw-r--r--tests/ui/block-result/block-must-not-have-result-do.stderr9
-rw-r--r--tests/ui/block-result/block-must-not-have-result-res.rs10
-rw-r--r--tests/ui/block-result/block-must-not-have-result-res.stderr11
-rw-r--r--tests/ui/block-result/block-must-not-have-result-while.rs6
-rw-r--r--tests/ui/block-result/block-must-not-have-result-while.stderr21
-rw-r--r--tests/ui/block-result/consider-removing-last-semi.fixed20
-rw-r--r--tests/ui/block-result/consider-removing-last-semi.rs20
-rw-r--r--tests/ui/block-result/consider-removing-last-semi.stderr36
-rw-r--r--tests/ui/block-result/issue-11714.rs7
-rw-r--r--tests/ui/block-result/issue-11714.stderr14
-rw-r--r--tests/ui/block-result/issue-13428.rs16
-rw-r--r--tests/ui/block-result/issue-13428.stderr22
-rw-r--r--tests/ui/block-result/issue-13624.rs29
-rw-r--r--tests/ui/block-result/issue-13624.stderr19
-rw-r--r--tests/ui/block-result/issue-20862.rs9
-rw-r--r--tests/ui/block-result/issue-20862.stderr26
-rw-r--r--tests/ui/block-result/issue-22645.rs17
-rw-r--r--tests/ui/block-result/issue-22645.stderr28
-rw-r--r--tests/ui/block-result/issue-3563.rs7
-rw-r--r--tests/ui/block-result/issue-3563.stderr9
-rw-r--r--tests/ui/block-result/issue-5500.rs7
-rw-r--r--tests/ui/block-result/issue-5500.stderr19
-rw-r--r--tests/ui/block-result/unexpected-return-on-unit.rs14
-rw-r--r--tests/ui/block-result/unexpected-return-on-unit.stderr18
25 files changed, 399 insertions, 0 deletions
diff --git a/tests/ui/block-result/block-must-not-have-result-do.rs b/tests/ui/block-result/block-must-not-have-result-do.rs
new file mode 100644
index 000000000..4fdb69778
--- /dev/null
+++ b/tests/ui/block-result/block-must-not-have-result-do.rs
@@ -0,0 +1,5 @@
+fn main() {
+ loop {
+ true //~ ERROR mismatched types
+ }
+}
diff --git a/tests/ui/block-result/block-must-not-have-result-do.stderr b/tests/ui/block-result/block-must-not-have-result-do.stderr
new file mode 100644
index 000000000..914886f81
--- /dev/null
+++ b/tests/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/tests/ui/block-result/block-must-not-have-result-res.rs b/tests/ui/block-result/block-must-not-have-result-res.rs
new file mode 100644
index 000000000..7e86274a1
--- /dev/null
+++ b/tests/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/tests/ui/block-result/block-must-not-have-result-res.stderr b/tests/ui/block-result/block-must-not-have-result-res.stderr
new file mode 100644
index 000000000..0080d06dd
--- /dev/null
+++ b/tests/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/tests/ui/block-result/block-must-not-have-result-while.rs b/tests/ui/block-result/block-must-not-have-result-while.rs
new file mode 100644
index 000000000..418059bf2
--- /dev/null
+++ b/tests/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/tests/ui/block-result/block-must-not-have-result-while.stderr b/tests/ui/block-result/block-must-not-have-result-while.stderr
new file mode 100644
index 000000000..7f96aa289
--- /dev/null
+++ b/tests/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/tests/ui/block-result/consider-removing-last-semi.fixed b/tests/ui/block-result/consider-removing-last-semi.fixed
new file mode 100644
index 000000000..36a769fe5
--- /dev/null
+++ b/tests/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/tests/ui/block-result/consider-removing-last-semi.rs b/tests/ui/block-result/consider-removing-last-semi.rs
new file mode 100644
index 000000000..b9a731489
--- /dev/null
+++ b/tests/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/tests/ui/block-result/consider-removing-last-semi.stderr b/tests/ui/block-result/consider-removing-last-semi.stderr
new file mode 100644
index 000000000..9be0367ae
--- /dev/null
+++ b/tests/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 to return this value
+
+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 to return this value
+
+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 to return this value
+
+error: aborting due to 3 previous errors
+
+For more information about this error, try `rustc --explain E0308`.
diff --git a/tests/ui/block-result/issue-11714.rs b/tests/ui/block-result/issue-11714.rs
new file mode 100644
index 000000000..3dda7e801
--- /dev/null
+++ b/tests/ui/block-result/issue-11714.rs
@@ -0,0 +1,7 @@
+fn blah() -> i32 { //~ ERROR mismatched types
+ 1
+
+ ;
+}
+
+fn main() { }
diff --git a/tests/ui/block-result/issue-11714.stderr b/tests/ui/block-result/issue-11714.stderr
new file mode 100644
index 000000000..42fb3d3d4
--- /dev/null
+++ b/tests/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 to return this value
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0308`.
diff --git a/tests/ui/block-result/issue-13428.rs b/tests/ui/block-result/issue-13428.rs
new file mode 100644
index 000000000..ac8596435
--- /dev/null
+++ b/tests/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/tests/ui/block-result/issue-13428.stderr b/tests/ui/block-result/issue-13428.stderr
new file mode 100644
index 000000000..2b386d10c
--- /dev/null
+++ b/tests/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 to return this value
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0308`.
diff --git a/tests/ui/block-result/issue-13624.rs b/tests/ui/block-result/issue-13624.rs
new file mode 100644
index 000000000..4d2844cc5
--- /dev/null
+++ b/tests/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/tests/ui/block-result/issue-13624.stderr b/tests/ui/block-result/issue-13624.stderr
new file mode 100644
index 000000000..13070b4e8
--- /dev/null
+++ b/tests/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/tests/ui/block-result/issue-20862.rs b/tests/ui/block-result/issue-20862.rs
new file mode 100644
index 000000000..e435fd7ae
--- /dev/null
+++ b/tests/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/tests/ui/block-result/issue-20862.stderr b/tests/ui/block-result/issue-20862.stderr
new file mode 100644
index 000000000..37bad64c5
--- /dev/null
+++ b/tests/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/tests/ui/block-result/issue-22645.rs b/tests/ui/block-result/issue-22645.rs
new file mode 100644
index 000000000..5f7fb8dd3
--- /dev/null
+++ b/tests/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/tests/ui/block-result/issue-22645.stderr b/tests/ui/block-result/issue-22645.stderr
new file mode 100644
index 000000000..24341c0f5
--- /dev/null
+++ b/tests/ui/block-result/issue-22645.stderr
@@ -0,0 +1,28 @@
+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 for `Bob` to implement `Add<{integer}>`
+ --> $DIR/issue-22645.rs:8:19
+ |
+LL | impl<RHS: Scalar> Add <RHS> for Bob {
+ | ------ ^^^^^^^^^ ^^^
+ | |
+ | unsatisfied trait bound introduced here
+
+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/tests/ui/block-result/issue-3563.rs b/tests/ui/block-result/issue-3563.rs
new file mode 100644
index 000000000..0b652a1f5
--- /dev/null
+++ b/tests/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/tests/ui/block-result/issue-3563.stderr b/tests/ui/block-result/issue-3563.stderr
new file mode 100644
index 000000000..be551f6e8
--- /dev/null
+++ b/tests/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 a method with a similar name: `a`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0599`.
diff --git a/tests/ui/block-result/issue-5500.rs b/tests/ui/block-result/issue-5500.rs
new file mode 100644
index 000000000..577987a45
--- /dev/null
+++ b/tests/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/tests/ui/block-result/issue-5500.stderr b/tests/ui/block-result/issue-5500.stderr
new file mode 100644
index 000000000..211a60528
--- /dev/null
+++ b/tests/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/tests/ui/block-result/unexpected-return-on-unit.rs b/tests/ui/block-result/unexpected-return-on-unit.rs
new file mode 100644
index 000000000..2fcbfe8c0
--- /dev/null
+++ b/tests/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/tests/ui/block-result/unexpected-return-on-unit.stderr b/tests/ui/block-result/unexpected-return-on-unit.stderr
new file mode 100644
index 000000000..4acb955a8
--- /dev/null
+++ b/tests/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`.