Skip to content

Commit 671339c

Browse files
authored
Rollup merge of rust-lang#108960 - compiler-errors:no-body-def-id, r=cjgillot
Remove `body_def_id` from `Inherited` We can just use the body id from the obligation cause. Follow-up to rust-lang#108945, only my commit is relevant. r? `@cjgillot` cc `@spastorino`
2 parents 65db3cb + fd34549 commit 671339c

File tree

14 files changed

+55
-84
lines changed

14 files changed

+55
-84
lines changed

compiler/rustc_borrowck/src/region_infer/opaque_types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
325325
if errors.is_empty() {
326326
definition_ty
327327
} else {
328-
let reported = infcx.err_ctxt().report_fulfillment_errors(&errors, None);
328+
let reported = infcx.err_ctxt().report_fulfillment_errors(&errors);
329329
self.tcx.ty_error(reported)
330330
}
331331
}

compiler/rustc_const_eval/src/transform/check_consts/check.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
769769

770770
let errors = ocx.select_all_or_error();
771771
if !errors.is_empty() {
772-
infcx.err_ctxt().report_fulfillment_errors(&errors, None);
772+
infcx.err_ctxt().report_fulfillment_errors(&errors);
773773
}
774774
}
775775

compiler/rustc_hir_analysis/src/check/check.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ fn check_opaque_meets_bounds<'tcx>(
444444
// version.
445445
let errors = ocx.select_all_or_error();
446446
if !errors.is_empty() {
447-
infcx.err_ctxt().report_fulfillment_errors(&errors, None);
447+
infcx.err_ctxt().report_fulfillment_errors(&errors);
448448
}
449449
match origin {
450450
// Checked when type checking the function containing them.
@@ -1545,6 +1545,6 @@ pub(super) fn check_generator_obligations(tcx: TyCtxt<'_>, def_id: LocalDefId) {
15451545
let errors = fulfillment_cx.select_all_or_error(&infcx);
15461546
debug!(?errors);
15471547
if !errors.is_empty() {
1548-
infcx.err_ctxt().report_fulfillment_errors(&errors, None);
1548+
infcx.err_ctxt().report_fulfillment_errors(&errors);
15491549
}
15501550
}

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ fn compare_method_predicate_entailment<'tcx>(
320320
});
321321
}
322322
CheckImpliedWfMode::Skip => {
323-
let reported = infcx.err_ctxt().report_fulfillment_errors(&errors, None);
323+
let reported = infcx.err_ctxt().report_fulfillment_errors(&errors);
324324
return Err(reported);
325325
}
326326
}
@@ -720,7 +720,7 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
720720
// RPITs.
721721
let errors = ocx.select_all_or_error();
722722
if !errors.is_empty() {
723-
let reported = infcx.err_ctxt().report_fulfillment_errors(&errors, None);
723+
let reported = infcx.err_ctxt().report_fulfillment_errors(&errors);
724724
return Err(reported);
725725
}
726726

@@ -1731,7 +1731,7 @@ pub(super) fn compare_impl_const_raw(
17311731
// version.
17321732
let errors = ocx.select_all_or_error();
17331733
if !errors.is_empty() {
1734-
return Err(infcx.err_ctxt().report_fulfillment_errors(&errors, None));
1734+
return Err(infcx.err_ctxt().report_fulfillment_errors(&errors));
17351735
}
17361736

17371737
let outlives_environment = OutlivesEnvironment::new(param_env);
@@ -1831,7 +1831,7 @@ fn compare_type_predicate_entailment<'tcx>(
18311831
// version.
18321832
let errors = ocx.select_all_or_error();
18331833
if !errors.is_empty() {
1834-
let reported = infcx.err_ctxt().report_fulfillment_errors(&errors, None);
1834+
let reported = infcx.err_ctxt().report_fulfillment_errors(&errors);
18351835
return Err(reported);
18361836
}
18371837

@@ -2044,7 +2044,7 @@ pub(super) fn check_type_bounds<'tcx>(
20442044
// version.
20452045
let errors = ocx.select_all_or_error();
20462046
if !errors.is_empty() {
2047-
let reported = infcx.err_ctxt().report_fulfillment_errors(&errors, None);
2047+
let reported = infcx.err_ctxt().report_fulfillment_errors(&errors);
20482048
return Err(reported);
20492049
}
20502050

compiler/rustc_hir_analysis/src/check/wfcheck.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ pub(super) fn enter_wf_checking_ctxt<'tcx, F>(
111111

112112
let errors = wfcx.select_all_or_error();
113113
if !errors.is_empty() {
114-
infcx.err_ctxt().report_fulfillment_errors(&errors, None);
114+
infcx.err_ctxt().report_fulfillment_errors(&errors);
115115
return;
116116
}
117117

compiler/rustc_hir_analysis/src/coherence/builtin.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ fn visit_implementation_of_dispatch_from_dyn(tcx: TyCtxt<'_>, impl_did: LocalDef
345345
}),
346346
);
347347
if !errors.is_empty() {
348-
infcx.err_ctxt().report_fulfillment_errors(&errors, None);
348+
infcx.err_ctxt().report_fulfillment_errors(&errors);
349349
}
350350

