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

idempotence_tests are unstable when setting inline rustfmt comments #6011

Open
IVIURRAY opened this issue Jan 8, 2024 · 0 comments
Open

Comments

@IVIURRAY
Copy link
Contributor

IVIURRAY commented Jan 8, 2024

As I was generating the code for #6000 I noticed that when setting config options with rustfmt comments the test would become unstable. Sometimes the test would pass and sometimes the same test would fail without changing any code. We believe this is down to the order that the config items get applied. Setting one config param before the other can cause a conflict and incorrect setup for the test.

To resolve this, we moved the test's config into a .toml file (as can be seen in the MR) which applies them in the correct order.

More deatils can be found in #6000 and the comment here. I've pasted some of it below for quick reference.

My hunch is that the issue is related to setting the configs inline with the rustfmt comments like //rustfmt-{key}: {value} in read_config. From what I can tell read_significant_comments returns a HashMap<String, String>, and when we try to iterate over it we don't necessarily iterate over the configurations in the same order that they're listed in the file. Sometimes we set the max_width=120 before we set attr_fn_like_width=120, and in that case everything works out. In other cases we try to set attr_fn_like_width=120 first, and that fails since we don't allow any width configuration to exceed the max_width, which is still set to its default of 100. so attr_fn_like_width would also get set to 100.

How to reproduce?

Run the following test script. Run it multiple times...sometimes it passes and someetimes it fails.

// rustfmt-max_width: 120
// rustfmt-version: Two
// rustfmt-attr_fn_like_width: 120
pub enum Severity {
#[something(AAAAAAAAAAAAA, BBBBBBBBBBBBBB, CCCCCCCCCCCCCCCC, DDDDDDDDDDDDD, EEEEEEEEEEEE, FFFFFFFFFFF, GGGGGGGGGGG)]
AttrsWillWrap,
#[something_else(hhhhhhhhhhhhhhhh, iiiiiiiiiiiiiiii, jjjjjjjjjjjjjjj, kkkkkkkkkkkkk, llllllllllll, mmmmmmmmmmmmmm)]
AttsWontWrap,
}

@IVIURRAY IVIURRAY changed the title idempotence_tests are unable when setting inline rustfmt comments idempotence_tests are unstable when setting inline rustfmt comments Jan 8, 2024
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

No branches or pull requests

1 participant