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

fmt: fix layers with different ANSI settings sharing the same TypeId #3221

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kaffarell
Copy link
Contributor

Motivation

Previously, the FormattedFields struct stored the ANSI state as a boolean field, which could lead to inconsistencies when different layers used different ANSI settings (true/false). This happened because we store the FormattedFields in a HashMap using the TypeId as a key which obviously means that ansi=true and ansi=false would have the same key and the same formatted fields. This meant that whichever layer stored its fields first would determine the ANSI formatting for all subsequent layers.

Solution

This change refactors FormattedFields to use a const generic parameter for the ANSI state, allowing us to store two different FormattedFields (one with and one without ansi). Each layer can now store its fields with the correct ANSI setting without interfering with other layers.

Fixes: #1310
Fixes: #1817
Fixes: #3065
Fixes: #3116

Open Questions

We need to check if we can backport this, might be tricky, but would be valuable since:

  1. This issue occurs frequently (see issues above)
  2. The issue is difficult to debug and fix for the user

@hawkw @hds

Previously, the FormattedFields struct stored the ANSI state as a
boolean field, which could lead to inconsistencies when different layers
used different ANSI settings (true/false). This happened because we
store the FormattedFields in a HashMap using the TypeId as a key which
obviously means that ansi=true and ansi=false would have the same
key and the same formatted fields. This meant that whichever layer
stored its fields first would determine the ANSI formatting for all
subsequent layers.

This change refactors FormattedFields to use a const generic parameter
for the ANSI state, allowing us to store two different FormattedFields
(one with and one without ansi). Each layer can now store its fields
with the correct ANSI setting without interfering with other layers.

Fixes: tokio-rs#1310
Fixes: tokio-rs#1817
Fixes: tokio-rs#3065
Fixes: tokio-rs#3116

Signed-off-by: Gabriel Goller <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant