1
Fork 0

update FutureIncompatibilityReason

This commit is contained in:
lcnr 2022-01-27 10:49:32 +01:00
parent 25862ffc8d
commit 7fcf7745cc
3 changed files with 35 additions and 25 deletions

View file

@ -1793,6 +1793,10 @@ declare_lint! {
Warn, Warn,
"detects name collision with an existing but unstable method", "detects name collision with an existing but unstable method",
@future_incompatible = FutureIncompatibleInfo { @future_incompatible = FutureIncompatibleInfo {
reason: FutureIncompatibilityReason::Custom(
"once this associated item is added to the standard library, \
the ambiguity may cause an error or change in behavior!"
),
reference: "issue #48919 <https://github.com/rust-lang/rust/issues/48919>", reference: "issue #48919 <https://github.com/rust-lang/rust/issues/48919>",
// Note: this item represents future incompatibility of all unstable functions in the // Note: this item represents future incompatibility of all unstable functions in the
// standard library, and thus should never be removed or changed to an error. // standard library, and thus should never be removed or changed to an error.
@ -2335,6 +2339,10 @@ declare_lint! {
Warn, Warn,
"reservation of a two-phased borrow conflicts with other shared borrows", "reservation of a two-phased borrow conflicts with other shared borrows",
@future_incompatible = FutureIncompatibleInfo { @future_incompatible = FutureIncompatibleInfo {
reason: FutureIncompatibilityReason::Custom(
"this borrowing pattern was not meant to be accepted, \
and may become a hard error in the future"
),
reference: "issue #59159 <https://github.com/rust-lang/rust/issues/59159>", reference: "issue #59159 <https://github.com/rust-lang/rust/issues/59159>",
}; };
} }

View file

@ -163,12 +163,17 @@ pub enum FutureIncompatibilityReason {
/// This will be an error in a future release, and /// This will be an error in a future release, and
/// Cargo should create a report even for dependencies /// Cargo should create a report even for dependencies
FutureReleaseErrorReportNow, FutureReleaseErrorReportNow,
/// Code that changes meaning in some way in a
/// future release.
FutureReleaseSemanticsChange,
/// Previously accepted code that will become an /// Previously accepted code that will become an
/// error in the provided edition /// error in the provided edition
EditionError(Edition), EditionError(Edition),
/// Code that changes meaning in some way in /// Code that changes meaning in some way in
/// the provided edition /// the provided edition
EditionSemanticsChange(Edition), EditionSemanticsChange(Edition),
/// A custom reason.
Custom(&'static str),
} }
impl FutureIncompatibilityReason { impl FutureIncompatibilityReason {

View file

@ -221,7 +221,6 @@ pub fn struct_lint_level<'s, 'd>(
decorate: Box<dyn for<'b> FnOnce(LintDiagnosticBuilder<'b>) + 'd>, decorate: Box<dyn for<'b> FnOnce(LintDiagnosticBuilder<'b>) + 'd>,
) { ) {
// Check for future incompatibility lints and issue a stronger warning. // Check for future incompatibility lints and issue a stronger warning.
let lint_id = LintId::of(lint);
let future_incompatible = lint.future_incompatible; let future_incompatible = lint.future_incompatible;
let has_future_breakage = future_incompatible.map_or( let has_future_breakage = future_incompatible.map_or(
@ -345,31 +344,29 @@ pub fn struct_lint_level<'s, 'd>(
err.code(DiagnosticId::Lint { name, has_future_breakage, is_force_warn }); err.code(DiagnosticId::Lint { name, has_future_breakage, is_force_warn });
if let Some(future_incompatible) = future_incompatible { if let Some(future_incompatible) = future_incompatible {
let explanation = if lint_id == LintId::of(builtin::UNSTABLE_NAME_COLLISIONS) { let explanation = match future_incompatible.reason {
"once this associated item is added to the standard library, the ambiguity may \ FutureIncompatibilityReason::FutureReleaseError
cause an error or change in behavior!" | FutureIncompatibilityReason::FutureReleaseErrorReportNow => {
.to_owned() "this was previously accepted by the compiler but is being phased out; \
} else if lint_id == LintId::of(builtin::MUTABLE_BORROW_RESERVATION_CONFLICT) { it will become a hard error in a future release!"
"this borrowing pattern was not meant to be accepted, and may become a hard error \ .to_owned()
in the future" }
.to_owned() FutureIncompatibilityReason::FutureReleaseSemanticsChange => {
} else if let FutureIncompatibilityReason::EditionError(edition) = "this will change its meaning in a future release!".to_owned()
future_incompatible.reason }
{ FutureIncompatibilityReason::EditionError(edition) => {
let current_edition = sess.edition(); let current_edition = sess.edition();
format!( format!(
"this is accepted in the current edition (Rust {}) but is a hard error in Rust {}!", "this is accepted in the current edition (Rust {}) but is a hard error in Rust {}!",
current_edition, edition current_edition, edition
) )
} else if let FutureIncompatibilityReason::EditionSemanticsChange(edition) = }
future_incompatible.reason FutureIncompatibilityReason::EditionSemanticsChange(edition) => {
{ format!("this changes meaning in Rust {}", edition)
format!("this changes meaning in Rust {}", edition) }
} else { FutureIncompatibilityReason::Custom(reason) => reason.to_owned(),
"this was previously accepted by the compiler but is being phased out; \
it will become a hard error in a future release!"
.to_owned()
}; };
if future_incompatible.explain_reason { if future_incompatible.explain_reason {
err.warn(&explanation); err.warn(&explanation);
} }