-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
the implied edition
for playground needs to be 2021
in ch09-02 (at least)
#3970
Comments
Thanks for reporting this! I agree that we should make sure that all the playground links get generated using the edition in the |
This comment was marked as outdated.
This comment was marked as outdated.
I merged a baseline change for this in #3974, as it passed CI so things which have a hard requirement on it all pass. We likely still want to do a further pass to check the behavior of the other listings, and we will also want to figure out why this one (and any others like it!) passed CI (which is the really 😬 bit). |
it doesn't fail because they're only warnings not errors, when using edition 2015 instead of edition 2021. It would need a I guess diff --git a/book.toml b/book.toml
index 800adcf0f5bcd753..90f9cdebce43fff7 100644
--- a/book.toml
+++ b/book.toml
@@ -17,4 +17,4 @@ git-repository-url = "https://github.com
output-mode = "default"
[rust]
-edition = "2021"
+edition = "2015"
Ok so apparently ```rust,should_panic
#![allow(unused_variables)]
use std::fs::File;
fn main() {
let greeting_file_result = File::open("hello.txt");
let greeting_file = match greeting_file_result {
Ok(file) => file,
Err(error) => panic!("Problem opening the file: {error:?}"),
};
}
\``` and then |
I just circled back to this and checked on things, and I think the fix I landed to handle this did indeed handle everything we needed here. We will need to remember to hit that on future updates, like when the 2024 Edition lands in a few months, so I opened #4064 to help us remember! Going to go ahead and close this out now. Thanks again! |
main
branch to see if this has already been fixed, in this file:book/listings/ch09-error-handling/listing-09-04/src/main.rs
Line 1 in ee5c7ec
URL to the section(s) of the book with this problem:
https://doc.rust-lang.org/book/ch09-02-recoverable-errors-with-result.html#recoverable-errors-with-result
https://doc.rust-lang.org/nightly/book/ch09-02-recoverable-errors-with-result.html#recoverable-errors-with-result
Description of the problem:
There's an example there, this one:
which when you press the Play button, it clearly uses one of 2015 or 2018 editions instead of the 2021 one because the errors are these:
Also note that there's no button to open that code block in playground, there's only copy code and play button(which shows the output inline, while viewing the book), so to try it in playground, one must manually open the already-known playground url then paste the copied code there and see that it actually works (due to 2021 edition being default in playground).
Here's 2018 edition on playground
Here's 2021 edition on playground
The latter works as expected.
Suggested fix:
I don't know where this edition is enforced for playground(it doesn't seem like this knows), but, at least for this example, it should be
edition=2021
, because 2015 and 2018 show the above warnings and as you can see, it doesn't display correct outputProblem opening the file: {error:?}
which should beProblem opening the file: Os { code: 2, kind: NotFound, message: "No such file or directory" }
.I've checked the linked file and it is in a project with edition 2021, however, that doesn't mean that the play button knows to use that edition for playground.
It would seem that the workaround1 is quite possibly adding
edition2021
here just like it's done inbook/src/ch04-02-references-and-borrowing.md
Line 173 in ee5c7ec
A built
book.js
has 2015 as the default edition:well this default is from mdBook and been there since 2021 or earlier.
Footnotes
it's just a workaround because who knows in how many other places this is needed; ideally, that edition value would be gotten from
Cargo.toml
instead, somehow, everywhere where there's a play button... ↩The text was updated successfully, but these errors were encountered: