Open
Description
I tried this code:
trait Foo<'x> {
type Out;
fn foo(self) -> Self::Out;
}
struct Bar;
impl<'x> Foo<'x> for Bar {
type Out = ();
fn foo(self) -> Self::Out {
todo!()
}
}
fn make_static_foo<'x>(_: &'x ()) -> impl Foo<'x, Out: 'static> {
Bar
}
fn assert_static<T: 'static>(_: T) {}
fn test() {
let local = ();
assert_static(make_static_foo(&local).foo());
}
I expect it to compile, but instead it gives the following error:
error[E0597]: `local` does not live long enough
--> src/lib.rs:23:35
|
22 | let local = ();
| ----- binding `local` declared here
23 | assert_static(make_static_foo(&local).foo());
| ----------------^^^^^^-
| | |
| | borrowed value does not live long enough
| argument requires that `local` is borrowed for `'static`
24 | }
| - `local` dropped here while still borrowed
It looks like the Out: 'static
bound on make_static_foo
is just ignored.
The issue sounds similar to #106684, but it is actually the opposite:
In this issue the bound is in the RPIT instead of in the trait definition.
Meta
rustc --version --verbose
:
rustc 1.85.0-nightly (7f75bfa1a 2024-12-30)
binary: rustc
commit-hash: 7f75bfa1ad4e9a9d33a179a90603001515e91991
commit-date: 2024-12-30
host: x86_64-unknown-linux-gnu
release: 1.85.0-nightly
LLVM version: 19.1.6
Same happens on stable
Metadata
Metadata
Assignees
Labels
Area: Associated items (types, constants & functions)Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.Area: Lifetimes / regionsCategory: This is a bug.Status: A Minimal Complete and Verifiable Example has been found for this issueRelevant to the types team, which will review and decide on the PR/issue.