diff --git a/src/librustc_llvm/archive_ro.rs b/src/librustc_llvm/archive_ro.rs index b3f5f8e5360..0b24e55541b 100644 --- a/src/librustc_llvm/archive_ro.rs +++ b/src/librustc_llvm/archive_ro.rs @@ -39,14 +39,14 @@ impl ArchiveRO { /// /// If this archive is used with a mutable method, then an error will be /// raised. - pub fn open(dst: &Path) -> Option { + pub fn open(dst: &Path) -> Result { return unsafe { let s = path2cstr(dst); let ar = ::LLVMRustOpenArchive(s.as_ptr()); if ar.is_null() { - None + Err(::last_error().unwrap_or("failed to open archive".to_string())) } else { - Some(ArchiveRO { ptr: ar }) + Ok(ArchiveRO { ptr: ar }) } }; diff --git a/src/librustc_trans/back/archive.rs b/src/librustc_trans/back/archive.rs index 902065c8688..6ec40bd689c 100644 --- a/src/librustc_trans/back/archive.rs +++ b/src/librustc_trans/back/archive.rs @@ -126,7 +126,7 @@ impl<'a> ArchiveBuilder<'a> { Some(ref src) => src, None => return None, }; - self.src_archive = Some(ArchiveRO::open(src)); + self.src_archive = Some(ArchiveRO::open(src).ok()); self.src_archive.as_ref().unwrap().as_ref() } @@ -186,9 +186,8 @@ impl<'a> ArchiveBuilder<'a> { where F: FnMut(&str) -> bool + 'static { let archive = match ArchiveRO::open(archive) { - Some(ar) => ar, - None => return Err(io::Error::new(io::ErrorKind::Other, - "failed to open archive")), + Ok(ar) => ar, + Err(e) => return Err(io::Error::new(io::ErrorKind::Other, e)), }; self.additions.push(Addition::Archive { archive: archive, diff --git a/src/librustc_trans/metadata.rs b/src/librustc_trans/metadata.rs index 2c0148dfbb3..883808c5909 100644 --- a/src/librustc_trans/metadata.rs +++ b/src/librustc_trans/metadata.rs @@ -31,10 +31,10 @@ impl MetadataLoader for LlvmMetadataLoader { // just keeping the archive along while the metadata is in use. let archive = ArchiveRO::open(filename) .map(|ar| OwningRef::new(box ar)) - .ok_or_else(|| { - debug!("llvm didn't like `{}`", filename.display()); - format!("failed to read rlib metadata: '{}'", filename.display()) - })?; + .map_err(|e| { + debug!("llvm didn't like `{}`: {}", filename.display(), e); + format!("failed to read rlib metadata in '{}': {}", filename.display(), e) + })?; let buf: OwningRef<_, [u8]> = archive .try_map(|ar| { ar.iter() @@ -42,10 +42,10 @@ impl MetadataLoader for LlvmMetadataLoader { .find(|sect| sect.name() == Some(METADATA_FILENAME)) .map(|s| s.data()) .ok_or_else(|| { - debug!("didn't find '{}' in the archive", METADATA_FILENAME); - format!("failed to read rlib metadata: '{}'", - filename.display()) - }) + debug!("didn't find '{}' in the archive", METADATA_FILENAME); + format!("failed to read rlib metadata: '{}'", + filename.display()) + }) })?; Ok(buf.erase_owner()) }