Implement rustc side of report-future-incompat
This commit is contained in:
parent
ffe52882ed
commit
23018a55d9
22 changed files with 332 additions and 114 deletions
|
@ -18,3 +18,4 @@ rustc_span = { path = "../rustc_span" }
|
|||
rustc_fs_util = { path = "../rustc_fs_util" }
|
||||
num_cpus = "1.0"
|
||||
rustc_ast = { path = "../rustc_ast" }
|
||||
rustc_lint_defs = { path = "../rustc_lint_defs" }
|
||||
|
|
|
@ -9,8 +9,8 @@ extern crate rustc_macros;
|
|||
|
||||
pub mod cgu_reuse_tracker;
|
||||
pub mod utils;
|
||||
#[macro_use]
|
||||
pub mod lint;
|
||||
pub use lint::{declare_lint, declare_lint_pass, declare_tool_lint, impl_lint_pass};
|
||||
pub use rustc_lint_defs as lint;
|
||||
pub mod parse;
|
||||
|
||||
mod code_stats;
|
||||
|
|
|
@ -1,475 +0,0 @@
|
|||
pub use self::Level::*;
|
||||
use rustc_ast::node_id::{NodeId, NodeMap};
|
||||
use rustc_data_structures::stable_hasher::{HashStable, StableHasher, ToStableHashKey};
|
||||
use rustc_errors::{pluralize, Applicability, DiagnosticBuilder};
|
||||
use rustc_span::edition::Edition;
|
||||
use rustc_span::{sym, symbol::Ident, MultiSpan, Span, Symbol};
|
||||
|
||||
pub mod builtin;
|
||||
|
||||
/// Setting for how to handle a lint.
|
||||
#[derive(Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Debug, Hash)]
|
||||
pub enum Level {
|
||||
Allow,
|
||||
Warn,
|
||||
Deny,
|
||||
Forbid,
|
||||
}
|
||||
|
||||
rustc_data_structures::impl_stable_hash_via_hash!(Level);
|
||||
|
||||
impl Level {
|
||||
/// Converts a level to a lower-case string.
|
||||
pub fn as_str(self) -> &'static str {
|
||||
match self {
|
||||
Level::Allow => "allow",
|
||||
Level::Warn => "warn",
|
||||
Level::Deny => "deny",
|
||||
Level::Forbid => "forbid",
|
||||
}
|
||||
}
|
||||
|
||||
/// Converts a lower-case string to a level.
|
||||
pub fn from_str(x: &str) -> Option<Level> {
|
||||
match x {
|
||||
"allow" => Some(Level::Allow),
|
||||
"warn" => Some(Level::Warn),
|
||||
"deny" => Some(Level::Deny),
|
||||
"forbid" => Some(Level::Forbid),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Converts a symbol to a level.
|
||||
pub fn from_symbol(x: Symbol) -> Option<Level> {
|
||||
match x {
|
||||
sym::allow => Some(Level::Allow),
|
||||
sym::warn => Some(Level::Warn),
|
||||
sym::deny => Some(Level::Deny),
|
||||
sym::forbid => Some(Level::Forbid),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Specification of a single lint.
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub struct Lint {
|
||||
/// A string identifier for the lint.
|
||||
///
|
||||
/// This identifies the lint in attributes and in command-line arguments.
|
||||
/// In those contexts it is always lowercase, but this field is compared
|
||||
/// in a way which is case-insensitive for ASCII characters. This allows
|
||||
/// `declare_lint!()` invocations to follow the convention of upper-case
|
||||
/// statics without repeating the name.
|
||||
///
|
||||
/// The name is written with underscores, e.g., "unused_imports".
|
||||
/// On the command line, underscores become dashes.
|
||||
///
|
||||
/// See https://rustc-dev-guide.rust-lang.org/diagnostics.html#lint-naming
|
||||
/// for naming guidelines.
|
||||
pub name: &'static str,
|
||||
|
||||
/// Default level for the lint.
|
||||
///
|
||||
/// See https://rustc-dev-guide.rust-lang.org/diagnostics.html#diagnostic-levels
|
||||
/// for guidelines on choosing a default level.
|
||||
pub default_level: Level,
|
||||
|
||||
/// Description of the lint or the issue it detects.
|
||||
///
|
||||
/// e.g., "imports that are never used"
|
||||
pub desc: &'static str,
|
||||
|
||||
/// Starting at the given edition, default to the given lint level. If this is `None`, then use
|
||||
/// `default_level`.
|
||||
pub edition_lint_opts: Option<(Edition, Level)>,
|
||||
|
||||
/// `true` if this lint is reported even inside expansions of external macros.
|
||||
pub report_in_external_macro: bool,
|
||||
|
||||
pub future_incompatible: Option<FutureIncompatibleInfo>,
|
||||
|
||||
pub is_plugin: bool,
|
||||
|
||||
/// `Some` if this lint is feature gated, otherwise `None`.
|
||||
pub feature_gate: Option<Symbol>,
|
||||
|
||||
pub crate_level_only: bool,
|
||||
}
|
||||
|
||||
/// Extra information for a future incompatibility lint.
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub struct FutureIncompatibleInfo {
|
||||
/// e.g., a URL for an issue/PR/RFC or error code
|
||||
pub reference: &'static str,
|
||||
/// If this is an edition fixing lint, the edition in which
|
||||
/// this lint becomes obsolete
|
||||
pub edition: Option<Edition>,
|
||||
}
|
||||
|
||||
impl Lint {
|
||||
pub const fn default_fields_for_macro() -> Self {
|
||||
Lint {
|
||||
name: "",
|
||||
default_level: Level::Forbid,
|
||||
desc: "",
|
||||
edition_lint_opts: None,
|
||||
is_plugin: false,
|
||||
report_in_external_macro: false,
|
||||
future_incompatible: None,
|
||||
feature_gate: None,
|
||||
crate_level_only: false,
|
||||
}
|
||||
}
|
||||
|
||||
/// Gets the lint's name, with ASCII letters converted to lowercase.
|
||||
pub fn name_lower(&self) -> String {
|
||||
self.name.to_ascii_lowercase()
|
||||
}
|
||||
|
||||
pub fn default_level(&self, edition: Edition) -> Level {
|
||||
self.edition_lint_opts
|
||||
.filter(|(e, _)| *e <= edition)
|
||||
.map(|(_, l)| l)
|
||||
.unwrap_or(self.default_level)
|
||||
}
|
||||
}
|
||||
|
||||
/// Identifies a lint known to the compiler.
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct LintId {
|
||||
// Identity is based on pointer equality of this field.
|
||||
pub lint: &'static Lint,
|
||||
}
|
||||
|
||||
impl PartialEq for LintId {
|
||||
fn eq(&self, other: &LintId) -> bool {
|
||||
std::ptr::eq(self.lint, other.lint)
|
||||
}
|
||||
}
|
||||
|
||||
impl Eq for LintId {}
|
||||
|
||||
impl std::hash::Hash for LintId {
|
||||
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
|
||||
let ptr = self.lint as *const Lint;
|
||||
ptr.hash(state);
|
||||
}
|
||||
}
|
||||
|
||||
impl LintId {
|
||||
/// Gets the `LintId` for a `Lint`.
|
||||
pub fn of(lint: &'static Lint) -> LintId {
|
||||
LintId { lint }
|
||||
}
|
||||
|
||||
pub fn lint_name_raw(&self) -> &'static str {
|
||||
self.lint.name
|
||||
}
|
||||
|
||||
/// Gets the name of the lint.
|
||||
pub fn to_string(&self) -> String {
|
||||
self.lint.name_lower()
|
||||
}
|
||||
}
|
||||
|
||||
impl<HCX> HashStable<HCX> for LintId {
|
||||
#[inline]
|
||||
fn hash_stable(&self, hcx: &mut HCX, hasher: &mut StableHasher) {
|
||||
self.lint_name_raw().hash_stable(hcx, hasher);
|
||||
}
|
||||
}
|
||||
|
||||
impl<HCX> ToStableHashKey<HCX> for LintId {
|
||||
type KeyType = &'static str;
|
||||
|
||||
#[inline]
|
||||
fn to_stable_hash_key(&self, _: &HCX) -> &'static str {
|
||||
self.lint_name_raw()
|
||||
}
|
||||
}
|
||||
|
||||
// This could be a closure, but then implementing derive trait
|
||||
// becomes hacky (and it gets allocated).
|
||||
#[derive(PartialEq)]
|
||||
pub enum BuiltinLintDiagnostics {
|
||||
Normal,
|
||||
BareTraitObject(Span, /* is_global */ bool),
|
||||
AbsPathWithModule(Span),
|
||||
ProcMacroDeriveResolutionFallback(Span),
|
||||
MacroExpandedMacroExportsAccessedByAbsolutePaths(Span),
|
||||
ElidedLifetimesInPaths(usize, Span, bool, Span, String),
|
||||
UnknownCrateTypes(Span, String, String),
|
||||
UnusedImports(String, Vec<(Span, String)>),
|
||||
RedundantImport(Vec<(Span, bool)>, Ident),
|
||||
DeprecatedMacro(Option<Symbol>, Span),
|
||||
UnusedDocComment(Span),
|
||||
}
|
||||
|
||||
/// Lints that are buffered up early on in the `Session` before the
|
||||
/// `LintLevels` is calculated.
|
||||
#[derive(PartialEq)]
|
||||
pub struct BufferedEarlyLint {
|
||||
/// The span of code that we are linting on.
|
||||
pub span: MultiSpan,
|
||||
|
||||
/// The lint message.
|
||||
pub msg: String,
|
||||
|
||||
/// The `NodeId` of the AST node that generated the lint.
|
||||
pub node_id: NodeId,
|
||||
|
||||
/// A lint Id that can be passed to
|
||||
/// `rustc_lint::early::EarlyContextAndPass::check_id`.
|
||||
pub lint_id: LintId,
|
||||
|
||||
/// Customization of the `DiagnosticBuilder<'_>` for the lint.
|
||||
pub diagnostic: BuiltinLintDiagnostics,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct LintBuffer {
|
||||
pub map: NodeMap<Vec<BufferedEarlyLint>>,
|
||||
}
|
||||
|
||||
impl LintBuffer {
|
||||
pub fn add_early_lint(&mut self, early_lint: BufferedEarlyLint) {
|
||||
let arr = self.map.entry(early_lint.node_id).or_default();
|
||||
if !arr.contains(&early_lint) {
|
||||
arr.push(early_lint);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn add_lint(
|
||||
&mut self,
|
||||
lint: &'static Lint,
|
||||
node_id: NodeId,
|
||||
span: MultiSpan,
|
||||
msg: &str,
|
||||
diagnostic: BuiltinLintDiagnostics,
|
||||
) {
|
||||
let lint_id = LintId::of(lint);
|
||||
let msg = msg.to_string();
|
||||
self.add_early_lint(BufferedEarlyLint { lint_id, node_id, span, msg, diagnostic });
|
||||
}
|
||||
|
||||
pub fn take(&mut self, id: NodeId) -> Vec<BufferedEarlyLint> {
|
||||
self.map.remove(&id).unwrap_or_default()
|
||||
}
|
||||
|
||||
pub fn buffer_lint(
|
||||
&mut self,
|
||||
lint: &'static Lint,
|
||||
id: NodeId,
|
||||
sp: impl Into<MultiSpan>,
|
||||
msg: &str,
|
||||
) {
|
||||
self.add_lint(lint, id, sp.into(), msg, BuiltinLintDiagnostics::Normal)
|
||||
}
|
||||
|
||||
pub fn buffer_lint_with_diagnostic(
|
||||
&mut self,
|
||||
lint: &'static Lint,
|
||||
id: NodeId,
|
||||
sp: impl Into<MultiSpan>,
|
||||
msg: &str,
|
||||
diagnostic: BuiltinLintDiagnostics,
|
||||
) {
|
||||
self.add_lint(lint, id, sp.into(), msg, diagnostic)
|
||||
}
|
||||
}
|
||||
|
||||
/// Declares a static item of type `&'static Lint`.
|
||||
///
|
||||
/// See https://rustc-dev-guide.rust-lang.org/diagnostics.html for documentation
|
||||
/// and guidelines on writing lints.
|
||||
///
|
||||
/// The macro call should start with a doc comment explaining the lint
|
||||
/// which will be embedded in the rustc user documentation book. It should
|
||||
/// be written in markdown and have a format that looks like this:
|
||||
///
|
||||
/// ```rust,ignore (doc-example)
|
||||
/// /// The `my_lint_name` lint detects [short explanation here].
|
||||
/// ///
|
||||
/// /// ### Example
|
||||
/// ///
|
||||
/// /// ```rust
|
||||
/// /// [insert a concise example that triggers the lint]
|
||||
/// /// ```
|
||||
/// ///
|
||||
/// /// {{produces}}
|
||||
/// ///
|
||||
/// /// ### Explanation
|
||||
/// ///
|
||||
/// /// This should be a detailed explanation of *why* the lint exists,
|
||||
/// /// and also include suggestions on how the user should fix the problem.
|
||||
/// /// Try to keep the text simple enough that a beginner can understand,
|
||||
/// /// and include links to other documentation for terminology that a
|
||||
/// /// beginner may not be familiar with. If this is "allow" by default,
|
||||
/// /// it should explain why (are there false positives or other issues?). If
|
||||
/// /// this is a future-incompatible lint, it should say so, with text that
|
||||
/// /// looks roughly like this:
|
||||
/// ///
|
||||
/// /// This is a [future-incompatible] lint to transition this to a hard
|
||||
/// /// error in the future. See [issue #xxxxx] for more details.
|
||||
/// ///
|
||||
/// /// [issue #xxxxx]: https://github.com/rust-lang/rust/issues/xxxxx
|
||||
/// ```
|
||||
///
|
||||
/// The `{{produces}}` tag will be automatically replaced with the output from
|
||||
/// the example by the build system. You can build and view the rustc book
|
||||
/// with `x.py doc --stage=1 src/doc/rustc --open`. If the lint example is too
|
||||
/// complex to run as a simple example (for example, it needs an extern
|
||||
/// crate), mark it with `ignore` and manually paste the expected output below
|
||||
/// the example.
|
||||
#[macro_export]
|
||||
macro_rules! declare_lint {
|
||||
($(#[$attr:meta])* $vis: vis $NAME: ident, $Level: ident, $desc: expr) => (
|
||||
$crate::declare_lint!(
|
||||
$(#[$attr])* $vis $NAME, $Level, $desc,
|
||||
);
|
||||
);
|
||||
($(#[$attr:meta])* $vis: vis $NAME: ident, $Level: ident, $desc: expr,
|
||||
$(@future_incompatible = $fi:expr;)?
|
||||
$(@feature_gate = $gate:expr;)?
|
||||
$($v:ident),*) => (
|
||||
$(#[$attr])*
|
||||
$vis static $NAME: &$crate::lint::Lint = &$crate::lint::Lint {
|
||||
name: stringify!($NAME),
|
||||
default_level: $crate::lint::$Level,
|
||||
desc: $desc,
|
||||
edition_lint_opts: None,
|
||||
is_plugin: false,
|
||||
$($v: true,)*
|
||||
$(future_incompatible: Some($fi),)*
|
||||
$(feature_gate: Some($gate),)*
|
||||
..$crate::lint::Lint::default_fields_for_macro()
|
||||
};
|
||||
);
|
||||
($(#[$attr:meta])* $vis: vis $NAME: ident, $Level: ident, $desc: expr,
|
||||
$lint_edition: expr => $edition_level: ident
|
||||
) => (
|
||||
$(#[$attr])*
|
||||
$vis static $NAME: &$crate::lint::Lint = &$crate::lint::Lint {
|
||||
name: stringify!($NAME),
|
||||
default_level: $crate::lint::$Level,
|
||||
desc: $desc,
|
||||
edition_lint_opts: Some(($lint_edition, $crate::lint::Level::$edition_level)),
|
||||
report_in_external_macro: false,
|
||||
is_plugin: false,
|
||||
};
|
||||
);
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! declare_tool_lint {
|
||||
(
|
||||
$(#[$attr:meta])* $vis:vis $tool:ident ::$NAME:ident, $Level: ident, $desc: expr
|
||||
) => (
|
||||
$crate::declare_tool_lint!{$(#[$attr])* $vis $tool::$NAME, $Level, $desc, false}
|
||||
);
|
||||
(
|
||||
$(#[$attr:meta])* $vis:vis $tool:ident ::$NAME:ident, $Level:ident, $desc:expr,
|
||||
report_in_external_macro: $rep:expr
|
||||
) => (
|
||||
$crate::declare_tool_lint!{$(#[$attr])* $vis $tool::$NAME, $Level, $desc, $rep}
|
||||
);
|
||||
(
|
||||
$(#[$attr:meta])* $vis:vis $tool:ident ::$NAME:ident, $Level:ident, $desc:expr,
|
||||
$external:expr
|
||||
) => (
|
||||
$(#[$attr])*
|
||||
$vis static $NAME: &$crate::lint::Lint = &$crate::lint::Lint {
|
||||
name: &concat!(stringify!($tool), "::", stringify!($NAME)),
|
||||
default_level: $crate::lint::$Level,
|
||||
desc: $desc,
|
||||
edition_lint_opts: None,
|
||||
report_in_external_macro: $external,
|
||||
future_incompatible: None,
|
||||
is_plugin: true,
|
||||
feature_gate: None,
|
||||
crate_level_only: false,
|
||||
};
|
||||
);
|
||||
}
|
||||
|
||||
/// Declares a static `LintArray` and return it as an expression.
|
||||
#[macro_export]
|
||||
macro_rules! lint_array {
|
||||
($( $lint:expr ),* ,) => { lint_array!( $($lint),* ) };
|
||||
($( $lint:expr ),*) => {{
|
||||
vec![$($lint),*]
|
||||
}}
|
||||
}
|
||||
|
||||
pub type LintArray = Vec<&'static Lint>;
|
||||
|
||||
pub trait LintPass {
|
||||
fn name(&self) -> &'static str;
|
||||
}
|
||||
|
||||
/// Implements `LintPass for $ty` with the given list of `Lint` statics.
|
||||
#[macro_export]
|
||||
macro_rules! impl_lint_pass {
|
||||
($ty:ty => [$($lint:expr),* $(,)?]) => {
|
||||
impl $crate::lint::LintPass for $ty {
|
||||
fn name(&self) -> &'static str { stringify!($ty) }
|
||||
}
|
||||
impl $ty {
|
||||
pub fn get_lints() -> $crate::lint::LintArray { $crate::lint_array!($($lint),*) }
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/// Declares a type named `$name` which implements `LintPass`.
|
||||
/// To the right of `=>` a comma separated list of `Lint` statics is given.
|
||||
#[macro_export]
|
||||
macro_rules! declare_lint_pass {
|
||||
($(#[$m:meta])* $name:ident => [$($lint:expr),* $(,)?]) => {
|
||||
$(#[$m])* #[derive(Copy, Clone)] pub struct $name;
|
||||
$crate::impl_lint_pass!($name => [$($lint),*]);
|
||||
};
|
||||
}
|
||||
|
||||
pub fn add_elided_lifetime_in_path_suggestion(
|
||||
sess: &crate::Session,
|
||||
db: &mut DiagnosticBuilder<'_>,
|
||||
n: usize,
|
||||
path_span: Span,
|
||||
incl_angl_brckt: bool,
|
||||
insertion_span: Span,
|
||||
anon_lts: String,
|
||||
) {
|
||||
let (replace_span, suggestion) = if incl_angl_brckt {
|
||||
(insertion_span, anon_lts)
|
||||
} else {
|
||||
// When possible, prefer a suggestion that replaces the whole
|
||||
// `Path<T>` expression with `Path<'_, T>`, rather than inserting `'_, `
|
||||
// at a point (which makes for an ugly/confusing label)
|
||||
if let Ok(snippet) = sess.source_map().span_to_snippet(path_span) {
|
||||
// But our spans can get out of whack due to macros; if the place we think
|
||||
// we want to insert `'_` isn't even within the path expression's span, we
|
||||
// should bail out of making any suggestion rather than panicking on a
|
||||
// subtract-with-overflow or string-slice-out-out-bounds (!)
|
||||
// FIXME: can we do better?
|
||||
if insertion_span.lo().0 < path_span.lo().0 {
|
||||
return;
|
||||
}
|
||||
let insertion_index = (insertion_span.lo().0 - path_span.lo().0) as usize;
|
||||
if insertion_index > snippet.len() {
|
||||
return;
|
||||
}
|
||||
let (before, after) = snippet.split_at(insertion_index);
|
||||
(path_span, format!("{}{}{}", before, anon_lts, after))
|
||||
} else {
|
||||
(insertion_span, anon_lts)
|
||||
}
|
||||
};
|
||||
db.span_suggestion(
|
||||
replace_span,
|
||||
&format!("indicate the anonymous lifetime{}", pluralize!(n)),
|
||||
suggestion,
|
||||
Applicability::MachineApplicable,
|
||||
);
|
||||
}
|
File diff suppressed because it is too large
Load diff
|
@ -893,6 +893,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
|
|||
all `statement`s (including terminators), only `terminator` spans, or \
|
||||
computed `block` spans (one span encompassing a block's terminator and \
|
||||
all statements)."),
|
||||
emit_future_compat_report: bool = (false, parse_bool, [UNTRACKED],
|
||||
"emits a future-compatibility report for lints (RFC 2834)"),
|
||||
emit_stack_sizes: bool = (false, parse_bool, [UNTRACKED],
|
||||
"emit a section containing stack size metadata (default: no)"),
|
||||
fewer_names: bool = (false, parse_bool, [TRACKED],
|
||||
|
|
|
@ -3,7 +3,7 @@ use crate::code_stats::CodeStats;
|
|||
pub use crate::code_stats::{DataTypeKind, FieldInfo, SizeKind, VariantInfo};
|
||||
use crate::config::{self, CrateType, OutputType, PrintRequest, SanitizerSet, SwitchWithOptPath};
|
||||
use crate::filesearch;
|
||||
use crate::lint;
|
||||
use crate::lint::{self, LintId};
|
||||
use crate::parse::ParseSess;
|
||||
use crate::search_paths::{PathKind, SearchPath};
|
||||
|
||||
|
@ -21,7 +21,8 @@ use rustc_errors::annotate_snippet_emitter_writer::AnnotateSnippetEmitterWriter;
|
|||
use rustc_errors::emitter::{Emitter, EmitterWriter, HumanReadableErrorType};
|
||||
use rustc_errors::json::JsonEmitter;
|
||||
use rustc_errors::registry::Registry;
|
||||
use rustc_errors::{Applicability, DiagnosticBuilder, DiagnosticId, ErrorReported};
|
||||
use rustc_errors::{Applicability, Diagnostic, DiagnosticBuilder, DiagnosticId, ErrorReported};
|
||||
use rustc_lint_defs::FutureBreakage;
|
||||
use rustc_span::edition::Edition;
|
||||
use rustc_span::source_map::{FileLoader, MultiSpan, RealFileLoader, SourceMap, Span};
|
||||
use rustc_span::{sym, SourceFileHashAlgorithm, Symbol};
|
||||
|
@ -40,6 +41,10 @@ use std::str::FromStr;
|
|||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
|
||||
pub trait SessionLintStore: sync::Send + sync::Sync {
|
||||
fn name_to_lint(&self, lint_name: &str) -> LintId;
|
||||
}
|
||||
|
||||
pub struct OptimizationFuel {
|
||||
/// If `-zfuel=crate=n` is specified, initially set to `n`, otherwise `0`.
|
||||
remaining: u64,
|
||||
|
@ -131,6 +136,8 @@ pub struct Session {
|
|||
|
||||
features: OnceCell<rustc_feature::Features>,
|
||||
|
||||
lint_store: OnceCell<Lrc<dyn SessionLintStore>>,
|
||||
|
||||
/// The maximum recursion limit for potentially infinitely recursive
|
||||
/// operations such as auto-dereference and monomorphization.
|
||||
pub recursion_limit: OnceCell<Limit>,
|
||||
|
@ -297,6 +304,35 @@ impl Session {
|
|||
pub fn finish_diagnostics(&self, registry: &Registry) {
|
||||
self.check_miri_unleashed_features();
|
||||
self.diagnostic().print_error_count(registry);
|
||||
self.emit_future_breakage();
|
||||
}
|
||||
|
||||
fn emit_future_breakage(&self) {
|
||||
if !self.opts.debugging_opts.emit_future_compat_report {
|
||||
return;
|
||||
}
|
||||
|
||||
let diags = self.diagnostic().take_future_breakage_diagnostics();
|
||||
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);
|
||||
}
|
||||
|
||||
pub fn local_crate_disambiguator(&self) -> CrateDisambiguator {
|
||||
|
@ -337,6 +373,12 @@ impl Session {
|
|||
pub fn struct_warn(&self, msg: &str) -> DiagnosticBuilder<'_> {
|
||||
self.diagnostic().struct_warn(msg)
|
||||
}
|
||||
pub fn struct_span_allow<S: Into<MultiSpan>>(&self, sp: S, msg: &str) -> DiagnosticBuilder<'_> {
|
||||
self.diagnostic().struct_span_allow(sp, msg)
|
||||
}
|
||||
pub fn struct_allow(&self, msg: &str) -> DiagnosticBuilder<'_> {
|
||||
self.diagnostic().struct_allow(msg)
|
||||
}
|
||||
pub fn struct_span_err<S: Into<MultiSpan>>(&self, sp: S, msg: &str) -> DiagnosticBuilder<'_> {
|
||||
self.diagnostic().struct_span_err(sp, msg)
|
||||
}
|
||||
|
@ -611,6 +653,13 @@ impl Session {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn init_lint_store(&self, lint_store: Lrc<dyn SessionLintStore>) {
|
||||
self.lint_store
|
||||
.set(lint_store)
|
||||
.map_err(|_| ())
|
||||
.expect("`lint_store` was initialized twice");
|
||||
}
|
||||
|
||||
/// Calculates the flavor of LTO to use for this compilation.
|
||||
pub fn lto(&self) -> config::Lto {
|
||||
// If our target has codegen requirements ignore the command line
|
||||
|
@ -1388,6 +1437,7 @@ pub fn build_session(
|
|||
crate_types: OnceCell::new(),
|
||||
crate_disambiguator: OnceCell::new(),
|
||||
features: OnceCell::new(),
|
||||
lint_store: OnceCell::new(),
|
||||
recursion_limit: OnceCell::new(),
|
||||
type_length_limit: OnceCell::new(),
|
||||
const_eval_limit: OnceCell::new(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue