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

Wrong type deduction #5444

Closed
almindor opened this issue Jul 20, 2020 · 3 comments
Closed

Wrong type deduction #5444

almindor opened this issue Jul 20, 2020 · 3 comments
Labels
A-ty type system / type inference / traits / method resolution

Comments

@almindor
Copy link

almindor commented Jul 20, 2020

The following code causes Rust Analyzer to "deduce" the type of *obj to be a form of Iterator instead of the Object type and shows the error Expected 1 argument, found 0 on line 35 by the .position() method call. Hovering over the error in the editor (VSCode) is pointing to core::iter::traits::iterator::Iterator.

The code compiles fine legion = "0.2.4" is required as a dependency.

use legion::prelude::*;

#[derive(Clone, Default, Copy, Debug, PartialEq)]
struct Position {
    x: f32,
    y: f32,
}

#[derive(Clone, Default, Copy, Debug, PartialEq)]
struct Object {
    pos: Position,
}

impl Object {
    pub fn position(&self) -> &Position {
        &self.pos
    }
}

fn main() {
    // Create a world to store our entities
    let universe = Universe::new();
    let mut world = universe.create_world();

    // Create entities with `Position` and `Velocity` data
    world.insert((), std::iter::once((Position::default(), Object::default(),)));

    // Create a query which finds all `Position` and `Velocity` components
    let query = <(Write<Position>, Read<Object>)>::query();

    // Iterate through all entities that match the query in the world
    for (mut pos, obj) in query.iter_mut(&mut world) {
        *pos = *obj.position();
        println!("X: {:?}", pos);
    }
}
@lnicola lnicola added the A-ty type system / type inference / traits / method resolution label Jul 20, 2020
@bjorn3
Copy link
Member

bjorn3 commented Jul 20, 2020

This uses an use inside a function. This is not yet supported: #1165

@flodiebold
Copy link
Member

Yeah, duplicate of #1165 + #5419.

@almindor
Copy link
Author

Nothing to do with use see newly edited example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ty type system / type inference / traits / method resolution
Projects
None yet
Development

No branches or pull requests

4 participants