Skip to content
This repository has been archived by the owner on May 2, 2021. It is now read-only.

#![feature(nll)] incompatibility. #24

Closed
Coneko opened this issue Apr 1, 2018 · 4 comments
Closed

#![feature(nll)] incompatibility. #24

Coneko opened this issue Apr 1, 2018 · 4 comments

Comments

@Coneko
Copy link

Coneko commented Apr 1, 2018

Code:

#![feature(nll)]
#[macro_use]
extern crate rental;

rental! {
    mod rent_test {
        #[rental]
        pub struct OwnedSlice {
            buffer: Vec<u8>,
            slice: &'buffer [u8],
        }
    }
}

fn main() {
    let vec = vec![1, 2, 3];
    let _ = rent_test::OwnedSlice::new(vec, |slice| slice);
}

Error:

error: free region `'slice` does not outlive free region `'buffer`
  --> src/main.rs:5:1
   |
5  | / rental! {
6  | |     mod rent_test {
7  | |         #[rental]
8  | |         pub struct OwnedSlice {
...  |
12 | |     }
13 | | }
   | |_^
   |
   = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

Backtrace:

error: free region `'slice` does not outlive free region `'buffer`
  --> <rental macros>:5:33
   |
1  |  / { $ ( # [ $ attr : meta ] ) * mod $ rental_mod : ident { $ ( $ body : tt ) * }
2  |  | } => {
3  |  | $ ( # [ $ attr ] ) * mod $ rental_mod {
4  |  | # [ allow ( unused_imports ) ] use $ crate :: __rental_prelude ; # [
5  |  | allow ( unused ) ] # [ derive ( __rental_structs_and_impls ) ] enum
   |  |                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^
...   |
20 |  | ProceduralMasqueradeDummyType {
21 |  | Input = ( 0 , stringify ! ( $ ( $ body ) * ) ) . 0 } } } ;
   |  |__________________________________________________________- in this expansion of `rental!`
   |
  ::: src/main.rs:5:1
   |
5  | /  rental! {
6  | |      mod rent_test {
7  | |          #[rental]
8  | |          pub struct OwnedSlice {
...  |
12 | |      }
13 | |  }
   | |__- in this macro invocation

Not sure why the compiler thinks slice should outlive buffer, and if anything can be done about that, but maybe the crate could fail the build with an error message if it detects non lexical lifetimes are enabled.

@jpernst
Copy link
Owner

jpernst commented Apr 1, 2018

That's weird; I'll look into it. I didn't think NLL would affect rental. Hopefully it's easy to fix, but if not then I'll at least add a test case so any crater runs for NLL fail with a regression since I don't think working code is supposed to stop working under NLL.

@jpernst
Copy link
Owner

jpernst commented Apr 1, 2018

Update: After isolating and minifying, this is definitely a compiler bug. It seems there's an open issue for it already, since it appears to also break serde derive in some cases. I'll leave this issue open for now until a fix lands.

@Coneko
Copy link
Author

Coneko commented Apr 1, 2018

Thanks for the quick response! 🐶

@shepmaster
Copy link

The linked issue has been closed; can this be closed as well?

@jpernst jpernst closed this as completed Aug 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants