aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Herron <herron.philip@googlemail.com>2025-04-03 16:32:36 +0100
committerPhilip Herron <philip.herron@embecosm.com>2025-04-04 09:44:59 +0000
commit641f9a406118761f4399dc6e0636b2617bf90599 (patch)
tree944326a62a0f78cbeb5ea6e919322de84a2bc9ab
parent861dcf6f8f7b2e50f8dcbe59338cac8cac8efd26 (diff)
downloadgcc-641f9a406118761f4399dc6e0636b2617bf90599.zip
gcc-641f9a406118761f4399dc6e0636b2617bf90599.tar.gz
gcc-641f9a406118761f4399dc6e0636b2617bf90599.tar.bz2
gccrs: Fix ICE for reserved lifetime name
This is a reserved name so this changes the assertion to a diagnostic. Fixes Rust-GCC#3647 gcc/rust/ChangeLog: * typecheck/rust-typecheck-context.cc (TypeCheckContext::lookup_lifetime): emit error gcc/testsuite/ChangeLog: * rust/compile/issue-3647.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
-rw-r--r--gcc/rust/typecheck/rust-typecheck-context.cc11
-rw-r--r--gcc/testsuite/rust/compile/issue-3647.rs7
2 files changed, 17 insertions, 1 deletions
diff --git a/gcc/rust/typecheck/rust-typecheck-context.cc b/gcc/rust/typecheck/rust-typecheck-context.cc
index 907833f..95c78a7 100644
--- a/gcc/rust/typecheck/rust-typecheck-context.cc
+++ b/gcc/rust/typecheck/rust-typecheck-context.cc
@@ -514,7 +514,16 @@ TypeCheckContext::lookup_lifetime (const HIR::Lifetime &lifetime) const
{
if (lifetime.get_lifetime_type () == AST::Lifetime::NAMED)
{
- rust_assert (lifetime.get_name () != "static");
+ if (lifetime.get_name () == "static")
+ {
+ rich_location r (line_table, lifetime.get_locus ());
+ r.add_fixit_insert_after (lifetime.get_locus (),
+ "static is a reserved lifetime name");
+ rust_error_at (r, ErrorCode::E0262,
+ "invalid lifetime parameter name: %qs",
+ lifetime.get_name ().c_str ());
+ return tl::nullopt;
+ }
const auto name = lifetime.get_name ();
auto it = lifetime_name_interner.find (name);
if (it == lifetime_name_interner.end ())
diff --git a/gcc/testsuite/rust/compile/issue-3647.rs b/gcc/testsuite/rust/compile/issue-3647.rs
new file mode 100644
index 0000000..51d9478d
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-3647.rs
@@ -0,0 +1,7 @@
+#![allow(dead_code)]
+type A = fn();
+
+type B = for<'static> fn();
+// { dg-error "invalid lifetime parameter name: .static. .E0262." "" { target *-*-* } .-1 }
+
+pub fn main() {}