This repository was archived by the owner on May 28, 2025. It is now read-only.
Commit 7abdc84
committed
Auto merge of rust-lang#135536 - joshtriplett:str-impls, r=<try>
Add more impls of PartialEq and PartialOrd for strings
Currently, some combinations of `&String` and `&str` don't support
comparison operators. For instance, this:
```rust
fn main() {
let s1 = String::from("hello");
let s2 = "world";
_ = s1 < s2;
}
```
will fail with:
```
error[E0308]: mismatched types
--> src/main.rs:4:14
|
4 | _ = s1 < s2;
| -- ^^- help: try using a conversion method: `.to_string()`
| | |
| | expected `String`, found `&str`
| expected because this is `String`
```
Other combinations only work because the compiler implicitly relies on
impls on different reference types, and that makes such combinations
fragile, breaking if any other impls of `PartialOrd` show up.
Add some additional impls to make such cases work, and to improve
robustness when adding other impls in the future. In particular, I'm hoping that adding these makes it possible to add comparisons with other stringy types without creating as many inference issues.File tree
4 files changed
+73
-29
lines changed- library
- alloc/src
- core/src/str
- tests/ui/binop
4 files changed
+73
-29
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| 45 | + | |
45 | 46 | | |
46 | 47 | | |
47 | 48 | | |
| |||
2530 | 2531 | | |
2531 | 2532 | | |
2532 | 2533 | | |
| 2534 | + | |
2533 | 2535 | | |
2534 | 2536 | | |
2535 | 2537 | | |
2536 | 2538 | | |
2537 | 2539 | | |
2538 | 2540 | | |
| 2541 | + | |
| 2542 | + | |
| 2543 | + | |
| 2544 | + | |
| 2545 | + | |
| 2546 | + | |
| 2547 | + | |
| 2548 | + | |
| 2549 | + | |
| 2550 | + | |
| 2551 | + | |
| 2552 | + | |
| 2553 | + | |
| 2554 | + | |
| 2555 | + | |
| 2556 | + | |
| 2557 | + | |
| 2558 | + | |
| 2559 | + | |
| 2560 | + | |
| 2561 | + | |
| 2562 | + | |
| 2563 | + | |
| 2564 | + | |
| 2565 | + | |
| 2566 | + | |
| 2567 | + | |
| 2568 | + | |
| 2569 | + | |
| 2570 | + | |
| 2571 | + | |
| 2572 | + | |
| 2573 | + | |
| 2574 | + | |
| 2575 | + | |
| 2576 | + | |
2539 | 2577 | | |
2540 | 2578 | | |
2541 | 2579 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
33 | 49 | | |
34 | 50 | | |
35 | 51 | | |
| |||
48 | 64 | | |
49 | 65 | | |
50 | 66 | | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
51 | 83 | | |
52 | 84 | | |
53 | 85 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
70 | | - | |
71 | 70 | | |
72 | | - | |
73 | 71 | | |
74 | 72 | | |
75 | 73 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
271 | 271 | | |
272 | 272 | | |
273 | 273 | | |
274 | | - | |
275 | | - | |
276 | | - | |
277 | | - | |
278 | | - | |
279 | | - | |
280 | | - | |
281 | | - | |
282 | | - | |
283 | | - | |
284 | | - | |
285 | | - | |
286 | | - | |
287 | | - | |
288 | | - | |
289 | | - | |
290 | | - | |
291 | | - | |
292 | | - | |
293 | | - | |
294 | | - | |
295 | | - | |
296 | | - | |
297 | | - | |
298 | 274 | | |
299 | | - | |
| 275 | + | |
300 | 276 | | |
301 | 277 | | |
302 | 278 | | |
| |||
309 | 285 | | |
310 | 286 | | |
311 | 287 | | |
312 | | - | |
| 288 | + | |
313 | 289 | | |
314 | 290 | | |
315 | 291 | | |
316 | 292 | | |
317 | 293 | | |
318 | 294 | | |
319 | | - | |
| 295 | + | |
320 | 296 | | |
321 | 297 | | |
322 | 298 | | |
0 commit comments