Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign up"as uint" works on bare constructors of non-C-like enums #18154
Comments
kmcallister
added
I-wrong
A-diagnostics
labels
Oct 19, 2014
kmcallister
added
the
I-nominated
label
Nov 23, 2014
This comment has been minimized.
This comment has been minimized.
|
Nominating. |
This comment has been minimized.
This comment has been minimized.
|
Casting the nullary constructors is already forbidden. |
This comment has been minimized.
This comment has been minimized.
|
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. |
kmcallister
added a commit
to kmcallister/rust
that referenced
this issue
Nov 24, 2014
kmcallister
added a commit
to kmcallister/rust
that referenced
this issue
Nov 26, 2014
kmcallister
added a commit
to kmcallister/rust
that referenced
this issue
Nov 26, 2014
brson
added
P-medium
and removed
I-nominated
labels
Dec 11, 2014
This comment has been minimized.
This comment has been minimized.
|
P-high, not 1.0. Ugly wart, and we'd love someone to fix. |
This comment has been minimized.
This comment has been minimized.
|
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 |
This comment has been minimized.
This comment has been minimized.
+1 for this, but I guess it's too late for 1.0.x |
arielb1
referenced this issue
Jun 17, 2015
Closed
Casting enum causes ICE or unexpected result #26377
This comment has been minimized.
This comment has been minimized.
|
The segfault is gone BTW |
arielb1
removed
the
I-wrong
label
Jun 29, 2015
This comment has been minimized.
This comment has been minimized.
|
Updated code:
Still produces the same error. |
brson
added
T-compiler
I-wrong
labels
Jul 14, 2016
brson
added
I-nominated
I-wishlist
and removed
I-wrong
labels
Jul 14, 2016
alexcrichton
referenced this issue
Jul 14, 2016
Merged
test: Remove NOTE assertions from trace_macros-gate #34824
This comment has been minimized.
This comment has been minimized.
|
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? |
brson
added
the
P-low
label
Jul 14, 2016
This comment has been minimized.
This comment has been minimized.
New lints need RFCs nowadays. |
bors
added a commit
that referenced
this issue
Jul 14, 2016
bors
closed this
in
b2d1f7e
Jul 14, 2016
This comment has been minimized.
This comment has been minimized.
|
Closed erroneously! (sorry) |
alexcrichton
reopened this
Jul 14, 2016
arielb1
added
the
A-lint
label
Jul 21, 2016
This comment has been minimized.
This comment has been minimized.
|
triage: P-low |
rust-highfive
added
P-low
and removed
I-nominated
P-medium
P-low
labels
Jul 21, 2016
This comment has been minimized.
This comment has been minimized.
|
triage: P-low |
rust-highfive
added
P-low
and removed
P-low
labels
Jul 21, 2016
This comment has been minimized.
This comment has been minimized.
|
cc @Manishearth in case he wants to add it to Clippy |
This comment has been minimized.
This comment has been minimized.
|
I do think a lint is the only fix here. |
This comment has been minimized.
This comment has been minimized.
|
(consensus of compiler team is that this should be some form of lint) |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
closing. |
kmcallister commentedOct 19, 2014
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.