Skip to content

Commit a5f9af2

Browse files
committed
Remove the now-redundant field from Inherited
1 parent f26c91b commit a5f9af2

File tree

10 files changed

+29
-26
lines changed

10 files changed

+29
-26
lines changed

compiler/rustc_hir_typeck/src/autoderef.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,14 @@ use std::iter;
1212

1313
impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1414
pub fn autoderef(&'a self, span: Span, base_ty: Ty<'tcx>) -> Autoderef<'a, 'tcx> {
15-
Autoderef::new(self, self.param_env, self.body_id, span, base_ty, self.defining_use_anchor)
15+
Autoderef::new(
16+
self,
17+
self.param_env,
18+
self.body_id,
19+
span,
20+
base_ty,
21+
self.defining_use_anchor(),
22+
)
1623
}
1724

1825
pub fn try_overloaded_deref(

compiler/rustc_hir_typeck/src/check.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ pub(super) fn check_fn<'a, 'tcx>(
4646
fn_def_id,
4747
decl.output.span(),
4848
fcx.param_env,
49-
fcx.defining_use_anchor,
49+
fcx.defining_use_anchor(),
5050
));
5151

5252
fcx.ret_coercion = Some(RefCell::new(CoerceMany::new(ret_ty)));

compiler/rustc_hir_typeck/src/closure.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
565565
let cause = self.misc(hir_ty.span);
566566
let InferOk { value: (), obligations } = self
567567
.at(&cause, self.param_env)
568-
.define_opaque_types(self.defining_use_anchor)
568+
.define_opaque_types(self.defining_use_anchor())
569569
.eq(*expected_ty, supplied_ty)?;
570570
all_obligations.extend(obligations);
571571
}
@@ -578,7 +578,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
578578
let cause = &self.misc(decl.output.span());
579579
let InferOk { value: (), obligations } = self
580580
.at(cause, self.param_env)
581-
.define_opaque_types(self.defining_use_anchor)
581+
.define_opaque_types(self.defining_use_anchor())
582582
.eq(expected_sigs.liberated_sig.output(), supplied_output_ty)?;
583583
all_obligations.extend(obligations);
584584

@@ -735,7 +735,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
735735
body_def_id,
736736
self.tcx.def_span(expr_def_id),
737737
self.param_env,
738-
self.defining_use_anchor,
738+
self.defining_use_anchor(),
739739
);
740740
self.register_predicates(obligations);
741741

compiler/rustc_hir_typeck/src/coercion.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
145145
self.commit_if_ok(|_| {
146146
let at = self
147147
.at(&self.cause, self.fcx.param_env)
148-
.define_opaque_types(self.defining_use_anchor);
148+
.define_opaque_types(self.defining_use_anchor());
149149
if self.use_lub {
150150
at.lub(b, a)
151151
} else {
@@ -178,7 +178,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
178178
// due to `[type error]` and `_` not coercing together.
179179
let _ = self.commit_if_ok(|_| {
180180
self.at(&self.cause, self.param_env)
181-
.define_opaque_types(self.defining_use_anchor)
181+
.define_opaque_types(self.defining_use_anchor())
182182
.eq(a, b)
183183
});
184184
return success(vec![], self.fcx.tcx.ty_error(guar), vec![]);
@@ -585,8 +585,8 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
585585
}
586586
})?;
587587

588-
let mut selcx =
589-
traits::SelectionContext::new(self).with_defining_use_anchor(self.defining_use_anchor);
588+
let mut selcx = traits::SelectionContext::new(self)
589+
.with_defining_use_anchor(self.defining_use_anchor());
590590

