-
Notifications
You must be signed in to change notification settings - Fork 908
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
Rustfmt fails to format let-chain #5661
Comments
@yanchith Thanks for reaching out, but unless you can provide a code snippet to work off of then this isn't actionable. Additionally, what version of rustfmt are you ussing and are you using any non-default configuration options? |
Thanks, I edited the version and config into the original post. Yeah, I know this isn't great. I opened this hoping someone (possibly future me) will provide a repro case. |
@yanchith can you take a section of code that isn't formatted and create a dummy example from it? Given that this is deeply nested you're most likely running into issues with the If I had to guess, your issue is likely a duplicate of #3863, and if it's not related then the deeply nested nature of your program is the issue. Without seeing some code that reproduces the issue there isn't more I can do to help. |
Serendipity! It just happened, in a section of code I managed to isolate. Pasting the following to a file and using the config above should not change a single line, even though it is clearly misformatted. I also tried fn rewind_level(level: &mut Level) {
level.move_queue.clear();
level.move_queue_speed_factor = 1.0;
if have_player_caused_transaction(&level.transactions) {
if let Some(snapshot) = level.history.pop_snapshot() {
log::debug!("Rewinding one snapshot back with {} entities", snapshot.len(),);
level.entities.clear();
let mut manual = level.entities.manual_mode();
for entity in snapshot {
manual.insert(entity.id, entity);
}
manual.commit();
} else {
log::error!("Expected to find one snapshot to rewind, but found none");
}
} else {
let mut success = false;
if let Some(_) = level.history.pop_snapshot() {
success = true;
} else {
log::error!("Expected to find two snapshots to rewind, but found none");
}
if success && let Some(snapshot) = level.history.pop_snapshot() {
log::debug!(
"Rewinding two snapshots back with {} entities",
snapshot.len(),
);
level.entities.clear();
let mut manual = level.entities.manual_mode();
for entity in snapshot {
manual.insert(entity.id, entity);
}
manual.commit();
} else {
log::error!("Expected to find two snapshots to rewind, but found just one");
}
}
} EDIT: the |
Thanks for adding the code snippet. Yes, this issue is caused because rustfmt doesn't currently format |
I have a Rust source file with a couple of longer (~1000 lines) functions with deep nesting, and many comments.
I sometimes notice rustfmt give up and not modify some parts of the code, even when it's visually clear they should be modified (e.g. reindented).
rustfmt --check
doesn't report any errors.Not sure how to repro publicly, because I can't share the code this happens on, but if I ever see it happen on an open codebase, I'll share.
Also let me know if you'd accept a patch fixing this, maybe I can debug in my spare time.
version: rustfmt 1.5.1-nightly (8a97b481 2022-12-22)
config:
The text was updated successfully, but these errors were encountered: