Skip to content

Commit 9f190d7

Browse files
committed
Restore usage of io::Error
1 parent ec45166 commit 9f190d7

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

compiler/rustc_codegen_llvm/src/back/archive.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ fn get_llvm_object_symbols(
132132
if err.is_null() {
133133
return Ok(true);
134134
} else {
135-
let error = unsafe { *Box::from_raw(err as *mut String) };
135+
let error = unsafe { *Box::from_raw(err as *mut io::Error) };
136136
// These are the magic constants for LLVM bitcode files:
137137
// https://github.com/llvm/llvm-project/blob/7eadc1960d199676f04add402bb0aa6f65b7b234/llvm/lib/BinaryFormat/Magic.cpp#L90-L97
138138
if buf.starts_with(&[0xDE, 0xCE, 0x17, 0x0B]) || buf.starts_with(&[b'B', b'C', 0xC0, 0xDE])
@@ -150,21 +150,24 @@ fn get_llvm_object_symbols(
150150
eprintln!("warning: Failed to read symbol table from LLVM bitcode: {}", error);
151151
return Ok(true);
152152
} else {
153-
return Err(io::Error::new(io::ErrorKind::Other, format!("LLVM error: {}", error)));
153+
return Err(error);
154154
}
155155
}
156156

157157
unsafe extern "C" fn callback(state: *mut c_void, symbol_name: *const c_char) -> *mut c_void {
158158
let f = unsafe { &mut *(state as *mut &mut dyn FnMut(&[u8]) -> io::Result<()>) };
159159
match f(unsafe { CStr::from_ptr(symbol_name) }.to_bytes()) {
160160
Ok(()) => std::ptr::null_mut(),
161-
Err(err) => Box::into_raw(Box::new(err.to_string()) as Box<String>) as *mut c_void,
161+
Err(err) => Box::into_raw(Box::new(err) as Box<io::Error>) as *mut c_void,
162162
}
163163
}
164164

165165
unsafe extern "C" fn error_callback(error: *const c_char) -> *mut c_void {
166166
let error = unsafe { CStr::from_ptr(error) };
167-
Box::into_raw(Box::new(error.to_string_lossy().into_owned()) as Box<String>) as *mut c_void
167+
Box::into_raw(Box::new(io::Error::new(
168+
io::ErrorKind::Other,
169+
format!("LLVM error: {}", error.to_string_lossy()),
170+
)) as Box<io::Error>) as *mut c_void
168171
}
169172
}
170173

0 commit comments

Comments
 (0)