591591
// Create an obligation for `Source: CoerceUnsized<Target>`.
592592
let cause = ObligationCause::new(
@@ -1492,7 +1492,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
14921492
assert!(expression_ty.is_unit(), "if let hack without unit type");
14931493
fcx.at(cause, fcx.param_env)
14941494
// needed for tests/ui/type-alias-impl-trait/issue-65679-inst-opaque-ty-from-val-twice.rs
1495-
.define_opaque_types(fcx.defining_use_anchor)
1495+
.define_opaque_types(fcx.defining_use_anchor())
14961496
.eq_exp(label_expression_as_expected, expression_ty, self.merged_ty())
14971497
.map(|infer_ok| {
14981498
fcx.register_infer_ok_obligations(infer_ok);

compiler/rustc_hir_typeck/src/demand.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
115115
) -> Option<DiagnosticBuilder<'tcx, ErrorGuaranteed>> {
116116
match self
117117
.at(cause, self.param_env)
118-
.define_opaque_types(self.defining_use_anchor)
118+
.define_opaque_types(self.defining_use_anchor())
119119
.sup(expected, actual)
120120
{
121121
Ok(InferOk { obligations, value: () }) => {
@@ -149,7 +149,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
149149
) -> Option<DiagnosticBuilder<'tcx, ErrorGuaranteed>> {
150150
match self
151151
.at(cause, self.param_env)
152-
.define_opaque_types(self.defining_use_anchor)
152+
.define_opaque_types(self.defining_use_anchor())
153153
.eq(expected, actual)
154154
{
155155
Ok(InferOk { obligations, value: () }) => {

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -738,15 +738,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
738738
if let ty::subst::GenericArgKind::Type(ty) = ty.unpack()
739739
&& let ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) = *ty.kind()
740740
&& let Some(def_id) = def_id.as_local()
741-
&& self.opaque_type_origin(def_id, self.defining_use_anchor).is_some() {
741+
&& self.opaque_type_origin(def_id, self.defining_use_anchor()).is_some() {
742742
return None;
743743
}
744744
}
745745
}
746746

747747
let expect_args = self
748748
.fudge_inference_if_ok(|| {
749-
let ocx = ObligationCtxt::new_in_snapshot(self, self.defining_use_anchor);
749+
let ocx = ObligationCtxt::new_in_snapshot(self, self.defining_use_anchor());
750750

751751
// Attempt to apply a subtyping relationship between the formal
752752
// return type (likely containing type variables if the function
@@ -1460,7 +1460,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14601460
self.param_env,
14611461
original_values,
14621462
query_result,
1463-
self.defining_use_anchor,
1463+
self.defining_use_anchor(),
14641464
)
14651465
}
14661466

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1903,7 +1903,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
19031903
self.param_env,
19041904
ty::Binder::dummy(trait_ref),
19051905
);
1906-
match SelectionContext::new(&self).with_defining_use_anchor(self.defining_use_anchor).select(&obligation) {
1906+
match SelectionContext::new(&self).with_defining_use_anchor(self.defining_use_anchor()).select(&obligation) {
19071907
Ok(Some(traits::ImplSource::UserDefined(impl_source))) => {
19081908
Some(impl_source.impl_def_id)
19091909
}

compiler/rustc_hir_typeck/src/inherited.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,6 @@ use std::ops::Deref;
2828
pub struct Inherited<'tcx> {
2929
pub(super) infcx: InferCtxt<'tcx>,
3030

31-
/// The `DefId` of the item in whose context we are performing inference or typeck.
32-
/// It is used to check whether an opaque type use is a defining use.
33-
///
34-
/// Its default value is `DefiningAnchor::Error`, this way it is easier to catch errors that
35-
/// might come up during inference or typeck.
36-
pub(super) defining_use_anchor: DefiningAnchor,
37-
3831
pub(super) typeck_results: RefCell<ty::TypeckResults<'tcx>>,
3932

4033
pub(super) locals: RefCell<HirIdMap<super::LocalTy<'tcx>>>,
@@ -124,7 +117,6 @@ impl<'tcx> Inherited<'tcx> {
124117

125118
let defining_use_anchor = DefiningAnchor::Bind(typeck_results.borrow().hir_owner.def_id);
126119
Inherited {
127-
defining_use_anchor,
128120
typeck_results,
129121
infcx,
130122
fulfillment_cx: RefCell::new(<dyn TraitEngine<'_>>::new(tcx, defining_use_anchor)),
@@ -141,6 +133,10 @@ impl<'tcx> Inherited<'tcx> {
141133
}
142134
}
143135

136+
pub fn defining_use_anchor(&self) -> DefiningAnchor {
137+
self.fulfillment_cx.borrow().defining_use_anchor()
138+
}
139+
144140
#[instrument(level = "debug", skip(self))]
145141
pub(super) fn register_predicate(&self, obligation: traits::PredicateObligation<'tcx>) {
146142
if obligation.has_escaping_bound_vars() {

compiler/rustc_hir_typeck/src/method/probe.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1429,7 +1429,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
14291429
let predicate = ty::Binder::dummy(trait_ref);
14301430
let obligation = traits::Obligation::new(self.tcx, cause, self.param_env, predicate);
14311431
traits::SelectionContext::new(self)
1432-
.with_defining_use_anchor(self.defining_use_anchor)
1432+
.with_defining_use_anchor(self.defining_use_anchor())
14331433
.select(&obligation)
14341434
}
14351435

compiler/rustc_hir_typeck/src/op.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
778778
Err(rustc_trait_selection::traits::fully_solve_obligation(
779779
self,
780780
obligation,
781-
self.defining_use_anchor,
781+
self.defining_use_anchor(),
782782
))
783783
}
784784
}

0 commit comments

Comments
 (0)