Skip to content

Commit eb5690a

Browse files
committed
Make early lints translatable
1 parent 5c0b367 commit eb5690a

31 files changed

+1181
-610
lines changed

compiler/rustc_ast_passes/src/ast_validation.rs

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

compiler/rustc_expand/src/base.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -1367,14 +1367,14 @@ fn pretty_printing_compatibility_hack(item: &Item, sess: &Session) -> bool {
13671367
// FIXME: make this translatable
13681368
#[allow(rustc::untranslatable_diagnostic)]
13691369
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-
);
1370+
PROC_MACRO_BACK_COMPAT,
1371+
item.ident.span,
1372+
ast::CRATE_NODE_ID,
1373+
BuiltinLintDiag::ProcMacroBackCompat {
1374+
crate_name: "rental".to_string(),
1375+
fixed_version: "0.5.6".to_string(),
1376+
},
1377+
);
13781378
return true;
13791379
}
13801380
}

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
@@ -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<'c> EarlyContext<'c> {
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)