[gccrs COMMIT] gccrs: Track lifetimes per trait item
gerris.rs@gmail.com
gerris.rs@gmail.com
Tue Sep 8 12:08:51 GMT 2026
From: Philip Herron <herron.philip@googlemail.com>
Fixes Rust-GCC/gccrs#4861
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check.cc (TraitItemReference::get_type_from_fn): grab lifetimes
gcc/testsuite/ChangeLog:
* rust/compile/issue-4861.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
---
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/305320a0fbcbb14f30488c807fd35c7d1a813880
The commit has been mentioned in the following issue(s):
- Rust-GCC/gccrs#4861: https://github.com/Rust-GCC/gccrs/issues/4861
The commit has been mentioned in the following pull-request(s):
- https://github.com/Rust-GCC/gccrs/pull/4872
gcc/rust/typecheck/rust-hir-type-check.cc | 11 +++++++++++
gcc/testsuite/rust/compile/issue-4861.rs | 17 +++++++++++++++++
2 files changed, 28 insertions(+)
create mode 100644 gcc/testsuite/rust/compile/issue-4861.rs
diff --git a/gcc/rust/typecheck/rust-hir-type-check.cc b/gcc/rust/typecheck/rust-hir-type-check.cc
index e0f819ea1..d111207b7 100644
--- a/gcc/rust/typecheck/rust-hir-type-check.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check.cc
@@ -155,6 +155,17 @@ TraitItemReference::get_type_from_fn (/*const*/ HIR::TraitItemFunc &fn) const
{
auto binder_pin = context->push_clean_lifetime_resolver ();
+ auto &mappings = Analysis::Mappings::get ();
+ auto *trait
+ = mappings.lookup_trait_item_mapping (get_mappings ().get_hirid ());
+ rust_assert (trait != nullptr);
+ for (auto ¶m : trait->get_generic_params ())
+ if (param->get_kind () == HIR::GenericParam::GenericKind::LIFETIME)
+ {
+ auto &lifetime_param = static_cast<HIR::LifetimeParam &> (*param);
+ context->intern_and_insert_lifetime (lifetime_param.get_lifetime ());
+ }
+
std::vector<TyTy::SubstitutionParamMapping> substitutions
= inherited_substitutions;
diff --git a/gcc/testsuite/rust/compile/issue-4861.rs b/gcc/testsuite/rust/compile/issue-4861.rs
new file mode 100644
index 000000000..513f09f6f
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-4861.rs
@@ -0,0 +1,17 @@
+#![feature(no_core, lang_items)]
+#![no_core]
+
+#[lang = "sized"]
+pub trait Sized {}
+
+trait Searcher<'a> {
+ fn haystack(&self) -> &'a str;
+ fn with_lifetime<'b>(&self, value: &'b str) -> &'a str;
+ fn borrow(&'a self) -> &'a str;
+}
+
+trait Other<'a, 'b> {
+ fn first(&self) -> &'a str;
+ fn second(&self) -> &'b str;
+ fn method<'c>(&self, value: &'c str) -> &'c str;
+}
base-commit: 7a839f9477ac9e4e3e6659ae0ffe6ef587b87dbb
--
2.55.0
More information about the Gcc-rust
mailing list