Skip to content

Trait coercion when assigning struct field #12722

Closed
@kylecook80

Description

@kylecook80

Rust: master (0.10-pre)
OS: Mac OS X 10.9
Architecture: x86_64

There is some syntax that supposedly should work (according to both my experience and those on the rust irc channel) that results in a compilation error:

pub fn set_game_state<T: GameState>(&mut self, state: ~T) {
    self.state = state;
}

This results in a compilation error of:

error: mismatched types: expected `~game_state::GameState:Send` but found `~T` (expected trait game_state::GameState but found ~-ptr)

This code does work:

pub fn set_game_state(&mut self, state: ~GameState) {
    self.state = state;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions