-
-
Notifications
You must be signed in to change notification settings - Fork 2.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
Allow coercion of structs with field names that are the exact same #23048
Comments
this doesnt seem like a great idea and a much more tame version was already removed in #21817. imo something like this should exist as some kind of cast if at all e.g. |
Your idea is actually wrong, and when you need to do this, you directly declare that returning the same structure is better |
No comment here explains why this "doesn't seem like a great idea" or why "my idea is actually wrong" so I'm given zero explanation on the downsides of this. |
I mean, type safety? it feels kinda obvious why I said that. should structurally equivalent enums coerce? unions? pointers? if anything tuples here are the outlier, not normal structs (and I'm not saying those should change to be clear). I also feel like the pr I linked is a decent argument against it already |
Not going to assume I'm going to get an explanation either so I guess it's just that for some reason everyone uses tuples here or they simple haven't run into the same problem. This also doesn't apply to only structs but also unions, enums, etc. where you don't have a non-named variant anyway. Only tuples coercing is an inconsistency. |
Why shouldn't they?
|
enums are pretty commonly used to represent distinct integer types in the compiler and stdlib so i dont think any argument is going to get far there. its a useful property and there have been proposals to allow even stricter type distinctiveness. |
First actually useful piece of information on an explanation I see in this thread. That's a good point. |
To give these words some weight, I'm giving the OP a 1-month timeout before they are welcome back on the issue tracker. |
I hit this issue very often:
The fix would be to add
const Size = struct { width: u32, height: u32 };
and use that in both places.However, I don't want to have to pollute my top level namespace with
const
s for trivial short types like this if both types are the exact same.In fact sometimes I have to pollute my top level namespace with
const
s like that only for a single edge case where I happen to have the need to specify the result type explicitly. This is unfortunate.Another solution that seems to work:
However I don't like tuples for things like this because
.@"0"
etc. is cryptic and I want to use field names. No, I don't want to use destructuring either.If the field names and order are the same why are the two structs not compatible?
The text was updated successfully, but these errors were encountered: