Skip to content
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

Merged
merged 1 commit into from
Mar 28, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions src/librustc/driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,18 @@ impl Input {
}
}

// FIXME: remove unwrap_ after snapshot
#[cfg(stage0)]
fn unwrap_<T>(t: T) -> T {
t
}

#[cfg(not(stage0))]
fn unwrap_<T, E>(r: Result<T, E>) -> T {
r.unwrap()
}


pub fn phase_1_parse_input(sess: &Session, cfg: ast::CrateConfig, input: &Input)
-> ast::Crate {
let krate = time(sess.time_passes(), "parsing", (), |_| {
Expand All @@ -187,7 +199,8 @@ 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);
// unwrapping so IoError isn't ignored
unwrap_(krate.encode(&mut json));
}

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

(krate, map)
Expand Down
17 changes: 14 additions & 3 deletions src/librustc/metadata/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ use syntax::crateid::CrateId;

pub type Cmd = @crate_metadata;

// FIXME: remove unwrap_ after a snapshot
#[cfg(stage0)]
fn unwrap_<T>(t: T) -> T {
t
}

#[cfg(not(stage0))]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a // FIXME: remove unwrap_ after a snapshot comment here?

fn unwrap_<T, E>(r: Result<T, E>) -> T {
r.unwrap()
}

// A function that takes a def_id relative to the crate being searched and
// returns a def_id relative to the compilation environment, i.e. if we hit a
// def_id for an item defined in another crate, somebody needs to figure out
Expand All @@ -59,15 +70,15 @@ fn lookup_hash<'a>(d: ebml::Doc<'a>, eq_fn: |&[u8]| -> bool,
let table = reader::get_doc(index, tag_index_table);
let hash_pos = table.start + (hash % 256 * 4) as uint;
let pos = u64_from_be_bytes(d.data, hash_pos, 4) as uint;
let tagged_doc = reader::doc_at(d.data, pos);
let tagged_doc = unwrap_(reader::doc_at(d.data, pos));

let belt = tag_index_buckets_bucket_elt;

let mut ret = None;
reader::tagged_docs(tagged_doc.doc, belt, |elt| {
let pos = u64_from_be_bytes(elt.data, elt.start, 4) as uint;
if eq_fn(elt.data.slice(elt.start + 4, elt.end)) {
ret = Some(reader::doc_at(d.data, pos).doc);
ret = Some(unwrap_(reader::doc_at(d.data, pos)).doc);
false
} else {
true
Expand Down Expand Up @@ -853,7 +864,7 @@ pub fn get_item_variances(cdata: Cmd, id: ast::NodeId) -> ty::ItemVariances {
let item_doc = lookup_item(id, data);
let variance_doc = reader::get_doc(item_doc, tag_item_variances);
let mut decoder = reader::Decoder(variance_doc);
Decodable::decode(&mut decoder)
unwrap_(Decodable::decode(&mut decoder))
}

pub fn get_provided_trait_methods(intr: @IdentInterner, cdata: Cmd,
Expand Down
Loading