Open
Description
Code
I tried this code:
// GAT hack taken from https://docs.rs/lending-iterator/latest/lending_iterator.
pub trait LendingIterator: Sized
where
Self: for<'item> LendingIteratorItem<'item>,
{
fn next(&mut self) -> Option<<Self as LendingIteratorItem>::Item>;
}
/// Hack to express a GAT without GATs.
pub trait LendingIteratorItem<'item> {
type Item;
}
pub struct Wrapper<I> {
wrapped: Option<I>,
}
impl<'item, I> LendingIteratorItem<'item> for Wrapper<I>
where
I: LendingIteratorItem<'item>,
{
type Item = I::Item;
}
impl<I> LendingIterator for Wrapper<I>
where
I: LendingIterator,
{
fn next(&mut self) -> Option<<I as LendingIteratorItem>::Item> {
if let Some(first) = &mut self.wrapped {
if let Some(next) = first.next() {
return Some(next);
} else {
self.wrapped = None;
}
}
None
}
}
When running this with -Zpolonius
, this worked with nightly-2024-05-31. With nightly-2024-06-01, I get this error message:
error[E0506]: cannot assign to `self.wrapped` because it is borrowed
--> src/lib.rs:34:17
|
29 | fn next(&mut self) -> Option<<I as LendingIteratorItem>::Item> {
| - let's call the lifetime of this reference `'1`
30 | if let Some(first) = &mut self.wrapped {
| ----------------- `self.wrapped` is borrowed here
31 | if let Some(next) = first.next() {
32 | return Some(next);
| ---------- returning this value requires that `self.wrapped` is borrowed for `'1`
33 | } else {
34 | self.wrapped = None;
| ^^^^^^^^^^^^ `self.wrapped` is assigned to here but it was already borrowed
Bisection
searched nightlies: from nightly-2024-05-31 to nightly-2024-06-01
regressed nightly: nightly-2024-06-01
searched commit range: 6f3df08...ada5e2c
regressed commit: ada5e2c
bisected with cargo-bisect-rustc v0.6.8
Host triple: x86_64-unknown-linux-gnu
Reproduce with:
cargo bisect-rustc --start=2024-05-31 --end=2024-06-01
This is likely caused by #125652, cc @amandasystems.
Metadata
Metadata
Assignees
Labels
Area: The borrow checkerCategory: This is a bug.Issues related for using Polonius in the borrow checkerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.This issue requires a nightly compiler in some way.