From: lishin <[email protected]>
Add an unsupported error for ref patterns and subpatterns.
Add an unsupported ref-pattern test case,
and extend the existing block-exit test case.
gcc/rust/ChangeLog:
* backend/rust-compile-pattern.cc (CompilePatternLet::visit): Check ref
pattern base types and emit a sorry for unsupported Drop
ref/subpatterns.
gcc/testsuite/ChangeLog:
* rust/execute/drop-block-scope.rs: Extend test coverage for simple
immutable and mutable bindings.
* rust/compile/drop-ref-pattern.rs: New test.
Signed-off-by: lishin <[email protected]>
---
This change was merged into the gccrs repository and is posted here for
upstream visibility and potential drive-by review, as requested by GCC
release managers.
Each commit email contains a link to its details on github from where you can
find the Pull-Request and associated discussions.
Commit on github:
https://github.com/Rust-GCC/gccrs/commit/7392685d278417588be6bb0fe0d665a031d7b8e7
The commit has NOT been mentioned in any issue.
The commit has been mentioned in the following pull-request(s):
- https://github.com/Rust-GCC/gccrs/pull/4564
gcc/rust/backend/rust-compile-pattern.cc | 17 ++++++++++++--
.../rust/compile/drop-ref-pattern.rs | 23 +++++++++++++++++++
.../rust/execute/drop-block-scope.rs | 9 +++++++-
3 files changed, 46 insertions(+), 3 deletions(-)
create mode 100644 gcc/testsuite/rust/compile/drop-ref-pattern.rs
diff --git a/gcc/rust/backend/rust-compile-pattern.cc
b/gcc/rust/backend/rust-compile-pattern.cc
index eb1541c8a..021e438b6 100644
--- a/gcc/rust/backend/rust-compile-pattern.cc
+++ b/gcc/rust/backend/rust-compile-pattern.cc
@@ -1369,10 +1369,23 @@ CompilePatternLet::visit (HIR::IdentifierPattern
&pattern)
ctx->add_statement (s);
}
- if (!pattern.has_subpattern () && !pattern.get_is_ref ()
- && type_has_drop_impl (ctx, ty))
+ TyTy::BaseType *drop_ty = ty;
+ if (pattern.get_is_ref ())
+ {
+ auto ref_ty = ty->try_as<TyTy::ReferenceType> ();
+ rust_assert (ref_ty != nullptr);
+ drop_ty = ref_ty->get_base ();
+ }
+
+ if (!type_has_drop_impl (ctx, drop_ty))
+ return;
+
+ if (!pattern.has_subpattern () && !pattern.get_is_ref ())
ctx->note_simple_drop_candidate (pattern.get_mappings ().get_hirid (),
pattern.get_locus ());
+ else
+ rust_sorry_at (pattern.get_locus (),
+ "drop trait not supported for subpatterns and ref patterns");
}
void
diff --git a/gcc/testsuite/rust/compile/drop-ref-pattern.rs
b/gcc/testsuite/rust/compile/drop-ref-pattern.rs
new file mode 100644
index 000000000..f0053dcd2
--- /dev/null
+++ b/gcc/testsuite/rust/compile/drop-ref-pattern.rs
@@ -0,0 +1,23 @@
+#![feature(no_core)]
+#![feature(lang_items)]
+#![no_core]
+
+#[lang = "sized"]
+pub trait Sized {}
+
+#[lang = "drop"]
+pub trait Drop {
+ fn drop (&mut self);
+}
+
+struct Droppable;
+
+impl Drop for Droppable {
+ fn drop(&mut self) {}
+}
+
+fn main() {
+ {
+ let ref _x = Droppable; // { dg-message "sorry, unimplemented: drop
trait not supported for subpatterns and ref patterns" }
+ }
+}
\ No newline at end of file
diff --git a/gcc/testsuite/rust/execute/drop-block-scope.rs
b/gcc/testsuite/rust/execute/drop-block-scope.rs
index 678ad63d7..943cf5ee1 100644
--- a/gcc/testsuite/rust/execute/drop-block-scope.rs
+++ b/gcc/testsuite/rust/execute/drop-block-scope.rs
@@ -1,4 +1,5 @@
-// { dg-output "d\r*\n" }
+// { dg-output "d\r*\nd\r*\nd\r*\n" }
+// { dg-additional-options "-w" }
#![feature(no_core)]
#![feature(lang_items)]
#![no_core]
@@ -30,5 +31,11 @@ fn main() -> i32 {
{
let _x = Droppable;
}
+ {
+ let x = Droppable;
+ }
+ {
+ let mut x = Droppable;
+ }
0
}
--
2.54.0