aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorDavid Faust <david.faust@oracle.com>2022-05-03 15:12:24 -0700
committerDavid Faust <david.faust@oracle.com>2022-05-03 15:12:24 -0700
commit0472834ddf177038d343b193acab70b2859656f8 (patch)
tree06493fe060220f20270ec1a69dfe694e3f37199e /gcc
parentca722fe423bdd8c7895a40aac0410b2646917805 (diff)
downloadgcc-0472834ddf177038d343b193acab70b2859656f8.zip
gcc-0472834ddf177038d343b193acab70b2859656f8.tar.gz
gcc-0472834ddf177038d343b193acab70b2859656f8.tar.bz2
Preserve inside_loop context when compiling match
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/typecheck/rust-hir-type-check-expr.h2
-rw-r--r--gcc/testsuite/rust/execute/torture/match_loop1.rs51
2 files changed, 52 insertions, 1 deletions
diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.h b/gcc/rust/typecheck/rust-hir-type-check-expr.h
index 5633751..f1dff2c 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-expr.h
+++ b/gcc/rust/typecheck/rust-hir-type-check-expr.h
@@ -1027,7 +1027,7 @@ public:
// check the kase type
TyTy::BaseType *kase_block_ty
- = TypeCheckExpr::Resolve (kase.get_expr ().get (), false);
+ = TypeCheckExpr::Resolve (kase.get_expr ().get (), inside_loop);
kase_block_tys.push_back (kase_block_ty);
}
diff --git a/gcc/testsuite/rust/execute/torture/match_loop1.rs b/gcc/testsuite/rust/execute/torture/match_loop1.rs
new file mode 100644
index 0000000..d3aab6b
--- /dev/null
+++ b/gcc/testsuite/rust/execute/torture/match_loop1.rs
@@ -0,0 +1,51 @@
+// { dg-output "E::One\nE::Two\nbreak!\n" }
+
+extern "C" {
+ fn printf(s: *const i8, ...);
+}
+
+enum E {
+ One,
+ Two,
+ Other
+}
+
+fn foo () {
+ let mut x = E::One;
+
+ loop {
+ match x {
+ E::One => {
+ let a = "E::One\n\0";
+ let b = a as *const str;
+ let c = b as *const i8;
+ printf (c);
+
+ x = E::Two;
+ }
+ E::Two => {
+ let a = "E::Two\n\0";
+ let b = a as *const str;
+ let c = b as *const i8;
+ printf (c);
+
+ x = E::Other;
+ }
+ _ => {
+ let a = "break!\n\0";
+ let b = a as *const str;
+ let c = b as *const i8;
+ printf (c);
+
+ break;
+ }
+ }
+ }
+}
+
+
+fn main () -> i32 {
+ foo ();
+
+ 0
+}