#Why so
25 messages · Page 1 of 1 (latest)
?eval
pub trait test{
}
impl<T> test for T{
}
impl<T> test for &T{
}
impl<T> test for &mut T{
}
fn main(){
}```
warning: trait `test` should have an upper camel case name
--> src/main.rs:1:11
|
1 | pub trait test{
| ^^^^ help: convert the identifier to upper camel case: `Test`
|
= note: `#[warn(non_camel_case_types)]` on by default
error[E0119]: conflicting implementations of trait `test` for type `&_`
--> src/main.rs:8:1
|
5 | impl<T> test for T{
| ------------------ first implementation here
...
8 | impl<T> test for &T{
| ^^^^^^^^^^^^^^^^^^^ conflicting implementation for `&_`
error[E0119]: conflicting implementations of trait `test` for type `&mut _`
--> src/main.rs:11:1
|
5 | impl<T> test for T{
| ------------------ first implementation here
...
11 | impl<T> test for &mut T{
| ^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `&mut _`
For more information about this error, try `rustc --explain E0119`.```
But
?eval
pub trait test{
}
impl<T> test for &T{
}
impl<T> test for &mut T{
}
fn main(){
}
Why This is working fine.??
because T can be either &U or &mut U
?eval
trait Trait {}
struct Struct;
impl Trait for Struct {} // ✅
impl Trait for &Struct {} // ✅
impl Trait for &mut Struct {} // ✅
The operation timed out: deadline has elapsed```
Sorry can you make it clear
impl<T> test for T { includes all types
Oh
T = &Foo and T = &mut Foo too
Hmmm
It can be an issue
I was reading this
it's a good read
How can it practically create an issue
it literally says what I said
Sure leme read it more
trait Trait { fn foo(self); }
impl<T> Trait for T { fn foo(self) { println!("T"); } }
impl<T> Trait for &T { fn foo(self) { println!("&T"); } } // ❌
let int_ref: &i32 = &1;
int_ref.foo(); // which method should be called?