immunant / c2rust

Migrate C code to Rust
https://c2rust.com/
Other
3.93k stars 230 forks source link

hex literal error #161

Closed mmacedoeu closed 4 years ago

mmacedoeu commented 4 years ago

This: static const uint8_t access_conditions_and_gpb_bytes[4] = "\x78\x77\x88\xcb";

Got translated as: static mut access_conditions_and_gpb_bytes: [uint8_t; 4] = [120, 119, -120, -53];

Generating rust error:

1532 | [120, 119, -120, -53]; | ^^^^ cannot apply unary operator -

Expected result: static mut access_conditions_and_gpb_bytes: [uint8_t; 4] = [0x78, 0x77, 0x88, 0xcb];

thedataking commented 4 years ago

Hey @mmacedoeu, we ran into a similar problem when translating Python2. Are you using the latest master from GitHub or the crates.io version? In case of the latter, can you try master and let us know if that contains the fix you need?

mmacedoeu commented 4 years ago

I used master branch for this error

thedataking commented 4 years ago

@mmacedoeu Commit 314b083f8c13345d8f1c56e820ec1b9552ac62d4 should address this issue. Can you pull from master and confirm?

mmacedoeu commented 4 years ago

Got this error after git pull:

error[E0277]: the trait bound `pulldown_cmark::Event<'_>: std::borrow::Borrow<pulldown_cmark::parse::Event<'_>>` is not satisfied
   --> manual/preprocessors/include_md.rs:318:17
    |
318 |                 cmark(section_events, &mut buf, None)
    |                 ^^^^^ the trait `std::borrow::Borrow<pulldown_cmark::parse::Event<'_>>` is not implemented for `pulldown_cmark::Event<'_>`
    |
    = note: required by `pulldown_cmark_to_cmark::fmt::cmark`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0277`.
error: Could not compile `c2rust-manual-preprocessors`.
rinon commented 4 years ago

How exactly are you building c2rust? I've never seen that error with pulldown-cmark-to-cmark 1.2.0 and nightly-2019-06-22.

rinon commented 4 years ago

This seems to be due to cargo picking up version 0.1.2 of pulldown-cmark for mdbook and not allowing our crate to use version 0.2, which it requires. I still don't know why you're hitting this and we haven't, though (I discovered that by editing our Cargo.toml to downgrade to 0.1.2).

mmacedoeu commented 4 years ago

This is my Cargo.lock for mdbook:

[[package]] name = "mdbook" version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "ammonia 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "chrono 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)", "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", "elasticlunr-rs 2.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)", "error-chain 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)", "handlebars 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "iron 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "itertools 0.7.11 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "notify 4.0.13 (registry+https://github.com/rust-lang/crates.io-index)", "open 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "pulldown-cmark 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)", "shlex 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "staticfile 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "toml 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", "toml-query 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "ws 0.7.9 (registry+https://github.com/rust-lang/crates.io-index)", ]

Same as: https://github.com/immunant/c2rust/blob/master/Cargo.lock#L1251

rinon commented 4 years ago

Yeah, I'm not worried about that, but there might be something stale? You're allowing cargo to pull down new packages, right? I assume you tried a cargo clean then build?

mmacedoeu commented 4 years ago

I did cargo clean, cargo update, cargo build and also tried rm Cargo.lock before that

mmacedoeu commented 4 years ago

I removed manual from workspace members and it compiled, fixing this problem so I will close this issue. Thanks

rinon commented 4 years ago

You should never delete our Cargo.lock, it should work as is, as long as you didn't change any Cargo.toml files. I updated a few dependencies, but I can only replicate your issue if I modify Cargo.toml files to update more dependencies. Going to leave this closed as I can't properly replicate under normal circumstances.