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_sorted is an unstable method that already exists on the Iterator trait
fn is_sorted(self) -> bool where Self: Sized {true}
}
impl<T: ?Sized> MyIterator for T where T: Iterator { }
let x = vec![1, 2, 3];
let _ = x.iter().is_sorted();
{{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_sorted(my_iter)
or renaming or removing the method.