Skip to content

Commit 55b2e8a

Browse files
Convert to inline diagnostics in rustc_lint
1 parent cf16cd9 commit 55b2e8a

17 files changed

Lines changed: 1301 additions & 1797 deletions

Cargo.lock

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4148,7 +4148,6 @@ dependencies = [
41484148
"rustc_data_structures",
41494149
"rustc_errors",
41504150
"rustc_feature",
4151-
"rustc_fluent_macro",
41524151
"rustc_hir",
41534152
"rustc_index",
41544153
"rustc_infer",

compiler/rustc_driver_impl/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ pub static DEFAULT_LOCALE_RESOURCES: &[&str] = &[
117117
rustc_borrowck::DEFAULT_LOCALE_RESOURCE,
118118
rustc_const_eval::DEFAULT_LOCALE_RESOURCE,
119119
rustc_hir_analysis::DEFAULT_LOCALE_RESOURCE,
120-
rustc_lint::DEFAULT_LOCALE_RESOURCE,
121120
rustc_mir_build::DEFAULT_LOCALE_RESOURCE,
122121
rustc_parse::DEFAULT_LOCALE_RESOURCE,
123122
rustc_passes::DEFAULT_LOCALE_RESOURCE,

compiler/rustc_lint/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ rustc_attr_parsing = { path = "../rustc_attr_parsing" }
1414
rustc_data_structures = { path = "../rustc_data_structures" }
1515
rustc_errors = { path = "../rustc_errors" }
1616
rustc_feature = { path = "../rustc_feature" }
17-
rustc_fluent_macro = { path = "../rustc_fluent_macro" }
1817
rustc_hir = { path = "../rustc_hir" }
1918
rustc_index = { path = "../rustc_index" }
2019
rustc_infer = { path = "../rustc_infer" }

compiler/rustc_lint/messages.ftl

Lines changed: 0 additions & 1081 deletions
This file was deleted.

compiler/rustc_lint/src/async_closures.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,16 +108,18 @@ impl<'tcx> LateLintPass<'tcx> for AsyncClosureUsage {
108108
}
109109

110110
#[derive(LintDiagnostic)]
111-
#[diag(lint_closure_returning_async_block)]
111+
#[diag("closure returning async block can be made into an async closure")]
112112
struct ClosureReturningAsyncBlock {
113-
#[label]
113+
#[label(
114+
"this async block can be removed, and the closure can be turned into an async closure"
115+
)]
114116
async_decl_span: Span,
115117
#[subdiagnostic]
116118
sugg: AsyncClosureSugg,
117119
}
118120

