Closed froydnj closed 6 years ago
@Gankro Ah your latest comment appeared as I was writing this. Nor had I read the thread. Glad to here we all do want a lint. In light of that I think my point about making the lint easier to maintain is perhaps the best.
Relatedly, for refactoring existing Rust code, e.g. Servo, I'd want
unwrap
instead of void_unwrap
..foo()
to .try_foo().unwrap()
, which would then making auditing far easier--grep for unwrap
or try.*unwrap
.And again in terms of expediency, while the portability lint is not yet implemented, everything I mention an be done today. A road map could be
PanicOom
, and convert all collections to use infallible allocators. No clever thinking about algorithms is needed.Vec
, a good deal harder for tree-based ones (if we don't consume the collection lest it gets in an inconsistent state). To be clear, we identified that the lint was nice to have but in no way a blocker for our users. As such we planned to punt on it and solve it more robustly with actual lints. In the mean time we could provide the methods, and users could build wrapper types to hide infallibility if they chose want.
On the topic of different collections, only BTreeMap would run into issues with a naive translation. It shouldn't be too difficult to pre-allocate the nodes before starting the mutations.
@Gankro I think expecting users to write their own wrapper types is futile because the biggest benefit is trust between libraries, but I can't see any wrapper types outside of the libcollections becoming as standard.
I also forgot to mention how error-type polymorphism allows one to convert code bases function by function.
Is there anything you dislike about mine, besides it being a lot of work in your eyes?
Since the RFC was merged, and I believe future work in this area will require extensive discussion (either on internals or in RFC(s)) I'm closing this issue.
I was working on a Rust image library, which has code like:
This code should really be checking for overflow on the multiplications. But doing so only eliminates one class of problems with this code: it's still reasonable for a maliciously crafted image to have large
self.width
andself.height
values whose product doesn't overflowusize
and yet the amount of memory can't be allocated. (I discovered this through an image test suite that has images with...large widths and heights that ought to return errors, but panic'd in Rust.)Looking through the documentation, I didn't see any way of avoiding this panic-on-allocation failure, either at vector creation, or when trying to append elements to a vector.