Add more impls of PartialEq and PartialOrd for strings by joshtriplett · Pull Request #135536 · rust-lang/rust (original) (raw)
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
[ Show hidden characters]({{ revealButtonHref }})
joshtriplett added T-libs-api
Relevant to the library API team, which will review and decide on the PR/issue.
Marks issues that should be documented in the release notes of the next release.
This change is insta-stable, so needs a completed FCP to proceed.
This change needs a crater run to check for possible breakage in the ecosystem.
labels
bors added a commit to rust-lang-ci/rust that referenced this pull request
Add more impls of PartialEq and PartialOrd for strings
Currently, some combinations of &String
and &str
don't support
comparison operators. For instance, this:
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.
bors added a commit to rust-lang-ci/rust that referenced this pull request
Add more impls of PartialEq and PartialOrd for strings
Currently, some combinations of &String
and &str
don't support
comparison operators. For instance, this:
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.
rustbot added the T-bootstrap
Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)
label
rustbot added the T-bootstrap
Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)
label
joshtriplett removed the T-bootstrap
Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)
label
rustbot added the T-bootstrap
Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)
label
Currently, some combinations of &String
and &str
don't support
comparison operators. For instance, this:
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.
This avoids making a suggestion to write *x
if x
would also work.
In a couple of cases, adjust the test file, because otherwise the file produces:
error: failed to apply suggestions for tests/ui/iter_overeager_cloned.rs with rustfix
cannot replace slice of data that was already replaced
Add //@no-rustfix to the test file to ignore rustfix suggestions
This makes such comparisons more robust against the availability of other impls.
djc mentioned this pull request