give FutureIncompatibilityReason variants more explicit names

This commit is contained in:
Ralf Jung 2023-09-22 08:25:11 +02:00
parent b757318718
commit e888d470e9
4 changed files with 34 additions and 19 deletions

View file

@ -151,7 +151,12 @@ impl fmt::Display for DiagnosticLocation {
#[derive(Clone, Debug, PartialEq, Eq, Hash, Encodable, Decodable)]
pub enum DiagnosticId {
Error(String),
Lint { name: String, has_future_breakage: bool, is_force_warn: bool },
Lint {
name: String,
/// Indicates whether this lint should show up in cargo's future breakage report.
has_future_breakage: bool,
is_force_warn: bool,
},
}
/// A "sub"-diagnostic attached to a parent diagnostic.
@ -301,6 +306,7 @@ impl Diagnostic {
}
}
/// Indicates whether this diagnostic should show up in cargo's future breakage report.
pub fn has_future_breakage(&self) -> bool {
match self.code {
Some(DiagnosticId::Lint { has_future_breakage, .. }) => has_future_breakage,

View file

@ -1017,7 +1017,7 @@ declare_lint! {
"raw pointers must be aligned before dereferencing",
@future_incompatible = FutureIncompatibleInfo {
reference: "issue #68585 <https://github.com/rust-lang/rust/issues/104616>",
reason: FutureIncompatibilityReason::FutureReleaseErrorReportNow,
reason: FutureIncompatibilityReason::FutureReleaseErrorReportInDeps,
};
}
@ -1387,7 +1387,7 @@ declare_lint! {
"trait-object types were treated as different depending on marker-trait order",
@future_incompatible = FutureIncompatibleInfo {
reference: "issue #56484 <https://github.com/rust-lang/rust/issues/56484>",
reason: FutureIncompatibilityReason::FutureReleaseErrorReportNow,
reason: FutureIncompatibilityReason::FutureReleaseErrorReportInDeps,
};
}
@ -2006,7 +2006,7 @@ declare_lint! {
"detects proc macro derives using inaccessible names from parent modules",
@future_incompatible = FutureIncompatibleInfo {
reference: "issue #83583 <https://github.com/rust-lang/rust/issues/83583>",
reason: FutureIncompatibilityReason::FutureReleaseErrorReportNow,
reason: FutureIncompatibilityReason::FutureReleaseErrorReportInDeps,
};
}
@ -2618,7 +2618,7 @@ declare_lint! {
"a C-like enum implementing Drop is cast",
@future_incompatible = FutureIncompatibleInfo {
reference: "issue #73333 <https://github.com/rust-lang/rust/issues/73333>",
reason: FutureIncompatibilityReason::FutureReleaseErrorReportNow,
reason: FutureIncompatibilityReason::FutureReleaseErrorReportInDeps,
};
}
@ -2976,7 +2976,7 @@ declare_lint! {
"trailing semicolon in macro body used as expression",
@future_incompatible = FutureIncompatibleInfo {
reference: "issue #79813 <https://github.com/rust-lang/rust/issues/79813>",
reason: FutureIncompatibilityReason::FutureReleaseErrorReportNow,
reason: FutureIncompatibilityReason::FutureReleaseErrorReportInDeps,
};
}
@ -3709,7 +3709,7 @@ declare_lint! {
"detects usage of old versions of certain proc-macro crates",
@future_incompatible = FutureIncompatibleInfo {
reference: "issue #83125 <https://github.com/rust-lang/rust/issues/83125>",
reason: FutureIncompatibilityReason::FutureReleaseErrorReportNow,
reason: FutureIncompatibilityReason::FutureReleaseErrorReportInDeps,
};
}
@ -4222,7 +4222,7 @@ declare_lint! {
"impl method assumes more implied bounds than its corresponding trait method",
@future_incompatible = FutureIncompatibleInfo {
reference: "issue #105572 <https://github.com/rust-lang/rust/issues/105572>",
reason: FutureIncompatibilityReason::FutureReleaseErrorReportNow,
reason: FutureIncompatibilityReason::FutureReleaseErrorReportInDeps,
};
}
@ -4254,7 +4254,7 @@ declare_lint! {
"`[u8]` or `str` used in a packed struct with `derive`",
@future_incompatible = FutureIncompatibleInfo {
reference: "issue #107457 <https://github.com/rust-lang/rust/issues/107457>",
reason: FutureIncompatibilityReason::FutureReleaseErrorReportNow,
reason: FutureIncompatibilityReason::FutureReleaseErrorReportInDeps,
};
report_in_external_macro
}
@ -4483,7 +4483,7 @@ declare_lint! {
Warn,
"detects certain glob imports that require reporting an ambiguity error",
@future_incompatible = FutureIncompatibleInfo {
reason: FutureIncompatibilityReason::FutureReleaseError,
reason: FutureIncompatibilityReason::FutureReleaseErrorDontReportInDeps,
reference: "issue #114095 <https://github.com/rust-lang/rust/issues/114095>",
};
}
@ -4568,7 +4568,7 @@ declare_lint! {
Warn,
"elided lifetimes cannot be used in associated constants in impls",
@future_incompatible = FutureIncompatibleInfo {
reason: FutureIncompatibilityReason::FutureReleaseError,
reason: FutureIncompatibilityReason::FutureReleaseErrorDontReportInDeps,
reference: "issue #115010 <https://github.com/rust-lang/rust/issues/115010>",
};
}

View file

@ -347,12 +347,18 @@ pub struct FutureIncompatibleInfo {
/// The reason for future incompatibility
#[derive(Copy, Clone, Debug)]
pub enum FutureIncompatibilityReason {
/// This will be an error in a future release
/// for all editions
FutureReleaseError,
/// This will be an error in a future release for all editions
///
/// This will *not* show up in cargo's future breakage report.
/// The warning will hence only be seen in local crates, not in dependencies.
FutureReleaseErrorDontReportInDeps,
/// This will be an error in a future release, and
/// Cargo should create a report even for dependencies
FutureReleaseErrorReportNow,
///
/// This is the *only* reason that will make future incompatibility warnings show up in cargo's
/// reports. All other future incompatibility warnings are not visible when they occur in a
/// dependency.
FutureReleaseErrorReportInDeps,
/// Code that changes meaning in some way in a
/// future release.
FutureReleaseSemanticsChange,
@ -380,7 +386,7 @@ impl FutureIncompatibleInfo {
pub const fn default_fields_for_macro() -> Self {
FutureIncompatibleInfo {
reference: "",
reason: FutureIncompatibilityReason::FutureReleaseError,
reason: FutureIncompatibilityReason::FutureReleaseErrorDontReportInDeps,
explain_reason: true,
}
}

View file

@ -314,7 +314,10 @@ pub fn struct_lint_level(
// Default allow lints trigger too often for testing.
sess.opts.unstable_opts.future_incompat_test && lint.default_level != Level::Allow,
|incompat| {
matches!(incompat.reason, FutureIncompatibilityReason::FutureReleaseErrorReportNow)
matches!(
incompat.reason,
FutureIncompatibilityReason::FutureReleaseErrorReportInDeps
)
},
);
@ -404,8 +407,8 @@ pub fn struct_lint_level(
if let Some(future_incompatible) = future_incompatible {
let explanation = match future_incompatible.reason {
FutureIncompatibilityReason::FutureReleaseError
| FutureIncompatibilityReason::FutureReleaseErrorReportNow => {
FutureIncompatibilityReason::FutureReleaseErrorDontReportInDeps
| FutureIncompatibilityReason::FutureReleaseErrorReportInDeps => {
"this was previously accepted by the compiler but is being phased out; \
it will become a hard error in a future release!"
.to_owned()