Skip to content

Incorrect default object lifetime bounds in 1.34.2 #61179

Closed
@MaikKlein

Description

@MaikKlein
use std::ptr::NonNull;
trait Bar {}
struct Foo;
impl Foo {
    fn get_mut(&mut self, i: usize) -> Option<&mut (dyn Bar)> {
        None
    }
    fn foo(&mut self) {
        unsafe {
            let i1 = self
                .get_mut(0)
                .map(|val| NonNull::new_unchecked(val as *mut dyn Bar));
            if let Some(mut i1) = i1 {
                let mut i2 = self
                    .get_mut(1)
                    .map(|val| NonNull::new_unchecked(val as *mut dyn Bar));
                if let Some(mut i2) = i2 {
                    let r1 = i1.as_mut();
                    let r2 = i2.as_mut();
                }
            }
        }
    }
}
fn main() {}

This compiles under 1.34.2, but shouldn't. This doesn't compile in 1.34.0. It appears that the lifetime bounds where assumed to be 'static in 1.34.2. Option<&mut (dyn Bar +'static)>.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions