Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions compiler/rustc_codegen_ssa/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use rustc_lint_defs::builtin::LINKER_INFO;
use rustc_macros::{Decodable, Encodable};
use rustc_metadata::EncodedMetadata;
use rustc_middle::dep_graph::WorkProduct;
use rustc_middle::lint::LevelSpec;
use rustc_middle::lint::StableLevelSpec;
use rustc_middle::middle::debugger_visualizer::DebuggerVisualizerFile;
use rustc_middle::middle::dependency_format::Dependencies;
use rustc_middle::middle::exported_symbols::SymbolExportKind;
Expand Down Expand Up @@ -342,8 +342,8 @@ impl CompiledModules {
/// Instead, encode exactly the information we need.
#[derive(Copy, Clone, Debug, Encodable, Decodable)]
pub struct CodegenLintLevelSpecs {
linker_messages: LevelSpec,
linker_info: LevelSpec,
linker_messages: StableLevelSpec,
linker_info: StableLevelSpec,
}

impl CodegenLintLevelSpecs {
Expand Down
23 changes: 16 additions & 7 deletions compiler/rustc_lint/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,17 @@ use rustc_hir::def_id::{CrateNum, DefId};
use rustc_hir::definitions::{DefPathData, DisambiguatedDefPathData};
use rustc_hir::{Pat, PatKind};
use rustc_middle::bug;
use rustc_middle::lint::LevelSpec;
use rustc_middle::lint::{LevelSpec, StableLevelSpec, UnstableLevelSpec};
use rustc_middle::middle::privacy::EffectiveVisibilities;
use rustc_middle::ty::layout::{LayoutError, LayoutOfHelpers, TyAndLayout};
use rustc_middle::ty::print::{PrintError, PrintTraitRefExt as _, Printer, with_no_trimmed_paths};
use rustc_middle::ty::{
self, GenericArg, RegisteredTools, Ty, TyCtxt, TypingEnv, TypingMode, Unnormalized,
};
use rustc_session::lint::{FutureIncompatibleInfo, Lint, LintExpectationId, LintId};
use rustc_session::lint::{
FutureIncompatibleInfo, Lint, LintExpectationId, LintId, StableLintExpectationId,
UnstableLintExpectationId,
};
use rustc_session::{DynLintStore, Session};
use rustc_span::edit_distance::find_best_match_for_names;
use rustc_span::{Ident, Span, Symbol, sym};
Expand Down Expand Up @@ -510,6 +513,8 @@ pub struct EarlyContext<'a> {
}

pub trait LintContext {
type LintExpectationId: Copy + Into<LintExpectationId>;

fn sess(&self) -> &Session;

// FIXME: These methods should not take an Into<MultiSpan> -- instead, callers should need to
Expand Down Expand Up @@ -538,7 +543,7 @@ pub trait LintContext {
}

/// This returns the lint level spec for the given lint at the current location.
fn get_lint_level_spec(&self, lint: &'static Lint) -> LevelSpec;
fn get_lint_level_spec(&self, lint: &'static Lint) -> LevelSpec<Self::LintExpectationId>;

/// This function can be used to manually fulfill an expectation. This can
/// be used for lints which contain several spans, and should be suppressed,
Expand All @@ -547,7 +552,7 @@ pub trait LintContext {
/// Note that this function should only be called for [`LintExpectationId`]s
/// retrieved from the current lint pass. Buffered or manually created ids can
/// cause ICEs.
fn fulfill_expectation(&self, expectation: LintExpectationId) {
fn fulfill_expectation(&self, expectation: Self::LintExpectationId) {
// We need to make sure that submitted expectation ids are correctly fulfilled suppressed
// and stored between compilation sessions. To not manually do these steps, we simply create
// a dummy diagnostic and emit it as usual, which will be suppressed and stored like a
Expand All @@ -556,7 +561,7 @@ pub trait LintContext {
.dcx()
.struct_expect(
"this is a dummy diagnostic, to submit and store an expectation",
expectation,
expectation.into(),
)
.emit();
}
Expand Down Expand Up @@ -585,6 +590,8 @@ impl<'a> EarlyContext<'a> {
}

impl<'tcx> LintContext for LateContext<'tcx> {
type LintExpectationId = StableLintExpectationId;

/// Gets the overall compiler `Session` object.
fn sess(&self) -> &Session {
self.tcx.sess
Expand All @@ -604,12 +611,14 @@ impl<'tcx> LintContext for LateContext<'tcx> {
}
}

fn get_lint_level_spec(&self, lint: &'static Lint) -> LevelSpec {
fn get_lint_level_spec(&self, lint: &'static Lint) -> StableLevelSpec {
self.tcx.lint_level_spec_at_node(lint, self.last_node_with_lint_attrs)
}
}

impl LintContext for EarlyContext<'_> {
type LintExpectationId = UnstableLintExpectationId;

/// Gets the overall compiler `Session` object.
fn sess(&self) -> &Session {
self.builder.sess()
Expand All @@ -624,7 +633,7 @@ impl LintContext for EarlyContext<'_> {
self.builder.opt_span_lint(lint, span.map(|s| s.into()), decorator)
}

fn get_lint_level_spec(&self, lint: &'static Lint) -> LevelSpec {
fn get_lint_level_spec(&self, lint: &'static Lint) -> UnstableLevelSpec {
self.builder.lint_level_spec(lint)
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/early.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl<'ecx, T: EarlyLintPass> EarlyContextAndPass<'ecx, T> {
{
let is_crate_node = id == ast::CRATE_NODE_ID;
debug!(?id);
let push = self.context.builder.push(attrs, is_crate_node, None);
let push = self.context.builder.push(attrs, is_crate_node);

debug!("early context: enter_attrs({:?})", attrs);
lint_callback!(self, check_attributes, attrs);
Expand Down
30 changes: 11 additions & 19 deletions compiler/rustc_lint/src/expect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use rustc_data_structures::fx::FxHashSet;
use rustc_middle::lint::LintExpectation;
use rustc_middle::query::Providers;
use rustc_middle::ty::TyCtxt;
use rustc_session::lint::LintExpectationId;
use rustc_session::lint::builtin::UNFULFILLED_LINT_EXPECTATIONS;
use rustc_session::lint::{LintExpectationId, StableLintExpectationId};
use rustc_span::Symbol;

use crate::lints::{Expectation, ExpectationNote};
Expand All @@ -12,7 +12,7 @@ pub(crate) fn provide(providers: &mut Providers) {
*providers = Providers { lint_expectations, check_expectations, ..*providers };
}

fn lint_expectations(tcx: TyCtxt<'_>, (): ()) -> Vec<(LintExpectationId, LintExpectation)> {
fn lint_expectations(tcx: TyCtxt<'_>, (): ()) -> Vec<(StableLintExpectationId, LintExpectation)> {
let krate = tcx.hir_crate_items(());

let mut expectations = Vec::new();
Expand All @@ -31,30 +31,22 @@ fn check_expectations(tcx: TyCtxt<'_>, tool_filter: Option<Symbol>) {

// Turn a `LintExpectationId` into a `(AttrId, lint_index)` pair.
let canonicalize_id = |expect_id: &LintExpectationId| {
match *expect_id {
LintExpectationId::Unstable { attr_id, lint_index: Some(lint_index) } => {
(attr_id, lint_index)
}
LintExpectationId::Stable { hir_id, attr_index, lint_index: Some(lint_index) } => {
let (attr_id, lint_index) = match *expect_id {
LintExpectationId::Unstable(id) => (id.attr_id, id.lint_index),
LintExpectationId::Stable(id) => {
// We are an `eval_always` query, so looking at the attribute's `AttrId` is ok.
let attr_id = tcx.hir_attrs(hir_id)[attr_index as usize].id();

(attr_id, lint_index)
(tcx.hir_attrs(id.hir_id)[id.attr_index as usize].id(), id.lint_index)
}
_ => panic!("fulfilled expectations must have a lint index"),
}
};
(attr_id, lint_index.expect("fulfilled expectations must have a lint index"))
};

let fulfilled_expectations: FxHashSet<_> =
fulfilled_expectations.iter().map(canonicalize_id).collect();

for (expect_id, expectation) in lint_expectations {
// This check will always be true, since `lint_expectations` only holds stable ids
let LintExpectationId::Stable { hir_id, .. } = expect_id else {
unreachable!("at this stage all `LintExpectationId`s are stable");
};

let expect_id = canonicalize_id(expect_id);
let hir_id = expect_id.hir_id;
let expect_id = canonicalize_id(&LintExpectationId::Stable(*expect_id));

if !fulfilled_expectations.contains(&expect_id)
&& tool_filter.is_none_or(|filter| expectation.lint_tool == Some(filter))
Expand All @@ -63,7 +55,7 @@ fn check_expectations(tcx: TyCtxt<'_>, tool_filter: Option<Symbol>) {
let note = expectation.is_unfulfilled_lint_expectations;
tcx.emit_node_span_lint(
UNFULFILLED_LINT_EXPECTATIONS,
*hir_id,
hir_id,
expectation.emission_span,
Expectation { rationale, note },
);
Expand Down
8 changes: 0 additions & 8 deletions compiler/rustc_lint/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,14 +439,6 @@ fn late_lint_crate<'tcx>(tcx: TyCtxt<'tcx>) {

filtered_passes.push(Box::new(HardwiredLints));
let pass = RuntimeCombinedLateLintPass { passes: &mut filtered_passes[..] };
late_lint_crate_inner(tcx, context, pass);
}

fn late_lint_crate_inner<'tcx, T: LateLintPass<'tcx>>(
tcx: TyCtxt<'tcx>,
context: LateContext<'tcx>,
pass: T,
) {
let mut cx = LateContextAndPass { context, pass };

// Visit the whole crate.
Expand Down
Loading
Loading