rust-lang/rust

Tracking issue for future-incompatibility lint `deref_into_dyn_supertrait`

crlf0710 opened this issue · 5 comments

What is this lint about

We're planning to add the dyn upcasting coercion language feature (see https://github.com/rust-lang/dyn-upcasting-coercion-initiative). Unfortunately this new coercion rule will take priority over certain other coercion rules, which will mean some behavior change. See #89190 for initial bug report.

How to fix this warning/error

Ensure your own Deref implementation is consistent with the trait_upcasting feature brings and allow this lint. Or avoid this code pattern altogether.

Current status

Implementation: #89461

Could we get a more detailed summary of the case this lint is addressing? dyn upcasting / coercion seems to have made a lot of progress, but this aspect of it doesn't seem to have gotten much discussion that I recall.

@joshtriplett Sure.

It is known that from user's perspective, coercions has "priorities", and dyn upcasting coercion has a higher priority than user defined Deref-based coercions. In the end, this coercion "shadows" a rare certain setup of user Deref implementation, which mimicks dyn upcasting coercion manually(see #89190 for an example).

For now we don't want to affect user's code, since dyn upcasting coercion might take a little while before it's stablized. Though, if user provided code decide to do other things in the Deref/DerefMut implementation, (even rarer, but possible, like running a hook or something), there will be a silent behavior change, when dyn upcasting gets stablized in the future. This lint emits a warning for this matter, to make sure that user doesn't write such code in their Deref/DerefMut implementations, then the future migration to dyn upcasting coercion will be smooth.

I'm curious -- why wasn't this implemented as a lint on the impl?

@compiler-errors It could be implemented that way, and thinking about it from current view, that would be a better way (No removal of the lint is needed with that approach)

For future reference: the lint change suggested by @compiler-errors was implemented in #104742 (I just tried to do that again because I forgor). The lint now lints against Deref impls for dyn Trait with type Target = dyn SupertraitOfTrait (instead of linting against the use of such Deref impl like it used to).