Skip to content

Commit 72833e4

Browse files
committed
Auto 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.
2 parents 2a6828e + 81eea9e commit 72833e4

File tree

3 files changed

+14
-15
lines changed

3 files changed

+14
-15
lines changed

src/librustc_llvm/archive_ro.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ impl ArchiveRO {
3939
///
4040
/// If this archive is used with a mutable method, then an error will be
4141
/// raised.
42-
pub fn open(dst: &Path) -> Option<ArchiveRO> {
42+
pub fn open(dst: &Path) -> Result<ArchiveRO, String> {
4343
return unsafe {
4444
let s = path2cstr(dst);
4545
let ar = ::LLVMRustOpenArchive(s.as_ptr());
4646
if ar.is_null() {
47-
None
47+
Err(::last_error().unwrap_or("failed to open archive".to_string()))
4848
} else {
49-
Some(ArchiveRO { ptr: ar })
49+
Ok(ArchiveRO { ptr: ar })
5050
}
5151
};
5252

src/librustc_trans/back/archive.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ impl<'a> ArchiveBuilder<'a> {
126126
Some(ref src) => src,
127127
None => return None,
128128
};
129-
self.src_archive = Some(ArchiveRO::open(src));
129+
self.src_archive = Some(ArchiveRO::open(src).ok());
130130
self.src_archive.as_ref().unwrap().as_ref()
131131
}
132132

@@ -186,9 +186,8 @@ impl<'a> ArchiveBuilder<'a> {
186186
where F: FnMut(&str) -> bool + 'static
187187
{
188188
let archive = match ArchiveRO::open(archive) {
189-
Some(ar) => ar,
190-
None => return Err(io::Error::new(io::ErrorKind::Other,
191-
"failed to open archive")),
189+
Ok(ar) => ar,
190+
Err(e) => return Err(io::Error::new(io::ErrorKind::Other, e)),
192191
};
193192
self.additions.push(Addition::Archive {
194193
archive: archive,

src/librustc_trans/metadata.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,21 @@ impl MetadataLoader for LlvmMetadataLoader {
3131
// just keeping the archive along while the metadata is in use.
3232
let archive = ArchiveRO::open(filename)
3333
.map(|ar| OwningRef::new(box ar))
34-
.ok_or_else(|| {
35-
debug!("llvm didn't like `{}`", filename.display());
36-
format!("failed to read rlib metadata: '{}'", filename.display())
37-
})?;
34+
.map_err(|e| {
35+
debug!("llvm didn't like `{}`: {}", filename.display(), e);
36+
format!("failed to read rlib metadata in '{}': {}", filename.display(), e)
37+
})?;
3838
let buf: OwningRef<_, [u8]> = archive
3939
.try_map(|ar| {
4040
ar.iter()
4141
.filter_map(|s| s.ok())
4242
.find(|sect| sect.name() == Some(METADATA_FILENAME))
4343
.map(|s| s.data())
4444
.ok_or_else(|| {
45-
debug!("didn't find '{}' in the archive", METADATA_FILENAME);
46-
format!("failed to read rlib metadata: '{}'",
47-
filename.display())
48-
})
45+
debug!("didn't find '{}' in the archive", METADATA_FILENAME);
46+
format!("failed to read rlib metadata: '{}'",
47+
filename.display())
48+
})
4949
})?;
5050
Ok(buf.erase_owner())
5151
}

0 commit comments

Comments
 (0)