Skip to content

Commit b866a84

Browse files
committed
obligations_for_self_ty to sub module
1 parent 5557f8c commit b866a84

File tree

3 files changed

+65
-59
lines changed

3 files changed

+65
-59
lines changed

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

-59
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use crate::errors::CtorIsPrivate;
33
use crate::method::{self, MethodCallee, SelfSource};
44
use crate::rvalue_scopes;
55
use crate::{BreakableCtxt, Diverges, Expectation, FnCtxt, LoweredTy};
6-
use rustc_data_structures::captures::Captures;
76
use rustc_data_structures::fx::FxHashSet;
87
use rustc_errors::{Applicability, Diag, ErrorGuaranteed, MultiSpan, StashKey};
98
use rustc_hir as hir;
@@ -636,64 +635,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
636635
ret_ty.builtin_deref(true).unwrap()
637636
}
638637

639-
#[instrument(skip(self), level = "debug")]
640-
fn self_type_matches_expected_vid(&self, self_ty: Ty<'tcx>, expected_vid: ty::TyVid) -> bool {
641-
let self_ty = self.shallow_resolve(self_ty);
642-
debug!(?self_ty);
643-
644-
match *self_ty.kind() {
645-
ty::Infer(ty::TyVar(found_vid)) => {
646-
let found_vid = self.root_var(found_vid);
647-
debug!("self_type_matches_expected_vid - found_vid={:?}", found_vid);
648-
expected_vid == found_vid
649-
}
650-
_ => false,
651-
}
652-
}
653-
654-
#[instrument(skip(self), level = "debug")]
655-
pub(in super::super) fn obligations_for_self_ty<'b>(
656-
&'b self,
657-
self_ty: ty::TyVid,
658-
) -> impl DoubleEndedIterator<Item = traits::PredicateObligation<'tcx>> + Captures<'tcx> + 'b
659-
{
660-
let ty_var_root = self.root_var(self_ty);
661-
trace!("pending_obligations = {:#?}", self.fulfillment_cx.borrow().pending_obligations());
662-
663-
self.fulfillment_cx.borrow().pending_obligations().into_iter().filter_map(
664-
move |obligation| match &obligation.predicate.kind().skip_binder() {
665-
ty::PredicateKind::Clause(ty::ClauseKind::Projection(data))
666-
if self.self_type_matches_expected_vid(
667-
data.projection_ty.self_ty(),
668-
ty_var_root,
669-
) =>
670-
{
671-
Some(obligation)
672-
}
673-
ty::PredicateKind::Clause(ty::ClauseKind::Trait(data))
674-
if self.self_type_matches_expected_vid(data.self_ty(), ty_var_root) =>
675-
{
676-
Some(obligation)
677-
}
678-
679-
ty::PredicateKind::Clause(ty::ClauseKind::Trait(..))
680-
| ty::PredicateKind::Clause(ty::ClauseKind::Projection(..))
681-
| ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType(..))
682-
| ty::PredicateKind::Subtype(..)
683-
| ty::PredicateKind::Coerce(..)
684-
| ty::PredicateKind::Clause(ty::ClauseKind::RegionOutlives(..))
685-
| ty::PredicateKind::Clause(ty::ClauseKind::TypeOutlives(..))
686-
| ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(..))
687-
| ty::PredicateKind::ObjectSafe(..)
688-
| ty::PredicateKind::NormalizesTo(..)
689-
| ty::PredicateKind::AliasRelate(..)
690-
| ty::PredicateKind::Clause(ty::ClauseKind::ConstEvaluatable(..))
691-
| ty::PredicateKind::ConstEquate(..)
692-
| ty::PredicateKind::Ambiguous => None,
693-
},
694-
)
695-
}
696-
697638
pub(in super::super) fn type_var_is_sized(&self, self_ty: ty::TyVid) -> bool {
698639
let sized_did = self.tcx.lang_items().sized_trait();
699640
self.obligations_for_self_ty(self_ty).any(|obligation| {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
use crate::FnCtxt;
2+
use rustc_middle::ty::{self, Ty};
3+
use rustc_infer::traits;
4+
use rustc_data_structures::captures::Captures;
5+
6+
impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
7+
#[instrument(skip(self), level = "debug")]
8+
pub(crate) fn obligations_for_self_ty<'b>(
9+
&'b self,
10+
self_ty: ty::TyVid,
11+
) -> impl DoubleEndedIterator<Item = traits::PredicateObligation<'tcx>> + Captures<'tcx> + 'b
12+
{
13+
let ty_var_root = self.root_var(self_ty);
14+
trace!("pending_obligations = {:#?}", self.fulfillment_cx.borrow().pending_obligations());
15+
16+
self.fulfillment_cx.borrow().pending_obligations().into_iter().filter_map(
17+
move |obligation| match &obligation.predicate.kind().skip_binder() {
18+
ty::PredicateKind::Clause(ty::ClauseKind::Projection(data))
19+
if self.self_type_matches_expected_vid(
20+
data.projection_ty.self_ty(),
21+
ty_var_root,
22+
) =>
23+
{
24+
Some(obligation)
25+
}
26+
ty::PredicateKind::Clause(ty::ClauseKind::Trait(data))
27+
if self.self_type_matches_expected_vid(data.self_ty(), ty_var_root) =>
28+
{
29+
Some(obligation)
30+
}
31+
32+
ty::PredicateKind::Clause(ty::ClauseKind::Trait(..))
33+
| ty::PredicateKind::Clause(ty::ClauseKind::Projection(..))
34+
| ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType(..))
35+
| ty::PredicateKind::Subtype(..)
36+
| ty::PredicateKind::Coerce(..)
37+
| ty::PredicateKind::Clause(ty::ClauseKind::RegionOutlives(..))
38+
| ty::PredicateKind::Clause(ty::ClauseKind::TypeOutlives(..))
39+
| ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(..))
40+
| ty::PredicateKind::ObjectSafe(..)
41+
| ty::PredicateKind::NormalizesTo(..)
42+
| ty::PredicateKind::AliasRelate(..)
43+
| ty::PredicateKind::Clause(ty::ClauseKind::ConstEvaluatable(..))
44+
| ty::PredicateKind::ConstEquate(..)
45+
| ty::PredicateKind::Ambiguous => None,
46+
},
47+
)
48+
}
49+
50+
#[instrument(level = "debug", skip(self), ret)]
51+
fn self_type_matches_expected_vid(&self, self_ty: Ty<'tcx>, expected_vid: ty::TyVid) -> bool {
52+
let self_ty = self.shallow_resolve(self_ty);
53+
debug!(?self_ty);
54+
55+
match *self_ty.kind() {
56+
ty::Infer(ty::TyVar(found_vid)) => {
57+
let found_vid = self.root_var(found_vid);
58+
debug!("self_type_matches_expected_vid - found_vid={:?}", found_vid);
59+
expected_vid == found_vid
60+
}
61+
_ => false,
62+
}
63+
}
64+
}

compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ mod _impl;
22
mod adjust_fulfillment_errors;
33
mod arg_matrix;
44
mod checks;
5+
mod inspect_obligations;
56
mod suggestions;
67

78
use crate::coercion::DynamicCoerceMany;

0 commit comments

Comments
 (0)