Skip to content

Commit 362f064

Browse files
committed
Make early lints translatable
1 parent a2f6c3b commit 362f064

30 files changed

+1180
-612
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-8
Original file line numberDiff line numberDiff line change
@@ -1555,14 +1555,14 @@ fn pretty_printing_compatibility_hack(item: &Item, sess: &Session) -> bool {
15551555
// FIXME: make this translatable
15561556
#[allow(rustc::untranslatable_diagnostic)]
15571557
sess.psess.buffer_lint_with_diagnostic(
1558-
PROC_MACRO_BACK_COMPAT,
1559-
item.ident.span,
1560-
ast::CRATE_NODE_ID,
1561-
BuiltinLintDiag::ProcMacroBackCompat(
1562-
"older versions of the `rental` crate will stop compiling in future versions of Rust; \
1563-
please update to `rental` v0.5.6, or switch to one of the `rental` alternatives".to_string()
1564-
)
1565-
);
1558+
PROC_MACRO_BACK_COMPAT,
1559+
item.ident.span,
1560+
ast::CRATE_NODE_ID,
1561+
BuiltinLintDiag::ProcMacroBackCompat {
1562+
crate_name: "rental".to_string(),
1563+
fixed_version: "0.5.6".to_string(),
1564+
},
1565+
);
15661566
return true;
15671567
}
15681568
}

compiler/rustc_lint/messages.ftl

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

compiler/rustc_lint/src/context.rs

+8-13
Original file line numberDiff line numberDiff line change
@@ -524,29 +524,24 @@ pub struct EarlyContext<'a> {
524524
pub buffered: LintBuffer,
525525
}
526526

527-
pub trait LintContext {
528-
fn sess(&self) -> &Session;
529-
527+
impl<'c> EarlyContext<'c> {
530528
/// Emit a lint at the appropriate level, with an optional associated span and an existing
531529
/// diagnostic.
532530
///
533531
/// [`lint_level`]: rustc_middle::lint::lint_level#decorate-signature
534532
#[rustc_lint_diagnostics]
535-
fn span_lint_with_diagnostics(
533+
pub fn span_lint_with_diagnostics(
536534
&self,
537535
lint: &'static Lint,
538-
span: Option<impl Into<MultiSpan>>,
539-
decorate: impl for<'a, 'b> FnOnce(&'b mut Diag<'a, ()>),
536+
span: MultiSpan,
540537
diagnostic: BuiltinLintDiag,
541538
) {
542-
// We first generate a blank diagnostic.
543-
self.opt_span_lint(lint, span, diagnostics::builtin_message(&diagnostic), |db| {
544-
// Now, set up surrounding context.
545-
diagnostics::builtin(self.sess(), diagnostic, db);
546-
// Rewrap `db`, and pass control to the user.
547-
decorate(db)
548-
});
539+
diagnostics::emit_buffered_lint(self, lint, span, diagnostic)
549540
}
541+
}
542+
543+
pub trait LintContext {
544+
fn sess(&self) -> &Session;
550545

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

0 commit comments

Comments
 (0)