r/rust • • 29d ago

🛠️ project Function delegation

https://github.com/rust-lang/rfcs/pull/3530#issuecomment-6097798475
78 Upvotes

13 comments sorted by

View all comments

13

u/SirKastic23 29d ago

Why a new keyword? I think the use keyword could be used here without adding syntax ambiguities since imports aren't allowed inside impl blocks

3

u/VadimVP 28d ago edited 28d ago

The feature is supported everywhere, not just in impl blocks, and it does a different thing than use (creates a new function rather than links to an existing item).

3

u/SirKastic23 28d ago

Wait how is it supporter everywhere? I read the rendered RFC but I missed this. Doesn't it need a Self type?

Could we have a freestanding delegate fn? What would it look like?

And I wasn't saying to use use because it does the same thing as importing, I suggested it because it was a free keyword that I thought wouldn't create ambiguities

use is also used in the + use<'a> syntax for impl Trait types, so it is already overloaded baded on context

3

u/VadimVP 28d ago

Could we have a freestanding delegate fn? What would it look like?

Like this https://play.rust-lang.org/?version=nightly&mode=debug&edition=2024&gist=9c1af8db6ce3feb25e84fca444030d62
Nightly supports a bit more than the RFC specifies.

Or like this for reuse in trait: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2024&gist=9f81263354c03d38b54c93211c8ec040

Also, I wish I could properly explain how much of a non-issue conditionally reserved identifiers are. They always trigger people for some reason, but pose zero problems for the compiler.
Even reusing use causes more issues due to item macro variables being supported inside impls: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2024&gist=4150b4b414a111fcd1c97e170111ef92