diff options
| author | bors <bors@rust-lang.org> | 2024-10-16 17:58:25 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-10-16 17:58:25 +0000 |
| commit | 7342830c05ec0996e9e4b7df550b1043dca7829c (patch) | |
| tree | 8299ba13bde1b11d0062029a84f63c73e736dbbb /compiler/rustc_trait_selection/src | |
| parent | bed75e7c21e8d18bd536a0f7c9e479d2f6707db3 (diff) | |
| parent | 06cd22ceab1a5dc01626958c5f41401ec237807a (diff) | |
| download | rust-7342830c05ec0996e9e4b7df550b1043dca7829c.tar.gz rust-7342830c05ec0996e9e4b7df550b1043dca7829c.zip | |
Auto merge of #131792 - matthiaskrgr:rollup-480nwg4, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - #130822 (Add `from_ref` and `from_mut` constructors to `core::ptr::NonNull`.) - #131381 (Implement edition 2024 match ergonomics restrictions) - #131594 (rustdoc: Rename "object safe" to "dyn compatible") - #131686 (Add fast-path when computing the default visibility) - #131699 (Try to improve error messages involving aliases in the solver) - #131757 (Ignore lint-non-snake-case-crate#proc_macro_ on targets without unwind) - #131783 (Fix explicit_iter_loop in rustc_serialize) - #131788 (Fix mismatched quotation mark) r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_trait_selection/src')
| -rw-r--r-- | compiler/rustc_trait_selection/src/solve/fulfill.rs | 25 | ||||
| -rw-r--r-- | compiler/rustc_trait_selection/src/solve/inspect/analyse.rs | 6 | ||||
| -rw-r--r-- | compiler/rustc_trait_selection/src/solve/select.rs | 3 |
3 files changed, 22 insertions, 12 deletions
diff --git a/compiler/rustc_trait_selection/src/solve/fulfill.rs b/compiler/rustc_trait_selection/src/solve/fulfill.rs index d9dc772eca9..53e5420d27a 100644 --- a/compiler/rustc_trait_selection/src/solve/fulfill.rs +++ b/compiler/rustc_trait_selection/src/solve/fulfill.rs @@ -14,7 +14,7 @@ use rustc_middle::bug; use rustc_middle::ty::error::{ExpectedFound, TypeError}; use rustc_middle::ty::{self, TyCtxt}; use rustc_next_trait_solver::solve::{GenerateProofTree, HasChanged, SolverDelegateEvalExt as _}; -use tracing::instrument; +use tracing::{instrument, trace}; use super::Certainty; use super::delegate::SolverDelegate; @@ -401,6 +401,7 @@ impl<'tcx> BestObligation<'tcx> { nested_goal.source(), GoalSource::ImplWhereBound | GoalSource::InstantiateHigherRanked + | GoalSource::AliasWellFormed ) && match self.consider_ambiguities { true => { matches!( @@ -415,6 +416,13 @@ impl<'tcx> BestObligation<'tcx> { }) }); } + + // Prefer a non-rigid candidate if there is one. + if candidates.len() > 1 { + candidates.retain(|candidate| { + !matches!(candidate.kind(), inspect::ProbeKind::RigidAlias { .. }) + }); + } } } @@ -429,8 +437,11 @@ impl<'tcx> ProofTreeVisitor<'tcx> for BestObligation<'tcx> { self.obligation.cause.span } + #[instrument(level = "trace", skip(self, goal), fields(goal = ?goal.goal()))] fn visit_goal(&mut self, goal: &inspect::InspectGoal<'_, 'tcx>) -> Self::Result { let candidates = self.non_trivial_candidates(goal); + trace!(candidates = ?candidates.iter().map(|c| c.kind()).collect::<Vec<_>>()); + let [candidate] = candidates.as_slice() else { return ControlFlow::Break(self.obligation.clone()); }; @@ -464,17 +475,13 @@ impl<'tcx> ProofTreeVisitor<'tcx> for BestObligation<'tcx> { polarity: ty::PredicatePolarity::Positive, })) } - ty::PredicateKind::Clause( - ty::ClauseKind::WellFormed(_) | ty::ClauseKind::Projection(..), - ) - | ty::PredicateKind::AliasRelate(..) => ChildMode::PassThrough, - _ => { - return ControlFlow::Break(self.obligation.clone()); - } + _ => ChildMode::PassThrough, }; let mut impl_where_bound_count = 0; for nested_goal in candidate.instantiate_nested_goals(self.span()) { + trace!(nested_goal = ?(nested_goal.goal(), nested_goal.source(), nested_goal.result())); + let make_obligation = |cause| Obligation { cause, param_env: nested_goal.goal().param_env, @@ -501,7 +508,7 @@ impl<'tcx> ProofTreeVisitor<'tcx> for BestObligation<'tcx> { (_, GoalSource::InstantiateHigherRanked) => { obligation = self.obligation.clone(); } - (ChildMode::PassThrough, _) => { + (ChildMode::PassThrough, _) | (_, GoalSource::AliasWellFormed) => { obligation = make_obligation(self.obligation.cause.clone()); } } diff --git a/compiler/rustc_trait_selection/src/solve/inspect/analyse.rs b/compiler/rustc_trait_selection/src/solve/inspect/analyse.rs index 254620e0b59..4975a9ce0c7 100644 --- a/compiler/rustc_trait_selection/src/solve/inspect/analyse.rs +++ b/compiler/rustc_trait_selection/src/solve/inspect/analyse.rs @@ -292,7 +292,8 @@ impl<'a, 'tcx> InspectGoal<'a, 'tcx> { | inspect::ProbeKind::Root { .. } | inspect::ProbeKind::TryNormalizeNonRigid { .. } | inspect::ProbeKind::TraitCandidate { .. } - | inspect::ProbeKind::OpaqueTypeStorageLookup { .. } => { + | inspect::ProbeKind::OpaqueTypeStorageLookup { .. } + | inspect::ProbeKind::RigidAlias { .. } => { // Nested probes have to prove goals added in their parent // but do not leak them, so we truncate the added goals // afterwards. @@ -316,7 +317,8 @@ impl<'a, 'tcx> InspectGoal<'a, 'tcx> { inspect::ProbeKind::Root { result } | inspect::ProbeKind::TryNormalizeNonRigid { result } | inspect::ProbeKind::TraitCandidate { source: _, result } - | inspect::ProbeKind::OpaqueTypeStorageLookup { result } => { + | inspect::ProbeKind::OpaqueTypeStorageLookup { result } + | inspect::ProbeKind::RigidAlias { result } => { // We only add a candidate if `shallow_certainty` was set, which means // that we ended up calling `evaluate_added_goals_and_make_canonical_response`. if let Some(shallow_certainty) = shallow_certainty { diff --git a/compiler/rustc_trait_selection/src/solve/select.rs b/compiler/rustc_trait_selection/src/solve/select.rs index 257fd263b94..1661852903c 100644 --- a/compiler/rustc_trait_selection/src/solve/select.rs +++ b/compiler/rustc_trait_selection/src/solve/select.rs @@ -177,7 +177,8 @@ fn to_selection<'tcx>( | ProbeKind::UpcastProjectionCompatibility | ProbeKind::OpaqueTypeStorageLookup { result: _ } | ProbeKind::Root { result: _ } - | ProbeKind::ShadowedEnvProbing => { + | ProbeKind::ShadowedEnvProbing + | ProbeKind::RigidAlias { result: _ } => { span_bug!(span, "didn't expect to assemble trait candidate from {:#?}", cand.kind()) } }) |
