https://gcc.gnu.org/g:aebe09f90ba2c3b38f46d64c034964e80b00b8dc
commit r17-1893-gaebe09f90ba2c3b38f46d64c034964e80b00b8dc Author: lishin <[email protected]> Date: Tue Jun 2 09:52:39 2026 +0000 gccrs: report unsupported Drop ref patterns 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]> Diff: --- gcc/rust/backend/rust-compile-pattern.cc | 17 +++++++++++++++-- gcc/testsuite/rust/compile/drop-ref-pattern.rs | 23 +++++++++++++++++++++++ gcc/testsuite/rust/execute/drop-block-scope.rs | 9 ++++++++- 3 files changed, 46 insertions(+), 3 deletions(-) diff --git a/gcc/rust/backend/rust-compile-pattern.cc b/gcc/rust/backend/rust-compile-pattern.cc index eb1541c8ab2d..021e438b66c0 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 000000000000..f0053dcd275c --- /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 678ad63d7529..943cf5ee1e57 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 }
