-
Notifications
You must be signed in to change notification settings - Fork 47
Fix serde deserialisation #237
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
Conversation
Looking good, though as you say we probably want to accumulate breaking changes for a 0.10 Maybe a test exercising the failure case of deserialization could be added (eg deserializing invalid indices). |
I am working on adding some tests, but this makes inference fail in strange places iff the #[test]
fn valid_vector() {
let vec = CsVecI::new(5, vec![0_u16, 3, 4], vec![1_u8, 5, 6]);
// Commenting this line and stuff works again...
let json = serde_json::to_string(&vec).unwrap();
} This complains with
It is really strange as these errors do not happen in locations affected by the feature flag. |
That's very strange indeed. I'm wondering if that's a compiler bug... |
Well, the issue arises for all the compiler versions I've tried (1.42.0, 1.45.1, 1.46.0) so this probably is not a compiler bug. But I do not understand. |
I managed to reduce the problem to the following, which shows that the problem is not in this crate, but either in the pub fn foo() {
// Inference at MARK succeeds when commenting the following line.
let json = serde_json::to_string(&()).unwrap();
}
pub fn bar() {
let a: Vec<usize> = Vec::new();
let b = Vec::new(); // MARK
assert_eq!(a, b);
} The problem is visible in the playground: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=c136cb6f7399b53905e1fab44506eb97 |
@ia0 That is a great minimal reproduction! It seems we also hit this issue when switching from |
Might be a variant of serde-rs/json#651 |
Indeed, that looks exactly like the same issue. |
Thanks @ia0 for the minimal reproduction. Seeing the related issues, it looks like there's no alternative to annotating the types explicitly. |
There are no problems when using this crate in another binary, even when using |
8133107
to
95535ea
Compare
95535ea
to
cf4f185
Compare
cf4f185
to
4cd2c34
Compare
4cd2c34
to
61b3dd5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All looking good now, thanks for the fixes onto the indptr changes!
Fixes #231 by first copying from a
Shadow
of the same structure. This fails on invalid structures, and ensures only valid structures can be deserialized.This unfortunately breaks backwards compatability as
CsVecBase
does not have aDeref
restriction, unlikeCsMatBase
. We should consider merging this when we are preparing for0.10
.