"as uint" works on bare constructors of non-C-like enums #18154
Comments
Nominating. |
Casting the nullary constructors is already forbidden. |
Hm, I now feel like this should be a lint, because it's a kind of heuristic syntactic thing rather than a typechecking rule. We would reasonably expect this code to work: let f: fn(u8) -> Tag = Inline;
// ...
let n = f as uint; Only when a literal enum constructor appears in the cast can we reasonably guess that the behavior is unintended. |
P-high, not 1.0. Ugly wart, and we'd love someone to fix. |
One possible solution is restricting casts from function pointers to uint. We could just say that is not legal but it is legal to cast to a function pointer to an unsafe pointer, and then (continue to) permit unsafe pointers to cast to uints. One of the main reasons we allow these wacky casts with |
+1 for this, but I guess it's too late for 1.0.x |
The segfault is gone BTW |
Updated code:
Still produces the same error. |
Triage: probably impossible to fix this in a satisfying way now, but there may be mitigations. Can we decide the fate here? If we make it a lint, can somebody mentor? |
New lints need RFCs nowadays. |
test: Remove NOTE assertions from trace_macros-gate If no NOTE assertions are present I believe they aren't asserted at all, and it looks like the number of NOTEs differs on distcheck vs `make check`, so let's just remove them all. Closes #18154
Closed erroneously! (sorry) |
triage: P-low |
triage: P-low |
cc @Manishearth in case he wants to add it to Clippy |
I do think a lint is the only fix here. |
(consensus of compiler team is that this should be some form of lint) |
closing. |
rustc 0.13.0-dev (222ae8b 2014-10-18 00:47:22 +0000)
compiles and produces
I think it's casting the constructor function itself as a function pointer? But this is super confusing behavior (caused a segfault in unsafe code) when I just refactored an enum to be not C-like and I want to get rid of remaining occurrences of
as uint
.Also it doesn't warn for
as u8
, even though it's too small for a function pointer.The text was updated successfully, but these errors were encountered: