summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_lint_defs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-07 05:48:42 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-07 05:48:42 +0000
commitcec1877e180393eba0f6ddb0cf97bf3a791631c7 (patch)
tree47b4dac2a9dd9a40c30c251b4d4a72d7ccf77e9f /compiler/rustc_lint_defs
parentAdding debian version 1.74.1+dfsg1-1. (diff)
downloadrustc-cec1877e180393eba0f6ddb0cf97bf3a791631c7.tar.xz
rustc-cec1877e180393eba0f6ddb0cf97bf3a791631c7.zip
Merging upstream version 1.75.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/Cargo.toml10
-rw-r--r--compiler/rustc_lint_defs/src/builtin.rs86
-rw-r--r--compiler/rustc_lint_defs/src/lib.rs8
3 files changed, 37 insertions, 67 deletions
diff --git a/compiler/rustc_lint_defs/Cargo.toml b/compiler/rustc_lint_defs/Cargo.toml
index 2bf34d82f..eb2a184ef 100644
--- a/compiler/rustc_lint_defs/Cargo.toml
+++ b/compiler/rustc_lint_defs/Cargo.toml
@@ -4,12 +4,14 @@ version = "0.0.0"
edition = "2021"
[dependencies]
-serde = { version = "1.0.125", features = ["derive"] }
+# tidy-alphabetical-start
rustc_ast = { path = "../rustc_ast" }
rustc_data_structures = { path = "../rustc_data_structures" }
rustc_error_messages = { path = "../rustc_error_messages" }
-rustc_span = { path = "../rustc_span" }
-rustc_serialize = { path = "../rustc_serialize" }
+rustc_hir = { path = "../rustc_hir" }
rustc_macros = { path = "../rustc_macros" }
+rustc_serialize = { path = "../rustc_serialize" }
+rustc_span = { path = "../rustc_span" }
rustc_target = { path = "../rustc_target" }
-rustc_hir = { path = "../rustc_hir" }
+serde = { version = "1.0.125", features = ["derive"] }
+# tidy-alphabetical-end
diff --git a/compiler/rustc_lint_defs/src/builtin.rs b/compiler/rustc_lint_defs/src/builtin.rs
index 69b462d32..bef9f469c 100644
--- a/compiler/rustc_lint_defs/src/builtin.rs
+++ b/compiler/rustc_lint_defs/src/builtin.rs
@@ -987,45 +987,6 @@ declare_lint! {
}
declare_lint! {
- /// The `invalid_alignment` lint detects dereferences of misaligned pointers during
- /// constant evaluation.
- ///
- /// ### Example
- ///
- /// ```rust,compile_fail
- /// #![feature(const_mut_refs)]
- /// const FOO: () = unsafe {
- /// let x = &[0_u8; 4];
- /// let y = x.as_ptr().cast::<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`.
- /// };
- /// ```
- ///
- /// {{produces}}
- ///
- /// ### Explanation
- ///
- /// The compiler allowed dereferencing raw pointers irrespective of alignment
- /// during const eval due to the const evaluator at the time not making it easy
- /// or cheap to check. Now that it is both, this is not accepted anymore.
- ///
- /// Since it was undefined behaviour to begin with, this breakage does not violate
- /// Rust's stability guarantees. Using undefined behaviour can cause arbitrary
- /// behaviour, including failure to build.
- ///
- /// [future-incompatible]: ../index.md#future-incompatible-lints
- pub INVALID_ALIGNMENT,
- Deny,
- "raw pointers must be aligned before dereferencing",
- @future_incompatible = FutureIncompatibleInfo {
- reason: FutureIncompatibilityReason::FutureReleaseErrorReportInDeps,
- reference: "issue #68585 <https://github.com/rust-lang/rust/issues/104616>",
- };
-}
-
-declare_lint! {
/// The `exported_private_dependencies` lint detects private dependencies
/// that are exposed in a public interface.
///
@@ -2256,15 +2217,16 @@ declare_lint! {
///
/// ### Explanation
///
- /// Previous versions of Rust allowed function pointers and wide raw pointers in patterns.
+ /// Previous versions of Rust allowed function pointers and all raw pointers in patterns.
/// While these work in many cases as expected by users, it is possible that due to
/// optimizations pointers are "not equal to themselves" or pointers to different functions
/// compare as equal during runtime. This is because LLVM optimizations can deduplicate
/// functions if their bodies are the same, thus also making pointers to these functions point
/// to the same location. Additionally functions may get duplicated if they are instantiated
- /// in different crates and not deduplicated again via LTO.
+ /// in different crates and not deduplicated again via LTO. Pointer identity for memory
+ /// created by `const` is similarly unreliable.
pub POINTER_STRUCTURAL_MATCH,
- Allow,
+ Warn,
"pointers are not structural-match",
@future_incompatible = FutureIncompatibleInfo {
reason: FutureIncompatibilityReason::FutureReleaseErrorDontReportInDeps,
@@ -3430,7 +3392,6 @@ declare_lint_pass! {
INDIRECT_STRUCTURAL_MATCH,
INEFFECTIVE_UNSTABLE_TRAIT_IMPL,
INLINE_NO_SANITIZE,
- INVALID_ALIGNMENT,
INVALID_DOC_ATTRIBUTES,
INVALID_MACRO_EXPORT_ARGUMENTS,
INVALID_TYPE_PARAM_DEFAULT,
@@ -3993,8 +3954,13 @@ declare_lint! {
}
declare_lint! {
- /// The `non_exhaustive_omitted_patterns` lint detects when a wildcard (`_` or `..`) in a
- /// pattern for a `#[non_exhaustive]` struct or enum is reachable.
+ /// The `non_exhaustive_omitted_patterns` lint aims to help consumers of a `#[non_exhaustive]`
+ /// struct or enum who want to match all of its fields/variants explicitly.
+ ///
+ /// The `#[non_exhaustive]` annotation forces matches to use wildcards, so exhaustiveness
+ /// checking cannot be used to ensure that all fields/variants are matched explicitly. To remedy
+ /// this, this allow-by-default lint warns the user when a match mentions some but not all of
+ /// the fields/variants of a `#[non_exhaustive]` struct or enum.
///
/// ### Example
///
@@ -4008,9 +3974,9 @@ declare_lint! {
///
/// // in crate B
/// #![feature(non_exhaustive_omitted_patterns_lint)]
+ /// #[warn(non_exhaustive_omitted_patterns)]
/// match Bar::A {
/// Bar::A => {},
- /// #[warn(non_exhaustive_omitted_patterns)]
/// _ => {},
/// }
/// ```
@@ -4018,29 +3984,32 @@ declare_lint! {
/// This will produce:
///
/// ```text
- /// warning: reachable patterns not covered of non exhaustive enum
+ /// warning: some variants are not matched explicitly
/// --> $DIR/reachable-patterns.rs:70:9
/// |
- /// LL | _ => {}
- /// | ^ pattern `B` not covered
+ /// LL | match Bar::A {
+ /// | ^ pattern `Bar::B` not covered
/// |
/// note: the lint level is defined here
/// --> $DIR/reachable-patterns.rs:69:16
/// |
/// LL | #[warn(non_exhaustive_omitted_patterns)]
/// | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- /// = help: ensure that all possible cases are being handled by adding the suggested match arms
+ /// = help: ensure that all variants are matched explicitly by adding the suggested match arms
/// = note: the matched value is of type `Bar` and the `non_exhaustive_omitted_patterns` attribute was found
/// ```
///
+ /// Warning: setting this to `deny` will make upstream non-breaking changes (adding fields or
+ /// variants to a `#[non_exhaustive]` struct or enum) break your crate. This goes against
+ /// expected semver behavior.
+ ///
/// ### Explanation
///
- /// Structs and enums tagged with `#[non_exhaustive]` force the user to add a
- /// (potentially redundant) wildcard when pattern-matching, to allow for future
- /// addition of fields or variants. The `non_exhaustive_omitted_patterns` lint
- /// detects when such a wildcard happens to actually catch some fields/variants.
- /// In other words, when the match without the wildcard would not be exhaustive.
- /// This lets the user be informed if new fields/variants were added.
+ /// Structs and enums tagged with `#[non_exhaustive]` force the user to add a (potentially
+ /// redundant) wildcard when pattern-matching, to allow for future addition of fields or
+ /// variants. The `non_exhaustive_omitted_patterns` lint detects when such a wildcard happens to
+ /// actually catch some fields/variants. In other words, when the match without the wildcard
+ /// would not be exhaustive. This lets the user be informed if new fields/variants were added.
pub NON_EXHAUSTIVE_OMITTED_PATTERNS,
Allow,
"detect when patterns of types marked `non_exhaustive` are missed",
@@ -4489,11 +4458,11 @@ declare_lint! {
/// on itself), the blanket impl is not considered to hold for `u8`. This will
/// change in a future release.
pub COINDUCTIVE_OVERLAP_IN_COHERENCE,
- Warn,
+ Deny,
"impls that are not considered to overlap may be considered to \
overlap in the future",
@future_incompatible = FutureIncompatibleInfo {
- reason: FutureIncompatibilityReason::FutureReleaseErrorDontReportInDeps,
+ reason: FutureIncompatibilityReason::FutureReleaseErrorReportInDeps,
reference: "issue #114040 <https://github.com/rust-lang/rust/issues/114040>",
};
}
@@ -4574,7 +4543,6 @@ declare_lint! {
/// ### Example
///
/// ```rust,compile_fail
- /// #![feature(return_position_impl_trait_in_trait)]
/// #![deny(refining_impl_trait)]
///
/// use std::fmt::Display;
diff --git a/compiler/rustc_lint_defs/src/lib.rs b/compiler/rustc_lint_defs/src/lib.rs
index 7ba589c3b..878c1a65d 100644
--- a/compiler/rustc_lint_defs/src/lib.rs
+++ b/compiler/rustc_lint_defs/src/lib.rs
@@ -321,7 +321,7 @@ pub struct Lint {
pub future_incompatible: Option<FutureIncompatibleInfo>,
- pub is_plugin: bool,
+ pub is_loaded: bool,
/// `Some` if this lint is feature gated, otherwise `None`.
pub feature_gate: Option<Symbol>,
@@ -399,7 +399,7 @@ impl Lint {
default_level: Level::Forbid,
desc: "",
edition_lint_opts: None,
- is_plugin: false,
+ is_loaded: false,
report_in_external_macro: false,
future_incompatible: None,
feature_gate: None,
@@ -735,7 +735,7 @@ macro_rules! declare_lint {
name: stringify!($NAME),
default_level: $crate::$Level,
desc: $desc,
- is_plugin: false,
+ is_loaded: false,
$($v: true,)*
$(feature_gate: Some($gate),)?
$(future_incompatible: Some($crate::FutureIncompatibleInfo {
@@ -777,7 +777,7 @@ macro_rules! declare_tool_lint {
edition_lint_opts: None,
report_in_external_macro: $external,
future_incompatible: None,
- is_plugin: true,
+ is_loaded: true,
$(feature_gate: Some($gate),)?
crate_level_only: false,
..$crate::Lint::default_fields_for_macro()