Skip to content

Do not freshen ReError #143159

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

Merged
merged 2 commits into from
Jun 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/method/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3055,7 +3055,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
pub(crate) fn note_unmet_impls_on_type(
&self,
err: &mut Diag<'_>,
errors: Vec<FulfillmentError<'tcx>>,
errors: &[FulfillmentError<'tcx>],
suggest_derive: bool,
) {
let preds: Vec<_> = errors
Expand Down
22 changes: 3 additions & 19 deletions compiler/rustc_hir_typeck/src/op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
lhs_expr.span,
format!("cannot use `{}` on type `{}`", s, lhs_ty_str),
);
self.note_unmet_impls_on_type(&mut err, errors, false);
self.note_unmet_impls_on_type(&mut err, &errors, false);
(err, None)
}
Op::BinOp(bin_op) => {
Expand Down Expand Up @@ -382,7 +382,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
err.span_label(rhs_expr.span, rhs_ty_str);
}
let suggest_derive = self.can_eq(self.param_env, lhs_ty, rhs_ty);
self.note_unmet_impls_on_type(&mut err, errors, suggest_derive);
self.note_unmet_impls_on_type(&mut err, &errors, suggest_derive);
(err, output_def_id)
}
};
Expand Down Expand Up @@ -582,22 +582,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// concatenation (e.g., "Hello " + "World!"). This means
// we don't want the note in the else clause to be emitted
} else if lhs_ty.has_non_region_param() {
// Look for a TraitPredicate in the Fulfillment errors,
// and use it to generate a suggestion.
//
// Note that lookup_op_method must be called again but
// with a specific rhs_ty instead of a placeholder so
// the resulting predicate generates a more specific
// suggestion for the user.
let errors = self
.lookup_op_method(
(lhs_expr, lhs_ty),
Some((rhs_expr, rhs_ty)),
lang_item_for_binop(self.tcx, op),
op.span(),
expected,
)
.unwrap_err();
if !errors.is_empty() {
for error in errors {
if let Some(trait_pred) =
Expand Down Expand Up @@ -946,7 +930,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
ty::Str | ty::Never | ty::Char | ty::Tuple(_) | ty::Array(_, _) => {}
ty::Ref(_, lty, _) if *lty.kind() == ty::Str => {}
_ => {
self.note_unmet_impls_on_type(&mut err, errors, true);
self.note_unmet_impls_on_type(&mut err, &errors, true);
}
}
}
Expand Down
9 changes: 4 additions & 5 deletions compiler/rustc_infer/src/infer/freshen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,16 @@ impl<'a, 'tcx> TypeFolder<TyCtxt<'tcx>> for TypeFreshener<'a, 'tcx> {

fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
match r.kind() {
ty::ReBound(..) => {
// leave bound regions alone
r
}
// Leave bound regions alone, since they affect selection via the leak check.
ty::ReBound(..) => r,
// Leave error regions alone, since they affect selection b/c of incompleteness.
ty::ReError(_) => r,

ty::ReEarlyParam(..)
| ty::ReLateParam(_)
| ty::ReVar(_)
| ty::RePlaceholder(..)
| ty::ReStatic
| ty::ReError(_)
| ty::ReErased => self.cx().lifetimes.re_erased,
}
}
Expand Down
13 changes: 0 additions & 13 deletions tests/crashes/132882.rs

This file was deleted.

23 changes: 23 additions & 0 deletions tests/ui/traits/eval-caching-error-region.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Regression test for #132882.

use std::ops::Add;

pub trait Numoid: Sized
where
&'missing Self: Add<Self>,
//~^ ERROR use of undeclared lifetime name `'missing`
{
}

// Proving `N: Numoid`'s well-formedness causes us to have to prove `&'missing N: Add<N>`.
// Since `'missing` is a region error, that will lead to us consider the predicate to hold,
// since it references errors. Since the freshener turns error regions into fresh regions,
// this means that subsequent lookups of `&'?0 N: Add<N>` will also hit this cache entry
// even if candidate assembly can't assemble anything for `&'?0 N: Add<?1>` anyways. This
// led to an ICE.
pub fn compute<N: Numoid>(a: N) {
let _ = &a + a;
//~^ ERROR cannot add `N` to `&N`
}

fn main() {}
33 changes: 33 additions & 0 deletions tests/ui/traits/eval-caching-error-region.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
error[E0261]: use of undeclared lifetime name `'missing`
--> $DIR/eval-caching-error-region.rs:7:6
|
LL | &'missing Self: Add<Self>,
| ^^^^^^^^ undeclared lifetime
|
= note: for more information on higher-ranked polymorphism, visit https://doc.rust-lang.org/nomicon/hrtb.html
help: consider making the bound lifetime-generic with a new `'missing` lifetime
|
LL | for<'missing> &'missing Self: Add<Self>,
| +++++++++++++
help: consider introducing lifetime `'missing` here
|
LL | pub trait Numoid<'missing>: Sized
| ++++++++++

error[E0369]: cannot add `N` to `&N`
--> $DIR/eval-caching-error-region.rs:19:16
|
LL | let _ = &a + a;
| -- ^ - N
| |
| &N
|
help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement
|
LL | pub fn compute<N: Numoid>(a: N) where &N: Add<N> {
| ++++++++++++++++

error: aborting due to 2 previous errors

Some errors have detailed explanations: E0261, E0369.
For more information about an error, try `rustc --explain E0261`.
Loading