From: Philip Herron <herron.phi...@googlemail.com>

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.phi...@googlemail.com>
---
 gcc/rust/typecheck/rust-typecheck-context.cc | 11 ++++++++++-
 gcc/testsuite/rust/compile/issue-3647.rs     |  7 +++++++
 2 files changed, 17 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/rust/compile/issue-3647.rs

diff --git a/gcc/rust/typecheck/rust-typecheck-context.cc 
b/gcc/rust/typecheck/rust-typecheck-context.cc
index f02e4846731..9112b998f16 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 00000000000..51d9478d7b1
--- /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() {}
-- 
2.49.0

Reply via email to