So I made some changes to my code and tried to compile it on my work computer. I got the following errors relative to ntapi package:
error[E0793]: reference to packed field is unaligned
--> C:\Users\u\.cargo\registry\src\github.com-1eccb9ec823\ntapi-0.3.6\src\ntexapi.rs:2785:52
|
2785 | *tick_count.QuadPart_mut() = read_volatile(&(*USER_SHARED_DATA).u.TickCountQuad);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
= help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
error[E0793]: reference to packed field is unaligned
--> C:\Users\u\.cargo\registry\src\github.com-1ecc9ec823\ntapi-0.3.6\src\ntexapi.rs:2809:25
|
2809 | ((read_volatile(&(*USER_SHARED_DATA).u.TickCountQuad)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
= help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
For more information about this error, try `rustc --explain E0793`.
error: could not compile `ntapi` due to 2 previous errors
warning: build failed, waiting for other jobs to finish...
Some hours of trying to figure out the problem followed. As described in this thread I tried to force update ntapi but I didn't manage to do it. When I got home I commited the changes and pulled on my home PC. Turned out it compile no problem on my home PC. I'm confused. Anyone knows what is happening here?
Cargo.toml:
[package]
name = "caravel"
version = "0.1.0"
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
tokio = { version = "1", features = ["full"] }
futures = "0.3"
anyhow = "1.0.32"
clap = "3.0.0-beta.5"
structopt = "0.3.16"
shell-words = "1.0.0"
futures-util = "0.3.17"
env_logger = "0.9"
log = "0.4"
[target.'cfg(not(target_os = "windows"))'.dependencies]
tokio-socketcan = "0.3.0"
cargo tree output:
caravel v0.1.0 ()
├── anyhow v1.0.44
├── clap v3.0.0-beta.5
│ ├── atty v0.2.14
│ │ └── winapi v0.3.9
│ ├── bitflags v1.3.2
│ ├── clap_derive v3.0.0-beta.5 (proc-macro)
│ │ ├── heck v0.3.3
│ │ │ └── unicode-segmentation v1.8.0
│ │ ├── proc-macro-error v1.0.4
│ │ │ ├── proc-macro-error-attr v1.0.4 (proc-macro)
│ │ │ │ ├── proc-macro2 v1.0.29
│ │ │ │ │ └── unicode-xid v0.2.2
│ │ │ │ └── quote v1.0.10
│ │ │ │ └── proc-macro2 v1.0.29 (*)
│ │ │ │ [build-dependencies]
│ │ │ │ └── version_check v0.9.3
│ │ │ ├── proc-macro2 v1.0.29 (*)
│ │ │ ├── quote v1.0.10 (*)
│ │ │ └── syn v1.0.80
│ │ │ ├── proc-macro2 v1.0.29 (*)
│ │ │ ├── quote v1.0.10 (*)
│ │ │ └── unicode-xid v0.2.2
│ │ │ [build-dependencies]
│ │ │ └── version_check v0.9.3
│ │ ├── proc-macro2 v1.0.29 (*)
│ │ ├── quote v1.0.10 (*)
│ │ └── syn v1.0.80 (*)
│ ├── indexmap v1.7.0
│ │ └── hashbrown v0.11.2
│ │ [build-dependencies]
│ │ └── autocfg v1.0.1
│ ├── lazy_static v1.4.0
│ ├── os_str_bytes v4.2.0
│ │ └── memchr v2.4.1
│ ├── strsim v0.10.0
│ ├── termcolor v1.1.2
│ │ └── winapi-util v0.1.5
│ │ └── winapi v0.3.9
│ ├── textwrap v0.14.2
│ │ └── unicode-width v0.1.9
│ └── unicase v2.6.0
│ [build-dependencies]
│ └── version_check v0.9.3
├── env_logger v0.9.0
│ ├── atty v0.2.14 (*)
│ ├── humantime v2.1.0
│ ├── log v0.4.14
│ │ └── cfg-if v1.0.0
│ ├── regex v1.5.4
│ │ ├── aho-corasick v0.7.18
│ │ │ └── memchr v2.4.1
│ │ ├── memchr v2.4.1
│ │ └── regex-syntax v0.6.25
│ └── termcolor v1.1.2 (*)
├── futures v0.3.17
│ ├── futures-channel v0.3.17
│ │ ├── futures-core v0.3.17
│ │ └── futures-sink v0.3.17
│ ├── futures-core v0.3.17
│ ├── futures-executor v0.3.17
│ │ ├── futures-core v0.3.17
│ │ ├── futures-task v0.3.17
│ │ └── futures-util v0.3.17
│ │ ├── futures-channel v0.3.17 (*)
│ │ ├── futures-core v0.3.17
│ │ ├── futures-io v0.3.17
│ │ ├── futures-macro v0.3.17 (proc-macro)
│ │ │ ├── proc-macro-hack v0.5.19 (proc-macro)
│ │ │ ├── proc-macro2 v1.0.29 (*)
│ │ │ ├── quote v1.0.10 (*)
│ │ │ └── syn v1.0.80 (*)
│ │ │ [build-dependencies]
│ │ │ └── autocfg v1.0.1
│ │ ├── futures-sink v0.3.17
│ │ ├── futures-task v0.3.17
│ │ ├── memchr v2.4.1
│ │ ├── pin-project-lite v0.2.7
│ │ ├── pin-utils v0.1.0
│ │ ├── proc-macro-hack v0.5.19 (proc-macro)
│ │ ├── proc-macro-nested v0.1.7
│ │ └── slab v0.4.5
│ │ [build-dependencies]
│ │ └── autocfg v1.0.1
│ ├── futures-io v0.3.17
│ ├── futures-sink v0.3.17
│ ├── futures-task v0.3.17
│ └── futures-util v0.3.17 (*)
├── futures-util v0.3.17 (*)
├── log v0.4.14 (*)
├── shell-words v1.0.0
├── structopt v0.3.25
│ ├── clap v2.33.3
│ │ ├── atty v0.2.14 (*)
│ │ ├── bitflags v1.3.2
│ │ ├── strsim v0.8.0
│ │ ├── textwrap v0.11.0
│ │ │ └── unicode-width v0.1.9
│ │ ├── unicode-width v0.1.9
│ │ └── vec_map v0.8.2
│ ├── lazy_static v1.4.0
│ └── structopt-derive v0.4.18 (proc-macro)
│ ├── heck v0.3.3 (*)
│ ├── proc-macro-error v1.0.4 (*)
│ ├── proc-macro2 v1.0.29 (*)
│ ├── quote v1.0.10 (*)
│ └── syn v1.0.80 (*)
└── tokio v1.12.0
├── bytes v1.1.0
├── memchr v2.4.1
├── mio v0.7.13
│ ├── log v0.4.14 (*)
│ ├── miow v0.3.7
│ │ └── winapi v0.3.9
│ ├── ntapi v0.3.6
│ │ └── winapi v0.3.9
│ └── winapi v0.3.9
├── num_cpus v1.13.0
│ └── libc v0.2.103
├── once_cell v1.8.0
├── parking_lot v0.11.2
│ ├── instant v0.1.11
│ │ └── cfg-if v1.0.0
│ ├── lock_api v0.4.5
│ │ └── scopeguard v1.1.0
│ └── parking_lot_core v0.8.5
│ ├── cfg-if v1.0.0
│ ├── instant v0.1.11 (*)
│ ├── smallvec v1.7.0
│ └── winapi v0.3.9
├── pin-project-lite v0.2.7
├── tokio-macros v1.4.1 (proc-macro)
│ ├── proc-macro2 v1.0.29 (*)
│ ├── quote v1.0.10 (*)
│ └── syn v1.0.80 (*)
└── winapi v0.3.9
[build-dependencies]
└── autocfg v1.0.1
cargo -V:
cargo 1.69.0 (6e9a83356 2023-04-12)
For some reason (I don't know why) Cargo picked an older version of tokio
that used (indirectly) an older version of ntapi
that used a construct that was always UB, but because it was allowed in the past, it used to only trigger a soft future-incompatibility warning. But as of Rust 1.69.0 it became a hard error, and therefore at work it didn't compile. It is likely that your version at home is lower, so it worked there.
Force Cargo to use new tokio
by setting its version to "1.28.0"
(the newest version), and it should work.