-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
smartstring breaks std::string::String? #7
Comments
It looks like things aren't dereffing to &str anymore because of something in This compiles just fine:
But this normally compiles and now fails to as soon as I
|
Note that right now `smartstring` influences String/&string references to deref to &str. So "String + &String" fails, while "String + (&String).as_str()" works. See bodil/smartstring#7
I filed rust-lang/rust#77143 with a simplified version of this, since it seems like a compiler bug. |
So it's expected behaviour. That's a bit of a papercut. Needs documentation then, I guess. |
"Expected behaviour" doesn't mean desirable behaviour, but Rust's type system has its limitations currently, I guess we're all still waiting patiently for Chalk to happen. I'd still like to explore options to get around this before writing it off as expected behaviour, though. |
I ran into this problem and had the hunch that it was related to #[test]
fn can_add_std_string_ref_to_std_string() {
let _ = "Hello, ".to_string() + &"world!".to_string();
} Then I commented out each of the
If all of the #[test]
fn can_add_ref_to_std_string() {
let _ = String::from("Hello, ") + &SmartString::<Compact>::from("world!");
}
#[test]
fn can_add_str_to_smart_string() {
let _ = SmartString::<Compact>::from("Hello, ") + "world!";
}
#[test]
fn can_add_std_string_ref_to_smart_string() {
let _ = SmartString::<Compact>::from("Hello, ") + &String::from("world!");
} Meaning you always have to add #[test]
fn can_add_to_std_string() {
let _ = String::from("Hello, ") + SmartString::<Compact>::from("world!");
} (It's currently enabled to compile by Actually, in addition to the breakage in the initial post, there are two implementations that break SummaryThis was a kind of convoluted post. Basically it looks like implementing some string additions break inference for certain other string additions. |
It's unfortunate that 1.x went out with this issue. I think the argument of @Erutuon is sound: SmartString does not need more Having |
still getting this issue. I installed the Rhai crate and it is breaking parts of my code that works before!! just because im adding strings with + really sucks |
I agree with the comment by @horazont above:
I'm curious how others are working around this issue. Is there an older version of I apologize if this is the wrong place to ask; I'm a Rust newbie and I'm very excited at the prospect of using this crate. (Edit: |
Summary: Upsides: - It seems more actively maintained. - Note: on Github issues, they have a couple open reports of fuzz failures (from their automation) but those are from a branch, not master. - It doesn't have this frustrating bug: bodil/smartstring#7 Downsides: - It doesn't convert String to an inlined value in `From`, but we don't actually rely on this (we use small strings mostly when working with directories where those elements are produced via an iterator of FileName). Reviewed By: ndmitchell Differential Revision: D42313656 fbshipit-source-id: 0708866fced3b32941047755b770244287f6ad94
Summary: Upsides: - It seems more actively maintained. - Note: on Github issues, they have a couple open reports of fuzz failures (from their automation) but those are from a branch, not master. - It doesn't have this frustrating bug: bodil/smartstring#7 Downsides: - It doesn't convert String to an inlined value in `From`, but we don't actually rely on this (we use small strings mostly when working with directories where those elements are produced via an iterator of FileName). Reviewed By: ndmitchell Differential Revision: D42313656 fbshipit-source-id: 0708866fced3b32941047755b770244287f6ad94
Summary: Upsides: - It seems more actively maintained. - Note: on Github issues, they have a couple open reports of fuzz failures (from their automation) but those are from a branch, not master. - It doesn't have this frustrating bug: bodil/smartstring#7 Downsides: - It doesn't convert String to an inlined value in `From`, but we don't actually rely on this (we use small strings mostly when working with directories where those elements are produced via an iterator of FileName). Reviewed By: ndmitchell Differential Revision: D42313656 fbshipit-source-id: 0708866fced3b32941047755b770244287f6ad94
Just a suggestion. Maybe hiding some of the offending Something like a This will preserve compatibility while allowing people in the know to get around this problem. |
Could we expedite this please? This causes anybody who uses Polars to receive this error if they add strings as describe. |
smartstring 0.2.3.
rust 1.44.1
this fails:
in a weird way:
The text was updated successfully, but these errors were encountered: