Blog post: Contexts and capabilities in Rust

Ah, you're right. That's interesting.

I wonder how often we could catch this sort of thing with a lint. Probably only in basic cases.

Another approach is to make it so you can write the where clause like

impl<K, V, S> HashMap<K, V, S>
where in('self) // <-- this is new
    K: Eq + Hash,
    S: BuildHasher,

which would tie the lifetimes together in the way I described. This is backwards compatible with the current form of where clauses that we see everywhere, in('static). We've wanted something that represents "the lifetime of Self" for other reasons before.

3 Likes