rust/tests/ui/rfcs/rfc-2632-const-trait-impl
bors 6fc0273b5a Auto merge of #112320 - compiler-errors:do-not-impl-via-obj, r=lcnr
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:
2f896da247/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs (L61-L132)

However, candidate assembly in the new solver is much more lovely, and I'd hate to add this list of opt-out cases into the new solver. Instead of maintaining this complex and hard-coded control flow, instead we can make this a property of the trait via a built-in attribute. We already have such a build attribute that's applied to every single trait that we care about: `rustc_deny_explicit_impl`. This PR adds `implement_via_object` as a meta-item to that attribute that allows us to opt a trait out of object-bound candidate assembly as well.

r? `@lcnr`
2023-06-20 08:42:37 +00:00
..
auxiliary
const_derives
specialization
assoc-type-const-bound-usage.rs
assoc-type.rs
assoc-type.stderr
attr-misuse.rs
attr-misuse.stderr Merge attrs, better validation 2023-06-20 04:38:55 +00:00
call-const-trait-method-fail.rs
call-const-trait-method-fail.stderr
call-const-trait-method-pass.rs
call-const-trait-method-pass.stderr
call-generic-in-impl.rs
call-generic-in-impl.stderr
call-generic-method-chain.rs
call-generic-method-chain.stderr
call-generic-method-dup-bound.rs
call-generic-method-dup-bound.stderr
call-generic-method-fail.rs
call-generic-method-fail.stderr
call-generic-method-nonconst-bound.rs
call-generic-method-nonconst.rs
call-generic-method-nonconst.stderr
call-generic-method-pass.rs
call-generic-method-pass.stderr
call.rs
const-and-non-const-impl.rs
const-and-non-const-impl.stderr
const-check-fns-in-const-impl.rs
const-check-fns-in-const-impl.stderr
const-closure-parse-not-item.rs
const-closure-trait-method-fail.rs
const-closure-trait-method-fail.stderr
const-closure-trait-method.rs
const-closures.rs
const-default-method-bodies.rs
const-default-method-bodies.stderr
const-drop-bound.rs
const-drop-fail-2.precise.stderr
const-drop-fail-2.rs
const-drop-fail-2.stderr
const-drop-fail-2.stock.stderr
const-drop-fail.precise.stderr
const-drop-fail.rs
const-drop-fail.stock.stderr
const-drop.rs
const-impl-norecover.rs
const-impl-norecover.stderr
const-impl-recovery.rs
const-impl-recovery.stderr
const-impl-requires-const-trait.rs
const-impl-requires-const-trait.stderr
const-impl-trait.rs
const-impl-trait.stderr
cross-crate-default-method-body-is-const.rs
cross-crate.gatednc.stderr
cross-crate.rs
cross-crate.stock.stderr
cross-crate.stocknc.stderr
default-method-body-is-const-body-checking.rs
default-method-body-is-const-body-checking.stderr
default-method-body-is-const-same-trait-ck.rs
default-method-body-is-const-same-trait-ck.stderr
default-method-body-is-const-with-staged-api.rs
do-not-const-check-override.rs
do-not-const-check.rs
feature-gate.gated.stderr
feature-gate.rs
feature-gate.stock.stderr
function-pointer-does-not-require-const.rs
gate.rs
gate.stderr
generic-bound.rs
generic-bound.stderr
hir-const-check.rs
hir-const-check.stderr
impl-tilde-const-trait.rs
impl-tilde-const-trait.stderr
impl-with-default-fn-fail.rs
impl-with-default-fn-fail.stderr
impl-with-default-fn-pass.rs
inherent-impl-const-bounds.rs
inherent-impl.rs
inherent-impl.stderr
issue-79450.rs
issue-79450.stderr
issue-88155.rs
issue-88155.stderr
issue-90052.rs
issue-90052.stderr
issue-92111.rs
issue-92230-wf-super-trait-env.rs
issue-100222.rs
issue-102156.rs
issue-102156.stderr
issue-102985.rs
issue-102985.stderr
issue-103677.rs
match-non-const-eq.gated.stderr
match-non-const-eq.rs
match-non-const-eq.stock.stderr
nested-closure.rs
non-const-op-const-closure-non-const-outer.rs
non-const-op-const-closure-non-const-outer.stderr
non-const-op-in-closure-in-const.rs
non-const-op-in-closure-in-const.stderr
specializing-constness-2.rs
specializing-constness-2.stderr
specializing-constness.rs
specializing-constness.stderr
staged-api-user-crate.rs
staged-api-user-crate.stderr
staged-api.rs
staged-api.stable.stderr
staged-api.unstable.stderr
static-const-trait-bound.rs
std-impl-gate.gated.stderr
std-impl-gate.rs
std-impl-gate.stock.stderr
super-traits-fail-2.nn.stderr
super-traits-fail-2.ny.stderr
super-traits-fail-2.rs
super-traits-fail-2.yn.stderr
super-traits-fail-2.yy.stderr
super-traits-fail-3.nn.stderr
super-traits-fail-3.ny.stderr
super-traits-fail-3.rs
super-traits-fail-3.yn.stderr
super-traits-fail.rs
super-traits-fail.stderr
super-traits.rs
syntax.rs
tilde_const_on_impl_bound.rs
tilde-const-and-const-params.rs
tilde-const-and-const-params.stderr
tilde-const-invalid-places.rs
tilde-const-invalid-places.stderr
tilde-const-syntax.rs
tilde-twice.rs
tilde-twice.stderr
trait-default-body-stability.rs
trait-default-body-stability.stderr
trait-method-ptr-in-consts-ice.rs
trait-where-clause-const.rs
trait-where-clause-const.stderr
trait-where-clause-run.rs
trait-where-clause-self-referential.rs
trait-where-clause.rs
trait-where-clause.stderr
without-tilde.rs
without-tilde.stderr