Repository navigation
Open
Labels
A-auto-traitsArea: auto traits (e.g., `auto trait Send {}`)A-borrow-checkerArea: The borrow checkerA-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.A-inferenceArea: Type inferenceA-varianceArea: Variance (https://doc.rust-lang.org/nomicon/subtyping.html)C-bugCategory: This is a bug.T-typesRelevant to the types team, which will review and decide on the PR/issue.
Description
This code is minimized from code discovered by @danielhenrymantilla.
I tried this code:
struct X<'a>(&'a ());
unsafe impl Send for X<'static> {} // non-`Send` otherwise.
fn require_send(_: impl Send) {}
fn foo1<'a>(_: &'a i32) -> impl use<'a> + Sized {
X::<'static>(&())
}
fn foo2<'a>(_: &'a i32) -> impl use<'a> + Send {
X::<'static>(&())
}
fn main() {
let x = 1;
require_send(foo1(&x));
let y = 2;
require_send(foo2(&y));
}error[E0597]: `x` does not live long enough
--> src/main.rs:17:23
|
16 | let x = 1;
| - binding `x` declared here
17 | require_send(foo1(&x));
| ------------------^^--
| | |
| | borrowed value does not live long enough
| argument requires that `x` is borrowed for `'static`
...
20 | }
| - `x` dropped here while still borrowed
|
note: requirement that the value outlives `'static` introduced here
--> src/main.rs:5:25
|
5 | fn require_send(_: impl Send) {}
| ^^^^
For more information about this error, try `rustc --explain E0597`.
I expected both the call to foo1 and foo2 to both compile. Instead, for some reason, only the call to foo1 caused a compile error. This seems incorrect, since auto traits ought to be seen through RPIT.
For some reason, in foo1, instead of the compiler imposing a requirement that the lifetime in X must be 'static, the compiler is instead imposing a requirement that 'a must be 'static.
Neither next-solver nor polonius fixes this.
cc @lcnr
Meta
Reproducible on the playground with version 1.98.0-nightly (2026-07-02 c397dae808f70caebab1)
Metadata
Metadata
Assignees
Labels
A-auto-traitsArea: auto traits (e.g., `auto trait Send {}`)A-borrow-checkerArea: The borrow checkerA-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.A-inferenceArea: Type inferenceA-varianceArea: Variance (https://doc.rust-lang.org/nomicon/subtyping.html)C-bugCategory: This is a bug.T-typesRelevant to the types team, which will review and decide on the PR/issue.
Activity
zachs18 commentedon Jul 5, 2026
I believe there is variance shennanigans happening in foo1 to make the actual return type be
X<'a>; if you makeXinvariant in its lifetime parameter then the issue seems not to happen: playgroundtheemathas commentedon Jul 5, 2026
Another instance of the issue (which similarly goes away when
Xis made invariant):Oddly enough: removing the
: 'staticfromfoo1makes the code compile.lcnr commentedon Jul 7, 2026
jup, the type of the RPIT is
X<'infer>with'static: 'infer. We get a member constraint'infer member ['a, 'static]. As'ais the smallest member region, we constrain'inferto be'ainstead of'static.This is intended behavior 🤔 I do think it's less than ideal, but don't have a good sense how we'd avoid this
impl Traitreturn value when the callee has a projection-typed parameter and is called through a closure #164337impl Traitreturn value when the callee has a projection-typed parameter and is called through a closure #164337