Simplify future incompatible reporting.
This commit is contained in:
parent
e9a387d6cf
commit
4d1daf8683
@ -9,7 +9,6 @@
|
|||||||
|
|
||||||
use Destination::*;
|
use Destination::*;
|
||||||
|
|
||||||
use rustc_lint_defs::FutureBreakage;
|
|
||||||
use rustc_span::source_map::SourceMap;
|
use rustc_span::source_map::SourceMap;
|
||||||
use rustc_span::{MultiSpan, SourceFile, Span};
|
use rustc_span::{MultiSpan, SourceFile, Span};
|
||||||
|
|
||||||
@ -193,7 +192,7 @@ pub trait Emitter {
|
|||||||
/// other formats can, and will, simply ignore it.
|
/// other formats can, and will, simply ignore it.
|
||||||
fn emit_artifact_notification(&mut self, _path: &Path, _artifact_type: &str) {}
|
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
|
/// Emit list of unused externs
|
||||||
fn emit_unused_externs(&mut self, _lint_level: &str, _unused_externs: &[&str]) {}
|
fn emit_unused_externs(&mut self, _lint_level: &str, _unused_externs: &[&str]) {}
|
||||||
|
@ -16,7 +16,7 @@ use crate::registry::Registry;
|
|||||||
use crate::DiagnosticId;
|
use crate::DiagnosticId;
|
||||||
use crate::ToolMetadata;
|
use crate::ToolMetadata;
|
||||||
use crate::{CodeSuggestion, SubDiagnostic};
|
use crate::{CodeSuggestion, SubDiagnostic};
|
||||||
use rustc_lint_defs::{Applicability, FutureBreakage};
|
use rustc_lint_defs::Applicability;
|
||||||
|
|
||||||
use rustc_data_structures::sync::Lrc;
|
use rustc_data_structures::sync::Lrc;
|
||||||
use rustc_span::hygiene::ExpnData;
|
use rustc_span::hygiene::ExpnData;
|
||||||
@ -134,17 +134,14 @@ impl Emitter for JsonEmitter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
let data: Vec<FutureBreakageItem> = diags
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|(breakage, mut diag)| {
|
.map(|mut diag| {
|
||||||
if diag.level == crate::Level::Allow {
|
if diag.level == crate::Level::Allow {
|
||||||
diag.level = crate::Level::Warning;
|
diag.level = crate::Level::Warning;
|
||||||
}
|
}
|
||||||
FutureBreakageItem {
|
FutureBreakageItem { diagnostic: Diagnostic::from_errors_diagnostic(&diag, self) }
|
||||||
future_breakage_date: breakage.date,
|
|
||||||
diagnostic: Diagnostic::from_errors_diagnostic(&diag, self),
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
let report = FutureIncompatReport { future_incompat_report: data };
|
let report = FutureIncompatReport { future_incompat_report: data };
|
||||||
@ -326,7 +323,6 @@ struct ArtifactNotification<'a> {
|
|||||||
|
|
||||||
#[derive(Encodable)]
|
#[derive(Encodable)]
|
||||||
struct FutureBreakageItem {
|
struct FutureBreakageItem {
|
||||||
future_breakage_date: Option<&'static str>,
|
|
||||||
diagnostic: Diagnostic,
|
diagnostic: Diagnostic,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,7 +23,6 @@ use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
|
|||||||
use rustc_data_structures::stable_hasher::StableHasher;
|
use rustc_data_structures::stable_hasher::StableHasher;
|
||||||
use rustc_data_structures::sync::{self, Lock, Lrc};
|
use rustc_data_structures::sync::{self, Lock, Lrc};
|
||||||
use rustc_data_structures::AtomicRef;
|
use rustc_data_structures::AtomicRef;
|
||||||
use rustc_lint_defs::FutureBreakage;
|
|
||||||
pub use rustc_lint_defs::{pluralize, Applicability};
|
pub use rustc_lint_defs::{pluralize, Applicability};
|
||||||
use rustc_serialize::json::Json;
|
use rustc_serialize::json::Json;
|
||||||
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
|
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
|
||||||
@ -790,7 +789,7 @@ impl Handler {
|
|||||||
self.inner.borrow_mut().emit_artifact_notification(path, artifact_type)
|
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)
|
self.inner.borrow_mut().emitter.emit_future_breakage_report(diags)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
//! compiler code, rather than using their own custom pass. Those
|
//! compiler code, rather than using their own custom pass. Those
|
||||||
//! lints are all available in `rustc_lint::builtin`.
|
//! 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;
|
use rustc_span::edition::Edition;
|
||||||
|
|
||||||
declare_lint! {
|
declare_lint! {
|
||||||
@ -3176,9 +3176,7 @@ declare_lint! {
|
|||||||
"detects usage of old versions of certain proc-macro crates",
|
"detects usage of old versions of certain proc-macro crates",
|
||||||
@future_incompatible = FutureIncompatibleInfo {
|
@future_incompatible = FutureIncompatibleInfo {
|
||||||
reference: "issue #83125 <https://github.com/rust-lang/rust/issues/83125>",
|
reference: "issue #83125 <https://github.com/rust-lang/rust/issues/83125>",
|
||||||
future_breakage: Some(FutureBreakage {
|
reason: FutureIncompatibilityReason::FutureReleaseErrorReportNow,
|
||||||
date: None
|
|
||||||
})
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,10 +152,6 @@ pub struct FutureIncompatibleInfo {
|
|||||||
/// Set to false for lints that already include a more detailed
|
/// Set to false for lints that already include a more detailed
|
||||||
/// explanation.
|
/// explanation.
|
||||||
pub explain_reason: bool,
|
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
|
/// The reason for future incompatibility
|
||||||
@ -164,6 +160,9 @@ pub enum FutureIncompatibilityReason {
|
|||||||
/// This will be an error in a future release
|
/// This will be an error in a future release
|
||||||
/// for all editions
|
/// for all editions
|
||||||
FutureReleaseError,
|
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
|
/// Previously accepted code that will become an
|
||||||
/// error in the provided edition
|
/// error in the provided edition
|
||||||
EditionError(Edition),
|
EditionError(Edition),
|
||||||
@ -182,18 +181,12 @@ impl FutureIncompatibilityReason {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug)]
|
|
||||||
pub struct FutureBreakage {
|
|
||||||
pub date: Option<&'static str>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl FutureIncompatibleInfo {
|
impl FutureIncompatibleInfo {
|
||||||
pub const fn default_fields_for_macro() -> Self {
|
pub const fn default_fields_for_macro() -> Self {
|
||||||
FutureIncompatibleInfo {
|
FutureIncompatibleInfo {
|
||||||
reference: "",
|
reference: "",
|
||||||
reason: FutureIncompatibilityReason::FutureReleaseError,
|
reason: FutureIncompatibilityReason::FutureReleaseError,
|
||||||
explain_reason: true,
|
explain_reason: true,
|
||||||
future_breakage: None,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ use rustc_hir::HirId;
|
|||||||
use rustc_index::vec::IndexVec;
|
use rustc_index::vec::IndexVec;
|
||||||
use rustc_session::lint::{
|
use rustc_session::lint::{
|
||||||
builtin::{self, FORBIDDEN_LINT_GROUPS},
|
builtin::{self, FORBIDDEN_LINT_GROUPS},
|
||||||
FutureIncompatibilityReason, Level, Lint, LintId,
|
FutureIncompatibilityReason, FutureIncompatibleInfo, Level, Lint, LintId,
|
||||||
};
|
};
|
||||||
use rustc_session::{DiagnosticMessageId, Session};
|
use rustc_session::{DiagnosticMessageId, Session};
|
||||||
use rustc_span::hygiene::MacroKind;
|
use rustc_span::hygiene::MacroKind;
|
||||||
@ -223,8 +223,13 @@ pub fn struct_lint_level<'s, 'd>(
|
|||||||
let lint_id = LintId::of(lint);
|
let lint_id = LintId::of(lint);
|
||||||
let future_incompatible = lint.future_incompatible;
|
let future_incompatible = lint.future_incompatible;
|
||||||
|
|
||||||
let has_future_breakage =
|
let has_future_breakage = matches!(
|
||||||
future_incompatible.map_or(false, |incompat| incompat.future_breakage.is_some());
|
future_incompatible,
|
||||||
|
Some(FutureIncompatibleInfo {
|
||||||
|
reason: FutureIncompatibilityReason::FutureReleaseErrorReportNow,
|
||||||
|
..
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
let mut err = match (level, span) {
|
let mut err = match (level, span) {
|
||||||
(Level::Allow, span) => {
|
(Level::Allow, span) => {
|
||||||
|
@ -20,8 +20,7 @@ use rustc_errors::annotate_snippet_emitter_writer::AnnotateSnippetEmitterWriter;
|
|||||||
use rustc_errors::emitter::{Emitter, EmitterWriter, HumanReadableErrorType};
|
use rustc_errors::emitter::{Emitter, EmitterWriter, HumanReadableErrorType};
|
||||||
use rustc_errors::json::JsonEmitter;
|
use rustc_errors::json::JsonEmitter;
|
||||||
use rustc_errors::registry::Registry;
|
use rustc_errors::registry::Registry;
|
||||||
use rustc_errors::{Diagnostic, DiagnosticBuilder, DiagnosticId, ErrorReported};
|
use rustc_errors::{DiagnosticBuilder, DiagnosticId, ErrorReported};
|
||||||
use rustc_lint_defs::FutureBreakage;
|
|
||||||
use rustc_macros::HashStable_Generic;
|
use rustc_macros::HashStable_Generic;
|
||||||
pub use rustc_span::def_id::StableCrateId;
|
pub use rustc_span::def_id::StableCrateId;
|
||||||
use rustc_span::source_map::{FileLoader, MultiSpan, RealFileLoader, SourceMap, Span};
|
use rustc_span::source_map::{FileLoader, MultiSpan, RealFileLoader, SourceMap, Span};
|
||||||
@ -317,23 +316,7 @@ impl Session {
|
|||||||
if diags.is_empty() {
|
if diags.is_empty() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// If any future-breakage lints were registered, this lint store
|
self.parse_sess.span_diagnostic.emit_future_breakage_report(diags);
|
||||||
// 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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn local_stable_crate_id(&self) -> StableCrateId {
|
pub fn local_stable_crate_id(&self) -> StableCrateId {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user