Commit 11dbd30
committed
Account for unbounded type param receiver in suggestions
When encountering
```rust
fn f<T>(a: T, b: T) -> std::cmp::Ordering {
a.cmp(&b) //~ ERROR E0599
}
```
output
```
error[E0599]: no method named `cmp` found for type parameter `T` in the current scope
--> $DIR/method-on-unbounded-type-param.rs:2:7
|
LL | fn f<T>(a: T, b: T) -> std::cmp::Ordering {
| - method `cmp` not found for this type parameter
LL | a.cmp(&b)
| ^^^ method cannot be called on `T` due to unsatisfied trait bounds
|
= help: items from traits can only be used if the type parameter is bounded by the trait
help: the following traits define an item `cmp`, perhaps you need to restrict type parameter `T` with one of them:
|
LL | fn f<T: Ord>(a: T, b: T) -> std::cmp::Ordering {
| +++++
LL | fn f<T: Iterator>(a: T, b: T) -> std::cmp::Ordering {
| ++++++++++
```
Fix #120186.1 parent 3a4c08c commit 11dbd30
File tree
2 files changed
+35
-22
lines changed- compiler/rustc_hir_typeck/src/method
- tests/ui/traits
2 files changed
+35
-22
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
563 | 563 | | |
564 | 564 | | |
565 | 565 | | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
566 | 577 | | |
567 | 578 | | |
568 | 579 | | |
| |||
1301 | 1312 | | |
1302 | 1313 | | |
1303 | 1314 | | |
1304 | | - | |
| 1315 | + | |
1305 | 1316 | | |
1306 | 1317 | | |
1307 | 1318 | | |
| |||
2884 | 2895 | | |
2885 | 2896 | | |
2886 | 2897 | | |
2887 | | - | |
2888 | | - | |
2889 | | - | |
2890 | | - | |
2891 | | - | |
2892 | | - | |
2893 | | - | |
2894 | | - | |
2895 | | - | |
2896 | | - | |
2897 | | - | |
2898 | | - | |
2899 | | - | |
| 2898 | + | |
2900 | 2899 | | |
2901 | 2900 | | |
2902 | 2901 | | |
| |||
2944 | 2943 | | |
2945 | 2944 | | |
2946 | 2945 | | |
| 2946 | + | |
| 2947 | + | |
| 2948 | + | |
| 2949 | + | |
| 2950 | + | |
| 2951 | + | |
| 2952 | + | |
| 2953 | + | |
| 2954 | + | |
| 2955 | + | |
| 2956 | + | |
| 2957 | + | |
| 2958 | + | |
| 2959 | + | |
2947 | 2960 | | |
2948 | 2961 | | |
2949 | 2962 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
8 | 8 | | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | | - | |
| 9 | + | |
| 10 | + | |
13 | 11 | | |
14 | | - | |
15 | | - | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| |||
0 commit comments