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
The main reason to _not_ do this is that it requires direct access to the provider trait, which is not as simple dealing with simple types. Furthermore, the provider trait may contain additional where clauses, which would also need to be propagated explicitly.
498
+
499
+
By making use of `IsProviderFor`, we are essentially "erasing" everything at the trait level, and use a single trait to represent all other provider traits. After all, the only thing that we are interested here is to propagate the constraints for the purpose of showing better error messages.
500
+
486
501
## Check Traits
487
502
488
503
Now that we have the wirings for `IsProviderFor` in place, we can implement _check traits_ to check
@@ -553,8 +568,6 @@ note: required by a bound in `CanUsePersonComponents`
553
568
```
554
569
555
570
As we can see, the use of `IsProviderFor` helps make it possible for us to debug our CGP programs again.
556
-
This significantly improves the developer experience for CGP, which was significantly harder to debug
557
-
prior to the introduction of this technique in v0.4.0.
558
571
559
572
## `CanUseComponent` Trait
560
573
@@ -614,3 +627,201 @@ error[E0277]: the trait bound `Person: CanUseComponent<StringFormatterComponent>
614
627
| ^^^^^^ the trait `Serialize` is not implemented for `Person`
615
628
...
616
629
```
630
+
631
+
## Limitations
632
+
633
+
The use of `IsProviderFor` significantly improves the developer experience for CGP, which was significantly harder
634
+
to debug prior to the introduction of this technique in v0.4.0.
635
+
636
+
At this point, you might be concerned of the additional boilerplate required to implement and propagate the constraints for `IsProviderFor`. However, as we will see in the [next chapter](./component-macros.md), the CGP macros will automate the bulk of the implementation of `IsProviderFor`, and only require lightweight attribute macros to be applied to enable the code generation.
637
+
638
+
It is worth noting that the `IsProviderFor` trait is introduced as a workaround to improve the error messages of CGP code in Rust. Hypothetically, if Rust could provide better support of showing the relevant error messages, we could entirely remove the use of `IsProviderFor` in future versions of CGP.
639
+
640
+
On the other hand, the use of `IsProviderFor` can serve as a great showcase to the Rust compiler team on what error messages should have been shown by default, and make it easier to evaluate what should be the official fix in the Rust compiler.
641
+
642
+
That said, the error messages shown via `IsProviderFor` can sometimes be too verbose, especially when an application contains many providers with deeply nested dependencies. The reason is that any unsatisfied constraint from deeply nested dependencies can propagate all the way up through chains of `IsProviderFor` implementations. Although this can help us pinpoint the root cause, it could generate too much noise when showing all errors from the intermediary layers.
643
+
644
+
When encountering heap of error messages generated from `IsProviderFor`, a useful tip is that the relevant error message may be hiding near the bottom. So it may be useful to read from the bottom up instead of top down.
645
+
646
+
## Interactive Debugging with Argus
647
+
648
+
A potential improvement that we are currently exploring is to make use of [Argus](https://cel.cs.brown.edu/paper/an-interactive-debugger-for-rust-trait-errors/) to help navigate error messages generated from CGP code. Argus provides an interactive debugger for trait-related errors, which may be well suited to be used for debugging CGP code.
649
+
650
+
We will add further details in the future to share potential integration with Argus. For now, interested readers are encouraged to check out the project, and perhaps make contribution to make such integration possible.
651
+
652
+
## Conclusion
653
+
654
+
In this chapter, we have learned how CGP makes use of the `IsProviderFor` trait to help show relevant error messages when encountering unsatisfied constraints. In the next chapter, we will walk through how to automate the generation of all the relevant boilerplates that we have learned so far, and write succint CGP code using macros.
655
+
656
+
We will show the full example that we have walked through earlier, with the addition of `IsProviderFor` into the code:
0 commit comments