From: Islam-Imad <[email protected]>

the problem is compiling if-expr doesn't set translated to unit type.

gcc/rust/ChangeLog:

        * backend/rust-compile-expr.cc (CompileExpr::visit): set unit type.

gcc/testsuite/ChangeLog:

        * rust/compile/issue-4517.rs: New test.

Signed-off-by: Islam-Imad <[email protected]>
---
 gcc/rust/backend/rust-compile-expr.cc    | 8 +++++---
 gcc/testsuite/rust/compile/issue-4517.rs | 5 +++++
 2 files changed, 10 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/rust/compile/issue-4517.rs

diff --git a/gcc/rust/backend/rust-compile-expr.cc 
b/gcc/rust/backend/rust-compile-expr.cc
index 40bd2829f65..55b3534a1be 100644
--- a/gcc/rust/backend/rust-compile-expr.cc
+++ b/gcc/rust/backend/rust-compile-expr.cc
@@ -360,6 +360,7 @@ CompileExpr::visit (HIR::IfExpr &expr)
 {
   auto stmt = CompileConditionalBlocks::compile (&expr, ctx, nullptr);
   ctx->add_statement (stmt);
+  translated = unit_expression (expr.get_locus ());
 }
 
 void
@@ -367,9 +368,7 @@ CompileExpr::visit (HIR::InlineAsm &expr)
 {
   CompileAsm asm_codegen (ctx);
   ctx->add_statement (asm_codegen.tree_codegen_asm (expr));
-  // translated = build_asm_expr (0, NULL_TREE, NULL_TREE, NULL_TREE, 
NULL_TREE,
-  //                  NULL_TREE, true, true);
-  // CompileAsm::asm_build_expr (expr);
+  translated = unit_expression (expr.get_locus ());
 }
 
 void
@@ -377,6 +376,7 @@ CompileExpr::visit (HIR::LlvmInlineAsm &expr)
 {
   CompileLlvmAsm asm_codegen (ctx);
   ctx->add_statement (asm_codegen.tree_codegen_asm (expr));
+  translated = unit_expression (expr.get_locus ());
 }
 
 void
@@ -848,6 +848,7 @@ CompileExpr::visit (HIR::WhileLoopExpr &expr)
 
   tree loop_expr = Backend::loop_expression (loop_block, expr.get_locus ());
   ctx->add_statement (loop_expr);
+  translated = unit_expression (expr.get_locus ());
 }
 
 void
@@ -1099,6 +1100,7 @@ CompileExpr::visit (HIR::AssignmentExpr &expr)
     = Backend::assignment_statement (lvalue, rvalue, expr.get_locus ());
 
   ctx->add_statement (assignment);
+  translated = unit_expression (expr.get_locus ());
 }
 
 // Helper for CompileExpr::visit (HIR::MatchExpr).
diff --git a/gcc/testsuite/rust/compile/issue-4517.rs 
b/gcc/testsuite/rust/compile/issue-4517.rs
new file mode 100644
index 00000000000..9db4082a191
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-4517.rs
@@ -0,0 +1,5 @@
+#![feature(no_core)]
+#![no_core]
+
+const _: () = if true {};
+const x: () = if true {}; // { dg-warning "unused name" "" { target *-*-* } }
-- 
2.50.1

Reply via email to