351351
// Finally, resolve all regions.
@@ -585,7 +585,7 @@ pub fn coerce_unsized_info<'tcx>(tcx: TyCtxt<'tcx>, impl_did: DefId) -> CoerceUn
585585
predicate_for_trait_def(tcx, param_env, cause, trait_def_id, 0, [source, target]);
586586
let errors = traits::fully_solve_obligation(&infcx, predicate);
587587
if !errors.is_empty() {
588-
infcx.err_ctxt().report_fulfillment_errors(&errors, None);
588+
infcx.err_ctxt().report_fulfillment_errors(&errors);
589589
}
590590

591591
// Finally, resolve all regions.

compiler/rustc_hir_analysis/src/impl_wf_check/min_specialization.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ fn get_impl_substs(
174174

175175
let errors = ocx.select_all_or_error();
176176
if !errors.is_empty() {
177-
ocx.infcx.err_ctxt().report_fulfillment_errors(&errors, None);
177+
ocx.infcx.err_ctxt().report_fulfillment_errors(&errors);
178178
return None;
179179
}
180180

compiler/rustc_hir_analysis/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ fn require_same_types<'tcx>(
176176
match &errors[..] {
177177
[] => true,
178178
errors => {
179-
infcx.err_ctxt().report_fulfillment_errors(errors, None);
179+
infcx.err_ctxt().report_fulfillment_errors(errors);
180180
false
181181
}
182182
}
@@ -309,7 +309,7 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) {
309309
ocx.register_bound(cause, param_env, norm_return_ty, term_did);
310310
let errors = ocx.select_all_or_error();
311311
if !errors.is_empty() {
312-
infcx.err_ctxt().report_fulfillment_errors(&errors, None);
312+
infcx.err_ctxt().report_fulfillment_errors(&errors);
313313
error = true;
314314
}
315315
// now we can take the return type of the given main function

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
581581

582582
if !errors.is_empty() {
583583
self.adjust_fulfillment_errors_for_expr_obligation(&mut errors);
584-
self.err_ctxt().report_fulfillment_errors(&errors, Some(self.inh.body_def_id));
584+
self.err_ctxt().report_fulfillment_errors(&errors);
585585
}
586586
}
587587

@@ -594,7 +594,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
594594
if !result.is_empty() {
595595
mutate_fulfillment_errors(&mut result);
596596
self.adjust_fulfillment_errors_for_expr_obligation(&mut result);
597-
self.err_ctxt().report_fulfillment_errors(&result, Some(self.inh.body_def_id));
597+
self.err_ctxt().report_fulfillment_errors(&result);
598598
}
599599
}
600600

