rust/compiler/rustc_hir_analysis/src
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
..
astconv Rollup merge of #112734 - dswij:bounds-predicates-clause, r=compiler-errors 2023-06-18 08:06:43 +02:00
check Rollup merge of #112596 - compiler-errors:missing-sig-with-rpitit, r=b-naber 2023-06-19 17:53:34 -07:00
coherence Auto merge of #112320 - compiler-errors:do-not-impl-via-obj, r=lcnr 2023-06-20 08:42:37 +00:00
collect Rollup merge of #112734 - dswij:bounds-predicates-clause, r=compiler-errors 2023-06-18 08:06:43 +02:00
impl_wf_check Move ConstEvaluatable to Clause 2023-06-17 21:27:13 +00:00
outlives Move ConstEvaluatable to Clause 2023-06-17 21:27:13 +00:00
structured_errors Use Option::is_some_and and Result::is_ok_and in the compiler 2023-05-24 14:20:41 +00:00
variance Move expansion of query macros in rustc_middle to rustc_middle::query 2023-05-15 08:49:13 +02:00
autoderef.rs Make TraitEngine::new use the right solver, add compare mode 2023-06-06 18:43:20 +00:00
bounds.rs Bound::predicates to return Clause 2023-06-17 17:16:30 +08:00
check_unused.rs Remove last instances of HashSet in query result types. 2023-03-01 10:20:45 +01:00
collect.rs Auto merge of #112320 - compiler-errors:do-not-impl-via-obj, r=lcnr 2023-06-20 08:42:37 +00:00
constrained_generic_params.rs IAT: Introduce AliasKind::Inherent 2023-05-04 16:59:10 +02:00
errors.rs Emit an error when RTN is used with ty/ct params 2023-06-05 19:52:04 +00:00
hir_wf_check.rs Move WF goal to clause 2023-06-17 21:20:20 +00:00
impl_wf_check.rs Error on unconstrained lifetime in RPITIT 2023-06-14 05:20:31 +00:00
lib.rs remove hash_drain_filter feature uses 2023-06-14 09:28:56 +02:00
structured_errors.rs rustc_typeck to rustc_hir_analysis 2022-09-27 10:37:23 +02:00