Skip to content

assoc types: type inference works with UFCS but not with method calls #22165

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

Open
japaric opened this issue Feb 11, 2015 · 4 comments
Open

assoc types: type inference works with UFCS but not with method calls #22165

japaric opened this issue Feb 11, 2015 · 4 comments
Labels
A-associated-items Area: Associated items (types, constants & functions) A-inference Area: Type inference A-type-system Area: Type system C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue.

Comments

@japaric
Copy link
Member

japaric commented Feb 11, 2015

STR

#![crate_type = "lib"]

trait Tuple {
    type Array: Toa<Item=Self>;
}

trait Toa {
    type Item;

    fn push(&mut self, Self::Item);
    fn with_capacity(usize) -> Self;
}

#[cfg(not(works))]
fn f<T: Tuple>(t: T) -> T::Array {
    let mut toa = Toa::with_capacity(1);
    toa.push(t);  //~ error: the type of this value must be known in this context
    toa
}

#[cfg(works)]
fn g<T: Tuple>(t: T) -> T::Array {
    let mut toa = Toa::with_capacity(1);
    Toa::push(&mut toa, t);
    toa
}

Version

rustc 1.0.0-nightly (134e00be7 2015-02-09 19:01:37 +0000)

cc @nikomatsakis

(Deja Vu, I feel like I've reported/seen a similar problem before, but it didn't involve associated types)

@kmcallister kmcallister added A-associated-items Area: Associated items (types, constants & functions) A-type-system Area: Type system labels Feb 11, 2015
@edwardw
Copy link
Contributor

edwardw commented Feb 21, 2015

cc me

@goffrie
Copy link
Contributor

goffrie commented Feb 22, 2015

I don't think this is really related to associated types. I feel like it's the same as the following test case:

fn test<I: Iterator<Item=i32>>(i: I) -> Vec<i32> {
    let v = i.collect();
    v.push(1); //~ error: the type of this value must be known in this context
    v
}

i.e. calling a method on a value whose type can only be inferred "later".

@steveklabnik
Copy link
Member

steveklabnik commented May 24, 2016

Triage: after a small update, the original still reproduces:

#![crate_type = "lib"]

trait Tuple: Sized {
    type Array: Toa<Item=Self>;
}

trait Toa {
    type Item;

    fn push(&mut self, Self::Item);
    fn with_capacity(usize) -> Self;
}

#[cfg(not(works))]
fn f<T: Tuple>(t: T) -> T::Array {
    let mut toa = Toa::with_capacity(1);
    toa.push(t);  //~ error: the type of this value must be known in this context
    toa
}

#[cfg(works)]
fn g<T: Tuple>(t: T) -> T::Array {
    let mut toa = Toa::with_capacity(1);
    Toa::push(&mut toa, t);
    toa
}

@Mark-Simulacrum Mark-Simulacrum added A-inference Area: Type inference C-bug Category: This is a bug. labels Jul 22, 2017
@steveklabnik
Copy link
Member

Triage: still reproduces

@Noratrieb Noratrieb added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue. labels Apr 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-associated-items Area: Associated items (types, constants & functions) A-inference Area: Type inference A-type-system Area: Type system C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

7 participants