Does mdbook not support the new Rust 2024 edition yet?
Some days ago, I started porting the books's examples to Rust 2024 -- actually it is more testing with Rust 2024, as most examples should be compatible.
For that, I edited book.toml:
[rust]
edition = "2024"
and rebuild the book with "mdbook clean; mdbook build" and shipped it with rsync.
The strange thing is, that the FFI example runs fine when clicking the run button, but when I copy it into Rust's playground (which uses now Rust 2024 as default) compile fails, because extern needs now an unsafe block. If I switch playground to 2021 edition, it works.
My only explanation is currently, that mdbook masks 2024 internally still ?
Edition 2024 support was added to mdbook 8 months ago and first released in v0.4.41. I don't know what is causing the discrepancy between mdbook and the playground.
Thanks for your fast reply. I will then ask in the mdbook GitHub issue tracker, even when answers there might took a bit longer. Also I might try the "mdbook test" command, which runs all the code examples. Perhaps that will report code examples incompatible with the 2024 edition.
I just tried the run button of one of your examples and the following JSON is send as the request payload to the playground (note that the edition is set to 2015—looks like a bug in the play button; it ignoring the edition of the code snippet):
{"version":"stable","optimize":"0","code":"#[link(name = \"c\")]\nextern \"C\" {\n fn abs(input: i32) -> i32;\n}\n\nfn main() {\n let value = -42;\n // Calling an external fn is unsafe because Rust cannot verify its implementation.\n unsafe {\n let result = abs(value);\n println!(\"abs({}) = {}\", value, result);\n }\n}","edition":"2015"}
Thank you very much for the detailed investigation. Do you suggest modifying file book.js manually? I got mdbook frm the Gentoo-Linux package manager, it is the latest version v0.4.45.
Ha, didn't realise I was looking at the already fixed version of book.js, I hadn't checked the history. That was pretty fast indeed. The next version will contain the fix for sure, it is already merged into master. If you don't want to wait for the next release, applying the fix to your book.js manually wouldn't be too bad IMO, it's just the 5 lines of code from the PR. You probably need to exclude book.js from rsync though.