Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide-diagnostics/src/handlers/unused_must_use.rs')
-rw-r--r--crates/ide-diagnostics/src/handlers/unused_must_use.rs135
1 files changed, 135 insertions, 0 deletions
diff --git a/crates/ide-diagnostics/src/handlers/unused_must_use.rs b/crates/ide-diagnostics/src/handlers/unused_must_use.rs
index e8d0717c91..2173dc9c0a 100644
--- a/crates/ide-diagnostics/src/handlers/unused_must_use.rs
+++ b/crates/ide-diagnostics/src/handlers/unused_must_use.rs
@@ -129,4 +129,139 @@ fn main() {
"#,
);
}
+
+ #[test]
+ fn block_tail_expression_in_stmt_position() {
+ check_diagnostics(
+ r#"
+#[must_use]
+fn produces() -> i32 { 0 }
+fn main() {
+ {
+ produces()
+ //^^^^^^^^^^ warn: unused return value that must be used
+ };
+}
+"#,
+ );
+ }
+
+ #[test]
+ fn unsafe_block_tail_expression_in_stmt_position() {
+ check_diagnostics(
+ r#"
+#[must_use]
+unsafe fn produces() -> i32 { 0 }
+fn main() {
+ unsafe {
+ produces()
+ //^^^^^^^^^^ warn: unused return value that must be used
+ };
+}
+"#,
+ );
+ }
+
+ #[test]
+ fn nested_block_tail_expression() {
+ check_diagnostics(
+ r#"
+#[must_use]
+fn produces() -> i32 { 0 }
+fn main() {
+ {
+ {
+ produces()
+ //^^^^^^^^^^ warn: unused return value that must be used
+ }
+ };
+}
+"#,
+ );
+ }
+
+ #[test]
+ fn no_warning_when_block_tail_is_bound() {
+ check_diagnostics(
+ r#"
+#[must_use]
+fn produces() -> i32 { 0 }
+fn main() {
+ let _x = {
+ produces()
+ };
+}
+"#,
+ );
+ }
+
+ #[test]
+ fn if_branches_in_stmt_position() {
+ check_diagnostics(
+ r#"
+#[must_use]
+fn produces() -> i32 { 0 }
+fn main() {
+ if true {
+ produces()
+ //^^^^^^^^^^ warn: unused return value that must be used
+ } else {
+ produces()
+ //^^^^^^^^^^ warn: unused return value that must be used
+ };
+}
+"#,
+ );
+ }
+
+ #[test]
+ fn match_arms_in_stmt_position() {
+ check_diagnostics(
+ r#"
+#[must_use]
+fn produces() -> i32 { 0 }
+fn main() {
+ match 0 {
+ 0 => produces(),
+ //^^^^^^^^^^ warn: unused return value that must be used
+ _ => produces(),
+ //^^^^^^^^^^ warn: unused return value that must be used
+ };
+}
+"#,
+ );
+ }
+
+ #[test]
+ fn const_block_in_stmt_position() {
+ check_diagnostics(
+ r#"
+#[must_use]
+const fn produces() -> i32 { 0 }
+fn main() {
+ const {
+ produces()
+ //^^^^^^^^^^ warn: unused return value that must be used
+ };
+}
+"#,
+ );
+ }
+
+ #[test]
+ fn must_use_type_through_block() {
+ check_diagnostics(
+ r#"
+#[must_use]
+struct Important;
+fn produces() -> Important { Important }
+fn main() {
+ {
+ produces()
+ //^^^^^^^^^^ warn: unused return value that must be used
+ };
+}
+"#,
+ );
+ }
}