Skip to content

Commit 4edd58f

Browse files
committed
Make early lints translatable
1 parent 30f1697 commit 4edd58f

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
@@ -1379,14 +1379,14 @@ fn pretty_printing_compatibility_hack(item: &Item, sess: &Session) -> bool {
13791379
// FIXME: make this translatable
13801380
#[allow(rustc::untranslatable_diagnostic)]
13811381
sess.psess.buffer_lint_with_diagnostic(
1382-
PROC_MACRO_BACK_COMPAT,
1383-
item.ident.span,
1384-
ast::CRATE_NODE_ID,
1385-
BuiltinLintDiag::ProcMacroBackCompat(
1386-
"older versions of the `rental` crate will stop compiling in future versions of Rust; \
1387-
please update to `rental` v0.5.6, or switch to one of the `rental` alternatives".to_string()
1388-
)
1389-
);
1382+
PROC_MACRO_BACK_COMPAT,
1383+
item.ident.span,
1384+
ast::CRATE_NODE_ID,
1385+
BuiltinLintDiag::ProcMacroBackCompat {
1386+
crate_name: "rental".to_string(),
1387+
fixed_version: "0.5.6".to_string(),
1388+
},
1389+
);
13901390
return true;
13911391
}
13921392
}

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)