Skip to content

Member function call breaks type inference #25166

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

Closed
stepancheg opened this issue May 7, 2015 · 3 comments
Closed

Member function call breaks type inference #25166

stepancheg opened this issue May 7, 2015 · 3 comments
Labels
A-type-system Area: Type system

Comments

@stepancheg
Copy link
Contributor

Code:

#[derive(Default)]
struct Foo;

impl Foo {
    fn set_quux(&mut self, v: u32) {
    }
}

fn main() {
    let mut v: Vec<Foo> = Vec::new();

    // this works perfectly: type of msg1 is inferred
    let mut msg1 = Default::default();
    v.push(msg1);

    // type of msg2 is explicitly specified
    let mut msg2: Foo = Default::default();
    msg2.set_quux(17);
    v.push(msg2);

    // type of msg3 could be inferred from parameter type of v.push(...)
    // although compiler reports:
    // error: the type of this value must be known in this context
    let mut msg3 = Default::default();
    msg3.set_quux(19); // <-- on this line
    v.push(msg3);
}
@pythonesque
Copy link
Contributor

I think this might be the same as (or at least related to) #25165, which is also an instance of type inference breaking when you use a member function.

@steveklabnik steveklabnik added the A-type-system Area: Type system label May 7, 2015
@steveklabnik
Copy link
Member

Triage: no change

@Mark-Simulacrum
Copy link
Member

Yeah, I'm going to close in favor of #25165 because it represents the underlying problem here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-type-system Area: Type system
Projects
None yet
Development

No branches or pull requests

4 participants