Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 3c1a1f3

Browse files
committed
migrate: expect.rs
1 parent 6ffecd2 commit 3c1a1f3

File tree

2 files changed

+41
-30
lines changed

2 files changed

+41
-30
lines changed

compiler/rustc_lint/src/expect.rs

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
use crate::builtin;
2-
use rustc_errors::fluent;
3-
use rustc_hir::HirId;
1+
#![deny(rustc::untranslatable_diagnostic)]
2+
#![deny(rustc::diagnostic_outside_of_impl)]
3+
use crate::lints::Expectation;
44
use rustc_middle::ty::query::Providers;
5-
use rustc_middle::{lint::LintExpectation, ty::TyCtxt};
5+
use rustc_middle::ty::TyCtxt;
6+
use rustc_session::lint::builtin::UNFULFILLED_LINT_EXPECTATIONS;
67
use rustc_session::lint::LintExpectationId;
78
use rustc_span::symbol::sym;
89
use rustc_span::Symbol;
@@ -28,34 +29,15 @@ fn check_expectations(tcx: TyCtxt<'_>, tool_filter: Option<Symbol>) {
2829
if !fulfilled_expectations.contains(&id)
2930
&& tool_filter.map_or(true, |filter| expectation.lint_tool == Some(filter))
3031
{
31-
emit_unfulfilled_expectation_lint(tcx, *hir_id, expectation);
32+
tcx.emit_spanned_lint(
33+
UNFULFILLED_LINT_EXPECTATIONS,
34+
*hir_id,
35+
expectation.emission_span,
36+
Expectation { expectation },
37+
);
3238
}
3339
} else {
3440
unreachable!("at this stage all `LintExpectationId`s are stable");
3541
}
3642
}
3743
}
38-
39-
fn emit_unfulfilled_expectation_lint(
40-
tcx: TyCtxt<'_>,
41-
hir_id: HirId,
42-
expectation: &LintExpectation,
43-
) {
44-
tcx.struct_span_lint_hir(
45-
builtin::UNFULFILLED_LINT_EXPECTATIONS,
46-
hir_id,
47-
expectation.emission_span,
48-
fluent::lint_expectation,
49-
|lint| {
50-
if let Some(rationale) = expectation.reason {
51-
lint.note(rationale.as_str());
52-
}
53-
54-
if expectation.is_unfulfilled_lint_expectations {
55-
lint.note(fluent::note);
56-
}
57-
58-
lint
59-
},
60-
);
61-
}

compiler/rustc_lint/src/lints.rs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ use std::num::NonZeroU32;
33
use rustc_errors::{fluent, AddToDiagnostic, Applicability, DecorateLint, DiagnosticMessage};
44
use rustc_hir::def_id::DefId;
55
use rustc_macros::{LintDiagnostic, Subdiagnostic};
6-
use rustc_middle::ty::{Predicate, Ty, TyCtxt};
6+
use rustc_middle::{
7+
lint::LintExpectation,
8+
ty::{Predicate, Ty, TyCtxt},
9+
};
710
use rustc_span::{edition::Edition, symbol::Ident, Span, Symbol};
811

912
use crate::{errors::OverruledAttributeSub, LateContext};
@@ -304,6 +307,32 @@ pub struct EnumIntrinsicsMemVariant<'a> {
304307
pub ty_param: Ty<'a>,
305308
}
306309

310+
// expect.rs
311+
pub struct Expectation<'a> {
312+
pub expectation: &'a LintExpectation,
313+
}
314+
315+
impl<'a> DecorateLint<'a, ()> for Expectation<'_> {
316+
fn decorate_lint<'b>(
317+
self,
318+
diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>,
319+
) -> &'b mut rustc_errors::DiagnosticBuilder<'a, ()> {
320+
if let Some(rationale) = self.expectation.reason {
321+
diag.note(rationale.as_str());
322+
}
323+
324+
if self.expectation.is_unfulfilled_lint_expectations {
325+
diag.note(fluent::note);
326+
}
327+
328+
diag
329+
}
330+
331+
fn msg(&self) -> DiagnosticMessage {
332+
fluent::lint_expectation
333+
}
334+
}
335+
307336
// internal.rs
308337
#[derive(LintDiagnostic)]
309338
#[diag(lint_default_hash_types)]

0 commit comments

Comments
 (0)