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

Associated types in constraints are not normalized #3232

Closed
lnicola opened this issue Feb 19, 2020 · 3 comments · Fixed by #3259
Closed

Associated types in constraints are not normalized #3232

lnicola opened this issue Feb 19, 2020 · 3 comments · Fixed by #3259
Labels
A-ty type system / type inference / traits / method resolution E-has-instructions Issue has some instructions and pointers to code to get started

Comments

@lnicola
Copy link
Member

lnicola commented Feb 19, 2020

trait T {
    type O;
}

impl T for () {
    type O = ();
}

fn f<X, F>(_v: F)
where
    X: T,
    F: FnOnce(&X::O),
{
}

fn main() {
    f::<(), _>(|_z| {}); // _z is inferred as `&<() as T>::O>`
}

Possibly unrelated, but inference no longer works if the code is changed to F: FnOnce(X::O). F: FnOnce(X) is fine, though.

Split off #3138.

https://github.com/rust-analyzer/rust-analyzer/blob/eb804261dce7f13056566377148a41f460feed28/crates/ra_hir_ty/src/infer.rs#L410 might need to be called on types returned by chalk.

@lnicola lnicola added A-ty type system / type inference / traits / method resolution E-has-instructions Issue has some instructions and pointers to code to get started labels Feb 19, 2020
@flodiebold
Copy link
Member

Interestingly, _z does get normalized when we use it in an expression 🤔

flodiebold added a commit to flodiebold/rust-analyzer that referenced this issue Feb 21, 2020
bors bot added a commit that referenced this issue Feb 21, 2020
3259: Normalize associated types in types coming from Chalk r=matklad a=flodiebold

Fixes #3232.

Co-authored-by: Florian Diebold <florian.diebold@freiheit.com>
@bors bors bot closed this as completed in e502013 Feb 21, 2020
@bors bors bot closed this as completed in #3259 Feb 21, 2020
@lnicola
Copy link
Member Author

lnicola commented Feb 21, 2020

@flodiebold should I file a new issue for the F: FnOnce(X::O) case 😆?

@flodiebold
Copy link
Member

It looks like that's just another case of rust-lang/chalk#234, though I have no idea why it works with &. We could maybe add it to #2603 and make that the list of cases to check once the Chalk issue is resolved 😅

cjhopman pushed a commit to cjhopman/rust-analyzer that referenced this issue Apr 10, 2020
lnicola pushed a commit to lnicola/rust-analyzer that referenced this issue Apr 7, 2024
RalfJung pushed a commit to RalfJung/rust-analyzer that referenced this issue Apr 27, 2024
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 E-has-instructions Issue has some instructions and pointers to code to get started
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants