You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I just tried compiling this program with the latest incoming, and it still compiled successfully. @vertexclique, did you say you got an error with this test program?
I quickly hacked up an example program that uses unsafe features, and it seems to compile and run properly. (I've included the example at the end of this comment.)
I do not know enough about how traits and methods are implemented, especially in the case of dynamic dispatch in object types, to say that we currently support unsafe methods; all I can see is that we do not obviously fail to support them. :) So I won't close this ticket immediately, but I'd like someone else on the team to consider doing so (or provide me with a pointer to something saying why we do not and/or can not support unsafe methods).
unsafefnf(x:*int) -> int{let p = x asint;let q = p + 8;// danger: assumes sizeof(int*) in a vec is 8 !let y = q as*int;*y
}traitx{unsafefnuwith(&self,x:*int) -> int;}implxfor(){unsafefnuwith(&self,x:*int) -> int{3+f(x)}}implxfor @(){unsafefnuwith(&self,x:*int) -> int{13+f(x)}}implxfor @int{unsafefnuwith(&self,x:*int) -> int{23+f(x)}}fnmain(){let obju = ();let objo = @();let obji = @3;let vec = [0,7,1000];
io::print(fmt!("%?\n", obju.uwith(&vec[0])));
io::print(fmt!("%?\n", objo.uwith(&vec[0])));
io::print(fmt!("%?\n", obji.uwith(&vec[0])));}
In case it is not clear: I was able to compile and run the code from the comment above. I had meant for this to demonstrate that unsafe methods might be implemented and might work; Niko separately pointed out that the code in the comment also demonstrates that there is a bug, since the calls to the unsafe uwith method should have been required to be enclosed in an unsafe block within their invocations inside main.
Activity
eholk commentedon Aug 1, 2012
This might be related to #2587.
vertexclique commentedon Oct 23, 2012
Latest head solved this with throwing error case
eholk commentedon Nov 26, 2012
I just tried compiling this program with the latest incoming, and it still compiled successfully. @vertexclique, did you say you got an error with this test program?
catamorphism commentedon Dec 6, 2012
Still wrong as of b60a0be (no error message)
kud1ing commentedon Feb 6, 2013
Can this be closed? I have a working example of unsafe fn foo() methods.
pnkfelix commentedon Mar 22, 2013
Indeed, I am wondering the same thing as kud1ing.
I quickly hacked up an example program that uses unsafe features, and it seems to compile and run properly. (I've included the example at the end of this comment.)
I do not know enough about how traits and methods are implemented, especially in the case of dynamic dispatch in object types, to say that we currently support unsafe methods; all I can see is that we do not obviously fail to support them. :) So I won't close this ticket immediately, but I'd like someone else on the team to consider doing so (or provide me with a pointer to something saying why we do not and/or can not support unsafe methods).
pnkfelix commentedon Mar 22, 2013
(either way, this is not a 0.6 milestone issue.)
pnkfelix commentedon Mar 25, 2013
In case it is not clear: I was able to compile and run the code from the comment above. I had meant for this to demonstrate that
unsafemethods might be implemented and might work; Niko separately pointed out that the code in the comment also demonstrates that there is a bug, since the calls to the unsafeuwithmethod should have been required to be enclosed in anunsafeblock within their invocations insidemain.nikomatsakis commentedon May 8, 2013
More examples in #6331
brson commentedon Jul 19, 2013
This is fixed.
Merge pull request rust-lang#3080 from topecongiro/issue-3031
Ensure storage markers are kept in std code (rust-lang#3080)
Merge rust-lang#3080
Merge pull request rust-lang#3080 from rust-lang/tshepang/misc