next.js
2d37f070 - [turbopack] Simplify up and dowcasts (#83456)

Commit
225 days ago
[turbopack] Simplify up and dowcasts (#83456) ## What Casting `ResolvedVc<Box<dyn Module>>` to `ResolvedVc<Box<dyn Module>>` is confusing, so we should reject it. Ditto for no op `upcast`s. This PR makes such calls illegal and eliminates them from the codebase. ## How Introduce a new trait `UpcastStrict` that is only implemented for types that extend or implement different traits. This way we can say it is only valid to try to downcast if the target type is `UpcastStrict`. Then modify the type constraints on our casting utilties to require `UpcastStrict` instead of `Upcast` In the case of `Vc::upcast` i also introduced a `Vc::upcast_non_strict` to help with writing generic code or extension traits. ## Why? I got very confused by some `try_downcast` calls that turned out to be no-ops. Of course this might make some type theorists unhappy, and I don't disagree. Downcasting X->X is a legitimate operation. The ideal solution here would be a linter rule, but there doesn't appear to be any way to implement that.
Author
Parents
Loading