Skip to content

Commit bb1d842

Browse files
committed
Remove !Unpin related bounds
1 parent 82e48e2 commit bb1d842

File tree

6 files changed

+100
-754
lines changed

6 files changed

+100
-754
lines changed

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use rustc_lint::builtin::SELF_CONSTRUCTOR_FROM_OUTER_ITEM;
2323
use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow, AutoBorrowMutability};
2424
use rustc_middle::ty::{
2525
self, AdtKind, CanonicalUserType, GenericArgsRef, GenericParamDefKind, IsIdentity,
26-
SizedTraitKind, Ty, TyCtxt, TypeFoldable, TypeVisitable, TypeVisitableExt, Upcast, UserArgs,
26+
SizedTraitKind, Ty, TyCtxt, TypeFoldable, TypeVisitable, TypeVisitableExt, UserArgs,
2727
UserSelfTy,
2828
};
2929
use rustc_middle::{bug, span_bug};
@@ -463,29 +463,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
463463
}
464464
}
465465

466-
pub(crate) fn register_negative_bound(
467-
&self,
468-
ty: Ty<'tcx>,
469-
def_id: DefId,
470-
cause: traits::ObligationCause<'tcx>,
471-
) {
472-
if !ty.references_error() {
473-
let trait_ref = ty::TraitRef::new(self.tcx, def_id, [ty]);
474-
let predicate =
475-
ty::TraitPredicate { trait_ref, polarity: ty::PredicatePolarity::Negative }
476-
.upcast(self.tcx);
477-
self.fulfillment_cx.borrow_mut().register_predicate_obligation(
478-
self,
479-
traits::Obligation {
480-
cause,
481-
recursion_depth: 0,
482-
param_env: self.param_env,
483-
predicate,
484-
},
485-
);
486-
}
487-
}
488-
489466
pub(crate) fn lower_ty(&self, hir_ty: &hir::Ty<'tcx>) -> LoweredTy<'tcx> {
490467
let ty = self.lowerer().lower_ty(hir_ty);
491468
self.register_wf_obligation(ty.into(), hir_ty.span, ObligationCauseCode::WellFormed(None));

compiler/rustc_hir_typeck/src/pat.rs

Lines changed: 14 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use rustc_span::edition::Edition;
2727
use rustc_span::source_map::Spanned;
2828
use rustc_span::{BytePos, DUMMY_SP, Ident, Span, kw, sym};
2929
use rustc_trait_selection::infer::InferCtxtExt;
30-
use rustc_trait_selection::traits::{ObligationCause, ObligationCauseCode, ObligationCtxt};
30+
use rustc_trait_selection::traits::{ObligationCause, ObligationCauseCode};
3131
use tracing::{debug, instrument, trace};
3232
use ty::VariantDef;
3333
use ty::adjustment::{PatAdjust, PatAdjustment};
@@ -402,38 +402,19 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
402402
let ty = self.check_pat_inner(pat, opt_path_res, adjust_mode, expected, pat_info);
403403
self.write_ty(pat.hir_id, ty);
404404

405-
// If we implicitly inserted overloaded dereferences and pinned dereferences before matching,
406-
// check the pattern to see if the dereferenced types need `DerefMut` or `!Unpin` bounds.
407-
if let Some(derefed_tys) = self.typeck_results.borrow().pat_adjustments().get(pat.hir_id) {
408-
let mut has_overloaded_deref = false;
409-
let mut has_pin_deref = false;
410-
derefed_tys.iter().for_each(|adjust| match adjust.kind {
411-
PatAdjust::BuiltinDeref => {}
412-
PatAdjust::OverloadedDeref => has_overloaded_deref = true,
413-
PatAdjust::PinDeref => has_pin_deref = true,
414-
});
415-
if has_overloaded_deref {
416-
self.register_deref_mut_bounds_if_needed(
417-
pat.span,
418-
pat,
419-
derefed_tys.iter().filter_map(|adjust| match adjust.kind {
420-
PatAdjust::OverloadedDeref => Some(adjust.source),
421-
PatAdjust::BuiltinDeref | PatAdjust::PinDeref => None,
422-
}),
423-
);
424-
}
425-
if has_pin_deref {
426-
self.register_not_unpin_bounds_if_needed(
427-
pat.span,
428-
pat,
429-
derefed_tys.iter().filter_map(|adjust| match adjust.kind {
430-
PatAdjust::BuiltinDeref | PatAdjust::OverloadedDeref => None,
431-
PatAdjust::PinDeref => {
432-
Some(adjust.source.pinned_ref().expect("expected pinned reference").0)
433-
}
434-
}),
435-
);
436-
}
405+
// If we implicitly inserted overloaded dereferences before matching check the pattern to
406+
// see if the dereferenced types need `DerefMut` bounds.
407+
if let Some(derefed_tys) = self.typeck_results.borrow().pat_adjustments().get(pat.hir_id)
408+
&& derefed_tys.iter().any(|adjust| adjust.kind == PatAdjust::OverloadedDeref)
409+
{
410+
self.register_deref_mut_bounds_if_needed(
411+
pat.span,
412+
pat,
413+
derefed_tys.iter().filter_map(|adjust| match adjust.kind {
414+
PatAdjust::OverloadedDeref => Some(adjust.source),
415+
PatAdjust::BuiltinDeref | PatAdjust::PinDeref => None,
416+
}),
417+
);
437418
}
438419

439420
// (note_1): In most of the cases where (note_1) is referenced
@@ -582,9 +563,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
582563
self.misc(pat.span),
583564
)
584565
}
585-
// Once we've checked `pat`, we'll add a `!Unpin` bound if it contains any
586-
// `ref pin` bindings. See `Self::register_not_unpin_bounds_if_needed`.
587-
588566
debug!("default binding mode is now {:?}", binding_mode);
589567

590568
// Use the old pat info to keep `current_depth` to its old value.
@@ -2677,44 +2655,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
26772655
}
26782656
}
26792657

