Rollup merge of #142339 - oli-obk:not-null-pattern-types, r=BoxyUwU
Add NonNull pattern types These are the final piece missing for * https://github.com/rust-lang/rust/pull/136006 We cannot use the previous scheme of using an integer range for raw pointers, as we're not just changing the layout of raw pointers anymore, but also the type representation. And we can't represent "any provenance or NonZero<usize>" natively as patterns. So I created a new `!null` pattern. Since this is all unstable representation stuff for replacing rustc_layout_scalar_range_start with pattern types, the divergence from normal patterns is fine, especially since T-lang seems interested in exploring general negation patterns r? `@BoxyUwU`
This commit is contained in:
@@ -115,6 +115,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||
ImplSource::Builtin(BuiltinImplSource::Misc, data)
|
||||
}
|
||||
|
||||
PointerLikeCandidate => {
|
||||
let data = self.confirm_pointer_like_candidate(obligation);
|
||||
ImplSource::Builtin(BuiltinImplSource::Misc, data)
|
||||
}
|
||||
|
||||
TraitAliasCandidate => {
|
||||
let data = self.confirm_trait_alias_candidate(obligation);
|
||||
ImplSource::Builtin(BuiltinImplSource::Misc, data)
|
||||
@@ -631,6 +636,25 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||
Ok(nested)
|
||||
}
|
||||
|
||||
fn confirm_pointer_like_candidate(
|
||||
&mut self,
|
||||
obligation: &PolyTraitObligation<'tcx>,
|
||||
) -> PredicateObligations<'tcx> {
|
||||
debug!(?obligation, "confirm_pointer_like_candidate");
|
||||
let placeholder_predicate = self.infcx.enter_forall_and_leak_universe(obligation.predicate);
|
||||
let self_ty = self.infcx.shallow_resolve(placeholder_predicate.self_ty());
|
||||
let ty::Pat(base, _) = *self_ty.kind() else { bug!() };
|
||||
let cause = obligation.derived_cause(ObligationCauseCode::BuiltinDerived);
|
||||
|
||||
self.collect_predicates_for_types(
|
||||
obligation.param_env,
|
||||
cause,
|
||||
obligation.recursion_depth + 1,
|
||||
placeholder_predicate.def_id(),
|
||||
vec![base],
|
||||
)
|
||||
}
|
||||
|
||||
fn confirm_trait_alias_candidate(
|
||||
&mut self,
|
||||
obligation: &PolyTraitObligation<'tcx>,
|
||||
|
||||
@@ -2036,6 +2036,7 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
|
||||
| TraitUpcastingUnsizeCandidate(_)
|
||||
| BuiltinObjectCandidate
|
||||
| BuiltinUnsizeCandidate
|
||||
| PointerLikeCandidate
|
||||
| BikeshedGuaranteedNoDropCandidate => false,
|
||||
// Non-global param candidates have already been handled, global
|
||||
// where-bounds get ignored.
|
||||
|
||||
@@ -705,6 +705,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
|
||||
check(start);
|
||||
check(end);
|
||||
}
|
||||
ty::PatternKind::NotNull => {}
|
||||
ty::PatternKind::Or(patterns) => {
|
||||
for pat in patterns {
|
||||
self.add_wf_preds_for_pat_ty(base_ty, pat)
|
||||
|
||||
Reference in New Issue
Block a user