Skip to content

New lint: multiple-bound-locations #7181

Closed
@nico-abram

Description

@nico-abram

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(); }

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions