-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Presence of Add impl for unrelated type prevents compilation #77143
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
Comments
This seems like expected behavior |
I'm confused -- why would |
Because the trait system then has two impls available to select from, |
Hmm, okay. So I guess this is a duplicate for #44619. |
@jonas-schievink It doesn't compile even if a mod x {
struct FakeString {}
impl std::ops::Add<FakeString> for String {
type Output = Self;
fn add(mut self, rhs: FakeString) -> Self::Output {
unreachable!()
}
}
}
mod y {
pub fn hw() {
println!("{}", "Hello".to_string() + &(" World".to_string()));
}
} |
Yeah, that doesn't affect trait selection to my knowledge |
Is there a workaround for this issue, short of removing the offending Add implementations? (as they can be in dependencies. e.g: I'm unable to add prometheus_client, as it breaks other code in the project) |
They interact with builtin implementation in confusing ways: rust-lang/rust#77143 Fixes prometheus#68
They interact with builtin implementation in confusing ways: rust-lang/rust#77143 Fixes prometheus#68 Signed-off-by: Benedek Thaler <erenon2@gmail.com>
They interact with builtin implementation in confusing ways: rust-lang/rust#77143 Fixes prometheus#68 Signed-off-by: Benedek Thaler <erenon2@gmail.com>
They conflict with builtin implementations, see rust-lang/rust#77143 Signed-off-by: Benedek Thaler <erenon2@gmail.com>
They conflict with builtin implementations, see rust-lang/rust#77143 Signed-off-by: Benedek Thaler <erenon2@gmail.com> Signed-off-by: ackintosh <sora.akatsuki@gmail.com>
# Objective Fixes #18606 When a type implements `Add` for `String`, the compiler can get confused when attempting to add a `&String` to a `String`. Unfortunately, this seems to be [expected behavior](rust-lang/rust#77143 (comment)) which causes problems for generic types since the current `TypePath` derive generates code that appends strings in this manner. ## Solution Explicitly use the `Add<&str>` implementation in the `TypePath` derive macro. ## Testing You can test locally by running: ``` cargo check -p bevy_reflect --tests ```
# Objective Fixes #18606 When a type implements `Add` for `String`, the compiler can get confused when attempting to add a `&String` to a `String`. Unfortunately, this seems to be [expected behavior](rust-lang/rust#77143 (comment)) which causes problems for generic types since the current `TypePath` derive generates code that appends strings in this manner. ## Solution Explicitly use the `Add<&str>` implementation in the `TypePath` derive macro. ## Testing You can test locally by running: ``` cargo check -p bevy_reflect --tests ```
Simplified version of bodil/smartstring#7.
I tried this code:
I expected to see this happen: this should compile correctly.
Instead, it fails like this:
Removing the
Add
impl makes it work.Meta
This is on current stable, 1.46.0.
The text was updated successfully, but these errors were encountered: