Idiomatic: Fix various broken code examples#3159
Merged
mgeisler merged 1 commit intogoogle:mainfrom Apr 12, 2026
Merged
Conversation
mgeisler
reviewed
Apr 12, 2026
Comment on lines
16
to
+19
| # // Copyright 2025 Google LLC | ||
| # // SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| impl <T> Vec<T> { | ||
| // Creates an empty vec. | ||
| impl<T> Vec<T> { |
Collaborator
There was a problem hiding this comment.
Thanks for fixing the formatting (and all the other things!)
It just occurred to me that the # syntax very likely is what prevents dprint from formatting this code block. It knows it's Rust from the info string and it knows to split on ,, but rustfmt will not be happy with the # lines.
Cc @gribozavr as another side-effect of #3101.
mgeisler
approved these changes
Apr 12, 2026
Collaborator
mgeisler
left a comment
There was a problem hiding this comment.
Thank you for bringing this up to standard.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Many of the code snippets in Idiomatic are broken in various ways that make them either not run in the slides or not show the error the slide is intended to illustrate. This PR fixes a number of common issues:
letinside a struct definition.mainfn. Not all examples need amain, but several code examples had code that only compiles if it's in a function, and so was failing to compile in the slides. Note that these were not caught in tests because there seems to be a difference in behavior between how we test the code vs how the code works in the slides.fnkeyword on method definitions.In a few places I made more opinionated changes that I'm including here because splitting them out into a separate PR would just result in merge conflicts later:
hash.md- Removed thefriendsfield. It wasn't necessary for demonstrating theHashtrait, and removing it allows the slide to be more concise.newtype_pattern.md- Tweak the exercise to show that you can't pass an inner type where a newtype wrapper is expected (inverse of what it was previously demonstrating). I think this is a slightly clearer way to show what the slide is demonstrating.pubkeyword in a few places.#prefix on lines that I think should be kept visible in the code snippet (though note that none of the hidden lines are ever hidden because the code snippets are editable, see Examples with hidden lines should be editable #2811).