mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 23:34:48 +00:00
6fc0273b5a
Add `implement_via_object` to `rustc_deny_explicit_impl` to control object candidate assembly
Some built-in traits are special, since they are used to prove facts about the program that are important for later phases of compilation such as codegen and CTFE. For example, the `Unsize` trait is used to assert to the compiler that we are able to unsize a type into another type. It doesn't have any methods because it doesn't actually *instruct* the compiler how to do this unsizing, but this is later used (alongside an exhaustive match of combinations of unsizeable types) during codegen to generate unsize coercion code.
Due to this, these built-in traits are incompatible with the type erasure provided by object types. For example, the existence of `dyn Unsize<T>` does not mean that the compiler is able to unsize `Box<dyn Unsize<T>>` into `Box<T>`, since `Unsize` is a *witness* to the fact that a type can be unsized, and it doesn't actually encode that unsizing operation in its vtable as mentioned above.
The old trait solver gets around this fact by having complex control flow that never considers object bounds for certain built-in traits:
|
||
---|---|---|
.. | ||
box-instead-of-dyn-fn.rs | ||
box-instead-of-dyn-fn.stderr | ||
issue-30355.rs | ||
issue-30355.stderr | ||
issue-40231-1.rs | ||
issue-40231-2.rs | ||
issue-71659.current.stderr | ||
issue-71659.next.stderr | ||
issue-71659.rs | ||
issue-75707.rs | ||
issue-75707.stderr | ||
issue-75899-but-gats.rs | ||
issue-75899.rs | ||
issue-91801.rs | ||
issue-91801.stderr | ||
issue-91803.rs | ||
issue-91803.stderr | ||
issue-97732.rs | ||
maybe-bounds-where-cpass.rs | ||
maybe-bounds-where.rs | ||
maybe-bounds-where.stderr | ||
param-mentioned-by-different-field.rs | ||
param-mentioned-by-different-field.stderr | ||
return-unsized-from-trait-method.rs | ||
return-unsized-from-trait-method.stderr | ||
unchanged-param.rs | ||
unsized2.rs | ||
unsized3-rpass.rs | ||
unsized3.rs | ||
unsized3.stderr | ||
unsized5.rs | ||
unsized5.stderr | ||
unsized6.rs | ||
unsized6.stderr | ||
unsized7.rs | ||
unsized7.stderr | ||
unsized-bare-typaram.rs | ||
unsized-bare-typaram.stderr | ||
unsized-enum2.rs | ||
unsized-enum2.stderr | ||
unsized-enum.rs | ||
unsized-enum.stderr | ||
unsized-fn-arg.fixed | ||
unsized-fn-arg.rs | ||
unsized-fn-arg.stderr | ||
unsized-fn-param.rs | ||
unsized-fn-param.stderr | ||
unsized-inherent-impl-self-type.rs | ||
unsized-inherent-impl-self-type.stderr | ||
unsized-struct.rs | ||
unsized-struct.stderr | ||
unsized-trait-impl-self-type.rs | ||
unsized-trait-impl-self-type.stderr | ||
unsized-trait-impl-trait-arg.rs | ||
unsized-trait-impl-trait-arg.stderr | ||
unsized-tuple-impls.rs | ||
unsized.rs |