2680-
/// Check if the interior of a pin pattern (either explicit or implicit) has any `ref pin`
2681-
/// bindings of non-`Unpin` types, which would require `!Unpin` to be emitted.
2682-
fn register_not_unpin_bounds_if_needed(
2683-
&self,
2684-
span: Span,
2685-
inner: &'tcx Pat<'tcx>,
2686-
derefed_tys: impl IntoIterator<Item = Ty<'tcx>>,
2687-
) {
2688-
// Check if there are subpatterns with `ref pin` binding modes of non-`Unpin` types.
2689-
let unpin = self.tcx.require_lang_item(hir::LangItem::Unpin, span);
2690-
let cause = self.misc(span);
2691-
let unpin_obligations = self.probe(|_| {
2692-
let ocx = ObligationCtxt::new(&self);
2693-
self.typeck_results.borrow().pat_walk_ref_pin_binding_of_non_unpin_type(inner, |ty| {
2694-
let ty = ocx
2695-
.normalize(&cause, self.param_env, ty)
2696-
.pinned_ref()
2697-
.expect("expect pinned reference")
2698-
.0;
2699-
debug!("check if `Unpin` is implemented for `{ty:?}`");
2700-
ocx.register_bound(cause.clone(), self.param_env, ty, unpin);
2701-
});
2702-
ocx.select_all_or_error()
2703-
});
2704-
2705-
// If any, the current pattern type should implement `!Unpin`.
2706-
if !unpin_obligations.is_empty() {
2707-
for pinned_derefed_ty in derefed_tys {
2708-
debug!("register `!Unpin` for `{pinned_derefed_ty:?}`");
2709-
self.register_negative_bound(
2710-
pinned_derefed_ty,
2711-
self.tcx.require_lang_item(hir::LangItem::Unpin, span),
2712-
self.misc(span),
2713-
);
2714-
}
2715-
}
2716-
}
2717-
27182658
// Precondition: Pat is Ref(inner)
27192659
fn check_pat_ref(
27202660
&self,

0 commit comments

Comments
 (0)