From: lishin Date: Tue, 2 Jun 2026 09:52:39 +0000 (+0000) Subject: gccrs: report unsupported Drop ref patterns X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=aebe09f90ba2c3b38f46d64c034964e80b00b8dc;p=thirdparty%2Fgcc.git 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 --- diff --git a/gcc/rust/backend/rust-compile-pattern.cc b/gcc/rust/backend/rust-compile-pattern.cc index eb1541c8ab2..021e438b66c 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 (); + 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 00000000000..f0053dcd275 --- /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 678ad63d752..943cf5ee1e5 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 }