Skip to content

Spooky action-at-a-distance causing missed linewraps #3654

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
cramertj opened this issue Jun 25, 2019 · 7 comments
Closed

Spooky action-at-a-distance causing missed linewraps #3654

cramertj opened this issue Jun 25, 2019 · 7 comments

Comments

@cramertj
Copy link
Member

rustfmt output:

fn get_in_params() {
    m.in_params
        .iter()
        .map(|| {
            let direction = arg_types.get_arg(name); // removing this line causes formatting ?!?!?!
            match ty {
                Some(_) => {
                    if some_bool {
                    }
                    match size {
                        _ => {
                            if some_bool { // removing any of these lines causes formatting
                            } else { // the following line must be long or else formatting will happen
                                panic!("missing 'arg_type' attribute: string direction must be specified")
                            }
                        }
                    }
                }
                None => {
                    if some_bool {
                        let resolved_type = format!("ptr[{}, array[{}]]", to_c_name(&direction), ty_to_syzkaller_str(ast, ty).unwrap());
                    }
                }
            }
        })
        .collect() // removing this line causes formatting ?!?!?!
}

Removing or significantly editing basically any line causes the let resolved_type = ... line (which is too long and should be wrapped) to be reformatted.

@cramertj
Copy link
Member Author

Possibly related to #3638

@cramertj
Copy link
Member Author

note when reproducing: you'll have to remove the comments

@cramertj
Copy link
Member Author

version without comments:

fn get_in_params() {
    m.in_params
        .iter()
        .map(|| {
            let direction = arg_types.get_arg(name);
            match ty {
                Some(_) => {
                    if some_bool {
                    }
                    match size {
                        _ => {
                            if some_bool {
                            } else {
                                panic!("missing 'arg_type' attribute: string direction must be specified")
                            }
                        }
                    }
                }
                None => {
                    if some_bool {
                        let resolved_type = format!("ptr[{}, array[{}]]", to_c_name(&direction), ty_to_syzkaller_str(ast, ty).unwrap());
                    }
                }
            }
        })
        .collect()
}

@cramertj
Copy link
Member Author

reformatted after removing the let binding:

fn get_in_params() {
    m.in_params
        .iter()
        .map(|| match ty {
            Some(_) => {
                if some_bool {}
                match size {
                    _ => {
                        if some_bool {
                        } else {
                            panic!(
                                "missing 'arg_type' attribute: string direction must be specified"
                            )
                        }
                    }
                }
            }
            None => {
                if some_bool {
                    let resolved_type = format!(
                        "ptr[{}, array[{}]]",
                        to_c_name(&direction),
                        ty_to_syzkaller_str(ast, ty).unwrap()
                    );
                }
            }
        })
        .collect()
}

@scampi
Copy link
Contributor

scampi commented Sep 28, 2019

I think snippet at #3654 (comment) can be reformatted because the match is not wrapped in a block and therefore it is not indented.
This gives enough space for the panic! to be rewritten, allowing the match to be reformatted.

@scampi
Copy link
Contributor

scampi commented Sep 28, 2019

Maybe the match rewrite could allow for some branch to be unformatted, this would allow the Some to be left as is, but reformat the None branch.

@ytmimi
Copy link
Contributor

ytmimi commented Jul 20, 2022

I believe this is a duplicate of #3863

@ytmimi ytmimi closed this as not planned Won't fix, can't repro, duplicate, stale Jul 20, 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

4 participants