• Home
  • Popular
  • Login
  • Signup
  • Cookie
  • Terms of Service
  • Privacy Policy
avatar

Posted by John Dev


10 Jan, 2025

Updated at 21 Jan, 2025

Specialization on clone. What's the risk?

Hi,

The following issue is solved when I enable the specialization gated attribute:

impl<T> MyTrait for Vec<T>
where
        T: Copy + Sized + Send + Sync + ... <- other non relevant traits for the question
{}

But with min_specialization it fails, stating that

error: cannot specialize on trait `std::clone::Clone`
error: cannot specialize on trait `std::marker::Send`
error: cannot specialize on trait `std::marker::Sync`

So, now, using nightly, what are the real risks for my code to keep using the specialization attr?
I tried with many variants and they all work as expected with the full specialization attribute.

I tried with trait specialization attributes to reduce the cope of specialization, but apparently it didn't make it.

with

#![feature(min_specialization)]
#![feature(rustc_attrs)]

in my lib.rs

and

#[rustc_specialization_trait] 
impl<T> MyTrait for Vec<T>
where
        T: Copy + Sized + Send + Sync + ... <- other non relevant traits for the question
{}

the issue remains.

Thanks!

8 posts - 4 participants

Read full topic