about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--compiler/rustc_lint/src/unused.rs2
-rw-r--r--tests/ui/lint/unused/unused-parens-assign-expr-in-ret-issue-131989.rs9
2 files changed, 11 insertions, 0 deletions
diff --git a/compiler/rustc_lint/src/unused.rs b/compiler/rustc_lint/src/unused.rs
index b50a95e7d2b..52126afcf5a 100644
--- a/compiler/rustc_lint/src/unused.rs
+++ b/compiler/rustc_lint/src/unused.rs
@@ -1063,6 +1063,8 @@ impl UnusedDelimLint for UnusedParens {
                                 _,
                                 _,
                             ) if node.is_lazy()))
+                    && !(ctx == UnusedDelimsCtx::ReturnValue
+                        && matches!(inner.kind, ast::ExprKind::Assign(_, _, _)))
                 {
                     self.emit_unused_delims_expr(cx, value, ctx, left_pos, right_pos, is_kw)
                 }
diff --git a/tests/ui/lint/unused/unused-parens-assign-expr-in-ret-issue-131989.rs b/tests/ui/lint/unused/unused-parens-assign-expr-in-ret-issue-131989.rs
new file mode 100644
index 00000000000..56973f128e1
--- /dev/null
+++ b/tests/ui/lint/unused/unused-parens-assign-expr-in-ret-issue-131989.rs
@@ -0,0 +1,9 @@
+//@ check-pass
+#![warn(unused_parens)]
+
+fn foo() {
+    return (_ = 42);
+    // lint unused_parens should not be triggered here.
+}
+
+fn main() {}