Skip to content

Commit aff0ab4

Browse files
committed
Add label to method chains where assoc type remains the same
1 parent c77ad2d commit aff0ab4

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3027,6 +3027,11 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
30273027
span,
30283028
format!("`{assoc}` changed to `{ty}` here"),
30293029
));
3030+
} else {
3031+
span_labels.push((
3032+
span,
3033+
format!("`{assoc}` remains `{ty}` here"),
3034+
));
30303035
}
30313036
}
30323037
(Some((span, (assoc, ty))), None) => {

src/test/ui/iterators/invalid-iterator-chain.stderr

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ LL | .map(|x| x as f64)
5858
LL | .map(|x| x as i64)
5959
| ^^^^^^^^^^^^^^^^^ `std::iter::Iterator::Item` changed to `i64` here
6060
LL | .filter(|x| *x > 0)
61-
| ------------------
61+
| ------------------ `std::iter::Iterator::Item` remains `i64` here
6262
LL | .map(|x| { x + 1 })
63-
| ------------------
63+
| ------------------ `std::iter::Iterator::Item` remains `i64` here
6464
LL | .map(|x| { x; })
6565
| ^^^^^^^^^^^^^^^ `std::iter::Iterator::Item` changed to `()` here
6666
note: required by a bound in `std::iter::Iterator::sum`
@@ -136,16 +136,16 @@ LL | let a = vec![0];
136136
LL | let b = a.into_iter();
137137
| ^^^^^^^^^^^ `std::iter::Iterator::Item` is `{integer}` here
138138
LL | let c = b.map(|x| x + 1);
139-
| --------------
139+
| -------------- `std::iter::Iterator::Item` remains `{integer}` here
140140
LL | let d = c.filter(|x| *x > 10 );
141-
| --------------------
141+
| -------------------- `std::iter::Iterator::Item` remains `{integer}` here
142142
LL | let e = d.map(|x| {
143143
| _______________^
144144
LL | | x + 1;
145145
LL | | });
146146
| |______^ `std::iter::Iterator::Item` changed to `()` here
147147
LL | let f = e.filter(|_| false);
148-
| -----------------
148+
| ----------------- `std::iter::Iterator::Item` remains `()` here
149149
note: required by a bound in `collect`
150150
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
151151
|

0 commit comments

Comments
 (0)