stop auto-wrapping code snippets in fn main() #955
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I'm guessing this would be a semver breaking change, but would be happy to do the accompanying work of migrating code snippets in https://github.com/rust-lang/book to include
fn main() {}
wrapping explicitly (and#![allow(unused_variables)]
where necessary) if this change is accepted (and the book migration could actually happen first because of the currenttext.contains("fn main")
exclusion).This seems to be a somewhat persistent issue in code snippet formatting in the Rust book, particularly for
src/lib.rs
files, with some awkward fixes (see expanded Listing 11-12 in https://doc.rust-lang.org/stable/book/ch11-03-test-organization.html for implications of this approach, extraneous code still added) without a particularly good solution (using theignore
class seems undesirable).An alternative implementation could be adding support for a class like
nomain
ornowrap
instead of changing this default behavior.Refs #222 for initial implementation, #283 (
quick_main!
macro), #618, #712, rust-lang/book#1206, rust-lang/book#1874 (editable
preventsfn main()
wrapping), rust-lang/book#1982Examples of problematic code snippets in the Rust book: