Rust Lifetime Mismatch on 1.4 Nightly


#1

After upgrading to the latest nightly build of rust, my existing code fails to compile. It quotes a lifetime mismatch between Resources<'a> and Resources<'_>.
What is suspicious is it then quotes a struct called DestructorScopeData, which is part of rustc internals. I initially though it was an ICE, but now I think its just an unfortunate side affect of some of the changes to traits as of late.

I’ve looked through the contents of https://github.com/rust-lang/rust/issues/27579, and I see a few changes that might be the culprit but I don’t have enough knowledge about rustc internals to understand what is going on.

I’ve made a playground to demonstrate the issue. It compiles fine on stable and beta channels but on nightly it breaks:

http://is.gd/gMmOmT

I suppose I’m asking if this is my problem of rustc's problem, and if its my code then what can I do to fix it!
Thanks


#2

Lifetime elision got you. The return type of select, BufferViewHandle, has its 2 lifetime parameters elided, so your function declaration actually is

    fn select<'bvh_a, 'b, T, S, F>(&self, &'a BufferHandle<'a, R, T>, selector: F)
        -> BufferViewHandle<'bvh_a, 'b, R, T, S> where F: Fn(&T) -> &S;

The problem is that the function is defined for any lifetime 'bvh_a, not only the correct 'a. Since RFC1214, the predicates in BufferViewHandle are enforced, including R: Resources<'a>, which is substituted to R: Resources<'bvh_a>, which (of course) is not known to hold. Explicitly naming the lifetimes correctly ( https://play.rust-lang.org/?gist=7d1e96612ccf6084463b&version=nightly) fixes the problem.

I admit the error message is terrible - users shouldn’t actually see the placeholder DestructionScopeData. Reported: https://github.com/rust-lang/rust/issues/27942


#3

Thanks very much for the help. Now with that and a couple more fixes my code compiles fine.