Regression between nightlies with `-Zpolonius`
@amandasystems is already working on this.
Since Jul 1, 2024.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
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: https://github.com/rust-lang/rust/compare/6f3df08aadf71e8d4bf7e49f5dc10dfa6f254cb4...ada5e2c7b5427a591e30baeeee2698a5eb6db0bd
regressed commit: https://github.com/rust-lang/rust/commit/ada5e2c7b5427a591e30baeeee2698a5eb6db0bd
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 https://github.com/rust-lang/rust/pull/125652, cc @amandasystems.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.