Skip to content

Overly long expressions prevent surround code from being formatted #5576

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

Closed
matklad opened this issue Oct 26, 2022 · 4 comments
Closed

Overly long expressions prevent surround code from being formatted #5576

matklad opened this issue Oct 26, 2022 · 4 comments

Comments

@matklad
Copy link
Member

matklad commented Oct 26, 2022

Consider this snippet:

fn main() {
    this.wrap(1+1,|| match msg {
	() => {
		"comment me out xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
		let x =1+1;
	}
})
}

Here, the literal is very long, and theer's little rustfmt can do with it, which is expected. However, it seems that it also prevetns surrounding code from being reformatted (eg, spaces around +), and that seems like a bug.

In the real-world use-case, the long experssion is a tracing::info! call, which is a part of a hundred-lines long match, and rustfmt effectively doesn't work for the whole match expressions.

@ytmimi
Copy link
Contributor

ytmimi commented Oct 26, 2022

Thanks for reaching out. I believe this a duplicate of #3863 because of the chained .wrap call.

@ytmimi
Copy link
Contributor

ytmimi commented Oct 26, 2022

Would it be possible to post the real-world snippet?

@matklad
Copy link
Member Author

matklad commented Oct 26, 2022

@ytmimi
Copy link
Contributor

ytmimi commented Oct 26, 2022

Thanks for the link. I'm going to close this as a duplicate, but For what it's worth, I took a look at the snippet and these are the lines that are too long:

Length with indentation Line
129 info!(target: "adversary", "Producing {} block out of {}, height = {}", blocks_produced, num_blocks, height);
102 // timeout is set to 1.5 seconds to give some room as we wait in Nightly for 2 seconds
115 info!(target: "adversary", "Check Storage Consistency, timeout set to {:?} milliseconds", timeout);
104 error!(target: "client", "Storage Validation failed, {:?}", store_validator.errors);

chances are if we special cased formatting for tracing macros (related to #5516), we should be able to format the snippet since each macro call would likely be split over multiple lines.

@ytmimi ytmimi closed this as not planned Won't fix, can't repro, duplicate, stale Oct 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants