Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically taint InferCtxt when errors are emitted #126996

Merged
merged 8 commits into from
Jul 1, 2024
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
}

pub(crate) fn dcx(&self) -> DiagCtxtHandle<'tcx> {
pub(crate) fn dcx(&self) -> DiagCtxtHandle<'a> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'root_ctxt (or 'rcx) would be a better lifetime name than 'a for FnCtxt.

Copy link
Contributor Author

@oli-obk oli-obk Jun 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Preexisting and very 'root_ctxt is very verbose. I don't really think we should do it. 'rcx is not really better than 'a. We could use 'infcx, but it's used everywhere and does not spark joy. If someone wants to do that change, I won't stop them, but I don't want to do it, and definitely not in this PR.

self.infcx.dcx()
}

Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_typeck/src/pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1881,7 +1881,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
&self,
pat: &Pat<'_>,
fields: &'tcx [hir::PatField<'tcx>],
) -> Diag<'tcx> {
) -> Diag<'a> {
let mut err = self
.dcx()
.struct_span_err(pat.span, "pattern requires `..` due to inaccessible fields");
Expand Down Expand Up @@ -1973,7 +1973,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
unmentioned_fields: &[(&ty::FieldDef, Ident)],
have_inaccessible_fields: bool,
fields: &'tcx [hir::PatField<'tcx>],
) -> Diag<'tcx> {
) -> Diag<'a> {
let inaccessible = if have_inaccessible_fields { " and inaccessible fields" } else { "" };
let field_names = if let [(_, field)] = unmentioned_fields {
format!("field `{field}`{inaccessible}")
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_infer/src/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1607,7 +1607,7 @@ impl<'tcx> InferCtxt<'tcx> {
}
}

impl<'tcx> TypeErrCtxt<'_, 'tcx> {
impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
// [Note-Type-error-reporting]
// An invariant is that anytime the expected or actual type is Error (the special
// error type, meaning that an error occurred when typechecking this expression),
Expand All @@ -1623,9 +1623,9 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
sp: Span,
mk_diag: M,
actual_ty: Ty<'tcx>,
) -> Diag<'tcx>
) -> Diag<'a>
where
M: FnOnce(String) -> Diag<'tcx>,
M: FnOnce(String) -> Diag<'a>,
{
let actual_ty = self.resolve_vars_if_possible(actual_ty);
debug!("type_error_struct_with_diag({:?}, {:?})", sp, actual_ty);
Expand Down