Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit bc60d50

Browse files
compiler-errorsestebank
authored andcommitted
Provide associated type information in method chains
When encountering an unmet obligation that affects a method chain, like in iterator chains where one of the links has the wrong associated type, we point at every method call and mention their evaluated associated type at that point to give context to the user of where expectations diverged from the code as written. ``` note: the expression is of type `Map<std::slice::Iter<'_, {integer}>, [closure@$DIR/invalid-iterator-chain.rs:12:18: 12:21]>` --> $DIR/invalid-iterator-chain.rs:12:14 | LL | vec![0, 1] | ---------- this expression has type `Vec<{integer}>` LL | .iter() | ------ associated type `std::iter::Iterator::Item` is `&{integer}` here LL | .map(|x| { x; }) | ^^^^^^^^^^^^^^^ associated type `std::iter::Iterator::Item` is `()` here ```
1 parent d137783 commit bc60d50

File tree

6 files changed

+413
-34
lines changed

6 files changed

+413
-34
lines changed

compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
536536
|err| {
537537
self.note_obligation_cause_code(
538538
err,
539-
&predicate,
539+
predicate,
540540
obligation.param_env,
541541
obligation.cause.code(),
542542
&mut vec![],
@@ -1586,7 +1586,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
15861586
{
15871587
self.note_obligation_cause_code(
15881588
&mut diag,
1589-
&error.obligation.predicate,
1589+
error.obligation.predicate,
15901590
error.obligation.param_env,
15911591
code,
15921592
&mut vec![],
@@ -2601,7 +2601,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
26012601
if !self.maybe_note_obligation_cause_for_async_await(err, obligation) {
26022602
self.note_obligation_cause_code(
26032603
err,
2604-
&obligation.predicate,
2604+
obligation.predicate,
26052605
obligation.param_env,
26062606
obligation.cause.code(),
26072607
&mut vec![],

0 commit comments

Comments
 (0)