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
If two traits are dependent on each other and the implementing struct has lifetimes, the compiler cannot build the source code. The two traits work for all structs that do not have a lifetime.
However, you can avoid this error by commenting out the where clause from TPrivateFoo::execute().
I expected to see this happen:
Source code is successfully compiled
Instead, a compile time error occured:
error[E0609]: no field `counter` on type `&<DErrorBecauseOfLifetime<'_> as TFoo>::NativeStruct`
--> src\test.rs:57:25
|
57 | println!("{:?}", root.counter);
| ^^^^^^^ unknown field
This happens because there are considered to be two implementations of TFoo, the real one and one from the where, and the compiler doesn't unify them. Where bounds are preferred to real impls - and the associated type in the bound is unknown.
jieyouxu
added
C-discussion
Category: Discussion or questions that doesn't represent real issues.
and removed
C-bug
Category: This is a bug.
needs-triage
This issue may need triage. Remove it if it has been sufficiently triaged.
labels
Nov 24, 2024
Does this mean that the correct solution here is to simply remove the where clause in the impl block? That is not intuitive :(
If there is no lifetime defined in the struct (like DSuccessBecauseNoLifetime), there are not two implementations of TFoo and therefore the compilation will not fail. Do I understand that correctly?
If two traits are dependent on each other and the implementing struct has lifetimes, the compiler cannot build the source code. The two traits work for all structs that do not have a lifetime.
However, you can avoid this error by commenting out the where clause from TPrivateFoo::execute().
I tried this code:
I expected to see this happen:
Source code is successfully compiled
Instead, a compile time error occured:
Meta
Bug exists in both stable and nighlty build.
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: