-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Arbitrary functions shouldn't be isomorphic to tuple structs #10200
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
Comments
It's certainly a feature that we never use. |
I'm a little confused to what the problem is. I personally really like the fact that an enum tuple variant or a struct tuple has its name as a functional constructor. It's not something that I used that much, but I really enjoy doing it when I do use it. This code should not be passing the typechecker for sure. We don't allow arbitrary code to be run inside of a pattern, so the |
See above. The code passes the typechecker because, as you said, In order to make that not happen, I can't really see any way around either I think (1) is simplest but at that point we're essentially acknowledging that tuple structs aren't just functions, even when they look like functions. If we do that but still let you use them as functions in other contexts, we're basically just providing coercion for a really unusual use case (especially if we do what we should be doing and compile down tuple structs to not be function calls wherever possible, as per #7435). Right now, defining a tuple struct creates both a type and a value which happen to have the same name, which seems rather confusing to me pedagogically as well. To me, the added confusion doesn't really seem worth the very rare situation where we actually do want to treat them as functions, particularly since we can just use a closure in those situations. |
I don't think that forbidding tuple structs/enum tuples from being functions is the fix for this problem. In the above code, I don't think that this use case warrants removal of |
I'm using As far as your last point, yes, we can fix this without removing |
I don't think we should remove the fact that variant and struct constructors are functions, we should just change the pattern matching code to insist that the path is resolved to a variant or struct name. I'm rather surprised this is not how it works now but I'd have to look at the code to see why. |
From discussions on IRC, it seems that this problem only occurs with structs, not enum variants (which makes sense...) and the reason is because, in the cross-crate metadata, we encode a struct ctor as a normal fn, rather than giving it a distinct family (the same may be true in the intracrate case, I did not investigate) |
Rename `integer_arithmetic` The lack of official feedback in rust-lang#10200 made me give up on pursuing the matter but after yet another use-case that is not handled by `integer_arithmetic` (rust-lang#10615), I think it is worth trying again. --- changelog: Move/Deprecation: Rename `integer_arithmetic` to `arithmetic_side_effects` [rust-lang#10674](rust-lang/rust-clippy#10674) <!-- changelog_checked -->
Currently, if we define a tuple struct:
then
S
has the same type asThis allows us to write code that seems unintuitive / wrong:
It seems to me that we should disallow this. My preference would be to just make tuple structs unique, named type constructors that wrap tuple type constructors (not functions). So the type of
S
above might be (internally)Unique(Tuple(t1, ..., tn), S)
.The text was updated successfully, but these errors were encountered: