Learnability considerations of ".await" syntax

I consider the unavailability of auto-deref the worse threat to the readability of .await than familiarty issues. A lot of effort has been spent during polishing of the language to ensure the access to methods and fields of sub-structures is as ergonomic as possible and current code should and will thus never look like this:

`(&**box_ref).method()

With the current concept of .await it may be a bigger problem than obvious from smaller examples or even code written by experienced programmers. &mut impl (Future + Unpin) also implements Future, and so it is perfectly legal to await some future that is only accessible through another structs passed in as a reference, for example a reference to a box as above. So, inferred knowledge would suggest that field-like await follows the usual patterns of allowing auto-deref to happen and allow this by automatically mapping to a mutable reference to the inner value. However, this intuition completely fails for anything but the special cases explicitely implemented in the standard library which make it work by not leveraging their DerefMut implementations. I think this will cause confusion in two ways for new-comers:

  • Some cases seem to work as would be obvious (e.g. Box). This makes it less likely that one looks them up to realize that they have been special cased.
  • When then some case doesn't, how would one discover this restriction? Not through looking up fields. But it seems backwards and unintuitive that one should have to use syntax that is outdated everywhere else in the language for being too verbose, and which is the opposite of discoverable for newbies since it involves knowledge of both ops::DerefMut and finding the correct impl for references for Future.
  • That is, only when something already more complex than usual needs to occur in code, the special casing of .await comes along and makes that code require even more complex additions. I surely suspect this to throw many off-path and make them resort to unecessary boxing etc. just to get within the familiar bounds where everything works with mechanism as if by auto-deref.
8 Likes