1
Fork 0

Lint ambiguous glob re-exports

This commit is contained in:
许杰友 Jieyou Xu (Joe) 2023-03-20 03:11:28 +08:00
parent ab9bb3ea36
commit 1f67949f0e
No known key found for this signature in database
GPG key ID: C5FD5D32014FDB47
11 changed files with 228 additions and 26 deletions

View file

@ -3230,6 +3230,45 @@ declare_lint! {
};
}
declare_lint! {
/// The `ambiguous_glob_reexports` lint detects cases where names re-exported via globs
/// collide. Downstream users trying to use the same name re-exported from multiple globs
/// will receive a warning pointing out redefinition of the same name.
///
/// ### Example
///
/// ```rust,compile_fail
/// #![deny(ambiguous_glob_reexports)]
/// pub mod foo {
/// pub type X = u8;
/// }
///
/// pub mod bar {
/// pub type Y = u8;
/// pub type X = u8;
/// }
///
/// pub use foo::*;
/// pub use bar::*;
///
///
/// pub fn main() {}
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// This was previously accepted but it could silently break a crate's downstream users code.
/// For example, if `foo::*` and `bar::*` were re-exported before `bar::X` was added to the
/// re-exports, down stream users could use `this_crate::X` without problems. However, adding
/// `bar::X` would cause compilation errors in downstream crates because `X` is defined
/// multiple times in the same namespace of `this_crate`.
pub AMBIGUOUS_GLOB_REEXPORTS,
Warn,
"ambiguous glob re-exports",
}
declare_lint_pass! {
/// Does nothing as a lint pass, but registers some `Lint`s
/// that are used by other parts of the compiler.
@ -3337,6 +3376,7 @@ declare_lint_pass! {
NAMED_ARGUMENTS_USED_POSITIONALLY,
IMPLIED_BOUNDS_ENTAILMENT,
BYTE_SLICE_IN_PACKED_STRUCT_WITH_DERIVE,
AMBIGUOUS_GLOB_REEXPORTS,
]
}