Skip to content

No "consider borrowing here" suggestion for method on complex trait bound #89679

Open
@alice-i-cecile

Description

@alice-i-cecile

Using Bevy (see minimal repo here, the following code provides an unhelpful error message. The compiler does not notice that &A meets the trait bounds required and suggest a fix.

use bevy::prelude::*;

// The user requested A in the system, rather than &A
fn missing_reference_in_query_system(query: Query<A, With<B>>) {}

fn main() {
    App::new().add_system(missing_reference_in_query_system)).run();
}

The error message is

        the trait bound `A: WorldQuery` is not satisfied
        the trait `WorldQuery` is not implemented for `A`

Something along the lines of "The trait WorldQuery is implemented for &A, consider borrowing here." would go a long way to improve this.

Basic attempts at minimally reproducing this give the correct error message: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=c762dafa29c2c0bc89425661f383917b. This also works with needs_ref as a standalone function.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions