4 ms·
I don't think the analogy to modules is quite right. I think that maps better to: fn foo() {struct Cat;} fn bar() {struct Cat;} and foo::Cat != bar::Cat.
by GrantMoyer 2y ago
I don't think the analogy to modules is quite right. I think that maps better to:
fn foo() {struct Cat;}
fn bar() {struct Cat;}
and foo::Cat != bar::Cat. Whereas the a single function with a local type maps better to:
mod foo {struct Cat;}
mod bar {pub use ::foo::Cat;}
mod baz {pub use ::foo::Cat;}
and bar::Cat does equal baz::Cat.
But maybe I only think that construct maps better because I'm predisposed to the interpetation I described. I do see what your saying, and agree that Rust could work that way; I'm just not convinced it's a bug that it doesn't.
The behavior you describe would be more surprising to me than the existing behavior, but clearly that's not a universal sentiment, and I'm not sure which behavior would be less surprising to most people.
- noelwelsh 2y agoSeems reasonable to me. I was thinking more of closures, which capture their environment, but those are of course a distinct type in Rust.