-
Notifications
You must be signed in to change notification settings - Fork 1.7k
base trait method not resolved when using impl in return position #7273
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
Comments
After some more investigation it doesn't have to do with associated types, just with trait method resolution when using #[test]
fn super_trait_impl_return_trait_method_resolution() {
check_infer(
r#"
trait Base {
fn foo(self) -> usize;
}
trait Super : Base {}
fn base1() -> impl Base { loop {} }
fn super1() -> impl Super { loop {} }
fn test(base2: impl Base, super2: impl Super) {
base1().foo();
super1().foo();
base2.foo();
super2.foo();
}
"#,
expect![[r#"..."#]],
);
} gives:
I will investigate some more to see if I find a fix. |
After some println debugging and enabling the logs I think I found something. If I run trait Base {
fn foo(self) -> usize;
}
fn base1() -> impl Base { loop {} }
fn test() {
base1().foo();
} this are the logs for
and for trait Base {
fn foo(self) -> usize;
}
trait Super : Base {}
fn super1() -> impl Super { loop {} }
fn test() {
super1().foo();
} this are the logs
in both cases the call to And if I'm understanding correctly means that chalk is finding a solution for |
Yes, that's likely. It'd be helpful to create a Chalk test and report a bug there. I wonder though, I feel like that's been implemented before... |
I found rust-lang/chalk#335, which makes me think that impl Trait may not be fully supported yet. There must be some special handling for |
Thanks for reproducing this, it makes finding the underlying issue quite easy ❤️ Chalk indeed doesn't handle super traits for opaque types yet, filed rust-lang/chalk#677 |
I've fixed chalk#677, so this should be fixed once the next chalk release lands in rust-analyzer. |
7739: Bump deps r=lnicola a=lnicola Closes #7273 bors r+ Co-authored-by: Laurențiu Nicola <[email protected]>
7739: Bump deps r=lnicola a=lnicola Closes #7273 bors r+ Co-authored-by: Laurențiu Nicola <[email protected]>
Code that reproduces the issue:
After investigating in the rust-analyzer source and playing around with a test in
crates/hir_ty/src/tests/traits.rs
I found out that inference works when it's an argument:This is the test:
which at the moment gives:
The text was updated successfully, but these errors were encountered: