'static type kind may be confusing


#1

I found this quite confusing when the 'static bound was recently removed from Send. I had to update the bound on a trait object that I was passing around with Arc, the implementation of the object was basically a plain struct with no references so annotating the thing as having lifetime 'static seemed strange to me. Before the Send change, when I had to implement Send and Sync in order to send it across threads those all made sense, but the compiler asking me to add 'static made me stop and think. I had to go searching for a stack overflow that covers it and describes that the 'static bound doesn’t prescribe that the object have 'static lifetime but rather that it contains either no references at all, or only static ones.

The reference describes it similarly: Type Kinds

All the other Type Kinds: Send, Copy, Drop all look like traits; and all of them, including 'static act like traits when used as a bound. Why does 'static look like a lifetime bound when it’s really a bit different?

Now that I’ve done the research and learned what it is I don’t imagine it will cause me any pain. I just thought I’d bring it up as a possible point of confusion for new users, since now that it was removed from Send we will be seeing many more 'static bounds.


#2

There’s some information in the recently accepted and implemented rfc 458 and on the users forum.


#3

The reference is often a little out of date in some places. Firstly, ‘type kinds’ isn’t really the name we use to describe those traits any more—‘built-in traits’ is the more up-to-date term. Secondly, the reference is also inaccurate in that 'static isn’t really a special-cased ‘type kind’ any more—it’s just a specific version of a more general concept called ‘lifetime bounds’, introduced by RFC 192. Basically, they’re a generalisation of the 'static bound for other lifetimes, where T: 'a says that all references contained within T must live for at least as long as 'a.