未验证 提交 8d4293c1 编写于 作者: Y Yuki Okushi 提交者: GitHub

Rollup merge of #87070 - ehuss:simplify-future-report, r=oli-obk

Simplify future incompatible reporting.

This simplifies the implementation of the future incompatible reporting system. Instead of having a separate field in the future_incompatible definition, this reuses the `FutureIncompatibilityReason` enum. It also drops the "date" field. Cargo does not use the date field, and there isn't much of a need for this to be structured, and I am skeptical that the date can be predicted reliably. The date or release version can be listed in the lint text if desired.
......@@ -9,7 +9,6 @@
use Destination::*;
use rustc_lint_defs::FutureBreakage;
use rustc_span::source_map::SourceMap;
use rustc_span::{MultiSpan, SourceFile, Span};
......@@ -193,7 +192,7 @@ pub trait Emitter {
/// other formats can, and will, simply ignore it.
fn emit_artifact_notification(&mut self, _path: &Path, _artifact_type: &str) {}
fn emit_future_breakage_report(&mut self, _diags: Vec<(FutureBreakage, Diagnostic)>) {}
fn emit_future_breakage_report(&mut self, _diags: Vec<Diagnostic>) {}
/// Emit list of unused externs
fn emit_unused_externs(&mut self, _lint_level: &str, _unused_externs: &[&str]) {}
......
......@@ -16,7 +16,7 @@
use crate::DiagnosticId;
use crate::ToolMetadata;
use crate::{CodeSuggestion, SubDiagnostic};
use rustc_lint_defs::{Applicability, FutureBreakage};
use rustc_lint_defs::Applicability;
use rustc_data_structures::sync::Lrc;
use rustc_span::hygiene::ExpnData;
......@@ -134,17 +134,14 @@ fn emit_artifact_notification(&mut self, path: &Path, artifact_type: &str) {
}
}
fn emit_future_breakage_report(&mut self, diags: Vec<(FutureBreakage, crate::Diagnostic)>) {
fn emit_future_breakage_report(&mut self, diags: Vec<crate::Diagnostic>) {
let data: Vec<FutureBreakageItem> = diags
.into_iter()
.map(|(breakage, mut diag)| {
.map(|mut diag| {
if diag.level == crate::Level::Allow {
diag.level = crate::Level::Warning;
}
FutureBreakageItem {
future_breakage_date: breakage.date,
diagnostic: Diagnostic::from_errors_diagnostic(&diag, self),
}
FutureBreakageItem { diagnostic: Diagnostic::from_errors_diagnostic(&diag, self) }
})
.collect();
let report = FutureIncompatReport { future_incompat_report: data };
......@@ -326,7 +323,6 @@ struct ArtifactNotification<'a> {
#[derive(Encodable)]
struct FutureBreakageItem {
future_breakage_date: Option<&'static str>,
diagnostic: Diagnostic,
}
......
......@@ -23,7 +23,6 @@
use rustc_data_structures::stable_hasher::StableHasher;
use rustc_data_structures::sync::{self, Lock, Lrc};
use rustc_data_structures::AtomicRef;
use rustc_lint_defs::FutureBreakage;
pub use rustc_lint_defs::{pluralize, Applicability};
use rustc_serialize::json::Json;
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
......@@ -790,7 +789,7 @@ pub fn emit_artifact_notification(&self, path: &Path, artifact_type: &str) {
self.inner.borrow_mut().emit_artifact_notification(path, artifact_type)
}
pub fn emit_future_breakage_report(&self, diags: Vec<(FutureBreakage, Diagnostic)>) {
pub fn emit_future_breakage_report(&self, diags: Vec<Diagnostic>) {
self.inner.borrow_mut().emitter.emit_future_breakage_report(diags)
}
......
......@@ -6,7 +6,7 @@
//! compiler code, rather than using their own custom pass. Those
//! lints are all available in `rustc_lint::builtin`.
use crate::{declare_lint, declare_lint_pass, FutureBreakage, FutureIncompatibilityReason};
use crate::{declare_lint, declare_lint_pass, FutureIncompatibilityReason};
use rustc_span::edition::Edition;
declare_lint! {
......@@ -3176,9 +3176,7 @@
"detects usage of old versions of certain proc-macro crates",
@future_incompatible = FutureIncompatibleInfo {
reference: "issue #83125 <https://github.com/rust-lang/rust/issues/83125>",
future_breakage: Some(FutureBreakage {
date: None
})
reason: FutureIncompatibilityReason::FutureReleaseErrorReportNow,
};
}
......
......@@ -152,10 +152,6 @@ pub struct FutureIncompatibleInfo {
/// Set to false for lints that already include a more detailed
/// explanation.
pub explain_reason: bool,
/// Information about a future breakage, which will
/// be emitted in JSON messages to be displayed by Cargo
/// for upstream deps
pub future_breakage: Option<FutureBreakage>,
}
/// The reason for future incompatibility
......@@ -164,6 +160,9 @@ 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, and
/// Cargo should create a report even for dependencies
FutureReleaseErrorReportNow,
/// Previously accepted code that will become an
/// error in the provided edition
EditionError(Edition),
......@@ -182,18 +181,12 @@ pub fn edition(self) -> Option<Edition> {
}
}
#[derive(Copy, Clone, Debug)]
pub struct FutureBreakage {
pub date: Option<&'static str>,
}
impl FutureIncompatibleInfo {
pub const fn default_fields_for_macro() -> Self {
FutureIncompatibleInfo {
reference: "",
reason: FutureIncompatibilityReason::FutureReleaseError,
explain_reason: true,
future_breakage: None,
}
}
}
......
......@@ -8,7 +8,7 @@
use rustc_index::vec::IndexVec;
use rustc_session::lint::{
builtin::{self, FORBIDDEN_LINT_GROUPS},
FutureIncompatibilityReason, Level, Lint, LintId,
FutureIncompatibilityReason, FutureIncompatibleInfo, Level, Lint, LintId,
};
use rustc_session::{DiagnosticMessageId, Session};
use rustc_span::hygiene::MacroKind;
......@@ -223,8 +223,13 @@ fn struct_lint_level_impl(
let lint_id = LintId::of(lint);
let future_incompatible = lint.future_incompatible;
let has_future_breakage =
future_incompatible.map_or(false, |incompat| incompat.future_breakage.is_some());
let has_future_breakage = matches!(
future_incompatible,
Some(FutureIncompatibleInfo {
reason: FutureIncompatibilityReason::FutureReleaseErrorReportNow,
..
})
);
let mut err = match (level, span) {
(Level::Allow, span) => {
......
......@@ -20,8 +20,7 @@
use rustc_errors::emitter::{Emitter, EmitterWriter, HumanReadableErrorType};
use rustc_errors::json::JsonEmitter;
use rustc_errors::registry::Registry;
use rustc_errors::{Diagnostic, DiagnosticBuilder, DiagnosticId, ErrorReported};
use rustc_lint_defs::FutureBreakage;
use rustc_errors::{DiagnosticBuilder, DiagnosticId, ErrorReported};
use rustc_macros::HashStable_Generic;
pub use rustc_span::def_id::StableCrateId;
use rustc_span::source_map::{FileLoader, MultiSpan, RealFileLoader, SourceMap, Span};
......@@ -317,23 +316,7 @@ fn emit_future_breakage(&self) {
if diags.is_empty() {
return;
}
// If any future-breakage lints were registered, this lint store
// should be available
let lint_store = self.lint_store.get().expect("`lint_store` not initialized!");
let diags_and_breakage: Vec<(FutureBreakage, Diagnostic)> = diags
.into_iter()
.map(|diag| {
let lint_name = match &diag.code {
Some(DiagnosticId::Lint { name, has_future_breakage: true, .. }) => name,
_ => panic!("Unexpected code in diagnostic {:?}", diag),
};
let lint = lint_store.name_to_lint(&lint_name);
let future_breakage =
lint.lint.future_incompatible.unwrap().future_breakage.unwrap();
(future_breakage, diag)
})
.collect();
self.parse_sess.span_diagnostic.emit_future_breakage_report(diags_and_breakage);
self.parse_sess.span_diagnostic.emit_future_breakage_report(diags);
}
pub fn local_stable_crate_id(&self) -> StableCrateId {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册