Static rustc_lint::builtin::UNSTABLE_NAME_COLLISIONS

source ·
pub static UNSTABLE_NAME_COLLISIONS: &'static Lint
Expand description

The unstable_name_collisions lint detects that you have used a name that the standard library plans to add in the future.

§Example

trait MyIterator : Iterator {
    // is_partitioned is an unstable method that already exists on the Iterator trait
    fn is_partitioned<P>(self, predicate: P) -> bool
    where
        Self: Sized,
        P: FnMut(Self::Item) -> bool,
    {true}
}

impl<T: ?Sized> MyIterator for T where T: Iterator { }

let x = vec![1, 2, 3];
let _ = x.iter().is_partitioned(|_| true);

{{produces}}

§Explanation

When new methods are added to traits in the standard library, they are usually added in an “unstable” form which is only available on the nightly channel with a feature attribute. If there is any preexisting code which extends a trait to have a method with the same name, then the names will collide. In the future, when the method is stabilized, this will cause an error due to the ambiguity. This lint is an early-warning to let you know that there may be a collision in the future. This can be avoided by adding type annotations to disambiguate which trait method you intend to call, such as MyIterator::is_partitioned(my_iter, my_predicate) or renaming or removing the method.