Skip to content

Rust update from 1.63 to 1.64 introduce lifetime problem on build #103141

Closed
@Aboussejra

Description

@Aboussejra

Code

This is an attempt to reproduce a minimal example of a regression problem (backwards compatibility not assured) from a closed-source company codebase.

I tried this code: -> https://github.com/Aboussejra/rust_compiler_1.64_update_problem

pub struct VecNumber<'s> {
    pub vec_number: Vec<Number<'s>>,
    pub auxiliary_object: &'s Vec<usize>,
}

#[derive(Clone)]
pub struct Number<'s> {
    pub number: &'s usize,
}

impl<'s> VecNumber<'s> {
    pub fn vec_number_iterable_per_item_in_auxiliary_object(
        &self,
    ) -> impl Iterator<Item = (&'s usize, impl Iterator<Item = &Number<'s>> + Clone)> {
        self.auxiliary_object.iter().map(move |n| {
            let iter_number = self.vec_number.iter();
            (n, iter_number)
        })
    }
}

I expected to see the code building (This code is old and was building for years on rust 1.54, and builds on rust 1.63. the code works as intended in the proprietary codebase)

Instead, this happened:

error: lifetime may not live long enough
  --> src/main.rs:15:9
   |
11 |   impl<'s> VecNumber<'s> {
   |        -- lifetime `'s` defined here
12 |       pub fn vec_number_iterable_per_item_in_auxiliary_object(
13 |           &self,
   |           - let's call the lifetime of this reference `'1`
14 |       ) -> impl Iterator<Item = (&'s usize, impl Iterator<Item = &Number<'s>> + Clone)> {
15 | /         self.auxiliary_object.iter().map(move |n| {
16 | |             let iter_number = self.vec_number.iter();
17 | |             (n, iter_number)
18 | |         })
   | |__________^ associated function was supposed to return data with lifetime `'s` but it is returning data with lifetime `'1`

Version it worked on

It most recently worked on: 1.63 (from my repo, commit : 4c37cdc458abdecd0baf018500bbc0611bad568f)

rustc 1.63.0 (4b91a6ea7 2022-08-08)
binary: rustc
commit-hash: 4b91a6ea7258a947e59c6522cd5898e7c0a6a88f
commit-date: 2022-08-08
host: x86_64-unknown-linux-gnu
release: 1.63.0
LLVM version: 14.0.5

Version with regression

It does not work anymore on version 1.64: (from my repo, commit : 2728a5acdb645f93ef223a0bc15dd3545fd82c51)

rustc 1.64.0 (a55dd71d5 2022-09-19)
binary: rustc
commit-hash: a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52
commit-date: 2022-09-19
host: x86_64-unknown-linux-gnu
release: 1.64.0
LLVM version: 14.0.6

Backtrace

Including the backtrace by setting RUST_BACKTRACE=1 does not change anything to the error message.

I do not know why this problem occured though.

@rustbot modify labels: +regression-from-stable-to-{channel} -regression-untriaged
-->

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.P-criticalCritical priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions