Skip to content

Commit 3a35f36

Browse files
authored
Rollup merge of #143159 - compiler-errors:freshen-re-error, r=oli-obk
Do not freshen `ReError` Because `ReError` has `ErrorGuaranteed` in it, it affects candidate selection and thus causes incompleteness which leads to weirdness in eval. See the comment in the test. Also remove an unnecessary `lookup_op_method` since it doesn't effect tests. Fixes #132882. r? types
2 parents 0952f86 + 1347b48 commit 3a35f36

File tree

6 files changed

+64
-38
lines changed

6 files changed

+64
-38
lines changed

compiler/rustc_hir_typeck/src/method/suggest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3055,7 +3055,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
30553055
pub(crate) fn note_unmet_impls_on_type(
30563056
&self,
30573057
err: &mut Diag<'_>,
3058-
errors: Vec<FulfillmentError<'tcx>>,
3058+
errors: &[FulfillmentError<'tcx>],
30593059
suggest_derive: bool,
30603060
) {
30613061
let preds: Vec<_> = errors

compiler/rustc_hir_typeck/src/op.rs

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
322322
lhs_expr.span,
323323
format!("cannot use `{}` on type `{}`", s, lhs_ty_str),
324324
);
325-
self.note_unmet_impls_on_type(&mut err, errors, false);
325+
self.note_unmet_impls_on_type(&mut err, &errors, false);
326326
(err, None)
327327
}
328328
Op::BinOp(bin_op) => {
@@ -382,7 +382,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
382382
err.span_label(rhs_expr.span, rhs_ty_str);
383383
}
384384
let suggest_derive = self.can_eq(self.param_env, lhs_ty, rhs_ty);
385-
self.note_unmet_impls_on_type(&mut err, errors, suggest_derive);
385+
self.note_unmet_impls_on_type(&mut err, &errors, suggest_derive);
386386
(err, output_def_id)
387387
}
388388
};
@@ -582,22 +582,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
582582
// concatenation (e.g., "Hello " + "World!"). This means
583583
// we don't want the note in the else clause to be emitted
584584
} else if lhs_ty.has_non_region_param() {
585-
// Look for a TraitPredicate in the Fulfillment errors,
586-
// and use it to generate a suggestion.
587-
//
588-
// Note that lookup_op_method must be called again but
589-
// with a specific rhs_ty instead of a placeholder so
590-
// the resulting predicate generates a more specific
591-
// suggestion for the user.
592-
let errors = self
593-
.lookup_op_method(
594-
(lhs_expr, lhs_ty),
595-
Some((rhs_expr, rhs_ty)),
596-
lang_item_for_binop(self.tcx, op),
597-
op.span(),
598-
expected,
599-
)
600-
.unwrap_err();
601585
if !errors.is_empty() {
602586
for error in errors {
603587
if let Some(trait_pred) =
@@ -946,7 +930,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
946930
ty::Str | ty::Never | ty::Char | ty::Tuple(_) | ty::Array(_, _) => {}
947931
ty::Ref(_, lty, _) if *lty.kind() == ty::Str => {}
948932
_ => {
949-
self.note_unmet_impls_on_type(&mut err, errors, true);
933+
self.note_unmet_impls_on_type(&mut err, &errors, true);
950934
}
951935
}
952936
}

compiler/rustc_infer/src/infer/freshen.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,17 +110,16 @@ impl<'a, 'tcx> TypeFolder<TyCtxt<'tcx>> for TypeFreshener<'a, 'tcx> {
110110

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

118118
ty::ReEarlyParam(..)
119119
| ty::ReLateParam(_)
120120
| ty::ReVar(_)
121121
| ty::RePlaceholder(..)
122122
| ty::ReStatic
123-
| ty::ReError(_)
124123
| ty::ReErased => self.cx().lifetimes.re_erased,
125124
}
126125
}

tests/crashes/132882.rs

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Regression test for #132882.
2+
3+
use std::ops::Add;
4+
5+
pub trait Numoid: Sized
6+
where
7+
&'missing Self: Add<Self>,
8+
//~^ ERROR use of undeclared lifetime name `'missing`
9+
{
10+
}
11+
12+
// Proving `N: Numoid`'s well-formedness causes us to have to prove `&'missing N: Add<N>`.
13+
// Since `'missing` is a region error, that will lead to us consider the predicate to hold,
14+
// since it references errors. Since the freshener turns error regions into fresh regions,
15+
// this means that subsequent lookups of `&'?0 N: Add<N>` will also hit this cache entry
16+
// even if candidate assembly can't assemble anything for `&'?0 N: Add<?1>` anyways. This
17+
// led to an ICE.
18+
pub fn compute<N: Numoid>(a: N) {
19+
let _ = &a + a;
20+
//~^ ERROR cannot add `N` to `&N`
21+
}
22+
23+
fn main() {}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
error[E0261]: use of undeclared lifetime name `'missing`
2+
--> $DIR/eval-caching-error-region.rs:7:6
3+
|
4+
LL | &'missing Self: Add<Self>,
5+
| ^^^^^^^^ undeclared lifetime
6+
|
7+
= note: for more information on higher-ranked polymorphism, visit https://doc.rust-lang.org/nomicon/hrtb.html
8+
help: consider making the bound lifetime-generic with a new `'missing` lifetime
9+
|
10+
LL | for<'missing> &'missing Self: Add<Self>,
11+
| +++++++++++++
12+
help: consider introducing lifetime `'missing` here
13+
|
14+
LL | pub trait Numoid<'missing>: Sized
15+
| ++++++++++
16+
17+
error[E0369]: cannot add `N` to `&N`
18+
--> $DIR/eval-caching-error-region.rs:19:16
19+
|
20+
LL | let _ = &a + a;
21+
| -- ^ - N
22+
| |
23+
| &N
24+
|
25+
help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement
26+
|
27+
LL | pub fn compute<N: Numoid>(a: N) where &N: Add<N> {
28+
| ++++++++++++++++
29+
30+
error: aborting due to 2 previous errors
31+
32+
Some errors have detailed explanations: E0261, E0369.
33+
For more information about an error, try `rustc --explain E0261`.

0 commit comments

Comments
 (0)