@@ -1411,13 +1411,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14111411
} else {
14121412
let e = self.tainted_by_errors().unwrap_or_else(|| {
14131413
self.err_ctxt()
1414-
.emit_inference_failure_err(
1415-
Some(self.inh.body_def_id),
1416-
sp,
1417-
ty.into(),
1418-
E0282,
1419-
true,
1420-
)
1414+
.emit_inference_failure_err(self.body_id, sp, ty.into(), E0282, true)
14211415
.emit()
14221416
});
14231417
let err = self.tcx.ty_error(e);

compiler/rustc_hir_typeck/src/inherited.rs

+2-12
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ pub struct Inherited<'tcx> {
5858
pub(super) deferred_generator_interiors:
5959
RefCell<Vec<(LocalDefId, hir::BodyId, Ty<'tcx>, hir::GeneratorKind)>>,
6060

61-
pub(super) body_def_id: LocalDefId,
62-
6361
/// Whenever we introduce an adjustment from `!` into a type variable,
6462
/// we record that type variable here. This is later used to inform
6563
/// fallback. See the `fallback` module for details.
@@ -80,7 +78,6 @@ impl<'tcx> Deref for Inherited<'tcx> {
8078
/// without using `Rc` or something similar.
8179
pub struct InheritedBuilder<'tcx> {
8280
infcx: infer::InferCtxtBuilder<'tcx>,
83-
def_id: LocalDefId,
8481
typeck_results: RefCell<ty::TypeckResults<'tcx>>,
8582
}
8683

@@ -93,7 +90,6 @@ impl<'tcx> Inherited<'tcx> {
9390
.infer_ctxt()
9491
.ignoring_regions()
9592
.with_opaque_type_inference(DefiningAnchor::Bind(hir_owner.def_id)),
96-
def_id,
9793
typeck_results: RefCell::new(ty::TypeckResults::new(hir_owner)),
9894
}
9995
}
@@ -104,17 +100,12 @@ impl<'tcx> InheritedBuilder<'tcx> {
104100
where
105101
F: FnOnce(&Inherited<'tcx>) -> R,
106102
{
107-
let def_id = self.def_id;
108-
f(&Inherited::new(self.infcx.build(), def_id, self.typeck_results))
103+
f(&Inherited::new(self.infcx.build(), self.typeck_results))
109104
}
110105
}
111106

112107
impl<'tcx> Inherited<'tcx> {
113-
fn new(
114-
infcx: InferCtxt<'tcx>,
115-
def_id: LocalDefId,
116-
typeck_results: RefCell<ty::TypeckResults<'tcx>>,
117-
) -> Self {
108+
fn new(infcx: InferCtxt<'tcx>, typeck_results: RefCell<ty::TypeckResults<'tcx>>) -> Self {
118109
let tcx = infcx.tcx;
119110

120111
Inherited {
@@ -129,7 +120,6 @@ impl<'tcx> Inherited<'tcx> {
129120
deferred_asm_checks: RefCell::new(Vec::new()),
130121
deferred_generator_interiors: RefCell::new(Vec::new()),
131122
diverging_type_vars: RefCell::new(Default::default()),
132-
body_def_id: def_id,
133123
infer_var_info: RefCell::new(Default::default()),
134124
}
135125
}

compiler/rustc_hir_typeck/src/writeback.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@ impl<'cx, 'tcx> Resolver<'cx, 'tcx> {
748748
.infcx
749749
.err_ctxt()
750750
.emit_inference_failure_err(
751-
Some(self.tcx.hir().body_owner_def_id(self.body.id())),
751+
self.tcx.hir().body_owner_def_id(self.body.id()),
752752
self.span.to_span(self.tcx),
753753
p.into(),
754754
E0282,

compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
386386
#[instrument(level = "debug", skip(self, error_code))]
387387
pub fn emit_inference_failure_err(
388388
&self,
389-
body_def_id: Option<LocalDefId>,
389+
body_def_id: LocalDefId,
390390
failure_span: Span,
391391
arg: GenericArg<'tcx>,
392392
error_code: TypeAnnotationNeeded,
@@ -403,9 +403,9 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
403403
};
404404

405405
let mut local_visitor = FindInferSourceVisitor::new(&self, typeck_results, arg);
406-
if let Some(body_def_id) = body_def_id
407-
&& let Some(body_id) = self.tcx.hir().maybe_body_owned_by(body_def_id)
408-
{
406+
if let Some(body_id) = self.tcx.hir().maybe_body_owned_by(
407+
self.tcx.typeck_root_def_id(body_def_id.to_def_id()).expect_local(),
408+
) {
409409
let expr = self.tcx.hir().body(body_id).value;
410410
local_visitor.visit_expr(expr);
411411
}

0 commit comments

Comments
 (0)