Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect default object lifetime bounds in 1.34.2 #61179

Closed
MaikKlein opened this issue May 25, 2019 · 3 comments
Closed

Incorrect default object lifetime bounds in 1.34.2 #61179

MaikKlein opened this issue May 25, 2019 · 3 comments
Labels
C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@MaikKlein
Copy link
Contributor

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)>.

@jonas-schievink jonas-schievink added C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 25, 2019
@jonas-schievink
Copy link
Contributor

jonas-schievink commented May 25, 2019

This doesn't compile in 1.34.0.

It builds fine for me, however nightly is rejecting the code since rustc 1.35.0-nightly (87a436377 2019-03-03). That is a soundness fix introduced by #58673, I believe.

@jonas-schievink
Copy link
Contributor

Ah, I think you meant 1.35.0 instead. This is effectively a duplicate of #60927 then.

@MaikKlein
Copy link
Contributor Author

Oh yeah it does indeed compile in 1.34.0. I only checked it with https://rust.godbolt.org/z/YpLEHy Maybe not something that I should rely on.

Yeah it seems like a duplicate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants