Several times I have tried to use self or Self in nested functions but the compiler stops me. Any reason not to allow this? Nested functions (while they can be abused like anything else) are useful for code organization, but this is a papercut that deters their usage.
Perhaps it would be less controversial to just allow Self and not self. Because when I see the dot method call syntax, I expect to find that function as the direct child of some impl block.
After a little more thought, I realize that would imply pulling in other generic parameters. And functions are supposed to have a fresh environment of generics. Maybe there is no clean way to reconcile that .
As far as I understand, there are no deep reasons for this behaviour, it's just the way the language is currently designed. There is nothing, in principle, preventing the inner functions from using the generics of their parent function. There may be some reasons related to macros (i.e. what if a macro expands to an inner function with generics), but it could also be solved by appropriate hygiene.
The workaround for your specific case is to declare the inner function as an ordinary method, use a local closure which doesn't capture the environment, or to introduce proper generic parameters instead of Self, i.e.
That has no benefits, though, because it's more verbose, and the supposedly inner method would still be usable in any other function which has visibility of that impl block (like X::another in the example above). There is no way to declare a method which would be visible only inside of a function (not unless you use a local extension trait, which just isn't worth the boilerplate). Again, while there are technical reasons for that design, I don't think there are any fundamental reasons why it couldn't work otherwise. But that may require a lot of work, and the benefits are quite moot.