Skip to content

Idiomatic: Fix various broken code examples#3159

Merged
mgeisler merged 1 commit intogoogle:mainfrom
randomPoison:idiomatic-fix-examples
Apr 12, 2026
Merged

Idiomatic: Fix various broken code examples#3159
mgeisler merged 1 commit intogoogle:mainfrom
randomPoison:idiomatic-fix-examples

Conversation

@randomPoison
Copy link
Copy Markdown
Contributor

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:

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 the friends field. It wasn't necessary for demonstrating the Hash trait, 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.
  • A few minor tweaks to formatting.
  • Remove a few extraneous comments.
  • Add empty lines to help space things out and make them easier to read.
  • Remove pub keyword in a few places.
  • Remove the # 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).

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> {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator

@mgeisler mgeisler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for bringing this up to standard.

@mgeisler mgeisler merged commit 3501412 into google:main Apr 12, 2026
37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants