diff options
| author | Corey Farwell <coreyf@rwell.org> | 2017-08-02 01:22:26 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-08-02 01:22:26 +0000 |
| commit | ab3fb956f3b9b2cd5d444ec30dd58bdf25dea7c9 (patch) | |
| tree | 049ac4995acaa398d0a87ca8c42c2f3ef5869714 | |
| parent | 640cfc852ae17d51a2f5e75fcae9a93431a3b38c (diff) | |
| parent | 81eea9e4312253afb655c051d0bf0661744ab56e (diff) | |
| download | rust-ab3fb956f3b9b2cd5d444ec30dd58bdf25dea7c9.tar.gz rust-ab3fb956f3b9b2cd5d444ec30dd58bdf25dea7c9.zip | |
Rollup merge of #43389 - alexcrichton:thread-error, r=michaelwoerister
Thread through the original error when opening archives This updates the management of opening archives to thread through the original piece of error information from LLVM over to the end consumer, trans.
| -rw-r--r-- | src/librustc_llvm/archive_ro.rs | 6 | ||||
| -rw-r--r-- | src/librustc_trans/back/archive.rs | 7 | ||||
| -rw-r--r-- | src/librustc_trans/metadata.rs | 16 |
3 files changed, 14 insertions, 15 deletions
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<ArchiveRO> { + pub fn open(dst: &Path) -> Result<ArchiveRO, String> { 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()) } |
