Closed
Description
Although work on RFC 1861 for extern types has begun in issue #43467, it's not complete, and in the mean time, Rust gives very strange messages if one accidentally includes a type in an extern
block. For example:
use std::ffi::CString;
use std::os::raw::c_char;
extern {
fn strlen(s: *const c_char) -> usize;
pub struct S(c_char);
}
fn main() {
println!("{}", unsafe { strlen(CString::new("foo").unwrap().as_ptr()) });
}
On nightly, this elicits the following message:
Compiling playground v0.0.1 (file:///playground)
error: unmatched visibility `pub`
--> src/main.rs:7:5
|
7 | pub struct S(c_char);
| ^^^
A reader of our book came across this error message by accident and asked me about it. We were both mystified.