You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
associated type not normalized when a where-clause is present #28895
At least 1.3, 1.4, rustc 1.5.0-nightly (11a612795 2015-10-04)
STR
traitFoo{typeBar;}impl<T>FooforT{typeBar = u64;}fnfoo<T>() -> <TasFoo>::BarwhereT:Foo// <- the code compiles if this is removed{1}fnmain(){}
Expected Result
the code should compile
Actual Result
<anon>:7:14: 7:15 error: mismatched types:
expected `<T as Foo>::Bar`,
found `_`
(expected associated type,
found integral variable) [E0308]
<anon>:7 x = Some(1);
^
The root cause is that selection picks the where-clause candidate over any impl candidate, and this does not allow projection to make progress. This looks to be hard to fix.
@gmorenz this is because of the lifetime parameter. Because the associated type could depend on the choice of lifetime parameter, it doesn't get normalized.
error[E0308]: mismatched types
--> src/main.rs:7:3
5 | fn foo<T>() -> <T as Foo>::Bar
| --------------- expected `<T as Foo>::Bar` because of return type
6 | where T: Foo // <- the code compiles if this is removed
7 | { 1 }
| ^ expected associated type, found integer
|
= note: expected associated type `<T as Foo>::Bar`
found type `{integer}`
help: consider constraining the associated type `<T as Foo>::Bar` to `{integer}`
|
Activity
arielb1 commentedon Oct 7, 2015
The root cause is that selection picks the where-clause candidate over any impl candidate, and this does not allow projection to make progress. This looks to be hard to fix.
nikomatsakis commentedon Oct 8, 2015
Yes, this is to some extent a known limitation and the "expected result", but I would still classify it as a bug.
gmorenz commentedon Jan 20, 2020
(Note: Deleted and reposted since I screwed up the first version, and realized I could minimize it more)
I hit this case while trying to work around #68375 - I'm pretty sure it's the same bug
RustyYato commentedon Jan 20, 2020
Nope, you have a return value in
std1dbut not in the where clause formap_axisgmorenz commentedon Jan 20, 2020
Oops, you're right, minification mistake. Fixed that above, it doesn't substantially change the error message.
RustyYato commentedon Jan 20, 2020
@gmorenz this is because of the lifetime parameter. Because the associated type could depend on the choice of lifetime parameter, it doesn't get normalized.
That does seem related to this Issue.
Spoonbender commentedon Oct 17, 2022
Triage: no change
Dylan-DPC commentedon Aug 28, 2024
Current output: