Skip to content

Commit 8f63c00

Browse files
Migrate rustc_passes to use TyCtxt::emit_diag_node_span_lint
1 parent f02ce96 commit 8f63c00

5 files changed

Lines changed: 66 additions & 54 deletions

File tree

compiler/rustc_middle/src/middle/stability.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use std::num::NonZero;
55

66
use rustc_ast::NodeId;
7-
use rustc_errors::{Applicability, Diag, EmissionGuarantee, LintBuffer, msg};
7+
use rustc_errors::{Applicability, Diag, EmissionGuarantee, LintBuffer, LintDiagnostic, msg};
88
use rustc_feature::GateIssue;
99
use rustc_hir::attrs::{DeprecatedSince, Deprecation};
1010
use rustc_hir::def_id::{DefId, LocalDefId};
@@ -125,7 +125,19 @@ pub struct Deprecated {
125125
pub since_kind: DeprecatedSinceKind,
126126
}
127127

128-
impl<'a, G: EmissionGuarantee> rustc_errors::LintDiagnostic<'a, G> for Deprecated {
128+
impl<'a, G: EmissionGuarantee> rustc_errors::Diagnostic<'a, G> for Deprecated {
129+
fn into_diag(
130+
self,
131+
dcx: rustc_errors::DiagCtxtHandle<'a>,
132+
level: rustc_errors::Level,
133+
) -> Diag<'a, G> {
134+
let mut diag = Diag::new(dcx, level, "");
135+
self.decorate_lint(&mut diag);
136+
diag
137+
}
138+
}
139+
140+
impl<'a, G: EmissionGuarantee> LintDiagnostic<'a, G> for Deprecated {
129141
fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, G>) {
130142
diag.primary_message(match &self.since_kind {
131143
DeprecatedSinceKind::InEffect => msg!(
@@ -245,7 +257,7 @@ fn late_report_deprecation(
245257
note: depr.note.map(|ident| ident.name),
246258
since_kind: deprecated_since_kind(is_in_effect, depr.since),
247259
};
248-
tcx.emit_node_span_lint(lint, hir_id, method_span, diag);
260+
tcx.emit_diag_node_span_lint(lint, hir_id, method_span, diag);
249261
}
250262

251263
/// Result of `TyCtxt::eval_stability`.

compiler/rustc_passes/src/check_attr.rs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use rustc_hir::{
3333
Item, ItemKind, MethodKind, Node, ParamName, PartialConstStability, Safety, Stability,
3434
StabilityLevel, Target, TraitItem, find_attr,
3535
};
36-
use rustc_macros::LintDiagnostic;
36+
use rustc_macros::Diagnostic;
3737
use rustc_middle::hir::nested_filter;
3838
use rustc_middle::middle::resolve_bound_vars::ObjectLifetimeDefault;
3939
use rustc_middle::query::Providers;
@@ -57,18 +57,18 @@ use tracing::debug;
5757

5858
use crate::errors;
5959

60-
#[derive(LintDiagnostic)]
60+
#[derive(Diagnostic)]
6161
#[diag("`#[diagnostic::on_unimplemented]` can only be applied to trait definitions")]
6262
struct DiagnosticOnUnimplementedOnlyForTraits;
6363

64-
#[derive(LintDiagnostic)]
64+
#[derive(Diagnostic)]
6565
#[diag("`#[diagnostic::on_const]` can only be applied to trait impls")]
6666
struct DiagnosticOnConstOnlyForTraitImpls {
6767
#[label("not a trait impl")]
6868
item_span: Span,
6969
}
7070

71-
#[derive(LintDiagnostic)]
71+
#[derive(Diagnostic)]
7272
#[diag("`#[diagnostic::on_const]` can only be applied to non-const trait impls")]
7373
struct DiagnosticOnConstOnlyForNonConstTraitImpls {
7474
#[label("this is a const trait impl")]
@@ -453,7 +453,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
453453
.span_until_char(attr_span, '[')
454454
.shrink_to_hi();
455455

456-
self.tcx.emit_node_span_lint(
456+
self.tcx.emit_diag_node_span_lint(
457457
UNUSED_ATTRIBUTES,
458458
hir_id,
459459
attr.span,
@@ -464,7 +464,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
464464
},
465465
)
466466
}
467-
ast::AttrStyle::Inner => self.tcx.emit_node_span_lint(
467+
ast::AttrStyle::Inner => self.tcx.emit_diag_node_span_lint(
468468
UNUSED_ATTRIBUTES,
469469
hir_id,
470470
attr.span,
@@ -595,7 +595,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
595595
if _impl.of_trait.is_none()
596596
)
597597
{
598-
self.tcx.emit_node_span_lint(
598+
self.tcx.emit_diag_node_span_lint(
599599
MISPLACED_DIAGNOSTIC_ATTRIBUTES,
600600
hir_id,
601601
attr_span,
@@ -613,7 +613,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
613613
directive: Option<&Directive>,
614614
) {
615615
if !matches!(target, Target::Trait) {
616-
self.tcx.emit_node_span_lint(
616+
self.tcx.emit_diag_node_span_lint(
617617
MISPLACED_DIAGNOSTIC_ATTRIBUTES,
618618
hir_id,
619619
attr_span,
@@ -668,7 +668,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
668668
ItemLike::Item(it) => match it.expect_impl().constness {
669669
Constness::Const => {
670670
let item_span = self.tcx.hir_span(hir_id);
671-
self.tcx.emit_node_span_lint(
671+
self.tcx.emit_diag_node_span_lint(
672672
MISPLACED_DIAGNOSTIC_ATTRIBUTES,
673673
hir_id,
674674
attr_span,
@@ -682,7 +682,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
682682
}
683683
}
684684
let item_span = self.tcx.hir_span(hir_id);
685-
self.tcx.emit_node_span_lint(
685+
self.tcx.emit_diag_node_span_lint(
686686
MISPLACED_DIAGNOSTIC_ATTRIBUTES,
687687
hir_id,
688688
attr_span,
@@ -707,11 +707,11 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
707707
let attrs = self.tcx.codegen_fn_attrs(did);
708708
// Not checking naked as `#[inline]` is forbidden for naked functions anyways.
709709
if attrs.contains_extern_indicator() {
710-
self.tcx.emit_node_span_lint(
710+
self.tcx.emit_diag_node_span_lint(
711711
UNUSED_ATTRIBUTES,
712712
hir_id,
713713
attr_span,
714-
errors::InlineIgnoredForExported {},
714+
errors::InlineIgnoredForExported,
715715
);
716716
}
717717
}
@@ -1058,7 +1058,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
10581058
match target {
10591059
Target::Use | Target::ExternCrate => {}
10601060
_ => {
1061-
self.tcx.emit_node_span_lint(
1061+
self.tcx.emit_diag_node_span_lint(
10621062
INVALID_DOC_ATTRIBUTES,
10631063
hir_id,
10641064
span,
@@ -1073,7 +1073,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
10731073

10741074
fn check_doc_masked(&self, span: Span, hir_id: HirId, target: Target) {
10751075
if target != Target::ExternCrate {
1076-
self.tcx.emit_node_span_lint(
1076+
self.tcx.emit_diag_node_span_lint(
10771077
INVALID_DOC_ATTRIBUTES,
10781078
hir_id,
10791079
span,
@@ -1086,7 +1086,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
10861086
}
10871087

10881088
if self.tcx.extern_mod_stmt_cnum(hir_id.owner.def_id).is_none() {
1089-
self.tcx.emit_node_span_lint(
1089+
self.tcx.emit_diag_node_span_lint(
10901090
INVALID_DOC_ATTRIBUTES,
10911091
hir_id,
10921092
span,
@@ -1238,7 +1238,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
12381238
return;
12391239
}
12401240

1241-
self.tcx.emit_node_span_lint(
1241+
self.tcx.emit_diag_node_span_lint(
12421242
UNUSED_ATTRIBUTES,
12431243
hir_id,
12441244
attr_span,
@@ -1475,7 +1475,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
14751475
if let ItemLike::Item(item) = item { is_c_like_enum(item) } else { false }
14761476
}))
14771477
{
1478-
self.tcx.emit_node_span_lint(
1478+
self.tcx.emit_diag_node_span_lint(
14791479
CONFLICTING_REPR_HINTS,
14801480
hir_id,
14811481
hint_spans.collect::<Vec<Span>>(),
@@ -1571,7 +1571,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
15711571
if self.tcx.def_kind(self.tcx.local_parent(hir_id.owner.def_id))
15721572
== DefKind::Impl { of_trait: true } =>
15731573
{
1574-
self.tcx.emit_node_span_lint(
1574+
self.tcx.emit_diag_node_span_lint(
15751575
UNUSED_ATTRIBUTES,
15761576
hir_id,
15771577
attr_span,
@@ -1592,7 +1592,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
15921592
let is_decl_macro = !macro_definition.macro_rules;
15931593

15941594
if is_decl_macro {
1595-
self.tcx.emit_node_span_lint(
1595+
self.tcx.emit_diag_node_span_lint(
15961596
UNUSED_ATTRIBUTES,
15971597
hir_id,
15981598
attr_span,
@@ -1644,7 +1644,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
16441644
.span_until_char(attr_span, '[')
16451645
.shrink_to_hi();
16461646

1647-
self.tcx.emit_node_span_lint(
1647+
self.tcx.emit_diag_node_span_lint(
16481648
UNUSED_ATTRIBUTES,
16491649
hir_id,
16501650
attr_span,
@@ -1655,7 +1655,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
16551655
},
16561656
)
16571657
}
1658-
Some(ast::AttrStyle::Inner) | None => self.tcx.emit_node_span_lint(
1658+
Some(ast::AttrStyle::Inner) | None => self.tcx.emit_diag_node_span_lint(
16591659
UNUSED_ATTRIBUTES,
16601660
hir_id,
16611661
attr.span(),
@@ -1681,7 +1681,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
16811681
return;
16821682
};
16831683

1684-
self.tcx.emit_node_span_lint(
1684+
self.tcx.emit_diag_node_span_lint(
16851685
UNUSED_ATTRIBUTES,
16861686
hir_id,
16871687
attr.span(),
@@ -1849,7 +1849,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
18491849
"#[export_name]"
18501850
};
18511851

1852-
self.tcx.emit_node_span_lint(
1852+
self.tcx.emit_diag_node_span_lint(
18531853
lint::builtin::UNUSED_ATTRIBUTES,
18541854
hir_id,
18551855
no_mangle_span,
@@ -2193,7 +2193,7 @@ fn check_duplicates(
21932193
} else {
21942194
(attr_span, *entry.get())
21952195
};
2196-
tcx.emit_node_span_lint(
2196+
tcx.emit_diag_node_span_lint(
21972197
UNUSED_ATTRIBUTES,
21982198
hir_id,
21992199
this,

compiler/rustc_passes/src/dead.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
232232
&& !assign.span.from_expansion()
233233
{
234234
let is_field_assign = matches!(lhs.kind, hir::ExprKind::Field(..));
235-
self.tcx.emit_node_span_lint(
235+
self.tcx.emit_diag_node_span_lint(
236236
lint::builtin::DEAD_CODE,
237237
assign.hir_id,
238238
assign.span,
@@ -1104,7 +1104,7 @@ impl<'tcx> DeadVisitor<'tcx> {
11041104
};
11051105

11061106
let hir_id = tcx.local_def_id_to_hir_id(first_item.def_id);
1107-
self.tcx.emit_node_span_lint(DEAD_CODE, hir_id, MultiSpan::from_spans(spans), diag);
1107+
self.tcx.emit_diag_node_span_lint(DEAD_CODE, hir_id, MultiSpan::from_spans(spans), diag);
11081108
}
11091109

11101110
fn warn_multiple(

0 commit comments

Comments
 (0)