Skip to main content

## AMBIGUOUS_GLOB_IMPORTED_TRAITS

# Static AMBIGUOUS_GLOB_IMPORTED_TRAITS

Source

    pub static AMBIGUOUS_GLOB_IMPORTED_TRAITS: &Lint

Expand description

The `ambiguous_glob_imported_traits` lint reports uses of traits that are imported ambiguously via glob imports. Previously, this was not enforced due to a bug in rustc.

#### §Example

ⓘ

    #![deny(ambiguous_glob_imported_traits)]
    mod m1 {
       pub trait Trait {
               fn method1(&self) {}
           }
           impl Trait for u8 {}
       }
       mod m2 {
           pub trait Trait {
               fn method2(&self) {}
           }
           impl Trait for u8 {}
       }

     fn main() {
         use m1::*;
         use m2::*;
         0u8.method1();
         0u8.method2();
     }

{{produces}}

#### §Explanation

When multiple traits with the same name are brought into scope through glob imports, one trait becomes the “primary” one while the others are shadowed. Methods from the shadowed traits (e.g. `method2`) become inaccessible, while methods from the “primary” trait (e.g. `method1`) still resolve. Ideally, none of the ambiguous traits would be in scope, but we have to allow this for now because of backwards compatibility. This lint reports uses of these “primary” traits that are ambiguous.

This is a future-incompatible lint to transition this to a hard error in the future.