-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
serialize: use Result #13107
serialize: use Result #13107
Conversation
Yay! ❤️ The next person to take a snapshot will get to have fun with (Also, this needs a rebase.) |
Rebase already? Hah, I rebased just before submitting :-) |
This is great work. Once this clears travis, r=me. |
(cc @wycats: a magical @seanmonstar fixed all/some of your problems for you.) |
I'm a little worried about the explosion of generics when dealing with serialization things. Dealing with decodable/encodable already has a few type parameters which makes signatures a bit unwieldy, and adding another for an error seems a little sad. Is it crucial that all encoders/decoders need their own error type? Could this all possibly return |
My decoders definitely want their own Error type. I think this is just a side effect of not having yet nailed down the expected patterns for Result propagation. |
There is definitely errors that could occur besides IoError. Take this example: #[deriving(Decodable)]
struct Bar {
foo: uint
}
let json_str = "{\"foo\":false}";
// assume we've merged Parser and Decoder (a future PR)
let decoder = json::Decoder::from_str(json_str);
let bar = match Decodable::decode(decoder) {
Ok(b) => b,
Err(e) => fail!("{}", e)
}; This isn't an IoError. With Encoders, it's certainly possible that they could only return enum Foo {
Bar(~str, ~str)
}
impl<D: Decoder, E> Decodable<D, E> for Foo {
fn decode(&self, d: &mut D) -> Result<(), E> {
match *self {
Bar(ref a, ref b) => {
// i forget to use `emit_enum_variant`
d.emit_enum(|d| {
try!(d.emit_enum_variant_arg(0, |d| d.emit_str(a)));
d.emit_enum_variant_arg(1, |d| d.emit_str(b))
})
}
}
}
} A Decoder could be keeping track of a state, and notice that you emitted values wrongly, and return some @erickt As for Travis: it seems it failed downloading llvm dependencies? Can anyone give it a kick? |
I kicked off the relevant travis build, and it sounds like custom errors is necessary. Thanks for the explanation! |
Oh wow, I somehow missed a bunch of encode stuff in rustc/metadata. Working on it... |
there we go, had missed a bunch of in rustc/middle/astencode as well. Sorry for the |
@erickt r? |
@@ -187,7 +187,7 @@ pub fn phase_1_parse_input(sess: &Session, cfg: ast::CrateConfig, input: &Input) | |||
if sess.opts.debugging_opts & session::AST_JSON_NOEXPAND != 0 { | |||
let mut stdout = io::BufferedWriter::new(io::stdout()); | |||
let mut json = json::PrettyEncoder::new(&mut stdout); | |||
krate.encode(&mut json); | |||
let _ = krate.encode(&mut json); |
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.
You should do krate.encode(&mut json).unwrap()
here, so we'll fail instead of silently ignoring an error.
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.
this was just to remove the unused result warning, because stage0 has it returning ()
. I could add in the staged unwrap_
functions here as well.
Epic work. r=me with my minor comments addressed. |
@erickt just force pushed up all the FIXMEs and an unwrap_ in rustc/driver. |
@erickt i had missed a doc example, I've fixed and ran them locally to be sure. |
All of Decoder and Encoder's methods now return a Result. Encodable.encode() and Decodable.decode() return a Result as well. fixes rust-lang#12292
something else landed before bors got to this, requiring another rebase against master. |
All of Decoder and Encoder's methods now return a Result. Encodable.encode() and Decodable.decode() return a Result as well. fixes #12292
Suggest struct when completing enum closes rust-lang#13107
Add test for `try_err` lint within try blocks. Fixes rust-lang#5757 Turns out the current `try_err` implementation already skips expressions inside of a try block. When inside of a try block, `Err(_)?` is desugared to a `break` instead of normal `return` . This makes `find_return_type()` function at [this line](https://github.com/rust-lang/rust-clippy/blob/eb4d88e690c431691bc0fd8eaa9f7096ecc2a723/clippy_lints/src/matches/try_err.rs#L29) always returns `None` and skips the check. I just added a test case for try block. changelog: none
All of Decoder and Encoder's methods now return a Result.
Encodable.encode() and Decodable.decode() return a Result as well.
fixes #12292