Skip to content

Commit 2a0d712

Browse files
committed
Do not mention long types in E0599 label
The type is already mentioned in the main message and the list of unmet bounds.
1 parent ba64ba8 commit 2a0d712

File tree

4 files changed

+12
-5
lines changed

4 files changed

+12
-5
lines changed

compiler/rustc_hir_typeck/src/method/suggest.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
895895
}
896896
}
897897
} else {
898-
err.span_label(span, format!("{item_kind} cannot be called on `{ty_str}` due to unsatisfied trait bounds"));
898+
let ty_str = if ty_str.len() > 50 {
899+
String::new()
900+
} else {
901+
format!("on `{ty_str}` ")
902+
};
903+
err.span_label(span, format!(
904+
"{item_kind} cannot be called {ty_str}due to unsatisfied trait bounds"
905+
));
899906
}
900907
};
901908

src/test/ui/higher-rank-trait-bounds/issue-30786.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ LL | pub struct Map<S, F> {
88
| doesn't satisfy `_: StreamExt`
99
...
1010
LL | let filter = map.filterx(|x: &_| true);
11-
| ^^^^^^^ method cannot be called on `Map<Repeat, [closure@$DIR/issue-30786.rs:117:27: 117:34]>` due to unsatisfied trait bounds
11+
| ^^^^^^^ method cannot be called due to unsatisfied trait bounds
1212
|
1313
note: the following trait bounds were not satisfied:
1414
`&'a mut &Map<Repeat, [closure@$DIR/issue-30786.rs:117:27: 117:34]>: Stream`
@@ -29,7 +29,7 @@ LL | pub struct Filter<S, F> {
2929
| doesn't satisfy `_: StreamExt`
3030
...
3131
LL | let count = filter.countx();
32-
| ^^^^^^ method cannot be called on `Filter<Map<Repeat, for<'a> fn(&'a u64) -> &'a u64 {identity::<u64>}>, [closure@$DIR/issue-30786.rs:129:30: 129:37]>` due to unsatisfied trait bounds
32+
| ^^^^^^ method cannot be called due to unsatisfied trait bounds
3333
|
3434
note: the following trait bounds were not satisfied:
3535
`&'a mut &Filter<Map<Repeat, for<'a> fn(&'a u64) -> &'a u64 {identity::<u64>}>, [closure@$DIR/issue-30786.rs:129:30: 129:37]>: Stream`

src/test/ui/issues/issue-31173.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ error[E0599]: the method `collect` exists for struct `Cloned<TakeWhile<&mut std:
1313
--> $DIR/issue-31173.rs:12:10
1414
|
1515
LL | .collect();
16-
| ^^^^^^^ method cannot be called on `Cloned<TakeWhile<&mut std::vec::IntoIter<u8>, [closure@$DIR/issue-31173.rs:7:21: 7:25]>>` due to unsatisfied trait bounds
16+
| ^^^^^^^ method cannot be called due to unsatisfied trait bounds
1717
--> $SRC_DIR/core/src/iter/adapters/take_while.rs:LL:COL
1818
|
1919
= note: doesn't satisfy `<_ as Iterator>::Item = &_`

src/test/ui/mismatched_types/issue-36053-2.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ error[E0599]: the method `count` exists for struct `Filter<Fuse<std::iter::Once<
1717
--> $DIR/issue-36053-2.rs:7:55
1818
|
1919
LL | once::<&str>("str").fuse().filter(|a: &str| true).count();
20-
| --------- ^^^^^ method cannot be called on `Filter<Fuse<std::iter::Once<&str>>, [closure@$DIR/issue-36053-2.rs:7:39: 7:48]>` due to unsatisfied trait bounds
20+
| --------- ^^^^^ method cannot be called due to unsatisfied trait bounds
2121
| |
2222
| doesn't satisfy `<_ as FnOnce<(&&str,)>>::Output = bool`
2323
| doesn't satisfy `_: FnMut<(&&str,)>`

0 commit comments

Comments
 (0)