Skip to content

Commit 8004e6a

Browse files
committed
Make early lints translatable
1 parent b7abf01 commit 8004e6a

27 files changed

+1176
-550
lines changed

compiler/rustc_ast_passes/src/ast_validation.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1510,7 +1510,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
15101510
DEPRECATED_WHERE_CLAUSE_LOCATION,
15111511
item.id,
15121512
err.span,
1513-
BuiltinLintDiag::DeprecatedWhereclauseLocation(sugg),
1513+
BuiltinLintDiag::DeprecatedWhereclauseLocation(err.span, sugg),
15141514
);
15151515
}
15161516

compiler/rustc_expand/src/base.rs

+8-10
Original file line numberDiff line numberDiff line change
@@ -1364,17 +1364,15 @@ fn pretty_printing_compatibility_hack(item: &Item, sess: &Session) -> bool {
13641364
};
13651365

13661366
if crate_matches {
1367-
// FIXME: make this translatable
1368-
#[allow(rustc::untranslatable_diagnostic)]
13691367
sess.psess.buffer_lint_with_diagnostic(
1370-
PROC_MACRO_BACK_COMPAT,
1371-
item.ident.span,
1372-
ast::CRATE_NODE_ID,
1373-
BuiltinLintDiag::ProcMacroBackCompat(
1374-
"older versions of the `rental` crate will stop compiling in future versions of Rust; \
1375-
please update to `rental` v0.5.6, or switch to one of the `rental` alternatives".to_string()
1376-
)
1377-
);
1368+
PROC_MACRO_BACK_COMPAT,
1369+
item.ident.span,
1370+
ast::CRATE_NODE_ID,
1371+
BuiltinLintDiag::ProcMacroBackCompat {
1372+
crate_name: "rental".to_string(),
1373+
fixed_version: "0.5.6".to_string(),
1374+
},
1375+
);
13781376
return true;
13791377
}
13801378
}

compiler/rustc_lint/messages.ftl

+176-2
Large diffs are not rendered by default.

compiler/rustc_lint/src/context.rs

+8-13
Original file line numberDiff line numberDiff line change
@@ -527,29 +527,24 @@ pub struct EarlyContext<'a> {
527527
pub buffered: LintBuffer,
528528
}
529529

530-
pub trait LintContext {
531-
fn sess(&self) -> &Session;
532-
530+
impl EarlyContext<'_> {
533531
/// Emit a lint at the appropriate level, with an optional associated span and an existing
534532
/// diagnostic.
535533
///
536534
/// [`lint_level`]: rustc_middle::lint::lint_level#decorate-signature
537535
#[rustc_lint_diagnostics]
538-
fn span_lint_with_diagnostics(
536+
pub fn span_lint_with_diagnostics(
539537
&self,
540538
lint: &'static Lint,
541-
span: Option<impl Into<MultiSpan>>,
542-
decorate: impl for<'a, 'b> FnOnce(&'b mut Diag<'a, ()>),
539+
span: MultiSpan,
543540
diagnostic: BuiltinLintDiag,
544541
) {
545-
// We first generate a blank diagnostic.
546-
self.opt_span_lint(lint, span, diagnostics::builtin_message(&diagnostic), |db| {
547-
// Now, set up surrounding context.
548-
diagnostics::builtin(self.sess(), diagnostic, db);
549-
// Rewrap `db`, and pass control to the user.
550-
decorate(db)
551-
});
542+
diagnostics::emit_buffered_lint(self, lint, span, diagnostic)
552543
}
544+
}
545+
546+
pub trait LintContext {
547+
fn sess(&self) -> &Session;
553548

554549
// FIXME: These methods should not take an Into<MultiSpan> -- instead, callers should need to
555550
// set the span in their `decorate` function (preferably using set_span).

0 commit comments

Comments
 (0)