why can't I compare a &str to a Rc<String>
-
-
Replying to @mountain_ghosts
does &* on the Rc help
1 reply 0 retweets 2 likes -
Replying to @steveklabnik
yeah, just, idk why I'm surprised given the type system rules but this caught me off guard
2 replies 0 retweets 1 like -
Replying to @mountain_ghosts @steveklabnik
It's just not an impl that anyone thought to write explicitly. Auto-deref isn't ever used when satisfying traits, so unless there's an explicit `PartialEq<Rc<String>> for str`, it'll fail.
1 reply 0 retweets 7 likes -
Replying to @sgrif @mountain_ghosts
ahh
1 reply 0 retweets 1 like -
Replying to @steveklabnik @sgrif
yeah it makes more sense when you realise it's invoking a function of two arguments, and Deref doesn't mean that fn will try to find a common deref target to make the type system happy
1 reply 0 retweets 3 likes -
Replying to @mountain_ghosts @steveklabnik
Nah, it can pick one. It's just because traits are involved (and there are multiple deref targets to choose from, though it could just pick the first in the chain tbh) https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=00257fc8db0914a33c6e000a038111e8 …
2 replies 0 retweets 2 likes -
Replying to @sgrif @steveklabnik
right, if there's a common trait target both are aiming for, I imagine it's really ambiguous which common type the compiler would make both deref to in order to make the trait work
1 reply 0 retweets 0 likes -
Replying to @mountain_ghosts @steveklabnik
It's not ambiguous at all (if it was, &* wouldn't work either). The impls don't even have to be related, there just has to be more than one of them.
1 reply 0 retweets 0 likes
https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=216887fb1dc286b33dd9a6ebfee729fe … Only one valid type can be deref'd to, there's no ambiguity. It's just because the compiler chooses not to autoderef to satisfy traits (which I suspect has a good reason, but I've always seen as relatively arbitrary)
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.