Remove body_def_id from Inherited

This commit is contained in:
Michael Goulet 2023-03-09 23:23:43 +00:00
parent 5b99723439
commit fd34549686
14 changed files with 55 additions and 84 deletions

View File

@ -325,7 +325,7 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
if errors.is_empty() {
definition_ty
} else {
let reported = infcx.err_ctxt().report_fulfillment_errors(&errors, None);
let reported = infcx.err_ctxt().report_fulfillment_errors(&errors);
self.tcx.ty_error(reported)
}
}

View File

@ -769,7 +769,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
let errors = ocx.select_all_or_error();
if !errors.is_empty() {
infcx.err_ctxt().report_fulfillment_errors(&errors, None);
infcx.err_ctxt().report_fulfillment_errors(&errors);
}
}

View File

@ -444,7 +444,7 @@ fn check_opaque_meets_bounds<'tcx>(
// version.
let errors = ocx.select_all_or_error();
if !errors.is_empty() {
infcx.err_ctxt().report_fulfillment_errors(&errors, None);
infcx.err_ctxt().report_fulfillment_errors(&errors);
}
match origin {
// Checked when type checking the function containing them.
@ -1545,6 +1545,6 @@ pub(super) fn check_generator_obligations(tcx: TyCtxt<'_>, def_id: LocalDefId) {
let errors = fulfillment_cx.select_all_or_error(&infcx);
debug!(?errors);
if !errors.is_empty() {
infcx.err_ctxt().report_fulfillment_errors(&errors, None);
infcx.err_ctxt().report_fulfillment_errors(&errors);
}
}

View File

@ -320,7 +320,7 @@ fn compare_method_predicate_entailment<'tcx>(
});
}
CheckImpliedWfMode::Skip => {
let reported = infcx.err_ctxt().report_fulfillment_errors(&errors, None);
let reported = infcx.err_ctxt().report_fulfillment_errors(&errors);
return Err(reported);
}
}
@ -720,7 +720,7 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
// RPITs.
let errors = ocx.select_all_or_error();
if !errors.is_empty() {
let reported = infcx.err_ctxt().report_fulfillment_errors(&errors, None);
let reported = infcx.err_ctxt().report_fulfillment_errors(&errors);
return Err(reported);
}
@ -1731,7 +1731,7 @@ pub(super) fn compare_impl_const_raw(
// version.
let errors = ocx.select_all_or_error();
if !errors.is_empty() {
return Err(infcx.err_ctxt().report_fulfillment_errors(&errors, None));
return Err(infcx.err_ctxt().report_fulfillment_errors(&errors));
}
let outlives_environment = OutlivesEnvironment::new(param_env);
@ -1831,7 +1831,7 @@ fn compare_type_predicate_entailment<'tcx>(
// version.
let errors = ocx.select_all_or_error();
if !errors.is_empty() {
let reported = infcx.err_ctxt().report_fulfillment_errors(&errors, None);
let reported = infcx.err_ctxt().report_fulfillment_errors(&errors);
return Err(reported);
}
@ -2044,7 +2044,7 @@ pub(super) fn check_type_bounds<'tcx>(
// version.
let errors = ocx.select_all_or_error();
if !errors.is_empty() {
let reported = infcx.err_ctxt().report_fulfillment_errors(&errors, None);
let reported = infcx.err_ctxt().report_fulfillment_errors(&errors);
return Err(reported);
}

View File

@ -111,7 +111,7 @@ pub(super) fn enter_wf_checking_ctxt<'tcx, F>(
let errors = wfcx.select_all_or_error();
if !errors.is_empty() {
infcx.err_ctxt().report_fulfillment_errors(&errors, None);
infcx.err_ctxt().report_fulfillment_errors(&errors);
return;
}

View File

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

View File

@ -174,7 +174,7 @@ fn get_impl_substs(
let errors = ocx.select_all_or_error();
if !errors.is_empty() {
ocx.infcx.err_ctxt().report_fulfillment_errors(&errors, None);
ocx.infcx.err_ctxt().report_fulfillment_errors(&errors);
return None;
}

View File

@ -176,7 +176,7 @@ fn require_same_types<'tcx>(
match &errors[..] {
[] => true,
errors => {
infcx.err_ctxt().report_fulfillment_errors(errors, None);
infcx.err_ctxt().report_fulfillment_errors(errors);
false
}
}
@ -309,7 +309,7 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) {
ocx.register_bound(cause, param_env, norm_return_ty, term_did);
let errors = ocx.select_all_or_error();
if !errors.is_empty() {
infcx.err_ctxt().report_fulfillment_errors(&errors, None);
infcx.err_ctxt().report_fulfillment_errors(&errors);
error = true;
}
// now we can take the return type of the given main function

View File

@ -581,7 +581,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if !errors.is_empty() {
self.adjust_fulfillment_errors_for_expr_obligation(&mut errors);
self.err_ctxt().report_fulfillment_errors(&errors, Some(self.inh.body_def_id));
self.err_ctxt().report_fulfillment_errors(&errors);
}
}
@ -594,7 +594,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if !result.is_empty() {
mutate_fulfillment_errors(&mut result);
self.adjust_fulfillment_errors_for_expr_obligation(&mut result);
self.err_ctxt().report_fulfillment_errors(&result, Some(self.inh.body_def_id));
self.err_ctxt().report_fulfillment_errors(&result);
}
}
@ -1411,13 +1411,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} else {
let e = self.tainted_by_errors().unwrap_or_else(|| {
self.err_ctxt()
.emit_inference_failure_err(
Some(self.inh.body_def_id),
sp,
ty.into(),
E0282,
true,
)
.emit_inference_failure_err(self.body_id, sp, ty.into(), E0282, true)
.emit()
});
let err = self.tcx.ty_error(e);

View File

@ -58,8 +58,6 @@ pub struct Inherited<'tcx> {
pub(super) deferred_generator_interiors:
RefCell<Vec<(LocalDefId, hir::BodyId, Ty<'tcx>, hir::GeneratorKind)>>,
pub(super) body_def_id: LocalDefId,
/// Whenever we introduce an adjustment from `!` into a type variable,
/// we record that type variable here. This is later used to inform
/// fallback. See the `fallback` module for details.
@ -80,7 +78,6 @@ impl<'tcx> Deref for Inherited<'tcx> {
/// without using `Rc` or something similar.
pub struct InheritedBuilder<'tcx> {
infcx: infer::InferCtxtBuilder<'tcx>,
def_id: LocalDefId,
typeck_results: RefCell<ty::TypeckResults<'tcx>>,
}
@ -93,7 +90,6 @@ impl<'tcx> Inherited<'tcx> {
.infer_ctxt()
.ignoring_regions()
.with_opaque_type_inference(DefiningAnchor::Bind(hir_owner.def_id)),
def_id,
typeck_results: RefCell::new(ty::TypeckResults::new(hir_owner)),
}
}
@ -104,17 +100,12 @@ impl<'tcx> InheritedBuilder<'tcx> {
where
F: FnOnce(&Inherited<'tcx>) -> R,
{
let def_id = self.def_id;
f(&Inherited::new(self.infcx.build(), def_id, self.typeck_results))
f(&Inherited::new(self.infcx.build(), self.typeck_results))
}
}
impl<'tcx> Inherited<'tcx> {
fn new(
infcx: InferCtxt<'tcx>,
def_id: LocalDefId,
typeck_results: RefCell<ty::TypeckResults<'tcx>>,
) -> Self {
fn new(infcx: InferCtxt<'tcx>, typeck_results: RefCell<ty::TypeckResults<'tcx>>) -> Self {
let tcx = infcx.tcx;
Inherited {
@ -129,7 +120,6 @@ impl<'tcx> Inherited<'tcx> {
deferred_asm_checks: RefCell::new(Vec::new()),
deferred_generator_interiors: RefCell::new(Vec::new()),
diverging_type_vars: RefCell::new(Default::default()),
body_def_id: def_id,
infer_var_info: RefCell::new(Default::default()),
}
}

View File

@ -748,7 +748,7 @@ impl<'cx, 'tcx> Resolver<'cx, 'tcx> {
.infcx
.err_ctxt()
.emit_inference_failure_err(
Some(self.tcx.hir().body_owner_def_id(self.body.id())),
self.tcx.hir().body_owner_def_id(self.body.id()),
self.span.to_span(self.tcx),
p.into(),
E0282,

View File

@ -386,7 +386,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
#[instrument(level = "debug", skip(self, error_code))]
pub fn emit_inference_failure_err(
&self,
body_def_id: Option<LocalDefId>,
body_def_id: LocalDefId,
failure_span: Span,
arg: GenericArg<'tcx>,
error_code: TypeAnnotationNeeded,
@ -403,9 +403,9 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
};
let mut local_visitor = FindInferSourceVisitor::new(&self, typeck_results, arg);
if let Some(body_def_id) = body_def_id
&& let Some(body_id) = self.tcx.hir().maybe_body_owned_by(body_def_id)
{
if let Some(body_id) = self.tcx.hir().maybe_body_owned_by(
self.tcx.typeck_root_def_id(body_def_id.to_def_id()).expect_local(),
) {
let expr = self.tcx.hir().body(body_id).value;
local_visitor.visit_expr(expr);
}

View File

@ -124,11 +124,7 @@ pub trait TypeErrCtxtExt<'tcx> {
+ Print<'tcx, FmtPrinter<'tcx, 'tcx>, Output = FmtPrinter<'tcx, 'tcx>>,
<T as Print<'tcx, FmtPrinter<'tcx, 'tcx>>>::Error: std::fmt::Debug;
fn report_fulfillment_errors(
&self,
errors: &[FulfillmentError<'tcx>],
body_def_id: Option<LocalDefId>,
) -> ErrorGuaranteed;
fn report_fulfillment_errors(&self, errors: &[FulfillmentError<'tcx>]) -> ErrorGuaranteed;
fn report_overflow_obligation<T>(
&self,
@ -386,11 +382,7 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
}
impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
fn report_fulfillment_errors(
&self,
errors: &[FulfillmentError<'tcx>],
body_def_id: Option<LocalDefId>,
) -> ErrorGuaranteed {
fn report_fulfillment_errors(&self, errors: &[FulfillmentError<'tcx>]) -> ErrorGuaranteed {
#[derive(Debug)]
struct ErrorDescriptor<'tcx> {
predicate: ty::Predicate<'tcx>,
@ -467,7 +459,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
for from_expansion in [false, true] {
for (error, suppressed) in iter::zip(errors, &is_suppressed) {
if !suppressed && error.obligation.cause.span.from_expansion() == from_expansion {
self.report_fulfillment_error(error, body_def_id);
self.report_fulfillment_error(error);
}
}
}
@ -1491,11 +1483,7 @@ trait InferCtxtPrivExt<'tcx> {
// `error` occurring implies that `cond` occurs.
fn error_implies(&self, cond: ty::Predicate<'tcx>, error: ty::Predicate<'tcx>) -> bool;
fn report_fulfillment_error(
&self,
error: &FulfillmentError<'tcx>,
body_def_id: Option<LocalDefId>,
);
fn report_fulfillment_error(&self, error: &FulfillmentError<'tcx>);
fn report_projection_error(
&self,
@ -1558,11 +1546,7 @@ trait InferCtxtPrivExt<'tcx> {
trait_ref_and_ty: ty::Binder<'tcx, (ty::TraitPredicate<'tcx>, Ty<'tcx>)>,
) -> PredicateObligation<'tcx>;
fn maybe_report_ambiguity(
&self,
obligation: &PredicateObligation<'tcx>,
body_def_id: Option<LocalDefId>,
);
fn maybe_report_ambiguity(&self, obligation: &PredicateObligation<'tcx>);
fn predicate_can_apply(
&self,
@ -1644,11 +1628,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
}
#[instrument(skip(self), level = "debug")]
fn report_fulfillment_error(
&self,
error: &FulfillmentError<'tcx>,
body_def_id: Option<LocalDefId>,
) {
fn report_fulfillment_error(&self, error: &FulfillmentError<'tcx>) {
match error.code {
FulfillmentErrorCode::CodeSelectionError(ref selection_error) => {
self.report_selection_error(
@ -1661,7 +1641,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
self.report_projection_error(&error.obligation, e);
}
FulfillmentErrorCode::CodeAmbiguity => {
self.maybe_report_ambiguity(&error.obligation, body_def_id);
self.maybe_report_ambiguity(&error.obligation);
}
FulfillmentErrorCode::CodeSubtypeError(ref expected_found, ref err) => {
self.report_mismatched_types(
@ -2226,11 +2206,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
}
#[instrument(skip(self), level = "debug")]
fn maybe_report_ambiguity(
&self,
obligation: &PredicateObligation<'tcx>,
body_def_id: Option<LocalDefId>,
) {
fn maybe_report_ambiguity(&self, obligation: &PredicateObligation<'tcx>) {
// Unable to successfully determine, probably means
// insufficient type information, but could mean
// ambiguous impls. The latter *ought* to be a
@ -2272,7 +2248,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
if self.tcx.lang_items().sized_trait() == Some(trait_ref.def_id()) {
if let None = self.tainted_by_errors() {
self.emit_inference_failure_err(
body_def_id,
obligation.cause.body_id,
span,
trait_ref.self_ty().skip_binder().into(),
ErrorCode::E0282,
@ -2300,7 +2276,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
let mut err = if let Some(subst) = subst {
self.emit_inference_failure_err(
body_def_id,
obligation.cause.body_id,
span,
subst,
ErrorCode::E0283,
@ -2352,7 +2328,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
self.report_similar_impl_candidates(
impl_candidates,
trait_ref,
body_def_id.unwrap_or(obligation.cause.body_id),
obligation.cause.body_id,
&mut err,
false,
);
@ -2374,10 +2350,9 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
self.suggest_fully_qualified_path(&mut err, def_id, span, trait_ref.def_id());
}
if let (Some(body_def_id), Some(ty::subst::GenericArgKind::Type(_))) =
(body_def_id, subst.map(|subst| subst.unpack()))
if let Some(ty::subst::GenericArgKind::Type(_)) = subst.map(|subst| subst.unpack())
{
let body_id = self.tcx.hir().body_owned_by(body_def_id);
let body_id = self.tcx.hir().body_owned_by(obligation.cause.body_id);
let mut expr_finder = FindExprBySpan::new(span);
expr_finder.visit_expr(&self.tcx.hir().body(body_id).value);
@ -2473,7 +2448,13 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
return;
}
self.emit_inference_failure_err(body_def_id, span, arg, ErrorCode::E0282, false)
self.emit_inference_failure_err(
obligation.cause.body_id,
span,
arg,
ErrorCode::E0282,
false,
)
}
ty::PredicateKind::Subtype(data) => {
@ -2487,7 +2468,13 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
let SubtypePredicate { a_is_expected: _, a, b } = data;
// both must be type variables, or the other would've been instantiated
assert!(a.is_ty_var() && b.is_ty_var());
self.emit_inference_failure_err(body_def_id, span, a.into(), ErrorCode::E0282, true)
self.emit_inference_failure_err(
obligation.cause.body_id,
span,
a.into(),
ErrorCode::E0282,
true,
)
}
ty::PredicateKind::Clause(ty::Clause::Projection(data)) => {
if predicate.references_error() || self.tainted_by_errors().is_some() {
@ -2501,7 +2488,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
.find(|g| g.has_non_region_infer());
if let Some(subst) = subst {
let mut err = self.emit_inference_failure_err(
body_def_id,
obligation.cause.body_id,
span,
subst,
ErrorCode::E0284,
@ -2530,7 +2517,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
let subst = data.walk().find(|g| g.is_non_region_infer());
if let Some(subst) = subst {
let err = self.emit_inference_failure_err(
body_def_id,
obligation.cause.body_id,
span,
subst,
ErrorCode::E0284,

View File

@ -210,7 +210,7 @@ fn do_normalize_predicates<'tcx>(
let predicates = match fully_normalize(&infcx, cause, elaborated_env, predicates) {
Ok(predicates) => predicates,
Err(errors) => {
let reported = infcx.err_ctxt().report_fulfillment_errors(&errors, None);
let reported = infcx.err_ctxt().report_fulfillment_errors(&errors);
return Err(reported);
}
};