Repository navigation
Description
The code below is the dangle example of tests/ui/borrowck/alias-liveness/rpit-hide-lifetime-for-swap.rs, with one change: the short-lived impl Swap value is passed through an identity closure, (|a| a)(hide(short)), before it is used.
use std::cell::RefCell;
use std::rc::Rc;
trait Swap: Sized {
fn swap(self, other: Self);
}
impl<T> Swap for Rc<RefCell<T>> {
fn swap(self, other: Self) {
<RefCell<T>>::swap(&self, &other);
}
}
fn hide<'a, 'b: 'a, T: 'static>(x: Rc<RefCell<&'b T>>) -> impl Swap + use<'a, 'b, T> + 'a {
x
}
fn dangle() -> &'static [i32; 3] {
let long = Rc::new(RefCell::new(&[4, 5, 6]));
let x = [1, 2, 3];
let short = Rc::new(RefCell::new(&x));
hide(long.clone()).swap((|a| a)(hide(short))); // `.swap(hide(short))` is rejected (E0597)
let res: &'static [i32; 3] = *long.borrow();
res
}
fn main() {
println!("{:?}", dangle());
}I expected to see this happen: E0597 (x does not live long enough), as without the closure, and as with -Zpolonius=off.
Instead, this happened: It compiles on nightly-2026-10-15 with default flags.
Related
This was accepted before #164337, which we reported earlier. With -Zpolonius=next, #164337's programs are first accepted on nightly-2025-05-24, while this program is accepted on nightly-2025-05-23 already.
LLM disclosure: The bug was found by an automated testing tool developed with the assistance of an LLM. This report text was drafted by an LLM and reviewed/edited by me.
Meta
rustc --version --verbose:
rustc 1.101.0-nightly (7df81381d 2026-10-14)
binary: rustc
commit-hash: 7df81381d027710708209f36b98d11b1c88f8d2e
commit-date: 2026-10-14
host: x86_64-unknown-linux-gnu
release: 1.101.0-nightly
LLVM version: 23.1.3
Activity
impl Traitreturn value when the callee has a projection-typed parameter and is called through a closure #164337jackh726 commentedon Oct 19, 2026
In the future, it would be good to first check on Zulip, or do a more thorough issue search, before opening issues if you're going to be doing automated discovery like this. (I generally think doing this discovery is good - but only if the issues are not opened as duplicates.)