diff options
| author | David Wood <david.wood2@arm.com> | 2025-01-16 11:30:39 +0000 |
|---|---|---|
| committer | David Wood <david.wood2@arm.com> | 2025-06-16 15:00:22 +0000 |
| commit | d43da6f4de19ccfc6ac5a8e6b16ab8cf2893692a (patch) | |
| tree | f329c84a05114bd22f78c8b97e969f7705f53be8 /compiler/rustc_next_trait_solver/src | |
| parent | d9ca9bd014074e2bac567eaa2b66bfacb2591028 (diff) | |
| download | rust-d43da6f4de19ccfc6ac5a8e6b16ab8cf2893692a.tar.gz rust-d43da6f4de19ccfc6ac5a8e6b16ab8cf2893692a.zip | |
trait_sel: `{Meta,Pointee}Sized` on `Sized` types
Introduce the `MetaSized` and `PointeeSized` traits as supertraits of `Sized` and initially implement it on everything that currently implements `Sized` to isolate any changes that simply adding the traits introduces.
Diffstat (limited to 'compiler/rustc_next_trait_solver/src')
4 files changed, 82 insertions, 0 deletions
diff --git a/compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs b/compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs index 0c267feefbe..434e2a818bd 100644 --- a/compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs +++ b/compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs @@ -212,6 +212,24 @@ where goal: Goal<I, Self>, ) -> Result<Candidate<I>, NoSolution>; + /// A type is `MetaSized` if its tail component is `MetaSized`. + /// + /// These components are given by built-in rules from + /// [`structural_traits::instantiate_constituent_tys_for_sized_trait`]. + fn consider_builtin_meta_sized_candidate( + ecx: &mut EvalCtxt<'_, D>, + goal: Goal<I, Self>, + ) -> Result<Candidate<I>, NoSolution>; + + /// A type is `PointeeSized` if its tail component is `PointeeSized`. + /// + /// These components are given by built-in rules from + /// [`structural_traits::instantiate_constituent_tys_for_sized_trait`]. + fn consider_builtin_pointee_sized_candidate( + ecx: &mut EvalCtxt<'_, D>, + goal: Goal<I, Self>, + ) -> Result<Candidate<I>, NoSolution>; + /// A type is `Copy` or `Clone` if its components are `Copy` or `Clone`. /// /// These components are given by built-in rules from @@ -467,6 +485,12 @@ where } else { match cx.as_lang_item(trait_def_id) { Some(TraitSolverLangItem::Sized) => G::consider_builtin_sized_candidate(self, goal), + Some(TraitSolverLangItem::MetaSized) => { + G::consider_builtin_meta_sized_candidate(self, goal) + } + Some(TraitSolverLangItem::PointeeSized) => { + G::consider_builtin_pointee_sized_candidate(self, goal) + } Some(TraitSolverLangItem::Copy | TraitSolverLangItem::Clone) => { G::consider_builtin_copy_clone_candidate(self, goal) } diff --git a/compiler/rustc_next_trait_solver/src/solve/effect_goals.rs b/compiler/rustc_next_trait_solver/src/solve/effect_goals.rs index 8413c2abbb9..dda00a0a2c5 100644 --- a/compiler/rustc_next_trait_solver/src/solve/effect_goals.rs +++ b/compiler/rustc_next_trait_solver/src/solve/effect_goals.rs @@ -205,6 +205,20 @@ where unreachable!("Sized is never const") } + fn consider_builtin_meta_sized_candidate( + _ecx: &mut EvalCtxt<'_, D>, + _goal: Goal<I, Self>, + ) -> Result<Candidate<I>, NoSolution> { + unreachable!("MetaSized is never const") + } + + fn consider_builtin_pointee_sized_candidate( + _ecx: &mut EvalCtxt<'_, D>, + _goal: Goal<I, Self>, + ) -> Result<Candidate<I>, NoSolution> { + unreachable!("PointeeSized is never const") + } + fn consider_builtin_copy_clone_candidate( _ecx: &mut EvalCtxt<'_, D>, _goal: Goal<I, Self>, diff --git a/compiler/rustc_next_trait_solver/src/solve/normalizes_to/mod.rs b/compiler/rustc_next_trait_solver/src/solve/normalizes_to/mod.rs index 2fddc0044cb..42aeb170d6b 100644 --- a/compiler/rustc_next_trait_solver/src/solve/normalizes_to/mod.rs +++ b/compiler/rustc_next_trait_solver/src/solve/normalizes_to/mod.rs @@ -420,6 +420,20 @@ where panic!("`Sized` does not have an associated type: {:?}", goal); } + fn consider_builtin_meta_sized_candidate( + _ecx: &mut EvalCtxt<'_, D>, + goal: Goal<I, Self>, + ) -> Result<Candidate<I>, NoSolution> { + panic!("`MetaSized` does not have an associated type: {:?}", goal); + } + + fn consider_builtin_pointee_sized_candidate( + _ecx: &mut EvalCtxt<'_, D>, + goal: Goal<I, Self>, + ) -> Result<Candidate<I>, NoSolution> { + panic!("`PointeeSized` does not have an associated type: {:?}", goal); + } + fn consider_builtin_copy_clone_candidate( _ecx: &mut EvalCtxt<'_, D>, goal: Goal<I, Self>, diff --git a/compiler/rustc_next_trait_solver/src/solve/trait_goals.rs b/compiler/rustc_next_trait_solver/src/solve/trait_goals.rs index 110c67a8e21..50a7647be62 100644 --- a/compiler/rustc_next_trait_solver/src/solve/trait_goals.rs +++ b/compiler/rustc_next_trait_solver/src/solve/trait_goals.rs @@ -260,6 +260,36 @@ where ) } + fn consider_builtin_meta_sized_candidate( + ecx: &mut EvalCtxt<'_, D>, + goal: Goal<I, Self>, + ) -> Result<Candidate<I>, NoSolution> { + if goal.predicate.polarity != ty::PredicatePolarity::Positive { + return Err(NoSolution); + } + + ecx.probe_and_evaluate_goal_for_constituent_tys( + CandidateSource::BuiltinImpl(BuiltinImplSource::Misc), + goal, + structural_traits::instantiate_constituent_tys_for_sized_trait, + ) + } + + fn consider_builtin_pointee_sized_candidate( + ecx: &mut EvalCtxt<'_, D>, + goal: Goal<I, Self>, + ) -> Result<Candidate<I>, NoSolution> { + if goal.predicate.polarity != ty::PredicatePolarity::Positive { + return Err(NoSolution); + } + + ecx.probe_and_evaluate_goal_for_constituent_tys( + CandidateSource::BuiltinImpl(BuiltinImplSource::Misc), + goal, + structural_traits::instantiate_constituent_tys_for_sized_trait, + ) + } + fn consider_builtin_copy_clone_candidate( ecx: &mut EvalCtxt<'_, D>, goal: Goal<I, Self>, |