119121
#[derive(Subdiagnostic)]
120-
#[multipart_suggestion(lint_suggestion, applicability = "maybe-incorrect")]
122+
#[multipart_suggestion("turn this into an async closure", applicability = "maybe-incorrect")]
121123
struct AsyncClosureSugg {
122124
#[suggestion_part(code = "")]
123125
deletion_span: Span,

compiler/rustc_lint/src/builtin.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use rustc_ast::visit::{FnCtxt, FnKind};
2222
use rustc_ast::{self as ast, *};
2323
use rustc_ast_pretty::pprust::expr_to_string;
2424
use rustc_attr_parsing::AttributeParser;
25-
use rustc_errors::{Applicability, LintDiagnostic};
25+
use rustc_errors::{Applicability, LintDiagnostic, inline_fluent};
2626
use rustc_feature::GateIssue;
2727
use rustc_hir as hir;
2828
use rustc_hir::attrs::{AttributeKind, DocAttribute};
@@ -61,10 +61,7 @@ use crate::lints::{
6161
BuiltinUnreachablePub, BuiltinUnsafe, BuiltinUnstableFeatures, BuiltinUnusedDocComment,
6262
BuiltinUnusedDocCommentSub, BuiltinWhileTrue, InvalidAsmLabel,
6363
};
64-
use crate::{
65-
EarlyContext, EarlyLintPass, LateContext, LateLintPass, Level, LintContext,
66-
fluent_generated as fluent,
67-
};
64+
use crate::{EarlyContext, EarlyLintPass, LateContext, LateLintPass, Level, LintContext};
6865
declare_lint! {
6966
/// The `while_true` lint detects `while true { }`.
7067
///
@@ -2655,8 +2652,12 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue {
26552652
let conjured_ty = cx.typeck_results().expr_ty(expr);
26562653
if let Some(err) = with_no_trimmed_paths!(ty_find_init_error(cx, conjured_ty, init)) {
26572654
let msg = match init {
2658-
InitKind::Zeroed => fluent::lint_builtin_unpermitted_type_init_zeroed,
2659-
InitKind::Uninit => fluent::lint_builtin_unpermitted_type_init_uninit,
2655+
InitKind::Zeroed => {
2656+
inline_fluent!("the type `{$ty}` does not permit zero-initialization")
2657+
}
2658+
InitKind::Uninit => {
2659+
inline_fluent!("the type `{$ty}` does not permit being left uninitialized")
2660+
}
26602661
};
26612662
let sub = BuiltinUnpermittedTypeInitSub { err };
26622663
cx.emit_span_lint(

compiler/rustc_lint/src/errors.rs

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
use rustc_errors::codes::*;
2-
use rustc_errors::{Diag, EmissionGuarantee, Subdiagnostic};
2+
use rustc_errors::{Diag, EmissionGuarantee, Subdiagnostic, inline_fluent};
33
use rustc_macros::{Diagnostic, Subdiagnostic};
44
use rustc_session::lint::Level;
55
use rustc_span::{Span, Symbol};
66

7-
use crate::fluent_generated as fluent;
8-
97
#[derive(Diagnostic)]
10-
#[diag(lint_overruled_attribute, code = E0453)]
8+
#[diag("{$lint_level}({$lint_source}) incompatible with previous forbid", code = E0453)]
119
pub(crate) struct OverruledAttribute<'a> {
1210
#[primary_span]
1311
pub span: Span,
14-
#[label]
12+
#[label("overruled by previous forbid")]
1513
pub overruled: Span,
1614
pub lint_level: &'a str,
1715
pub lint_source: Symbol,
@@ -29,24 +27,24 @@ impl Subdiagnostic for OverruledAttributeSub {
2927
fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
3028
match self {
3129
OverruledAttributeSub::DefaultSource { id } => {
32-
diag.note(fluent::lint_default_source);
30+
diag.note(inline_fluent!("`forbid` lint level is the default for {$id}"));
3331
diag.arg("id", id);
3432
}
3533
OverruledAttributeSub::NodeSource { span, reason } => {
36-
diag.span_label(span, fluent::lint_node_source);
34+
diag.span_label(span, inline_fluent!("`forbid` level set here"));
3735
if let Some(rationale) = reason {
3836
diag.note(rationale.to_string());
3937
}
4038
}
4139
OverruledAttributeSub::CommandLineSource => {
42-
diag.note(fluent::lint_command_line_source);
40+
diag.note(inline_fluent!("`forbid` lint level was set on command line"));
4341
}
4442
}
4543
}
4644
}
4745

4846
#[derive(Diagnostic)]
49-
#[diag(lint_malformed_attribute, code = E0452)]
47+
#[diag("malformed lint attribute input", code = E0452)]
5048
pub(crate) struct MalformedAttribute {
5149
#[primary_span]
5250
pub span: Span,
@@ -56,50 +54,55 @@ pub(crate) struct MalformedAttribute {
5654

5755
#[derive(Subdiagnostic)]
5856
pub(crate) enum MalformedAttributeSub {
59-
#[label(lint_bad_attribute_argument)]
57+
#[label("bad attribute argument")]
6058
BadAttributeArgument(#[primary_span] Span),
61-
#[label(lint_reason_must_be_string_literal)]
59+
#[label("reason must be a string literal")]
6260
ReasonMustBeStringLiteral(#[primary_span] Span),
63-
#[label(lint_reason_must_come_last)]
61+
#[label("reason in lint attribute must come last")]
6462
ReasonMustComeLast(#[primary_span] Span),
6563
}
6664

6765
#[derive(Diagnostic)]
68-
#[diag(lint_unknown_tool_in_scoped_lint, code = E0710)]
66+
#[diag("unknown tool name `{$tool_name}` found in scoped lint: `{$tool_name}::{$lint_name}`", code = E0710)]
6967
pub(crate) struct UnknownToolInScopedLint {
7068
#[primary_span]
7169
pub span: Option<Span>,
7270
pub tool_name: Symbol,
7371
pub lint_name: String,
74-
#[help]
72+
#[help("add `#![register_tool({$tool_name})]` to the crate root")]
7573
pub is_nightly_build: bool,
7674
}
7775

7876
#[derive(Diagnostic)]
79-
#[diag(lint_builtin_ellipsis_inclusive_range_patterns, code = E0783)]
77+
#[diag("`...` range patterns are deprecated", code = E0783)]
8078
pub(crate) struct BuiltinEllipsisInclusiveRangePatterns {
8179
#[primary_span]
8280
pub span: Span,
83-
#[suggestion(style = "short", code = "{replace}", applicability = "machine-applicable")]
81+
#[suggestion(
82+
"use `..=` for an inclusive range",
83+
style = "short",
84+
code = "{replace}",
85+
applicability = "machine-applicable"
86+
)]
8487
pub suggestion: Span,
8588
pub replace: String,
8689
}
8790

8891
#[derive(Subdiagnostic)]
89-
#[note(lint_requested_level)]
92+
#[note("requested on the command line with `{$level} {$lint_name}`")]
9093
pub(crate) struct RequestedLevel<'a> {
9194
pub level: Level,
9295
pub lint_name: &'a str,
9396
}
9497

9598
#[derive(Diagnostic)]
96-
#[diag(lint_unsupported_group, code = E0602)]
99+
#[diag("`{$lint_group}` lint group is not supported with ´--force-warn´", code = E0602)]
97100
pub(crate) struct UnsupportedGroup {
98101
pub lint_group: String,
99102
}
100103

101104
#[derive(Diagnostic)]
102-
#[diag(lint_check_name_unknown_tool, code = E0602)]
105+
#[diag("unknown lint tool: `{$tool_name}`", code = E0602)]
103106
pub(crate) struct CheckNameUnknownTool<'a> {
104107
pub tool_name: Symbol,
105108
#[subdiagnostic]

compiler/rustc_lint/src/if_let_rescope.rs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ use std::ops::ControlFlow;
33

44
use hir::intravisit::{self, Visitor};
55
use rustc_ast::Recovered;
6-
use rustc_errors::{Applicability, Diag, EmissionGuarantee, Subdiagnostic, SuggestionStyle};
6+
use rustc_errors::{
7+
Applicability, Diag, EmissionGuarantee, Subdiagnostic, SuggestionStyle, inline_fluent,
8+
};
79
use rustc_hir::{self as hir, HirIdSet};
810
use rustc_macros::{LintDiagnostic, Subdiagnostic};
911
use rustc_middle::ty::adjustment::Adjust;
@@ -303,13 +305,15 @@ impl<'tcx> LateLintPass<'tcx> for IfLetRescope {
303305
}
304306

305307
#[derive(LintDiagnostic)]
306-
#[diag(lint_if_let_rescope)]
308+
#[diag("`if let` assigns a shorter lifetime since Edition 2024")]
307309
struct IfLetRescopeLint {
308310
#[subdiagnostic]
309311
destructors: Vec<DestructorLabel>,
310-
#[label]
312+
#[label(
313+
"this value has a significant drop implementation which may observe a major change in drop order and requires your discretion"
314+
)]
311315
significant_droppers: Vec<Span>,
312-
#[help]
316+
#[help("the value is now dropped here in Edition 2024")]
313317
lifetime_ends: Vec<Span>,
314318
#[subdiagnostic]
315319
rewrite: Option<IfLetRescopeRewrite>,
@@ -352,7 +356,9 @@ impl Subdiagnostic for IfLetRescopeRewrite {
352356
.chain(repeat_n('}', closing_brackets.count))
353357
.collect(),
354358
));
355-
let msg = diag.eagerly_translate(crate::fluent_generated::lint_suggestion);
359+
let msg = diag.eagerly_translate(inline_fluent!(
360+
"a `match` with a single arm can preserve the drop order up to Edition 2021"
361+
));
356362
diag.multipart_suggestion_with_style(
357363
msg,
358364
suggestions,
@@ -363,7 +369,12 @@ impl Subdiagnostic for IfLetRescopeRewrite {
363369
}
364370

365371
#[derive(Subdiagnostic)]
366-
#[note(lint_if_let_dtor)]
372+
#[note(
373+
"{$dtor_kind ->
374+
[dyn] value may invoke a custom destructor because it contains a trait object
375+
*[concrete] value invokes this custom destructor
376+
}"
377+
)]
367378
struct DestructorLabel {
368379
#[primary_span]
369380
span: Span,

compiler/rustc_lint/src/impl_trait_overcaptures.rs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::cell::LazyCell;
33
use rustc_data_structures::debug_assert_matches;
44
use rustc_data_structures::fx::{FxHashMap, FxIndexMap, FxIndexSet};
55
use rustc_data_structures::unord::UnordSet;
6-
use rustc_errors::{LintDiagnostic, Subdiagnostic};
6+
use rustc_errors::{LintDiagnostic, Subdiagnostic, inline_fluent};
77
use rustc_hir as hir;
88
use rustc_hir::def::DefKind;
99
use rustc_hir::def_id::{DefId, LocalDefId};
@@ -28,7 +28,7 @@ use rustc_trait_selection::errors::{
2828
use rustc_trait_selection::regions::OutlivesEnvironmentBuildExt;
2929
use rustc_trait_selection::traits::ObligationCtxt;
3030

31-
use crate::{LateContext, LateLintPass, fluent_generated as fluent};
31+
use crate::{LateContext, LateLintPass};
3232

3333
declare_lint! {
3434
/// The `impl_trait_overcaptures` lint warns against cases where lifetime
@@ -435,21 +435,33 @@ struct ImplTraitOvercapturesLint<'tcx> {
435435

436436
impl<'a> LintDiagnostic<'a, ()> for ImplTraitOvercapturesLint<'_> {
437437
fn decorate_lint<'b>(self, diag: &'b mut rustc_errors::Diag<'a, ()>) {
438-
diag.primary_message(fluent::lint_impl_trait_overcaptures);
438+
diag.primary_message(inline_fluent!(
439+
"`{$self_ty}` will capture more lifetimes than possibly intended in edition 2024"
440+
));
439441
diag.arg("self_ty", self.self_ty.to_string())
440442
.arg("num_captured", self.num_captured)
441-
.span_note(self.uncaptured_spans, fluent::lint_note)
442-
.note(fluent::lint_note2);
443+
.span_note(
444+
self.uncaptured_spans,
445+
inline_fluent!(
446+
"specifically, {$num_captured ->
447+
[one] this lifetime is
448+
*[other] these lifetimes are
449+
} in scope but not mentioned in the type's bounds"
450+
),
451+
)
452+
.note(inline_fluent!(
453+
"all lifetimes in scope will be captured by `impl Trait`s in edition 2024"
454+
));
443455
if let Some(suggestion) = self.suggestion {
444456
suggestion.add_to_diag(diag);
445457
}
446458
}
447459
}
448460

449461
#[derive(LintDiagnostic)]
450-
#[diag(lint_impl_trait_redundant_captures)]
462+
#[diag("all possible in-scope parameters are already captured, so `use<...>` syntax is redundant")]
451463
struct ImplTraitRedundantCapturesLint {
452-
#[suggestion(lint_suggestion, code = "", applicability = "machine-applicable")]
464+
#[suggestion("remove the `use<...>` syntax", code = "", applicability = "machine-applicable")]
453465
capturing_span: Span,
454466
}
455467

compiler/rustc_lint/src/levels.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use rustc_ast::attr::AttributeExt;
22
use rustc_ast_pretty::pprust;
33
use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
44
use rustc_data_structures::unord::UnordSet;
5-
use rustc_errors::{Diag, LintDiagnostic, MultiSpan};
5+
use rustc_errors::{Diag, LintDiagnostic, MultiSpan, inline_fluent};
66
use rustc_feature::{Features, GateIssue};
77
use rustc_hir::HirId;
88
use rustc_hir::intravisit::{self, Visitor};
@@ -31,7 +31,6 @@ use crate::errors::{
3131
CheckNameUnknownTool, MalformedAttribute, MalformedAttributeSub, OverruledAttribute,
3232
OverruledAttributeSub, RequestedLevel, UnknownToolInScopedLint, UnsupportedGroup,
3333
};
34-
use crate::fluent_generated as fluent;
3534
use crate::late::unerased_lint_store;
3635
use crate::lints::{
3736
DeprecatedLintName, DeprecatedLintNameFromCommandLine, IgnoredUnlessCrateSpecified,
@@ -942,9 +941,9 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
942941
let lint = builtin::UNKNOWN_LINTS;
943942
let level = self.lint_level(builtin::UNKNOWN_LINTS);
944943
lint_level(self.sess, lint, level, Some(span.into()), |lint| {
945-
lint.primary_message(fluent::lint_unknown_gated_lint);
944+
lint.primary_message(inline_fluent!("unknown lint: `{$name}`"));
946945
lint.arg("name", lint_id.lint.name_lower());
947-
lint.note(fluent::lint_note);
946+
lint.note(inline_fluent!("the `{$name}` lint is unstable"));
948947
rustc_session::parse::add_feature_diagnostics_for_issue(
949948
lint,
950949
&self.sess,

0 commit comments

Comments
 (0)