Skip to content
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

Include trailing comma in multiline Debug representation #59076

Merged
merged 1 commit into from Apr 5, 2019

Conversation

Projects
None yet
@dtolnay
Copy link
Member

commented Mar 10, 2019

This PR changes the behavior of Formatter::debug_struct, debug_tuple, debug_list, debug_set, and debug_map to render trailing commas in {:#?} mode, which is the dominant style in modern Rust code.

Before:

Language {
    name: "Rust",
    trailing_commas: false
}

After:

Language {
    name: "Rust",
    trailing_commas: true,
}
@rust-highfive

This comment has been minimized.

Copy link
Collaborator

commented Mar 10, 2019

r? @kennytm

(rust_highfive has picked a reviewer for you, use r? to override)

@Mark-Simulacrum

This comment has been minimized.

Copy link
Member

commented Mar 11, 2019

Is there any reason to do this, beyond being nicer from a formatting perspective?

@rustbot modify labels to relnotes.

@rustbot rustbot added the relnotes label Mar 11, 2019

@dtolnay

This comment has been minimized.

Copy link
Member Author

commented Mar 11, 2019

I would say that's the only reason. I won't try to argue that this makes debugging easier. 😉

The current behavior of DebugStruct was designed before the code style for Rust had been as well established. You can see in RFC 640 which proposed {:#?} there is this code fragment under Motivation without a trailing comma:

pub struct BufferedStream<S> {
    inner: BufferedReader<InternalBufferedWriter<S>>
}

I believe if the feature were being implemented from scratch today it would certainly be done with a trailing comma. This PR only closes the gap between the way it was built in 2015 and the way we would build it today.

@petrochenkov

This comment has been minimized.

Copy link
Contributor

commented Mar 11, 2019

Is there any reason to do this, beyond being nicer from a formatting perspective?

Code in libcore/fmt is simpler, for example.
Being friendly to code generators is one of the primary reasons why trailing separators are supported in general.

@Mark-Simulacrum

This comment has been minimized.

Copy link
Member

commented Mar 11, 2019

I will make the note that this is likely to cause somewhat widespread test breakage in the community; I don't think that's a reason to not do this, but worth noting. We can run crater if we want to know ahead of time.

@bors try in case we decide to go ahead with a crater run

I presume we'll want an FCP for libs team? Let's try r? @Amanieu for the review

@rust-highfive rust-highfive assigned Amanieu and unassigned kennytm Mar 11, 2019

@bors

This comment has been minimized.

Copy link
Contributor

commented Mar 11, 2019

⌛️ Trying commit ddcfe2b with merge 0f4bc26...

bors added a commit that referenced this pull request Mar 11, 2019

Auto merge of #59076 - dtolnay:comma, r=<try>
Include trailing comma in multiline Debug representation

This PR changes the behavior of [`Formatter::debug_struct`](https://doc.rust-lang.org/std/fmt/struct.Formatter.html#method.debug_struct), [`debug_tuple`](https://doc.rust-lang.org/std/fmt/struct.Formatter.html#method.debug_tuple), [`debug_list`](https://doc.rust-lang.org/std/fmt/struct.Formatter.html#method.debug_list), [`debug_set`](https://doc.rust-lang.org/std/fmt/struct.Formatter.html#method.debug_set), and [`debug_map`](https://doc.rust-lang.org/std/fmt/struct.Formatter.html#method.debug_map) to render trailing commas in `{:#?}` mode, which is the dominant style in modern Rust code.

#### Before:

```console
Language {
    name: "Rust",
    trailing_commas: false
}
```

#### After:

```console
Language {
    name: "Rust",
    trailing_commas: true,
}
```
@bors

This comment has been minimized.

Copy link
Contributor

commented Mar 11, 2019

☀️ Try build successful - checks-travis
Build commit: 0f4bc26

@Centril Centril added this to the 1.35 milestone Mar 18, 2019

@Dylan-DPC

This comment has been minimized.

Copy link
Member

commented Mar 18, 2019

ping from triage @Amanieu / @rust-lang/libs any updates?

@alexcrichton

This comment has been minimized.

Copy link
Member

commented Mar 18, 2019

I would personally think that we can land this at any time (and should) but @Mark-Simulacrum do you feel that this definitely needs a crater run? I think I probably expect less breakage than you though

@Mark-Simulacrum

This comment has been minimized.

Copy link
Member

commented Mar 19, 2019

Not at all; I expect breakage but probably just local (i.e., tests) and we're generally pretty free to break those. We'll (someone from the release team) probably just open an issue once next beta is cut with this in it and we get a crater run on that, we can assess breakage then. Seems fine to land for now though!

@bors r=alexcrichton (I also glanced through but tests and nothing seems obviously bad)

@bors

This comment has been minimized.

Copy link
Contributor

commented Mar 19, 2019

📌 Commit ddcfe2b has been approved by alexcrichton

@bors

This comment has been minimized.

Copy link
Contributor

commented Mar 19, 2019

☔️ The latest upstream changes (presumably #59293) made this pull request unmergeable. Please resolve the merge conflicts.

@xfix

This comment has been minimized.

Copy link
Contributor

commented Mar 20, 2019

Well, it is a breaking change, and I saw code (although not in Rust) that parsed formatting output in order to get information that is otherwise unobtainable. However, while I can believe some Rust programmers did that, I would assume most were reasonable enough to use {:?} instead of {:#?} to avoid unnecessary whitespace.

@Centril

This comment has been minimized.

Copy link
Member

commented Mar 30, 2019

Ping from triage, @dtolnay, you have some rebasing todo.

@bors

This comment was marked as resolved.

Copy link
Contributor

commented Apr 1, 2019

🔒 Merge conflict

This pull request and the master branch diverged in a way that cannot be automatically merged. Please rebase on top of the latest master branch, and let the reviewer approve again.

How do I rebase?

Assuming self is your fork and upstream is this repository, you can resolve the conflict following these steps:

  1. git checkout comma (switch to your branch)
  2. git fetch upstream master (retrieve the latest master)
  3. git rebase upstream/master -p (rebase on top of it)
  4. Follow the on-screen instruction to resolve conflicts (check git status if you got lost).
  5. git push self comma --force-with-lease (update this PR)

You may also read Git Rebasing to Resolve Conflicts by Drew Blessing for a short tutorial.

Please avoid the "Resolve conflicts" button on GitHub. It uses git merge instead of git rebase which makes the PR commit history more difficult to read.

Sometimes step 4 will complete without asking for resolution. This is usually due to difference between how Cargo.lock conflict is handled during merge and rebase. This is normal, and you should still perform step 5 to update this PR.

Error message
Auto-merging src/test/ui/rfc-2361-dbg-macro/dbg-macro-expected-behavior.rs
CONFLICT (content): Merge conflict in src/test/ui/rfc-2361-dbg-macro/dbg-macro-expected-behavior.rs
Auto-merging src/test/ui/nll/ty-outlives/ty-param-closure-outlives-from-where-clause.stderr
Auto-merging src/test/ui/nll/ty-outlives/ty-param-closure-outlives-from-return-type.stderr
Auto-merging src/test/ui/nll/ty-outlives/ty-param-closure-approximate-lower-bound.stderr
Auto-merging src/test/ui/nll/ty-outlives/projection-two-region-trait-bound-closure.stderr
Auto-merging src/test/ui/nll/ty-outlives/projection-one-region-trait-bound-closure.stderr
Auto-merging src/test/ui/nll/ty-outlives/projection-one-region-closure.stderr
Auto-merging src/test/ui/nll/ty-outlives/projection-no-regions-closure.stderr
Auto-merging src/test/ui/nll/closure-requirements/return-wrong-bound-region.stderr
Auto-merging src/test/ui/nll/closure-requirements/propagate-from-trait-match.stderr
Auto-merging src/test/ui/nll/closure-requirements/propagate-fail-to-approximate-longer-wrong-bounds.stderr
Auto-merging src/test/ui/nll/closure-requirements/propagate-fail-to-approximate-longer-no-bounds.stderr
Auto-merging src/test/ui/nll/closure-requirements/propagate-approximated-val.stderr
Auto-merging src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-wrong-bound.stderr
Auto-merging src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-no-bound.stderr
Auto-merging src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-comparing-against-free.stderr
Auto-merging src/test/ui/nll/closure-requirements/propagate-approximated-ref.stderr
Auto-merging src/test/ui/nll/closure-requirements/propagate-approximated-fail-no-postdom.stderr
Auto-merging src/test/ui/nll/closure-requirements/escape-upvar-nested.stderr
Auto-merging src/test/ui/nll/closure-requirements/escape-argument.stderr
Auto-merging src/test/ui/nll/closure-requirements/escape-argument-callee.stderr
Automatic merge failed; fix conflicts and then commit the result.

@dtolnay dtolnay force-pushed the dtolnay:comma branch from ddcfe2b to c0d68d2 Apr 3, 2019

@dtolnay

This comment has been minimized.

Copy link
Member Author

commented Apr 3, 2019

Rebased to fix conflict with #57847 in src/test/ui/rfc-2361-dbg-macro/dbg-macro-expected-behavior.rs.
Passed ./x.py test locally.

@bors r=alexcrichton

@Centril Centril referenced this pull request Apr 3, 2019

Closed

Rollup of 5 pull requests #59670

bors added a commit that referenced this pull request Apr 3, 2019

Auto merge of #59670 - Centril:rollup-bqa1xeq, r=Centril
Rollup of 5 pull requests

Successful merges:

 - #59076 (Include trailing comma in multiline Debug representation)
 - #59619 (wasi: Implement more of the standard library)
 - #59639 (Never return uninhabited values at all)
 - #59643 (std: Upgrade `compiler_builtins` to fix wasi linkage)
 - #59664 (Updated the documentation of spin_loop and spin_loop_hint)

Failed merges:

r? @ghost
@Centril

This comment has been minimized.

Copy link
Member

commented Apr 3, 2019

Failed in #59670 (comment), @bors r-

bors added a commit to rust-lang/cargo that referenced this pull request Apr 3, 2019

Auto merge of #6818 - dtolnay:comma, r=alexcrichton
Accept trailing comma in test of impl Debug for PackageId

The standard library is planning to begin emitting trailing commas in multiline Debug representations to align with the dominant style in modern Rust code -- rust-lang/rust#59076.

```diff
  PackageId {
      name: "foo",
      version: "1.0.0",
-     source: "registry `https://github.com/rust-lang/crates.io-index`"
+     source: "registry `https://github.com/rust-lang/crates.io-index`",
  }
```

For now, change this tests to accept both with and without trailing comma. Once the trailing comma change reaches the stable channel we will be able to remove one of the cases.

@dtolnay dtolnay referenced this pull request Apr 3, 2019

Merged

Update cargo #59681

@dtolnay

This comment has been minimized.

Copy link
Member Author

commented Apr 4, 2019

Working on it -- I submitted rust-lang/cargo#6818 to fix the test case in Cargo, currently waiting on the Cargo update in rust-lang/rust: #59681.

Centril added a commit to Centril/rust that referenced this pull request Apr 5, 2019

Rollup merge of rust-lang#59681 - dtolnay:cargo, r=alexcrichton
Update cargo

20 commits in
63231f438a2b5b84ccf319a5de22343ee0316323..6f3e9c367abb497c64f360c3839dab5e74928d5c
2019-03-27 12:26:45 +0000 to 2019-04-04 14:11:33 +0000
- Fix Init for Fossil SCM project (rust-lang/cargo#6792)
- Fix member_manifest_version_error accessing the network (rust-lang/cargo#6799)
- Don't include email if it is empty (rust-lang/cargo#6802)
- Fix unused import warning (rust-lang/cargo#6807)
- Add some help and documentation for unstable flags (rust-lang/cargo#6791)
- Allow `cargo doc --open` with multiple packages (rust-lang/cargo#6803)
- Allow `cargo install --path P` to load config from P (rust-lang/cargo#6804)
- Add more suggestions on how to deal with excluding a package from a workspace (rust-lang/cargo#6805)
- Warn on version req with metadata (rust-lang/cargo#6806)
- cargo install: Be more restrictive about cli flags (rust-lang/cargo#6801)
- Support force-pushed repos with git-fetch-with-cli (rust-lang/cargo#6800)
- Cargo clippy (rust-lang/cargo#6759)
- Don't include metadata in wasm binary examples (rust-lang/cargo#6812)
- Update glossary for `feature` (rust-lang/cargo#6809)
- Include proc-macros in `build-override` (rust-lang/cargo#6811)
- Resolver: A dep is equivalent to one of the things it can resolve to (rust-lang/cargo#6776)
- Add some docs for `Downloads` (rust-lang/cargo#6815)
- Resolve: Be less strict while offline (rust-lang/cargo#6814)
- Accept trailing comma in test of impl Debug for PackageId (rust-lang/cargo#6818)
- Fix doc link (rust-lang/cargo#6820)

<br>

I specifically care about "Accept trailing comma in test of impl Debug for PackageId (rust-lang/cargo#6818)" to unblock rust-lang#59076.

Mentioning @ehuss.

bors added a commit that referenced this pull request Apr 5, 2019

Auto merge of #59681 - dtolnay:cargo, r=alexcrichton
Update cargo

20 commits in
63231f438a2b5b84ccf319a5de22343ee0316323..6f3e9c367abb497c64f360c3839dab5e74928d5c
2019-03-27 12:26:45 +0000 to 2019-04-04 14:11:33 +0000
- Fix Init for Fossil SCM project (rust-lang/cargo#6792)
- Fix member_manifest_version_error accessing the network (rust-lang/cargo#6799)
- Don't include email if it is empty (rust-lang/cargo#6802)
- Fix unused import warning (rust-lang/cargo#6807)
- Add some help and documentation for unstable flags (rust-lang/cargo#6791)
- Allow `cargo doc --open` with multiple packages (rust-lang/cargo#6803)
- Allow `cargo install --path P` to load config from P (rust-lang/cargo#6804)
- Add more suggestions on how to deal with excluding a package from a workspace (rust-lang/cargo#6805)
- Warn on version req with metadata (rust-lang/cargo#6806)
- cargo install: Be more restrictive about cli flags (rust-lang/cargo#6801)
- Support force-pushed repos with git-fetch-with-cli (rust-lang/cargo#6800)
- Cargo clippy (rust-lang/cargo#6759)
- Don't include metadata in wasm binary examples (rust-lang/cargo#6812)
- Update glossary for `feature` (rust-lang/cargo#6809)
- Include proc-macros in `build-override` (rust-lang/cargo#6811)
- Resolver: A dep is equivalent to one of the things it can resolve to (rust-lang/cargo#6776)
- Add some docs for `Downloads` (rust-lang/cargo#6815)
- Resolve: Be less strict while offline (rust-lang/cargo#6814)
- Accept trailing comma in test of impl Debug for PackageId (rust-lang/cargo#6818)
- Fix doc link (rust-lang/cargo#6820)

<br>

I specifically care about "Accept trailing comma in test of impl Debug for PackageId (rust-lang/cargo#6818)" to unblock #59076.

Mentioning @ehuss.
Include trailing comma in multiline Debug representation
This commit changes the behavior of Formatter::debug_struct,
debug_tuple, debug_list, debug_set, and debug_map to render trailing
commas in {:#?} mode, which is the dominant style in modern Rust code.

Before:

    Language {
        name: "Rust",
        trailing_commas: false
    }

After:

    Language {
        name: "Rust",
        trailing_commas: true,
    }

@dtolnay dtolnay force-pushed the dtolnay:comma branch from c0d68d2 to cfd31fb Apr 5, 2019

@dtolnay

This comment has been minimized.

Copy link
Member Author

commented Apr 5, 2019

Rebased on #59681 and tested again with ./x.py test. Is there a more exhaustive test command that I could run locally that would run the test suites of whichever tools are tested in Travis?

@bors r=alexcrichton

@bors

This comment has been minimized.

Copy link
Contributor

commented Apr 5, 2019

📌 Commit cfd31fb has been approved by alexcrichton

@bors

This comment has been minimized.

Copy link
Contributor

commented Apr 5, 2019

⌛️ Testing commit cfd31fb with merge 20dbf28...

bors added a commit that referenced this pull request Apr 5, 2019

Auto merge of #59076 - dtolnay:comma, r=alexcrichton
Include trailing comma in multiline Debug representation

This PR changes the behavior of [`Formatter::debug_struct`](https://doc.rust-lang.org/std/fmt/struct.Formatter.html#method.debug_struct), [`debug_tuple`](https://doc.rust-lang.org/std/fmt/struct.Formatter.html#method.debug_tuple), [`debug_list`](https://doc.rust-lang.org/std/fmt/struct.Formatter.html#method.debug_list), [`debug_set`](https://doc.rust-lang.org/std/fmt/struct.Formatter.html#method.debug_set), and [`debug_map`](https://doc.rust-lang.org/std/fmt/struct.Formatter.html#method.debug_map) to render trailing commas in `{:#?}` mode, which is the dominant style in modern Rust code.

#### Before:

```console
Language {
    name: "Rust",
    trailing_commas: false
}
```

#### After:

```console
Language {
    name: "Rust",
    trailing_commas: true,
}
```
@bors

This comment has been minimized.

Copy link
Contributor

commented Apr 5, 2019

☀️ Test successful - checks-travis, status-appveyor
Approved by: alexcrichton
Pushing 20dbf28 to master...

@bors bors added the merged-by-bors label Apr 5, 2019

@bors bors merged commit cfd31fb into rust-lang:master Apr 5, 2019

2 checks passed

Travis CI - Pull Request Build Passed
Details
homu Test successful
Details

@dtolnay dtolnay deleted the dtolnay:comma branch Apr 5, 2019

ra-kete added a commit to ra-kete/lalrpop that referenced this pull request Apr 28, 2019

Ignore trailing commas in `ExpectedDebug`
rust-lang/rust/pull/59076 changed the multiline Debug representation to
always include a trailing comma. This change currently breaks our tests
on beta and nightly, since we use this Debug representation to compare
expected parsing output.

We cannot simply add the trailing commas to the expected output strings,
since that would break on older rustc versions we support. Instead, this
commit makes it so that all trailing commas are stripped before the
comparison.

This workaround can be removed once rust-lang/rust/pull/59076 reaches
our minimum supported rustc version.

Marwes added a commit to lalrpop/lalrpop that referenced this pull request Apr 30, 2019

Ignore trailing commas in `ExpectedDebug` (#455)
* Ignore trailing commas in `ExpectedDebug`

rust-lang/rust/pull/59076 changed the multiline Debug representation to
always include a trailing comma. This change currently breaks our tests
on beta and nightly, since we use this Debug representation to compare
expected parsing output.

We cannot simply add the trailing commas to the expected output strings,
since that would break on older rustc versions we support. Instead, this
commit makes it so that all trailing commas are stripped before the
comparison.

This workaround can be removed once rust-lang/rust/pull/59076 reaches
our minimum supported rustc version.

* Bump minimum Rust version to 1.31.0

That's required by the current version rustc-demangle, which is a
dependency of mdbook.

Marwes added a commit to lalrpop/lalrpop that referenced this pull request Apr 30, 2019

Replace all uses of `try!` with `?` (#454)
* Ignore trailing commas in `ExpectedDebug`

rust-lang/rust/pull/59076 changed the multiline Debug representation to
always include a trailing comma. This change currently breaks our tests
on beta and nightly, since we use this Debug representation to compare
expected parsing output.

We cannot simply add the trailing commas to the expected output strings,
since that would break on older rustc versions we support. Instead, this
commit makes it so that all trailing commas are stripped before the
comparison.

This workaround can be removed once rust-lang/rust/pull/59076 reaches
our minimum supported rustc version.

* Bump minimum Rust version to 1.31.0

That's required by the current version rustc-demangle, which is a
dependency of mdbook.

* Replace all uses of `try!` with `?`

The `?` operator was added to replace the `try!` macro and should be
used in modern Rust code. `try` is also a reserved keyword in Rust 2018,
so this change prepares for a possible edition switch too.

netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this pull request May 31, 2019

rust: Update to 1.35.0.
Version 1.35.0 (2019-05-23)
==========================

Language
--------
- [`FnOnce`, `FnMut`, and the `Fn` traits are now implemented for `Box<FnOnce>`,
  `Box<FnMut>`, and `Box<Fn>` respectively.][59500]
- [You can now coerce closures into unsafe function pointers.][59580] e.g.
  ```rust
  unsafe fn call_unsafe(func: unsafe fn()) {
      func()
  }

  pub fn main() {
      unsafe { call_unsafe(|| {}); }
  }
  ```


Compiler
--------
- [Added the `armv6-unknown-freebsd-gnueabihf` and
  `armv7-unknown-freebsd-gnueabihf` targets.][58080]
- [Added the `wasm32-unknown-wasi` target.][59464]


Libraries
---------
- [`Thread` will now show its ID in `Debug` output.][59460]
- [`StdinLock`, `StdoutLock`, and `StderrLock` now implement `AsRawFd`.][59512]
- [`alloc::System` now implements `Default`.][59451]
- [Expanded `Debug` output (`{:#?}`) for structs now has a trailing comma on the
  last field.][59076]
- [`char::{ToLowercase, ToUppercase}` now
  implement `ExactSizeIterator`.][58778]
- [All `NonZero` numeric types now implement `FromStr`.][58717]
- [Removed the `Read` trait bounds
  on the `BufReader::{get_ref, get_mut, into_inner}` methods.][58423]
- [You can now call the `dbg!` macro without any parameters to print the file
  and line where it is called.][57847]
- [In place ASCII case conversions are now up to 4× faster.][59283]
  e.g. `str::make_ascii_lowercase`
- [`hash_map::{OccupiedEntry, VacantEntry}` now implement `Sync`
  and `Send`.][58369]

Stabilized APIs
---------------
- [`f32::copysign`]
- [`f64::copysign`]
- [`RefCell::replace_with`]
- [`RefCell::map_split`]
- [`ptr::hash`]
- [`Range::contains`]
- [`RangeFrom::contains`]
- [`RangeTo::contains`]
- [`RangeInclusive::contains`]
- [`RangeToInclusive::contains`]
- [`Option::copied`]

Cargo
-----
- [You can now set `cargo:rustc-cdylib-link-arg` at build time to pass custom
  linker arguments when building a `cdylib`.][cargo/6298] Its usage is highly
  platform specific.

Misc
----
- [The Rust toolchain is now available natively for musl based distros.][58575]

[59460]: rust-lang/rust#59460
[59464]: rust-lang/rust#59464
[59500]: rust-lang/rust#59500
[59512]: rust-lang/rust#59512
[59580]: rust-lang/rust#59580
[59283]: rust-lang/rust#59283
[59451]: rust-lang/rust#59451
[59076]: rust-lang/rust#59076
[58778]: rust-lang/rust#58778
[58717]: rust-lang/rust#58717
[58369]: rust-lang/rust#58369
[58423]: rust-lang/rust#58423
[58080]: rust-lang/rust#58080
[57847]: rust-lang/rust#57847
[58575]: rust-lang/rust#58575
[cargo/6298]: rust-lang/cargo#6298
[`f32::copysign`]: https://doc.rust-lang.org/stable/std/primitive.f32.html#method.copysign
[`f64::copysign`]: https://doc.rust-lang.org/stable/std/primitive.f64.html#method.copysign
[`RefCell::replace_with`]: https://doc.rust-lang.org/stable/std/cell/struct.RefCell.html#method.replace_with
[`RefCell::map_split`]: https://doc.rust-lang.org/stable/std/cell/struct.RefCell.html#method.map_split
[`ptr::hash`]: https://doc.rust-lang.org/stable/std/ptr/fn.hash.html
[`Range::contains`]: https://doc.rust-lang.org/std/ops/struct.Range.html#method.contains
[`RangeFrom::contains`]: https://doc.rust-lang.org/std/ops/struct.RangeFrom.html#method.contains
[`RangeTo::contains`]: https://doc.rust-lang.org/std/ops/struct.RangeTo.html#method.contains
[`RangeInclusive::contains`]: https://doc.rust-lang.org/std/ops/struct.RangeInclusive.html#method.contains
[`RangeToInclusive::contains`]: https://doc.rust-lang.org/std/ops/struct.RangeToInclusive.html#method.contains
[`Option::copied`]: https://doc.rust-lang.org/std/option/enum.Option.html#method.copied
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.