bsky
bsky

Reputation: 20232

transmute called with types of different sizes

I'm trying to build a Rust project with cargo build but I get this error:

error[E0512]: transmute called with types of different sizes
   |
90 |     ::std::mem::transmute(tenv)
   |     ^^^^^^^^^^^^^^^^^^^^^
   |
   = note: source type: i32 (32 bits)
   = note: target type: *mut traction::Environment<JNIPlatform<'a>, std::string::String> (64 bits)

The code on which this breaks is this:

let tenv = env.get_field_unsafe(obj, JFieldID::from(field), jni::signature::JavaType::Primitive(jni::signature::Primitive::Int)).unwrap_alog().i().unwrap();
::std::mem::transmute(tenv)

I have no knowledge of Rust so I can only guess what this does.

Since this is a type conversion issue I'm assuming this has something to do with my operating system. Other people who cloned the same repository didn't have any issue like this (both on macOS and Windows). I have macOS Sierra 10.12.6.

Another question: how does transmute know what type to convert the variable that's given to it? ::std::mem::transmute(tenv) takes only one argument, so how does it know both the source type and the destination type?

Upvotes: 0

Views: 985

Answers (1)

Gr&#233;gory OBANOS
Gr&#233;gory OBANOS

Reputation: 1051

The target type is a pointer, so it's architecture specific: 32 bits on a 32-bit platform, 64 bits on a 64-bit platform. usize and isize can be used in for this case.

If it's not your code, you should open an issue on the original repository.

You could try to build a 32-bit binary, using rustup default stable-i686

how does transmute know what type to convert the variable that's given to it? ::std::mem::transmute(tenv) takes only one argument, so how does it know both the source type and the destination type?

Rust infers the source and target type from the context, in the same way Iterator::collect does.

Upvotes: 1

Related Questions