Skip to content

Commit ff64381

Browse files
committed
auto merge of #13107 : seanmonstar/rust/encoder-errors, r=erickt
All of Decoder and Encoder's methods now return a Result. Encodable.encode() and Decodable.decode() return a Result as well. fixes #12292
2 parents 5a68892 + f1739b1 commit ff64381

27 files changed

+6481
-1342
lines changed

src/librustc/driver/driver.rs

+16-2
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,18 @@ impl Input {
168168
}
169169
}
170170

171+
// FIXME: remove unwrap_ after snapshot
172+
#[cfg(stage0)]
173+
fn unwrap_<T>(t: T) -> T {
174+
t
175+
}
176+
177+
#[cfg(not(stage0))]
178+
fn unwrap_<T, E>(r: Result<T, E>) -> T {
179+
r.unwrap()
180+
}
181+
182+
171183
pub fn phase_1_parse_input(sess: &Session, cfg: ast::CrateConfig, input: &Input)
172184
-> ast::Crate {
173185
let krate = time(sess.time_passes(), "parsing", (), |_| {
@@ -187,7 +199,8 @@ pub fn phase_1_parse_input(sess: &Session, cfg: ast::CrateConfig, input: &Input)
187199
if sess.opts.debugging_opts & session::AST_JSON_NOEXPAND != 0 {
188200
let mut stdout = io::BufferedWriter::new(io::stdout());
189201
let mut json = json::PrettyEncoder::new(&mut stdout);
190-
krate.encode(&mut json);
202+
// unwrapping so IoError isn't ignored
203+
unwrap_(krate.encode(&mut json));
191204
}
192205

193206
if sess.show_span() {
@@ -262,7 +275,8 @@ pub fn phase_2_configure_and_expand(sess: &Session,
262275
if sess.opts.debugging_opts & session::AST_JSON != 0 {
263276
let mut stdout = io::BufferedWriter::new(io::stdout());
264277
let mut json = json::PrettyEncoder::new(&mut stdout);
265-
krate.encode(&mut json);
278+
// unwrapping so IoError isn't ignored
279+
unwrap_(krate.encode(&mut json));
266280
}
267281

268282
(krate, map)

src/librustc/metadata/decoder.rs

+14-3
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,17 @@ use syntax::crateid::CrateId;
4747

4848
pub type Cmd = @crate_metadata;
4949

50+
// FIXME: remove unwrap_ after a snapshot
51+
#[cfg(stage0)]
52+
fn unwrap_<T>(t: T) -> T {
53+
t
54+
}
55+
56+
#[cfg(not(stage0))]
57+
fn unwrap_<T, E>(r: Result<T, E>) -> T {
58+
r.unwrap()
59+
}
60+
5061
// A function that takes a def_id relative to the crate being searched and
5162
// returns a def_id relative to the compilation environment, i.e. if we hit a
5263
// def_id for an item defined in another crate, somebody needs to figure out
@@ -59,15 +70,15 @@ fn lookup_hash<'a>(d: ebml::Doc<'a>, eq_fn: |&[u8]| -> bool,
5970
let table = reader::get_doc(index, tag_index_table);
6071
let hash_pos = table.start + (hash % 256 * 4) as uint;
6172
let pos = u64_from_be_bytes(d.data, hash_pos, 4) as uint;
62-
let tagged_doc = reader::doc_at(d.data, pos);
73+
let tagged_doc = unwrap_(reader::doc_at(d.data, pos));
6374

6475
let belt = tag_index_buckets_bucket_elt;
6576

6677
let mut ret = None;
6778
reader::tagged_docs(tagged_doc.doc, belt, |elt| {
6879
let pos = u64_from_be_bytes(elt.data, elt.start, 4) as uint;
6980
if eq_fn(elt.data.slice(elt.start + 4, elt.end)) {
70-
ret = Some(reader::doc_at(d.data, pos).doc);
81+
ret = Some(unwrap_(reader::doc_at(d.data, pos)).doc);
7182
false
7283
} else {
7384
true
@@ -853,7 +864,7 @@ pub fn get_item_variances(cdata: Cmd, id: ast::NodeId) -> ty::ItemVariances {
853864
let item_doc = lookup_item(id, data);
854865
let variance_doc = reader::get_doc(item_doc, tag_item_variances);
855866
let mut decoder = reader::Decoder(variance_doc);
856-
Decodable::decode(&mut decoder)
867+
unwrap_(Decodable::decode(&mut decoder))
857868
}
858869

859870
pub fn get_provided_trait_methods(intr: @IdentInterner, cdata: Cmd,

0 commit comments

Comments
 (0)