Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

New lint: multiple-bound-locations #7181

Closed
nico-abram opened this issue May 6, 2021 · 0 comments · Fixed by #12259
Closed

New lint: multiple-bound-locations #7181

nico-abram opened this issue May 6, 2021 · 0 comments · Fixed by #12259
Labels
A-lint Area: New lints

Comments

@nico-abram
Copy link
Contributor

What it does

Checks for generic functions that have bounds for a generic parameter in both a where clause and the parameter list

Categories (optional)

  • Kind: pedantic

What is the advantage of the recommended code over the original code

It makes the code less confusing, having bounds in multiple places makes it easy to miss one half. Specially if it's something small, for example (From nom documentation), here it is very easy to miss the : 'a bound on F

fn ws<'a, F: 'a, O, E: ParseError<&'a str>>(
    inner: F,
) -> impl FnMut(&'a str) -> IResult<&'a str, O, E>
where
    F: Fn(&'a str) -> IResult<&'a str, O, E>,
{
    delimited(
        nom::character::complete::multispace0,
        inner,
        nom::character::complete::multispace0,
    )
}

Drawbacks

None.

Example

fn f<'a, T: 'a>(x:T) where T: FnOnce() { x(); }

Could be written as:

fn f<'a, T>(x:T) where T: FnOnce() + 'a { x(); }
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-lint Area: New lints
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant