News for hackers. Stuff that matters.
Re:Unsoundness in Pin by svnpenn on Friday November 29, 2019 @11:39AM (#21665300)
I am new to Rust, but this:

    for<'a, T: ?Sized> &'a T !: DerefMut 
Seems like a hunk of unreadable code. Is this valid Rust?

https://internals.rust-lang.org/t/unsoundness-in-pin/11311/3...

Re:Unsoundness in Pin by kibwen on Friday November 29, 2019 @11:49AM (#21665354)
I think the `!` part might be a typo, and that pseudocode needs more context to be valid, but the individual elements are themselves valid even if you'd never see them composed in this way, and I wouldn't expect any regular user to have to ever read or write anything like this. The leading `for<>` indicates a higher-ranked lifetime (which I've never once needed in eight years of writing Rust (though to be fair, I think it's only existed for like six of those years...), the `!` is the "Never" type indicating a statically-impossible state (honestly it really should just be called `Never` rather than `!`, this is a leftover artifact of prehistoric versions of Rust that predate even me. Maybe I'll write an RFC to propose that), the `?Sized` is a one-of-a-kind trait bound that users might need rarely (but I don't bother with, generally), and the `'a` is a lifetime type parameter (which is common for anyone working with references, although it's such an important part of the language that you don't bat an eye at it after a while).
Re:Unsoundness in Pin by Rusky on Friday November 29, 2019 @11:55AM (#21665401)
No, it's bits of valid syntax thrown together informally to express an idea. There is no `!:` in Rust, and that `for` quantification never applies to types or bounds that way.
Re:Unsoundness in Pin by withoutboats on Friday November 29, 2019 @01:12PM (#21665881)
(and the idea I was expressing was "shared references never under any circumstance implement the DerefMut trait")
Re:Unsoundness in Pin by bascule on Friday November 29, 2019 @09:46PM (#21668202)
`for` used in a bound (in conjunction with a lifetime) is the syntax for Higher-Rank Trait Bounds (HRTB):

https://doc.rust-lang.org/beta/nomicon/hrtb.html

Re:Unsoundness in Pin by Rusky on Wednesday December 04, 2019 @02:23PM (#21705938)
Yes, but it's not used that way in this snippet...
Re:Unsoundness in Pin by dethinking on Friday November 29, 2019 @11:54AM (#21665395)
Yes, it’s a type signature. It looks typical of Rust internals, but it would be very verbose for user code.

You’re not wrong to find it illegible; apart from the syntax, that phrase invokes the concepts of lifetimes, mutability, borrowing, and traits, none of which have straightforward semantic analogues in other common languages.

But FWIW they’re primitive concepts in Rust. A typical Rust user wouldn’t read or write code that looks like that very much, but they would know what it means, if that makes any sense.

Edit: Seeing sibling comments about whether this snippet actually parses, I guess I should amend this to say that a typical Rust user has an idea of what it’s supposed to mean :)

Re:Unsoundness in Pin by hollerith on Friday November 29, 2019 @12:00PM (#21665436)
Signature for the type of which identifier? "for"?
Re:Unsoundness in Pin by dodobirdlord on Friday November 29, 2019 @02:33PM (#21666282)
First of all, it’s not actually valid syntax because I believe Rust doesn’t have negative trait bounds. But it’s a trait bound, so it’s (part) of a type signature. The type here is generic over both lifetimes and types (I think). My vague understanding is that for<‘a, T: ?Sized> means “in any lifetime, any type that is a member of ‘?Sized’”. And then the rest of the signature goes on to say (in made-up syntax) “does not implement DerefMut”. I think ?Sized means “size not known at compile time.”
Re:Unsoundness in Pin by dethinking on Friday November 29, 2019 @12:09PM (#21665484)
I think I originally had “piece of a type signature”, but I didn’t actually want to figure out which piece, so I fudged it. The point is well taken, I oughtn’t pretend I have a Rust parser in my head :)
Re:Unsoundness in Pin by staticassertion on Friday November 29, 2019 @05:05PM (#21667105)
I've been writing rust since just before 1.0 and I've never written a type signature like that. I understand it just fine (even though it is invalid, I get what they're saying), but yeah, never needed it.

It's both a good and bad thing that rust has these sort of deep areas where 95% of users won't ever have to go - Pin being another example. I think it's much more good than bad though.