rust-lang / rust-analyzer

A Rust compiler front-end for IDEs
https://rust-analyzer.github.io/
Apache License 2.0
14.35k stars 1.62k forks source link

Wrong offset. #17112

Open PushjoeYY opened 7 months ago

PushjoeYY commented 7 months ago

rust-analyzer version: v0.3.1924-standalone

rustc version: (eg. output of 1.77.1)

editor or extension: VSCode

related file: https://github.com/raydium-io/raydium-contract-instructions/blob/master/lib/src/amm_stats.rs

image (basic view of struct repr(C)) image (Correct offset,but the next field's offset should be 0x128) image (Wrong)

Veykril commented 7 months ago

That seems correct to me? The alignment of u128 is 0x10, so putting it at 0x128 would mean its unaligned, whereas 0x130 is the next aligned offset. only repr(packed) allows putting fields at unaligned offsets.

flodiebold commented 7 months ago

Alignment of u128 was 8 in Rust 1.76 but is now 16 in 1.77 if I understand correctly, so I guess we're doing it right now. (Do we get that dynamically from rustc somehow or is it hardcoded?)

Veykril commented 7 months ago

Ah right. We link statically against a mirror of the abi crate which we update when we sync with rustc, so vscode r-a will usually depend on the latest nightly version of that (where as using rustup r-a will always match correctly)

PushjoeYY commented 7 months ago

Oh, the reason must be that the data I received was generated by an older version of rustc. It's quite challenging to detect such compatibility issues.