-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Redefining built-in types does not work #20427
Comments
Nominating. Seems like this should be well-defined, though this behavior may be so useless there's no backwards compat risk. |
Could possibly do post-1.0 bugfix. |
@brson
the name lookup rightfully resolves |
So, the current algorithm is:
Modules, unlike most of other items, are not exposed to the discussed problem just because they are never full paths. It is possible to prohibit the built-in names only for items that can be used as full paths and are searched in type namespace, but IMO the most drastic solution would be the most appropriate here - prohibit built-in names for everything except for modules. Reusing the names of built-in types is never a good idea and modules are just an unfortunate exception. |
/cc @aturon |
To be clear: you're saying that you would not be able to define types (or values?) with names matching any primitive type? But modules are OK? That sounds potentially fine to me (and can always be relaxed later). |
Yes, only module items will be able to have names matching built-in types. |
A more fine-grained prohibition turned out to be easier to implement. |
Names of structs, enums, traits, type aliases and type parameters (i.e. all identifiers that can be used as full paths in type position) are not allowed to match the names of primitive types. See #20427 for more information. This is a minor [breaking-change]
Names of structs, enums, traits, type aliases and type parameters (i.e. all identifiers that can be used as full paths in type position) are not allowed to match the names of primitive types. See #20427 for more information. This is a minor [breaking-change]
Names of structs, enums, traits, type aliases and type parameters (i.e. all identifiers that can be used as full paths in type position) are not allowed to match the names of primitive types. See #20427 for more information. This is a minor [breaking-change]
@petrochenkov Has this been resolved? |
@aturon |
Thanks @petrochenkov! |
The implemented solution is only a band-aid and doesn't play well with post-UFCS rules and needs. |
@eddyb |
I've tried to summarize some implications of UFCS, including this one, in a comment on the UFCS issue. |
Note to self: what is the status now? |
assigning to @nrc to understand better what work remains here and how this should be proritized. |
To summarise the status: there is a fix (the issue was fixed not by allowing redefinition but preventing using the names of primitive types as the name of anything user-defined except for modules), however, there were then doubts that this fix may not play well with some of the consequences of UFCS, specifically how primitive types can be used as modules. There does now seem to be consensus that primitive types and their impls and modules are fixed by #23104 and so I don't believe there is anything else to do here. |
How so? #23104 does not make use of associated constants (#23606 is still not merged yet) so there is a chance things like The names of primitives cannot be considered a fixed set, so I still prefer a solution that explicitly puts them in the prelude - maybe the fix should be modified so it behaves like the primitives are always imported where the prelude would be, even if primitives aren't being rooted in libcore? |
@eddyb How do you think, would it make sense to migrate only part of primitive types to the new name lookup rules and keep the old rules for cc #8995 |
@petrochenkov Sadly, it's backwards incompatible to change modules with the same name as types to anything else. |
Ah, right, |
@petrochenkov You can move all the named built-in types to the prelude while keeping the existing modules. It's not pretty, but it should work. |
Similar example with existing prelude type: |
@petrochenkov What if |
The following code does not do what I expect it to do:
The text was updated successfully, but these errors were encountered: