summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_lint_defs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:20:39 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:20:39 +0000
commit1376c5a617be5c25655d0d7cb63e3beaa5a6e026 (patch)
tree3bb8d61aee02bc7a15eab3f36e3b921afc2075d0 /compiler/rustc_lint_defs
parentReleasing progress-linux version 1.69.0+dfsg1-1~progress7.99u1. (diff)
downloadrustc-1376c5a617be5c25655d0d7cb63e3beaa5a6e026.tar.xz
rustc-1376c5a617be5c25655d0d7cb63e3beaa5a6e026.zip
Merging upstream version 1.70.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'compiler/rustc_lint_defs')
-rw-r--r--compiler/rustc_lint_defs/src/builtin.rs56
-rw-r--r--compiler/rustc_lint_defs/src/lib.rs17
2 files changed, 61 insertions, 12 deletions
diff --git a/compiler/rustc_lint_defs/src/builtin.rs b/compiler/rustc_lint_defs/src/builtin.rs
index 46ec1a2dc..9d6ab0b75 100644
--- a/compiler/rustc_lint_defs/src/builtin.rs
+++ b/compiler/rustc_lint_defs/src/builtin.rs
@@ -1026,12 +1026,13 @@ declare_lint! {
/// ### Example
///
/// ```rust,compile_fail
- /// #![feature(const_ptr_read)]
+ /// #![feature(const_mut_refs)]
/// const FOO: () = unsafe {
/// let x = &[0_u8; 4];
/// let y = x.as_ptr().cast::<u32>();
- /// y.read(); // the address of a `u8` array is unknown and thus we don't know if
- /// // it is aligned enough for reading a `u32`.
+ /// let mut z = 123;
+ /// y.copy_to_nonoverlapping(&mut z, 1); // the address of a `u8` array is unknown
+ /// // and thus we don't know if it is aligned enough for copying a `u32`.
/// };
/// ```
///
@@ -3229,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.
@@ -3336,6 +3376,7 @@ declare_lint_pass! {
NAMED_ARGUMENTS_USED_POSITIONALLY,
IMPLIED_BOUNDS_ENTAILMENT,
BYTE_SLICE_IN_PACKED_STRUCT_WITH_DERIVE,
+ AMBIGUOUS_GLOB_REEXPORTS,
]
}
@@ -3967,14 +4008,9 @@ declare_lint! {
///
/// ### Example
///
- /// ```rust,ignore (need FFI)
- /// #![feature(ffi_unwind_calls)]
+ /// ```rust
/// #![feature(c_unwind)]
- ///
- /// # mod impl {
- /// # #[no_mangle]
- /// # pub fn "C-unwind" fn foo() {}
- /// # }
+ /// #![warn(ffi_unwind_calls)]
///
/// extern "C-unwind" {
/// fn foo();
diff --git a/compiler/rustc_lint_defs/src/lib.rs b/compiler/rustc_lint_defs/src/lib.rs
index 534aff7fb..7ea472ed5 100644
--- a/compiler/rustc_lint_defs/src/lib.rs
+++ b/compiler/rustc_lint_defs/src/lib.rs
@@ -8,7 +8,7 @@ extern crate rustc_macros;
pub use self::Level::*;
use rustc_ast::node_id::NodeId;
use rustc_ast::{AttrId, Attribute};
-use rustc_data_structures::fx::FxIndexMap;
+use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
use rustc_data_structures::stable_hasher::{HashStable, StableHasher, ToStableHashKey};
use rustc_error_messages::{DiagnosticMessage, MultiSpan};
use rustc_hir::HashStableContext;
@@ -529,10 +529,21 @@ pub enum BuiltinLintDiagnostics {
vis_span: Span,
ident_span: Span,
},
+ AmbiguousGlobReexports {
+ /// The name for which collision(s) have occurred.
+ name: String,
+ /// The name space for which the collision(s) occurred in.
+ namespace: String,
+ /// Span where the name is first re-exported.
+ first_reexport_span: Span,
+ /// Span where the same name is also re-exported.
+ duplicate_reexport_span: Span,
+ },
}
/// Lints that are buffered up early on in the `Session` before the
/// `LintLevels` is calculated.
+#[derive(Debug)]
pub struct BufferedEarlyLint {
/// The span of code that we are linting on.
pub span: MultiSpan,
@@ -551,7 +562,7 @@ pub struct BufferedEarlyLint {
pub diagnostic: BuiltinLintDiagnostics,
}
-#[derive(Default)]
+#[derive(Default, Debug)]
pub struct LintBuffer {
pub map: FxIndexMap<NodeId, Vec<BufferedEarlyLint>>,
}
@@ -601,6 +612,8 @@ impl LintBuffer {
}
}
+pub type RegisteredTools = FxIndexSet<Ident>;
+
/// Declares a static item of type `&'static Lint`.
///
/// See <https://rustc-dev-guide.rust-lang.org/diagnostics.html> for