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

Projection does not normalize the environment #21664

Closed
nikomatsakis opened this issue Jan 26, 2015 · 3 comments
Closed

Projection does not normalize the environment #21664

nikomatsakis opened this issue Jan 26, 2015 · 3 comments
Labels
A-associated-items Area: Associated items (types, constants & functions)

Comments

@nikomatsakis
Copy link
Contributor

Currently we store non-normalized predicts in the environment and normalize as we go, but we don't do that for projection, because it leads to a kind of infinite loop -- normalizing something requires drawing on the environment which requires normalizing something.

Here is an example of code that does not compile as a result:

pub trait Integral {
    type Opposite;
}

impl Integral for i32 {
    type Opposite = u32;
}

impl Integral for u32 {
    type Opposite = i32;
}

pub trait FnLike<A> {
    type R;
}

fn foo<T>()
    where T : FnLike<<i32 as Integral>::Opposite, R=bool>
{
    bar::<T>();
}

fn bar<T>()
    where T : FnLike<u32, R=bool>
{}

fn main() { }

This is blocking my attempts to make the fn return as associated type, because a situation much like the above arises when you do that.

@nikomatsakis
Copy link
Contributor Author

In any case, it seems like it would be best if we normalized the environment once, rather than redoing it each time we draw upon it. I'm just a bit unsure at the moment of what is the best way to do that.

@nikomatsakis nikomatsakis added the A-associated-items Area: Associated items (types, constants & functions) label Jan 26, 2015
@nikomatsakis
Copy link
Contributor Author

By the way, the error you get is:

lunch-box. rustc --stage0 ~/tmp/issue-21664.rs
/home/nmatsakis/tmp/issue-21664.rs:20:5: 20:13 error: type mismatch resolving `<T as FnLike<u32>>::R == bool`:
 expected associated type,
    found bool
/home/nmatsakis/tmp/issue-21664.rs:20     bar::<T>();
                                          ^~~~~~~~
/home/nmatsakis/tmp/issue-21664.rs:20:5: 20:13 note: required by `bar`
/home/nmatsakis/tmp/issue-21664.rs:20     bar::<T>();
                                          ^~~~~~~~
error: aborting due to previous error

@carllerche
Copy link
Member

cc me

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)
Projects
None yet
Development

No branches or pull requests

2 participants