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

Add infallible expr scanner fallback for scanning invalid code #340

Merged
merged 2 commits into from
Nov 3, 2024

Conversation

dtolnay
Copy link
Owner

@dtolnay dtolnay commented Nov 3, 2024

The infallible scanner has the same behavior as prior to #337, which exhibits bugs like #335 but that's okay because fallback is only going to be applied if the format arguments do not consist of syntactically valid expressions. This is useful for an IDE performing macro expansions while code is being typed.

    warning: this function's return value is unnecessarily wrapped by `Result`
       --> impl/src/fmt.rs:122:1
        |
    122 | / fn explicit_named_args(input: ParseStream) -> Result<Set<Ident>> {
    123 | |     let ahead = input.fork();
    124 | |     if let Ok(set) = try_explicit_named_args(&ahead) {
    125 | |         input.advance_to(&ahead);
    ...   |
    136 | |     Ok(Set::new())
    137 | | }
        | |_^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_wraps
        = note: `-W clippy::unnecessary-wraps` implied by `-W clippy::pedantic`
        = help: to override `-W clippy::pedantic` add `#[allow(clippy::unnecessary_wraps)]`
    help: remove `Result` from the return type...
        |
    122 | fn explicit_named_args(input: ParseStream) -> std::collections::BTreeSet<proc_macro2::Ident> {
        |                                               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    help: ...and then change returning expressions
        |
    126 ~         return set;
    127 |     }
    ...
    131 |         input.advance_to(&ahead);
    132 ~         return set;
    133 |     }
    134 |
    135 |     input.parse::<TokenStream>().unwrap();
    136 ~     Set::new()
        |
@dtolnay dtolnay merged commit b3bc3e7 into master Nov 3, 2024
18 checks passed
@dtolnay dtolnay deleted the fallbackscan branch November 3, 2024 04:15
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

Successfully merging this pull request may close these issues.

1 participant