Skip to content

Commit

Permalink
Make early lints translatable
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiretza committed Apr 27, 2024
1 parent 30f1697 commit 4edd58f
Show file tree
Hide file tree
Showing 30 changed files with 1,180 additions and 612 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_ast_passes/src/ast_validation.rs
Expand Up @@ -1510,7 +1510,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
DEPRECATED_WHERE_CLAUSE_LOCATION,
item.id,
err.span,
BuiltinLintDiag::DeprecatedWhereclauseLocation(sugg),
BuiltinLintDiag::DeprecatedWhereclauseLocation(err.span, sugg),
);
}

Expand Down
16 changes: 8 additions & 8 deletions compiler/rustc_expand/src/base.rs
Expand Up @@ -1379,14 +1379,14 @@ fn pretty_printing_compatibility_hack(item: &Item, sess: &Session) -> bool {
// FIXME: make this translatable
#[allow(rustc::untranslatable_diagnostic)]
sess.psess.buffer_lint_with_diagnostic(
PROC_MACRO_BACK_COMPAT,
item.ident.span,
ast::CRATE_NODE_ID,
BuiltinLintDiag::ProcMacroBackCompat(
"older versions of the `rental` crate will stop compiling in future versions of Rust; \
please update to `rental` v0.5.6, or switch to one of the `rental` alternatives".to_string()
)
);
PROC_MACRO_BACK_COMPAT,
item.ident.span,
ast::CRATE_NODE_ID,
BuiltinLintDiag::ProcMacroBackCompat {
crate_name: "rental".to_string(),
fixed_version: "0.5.6".to_string(),
},
);
return true;
}
}
Expand Down
183 changes: 181 additions & 2 deletions compiler/rustc_lint/messages.ftl

Large diffs are not rendered by default.

21 changes: 8 additions & 13 deletions compiler/rustc_lint/src/context.rs
Expand Up @@ -524,29 +524,24 @@ pub struct EarlyContext<'a> {
pub buffered: LintBuffer,
}

pub trait LintContext {
fn sess(&self) -> &Session;

impl<'c> EarlyContext<'c> {
/// Emit a lint at the appropriate level, with an optional associated span and an existing
/// diagnostic.
///
/// [`lint_level`]: rustc_middle::lint::lint_level#decorate-signature
#[rustc_lint_diagnostics]
fn span_lint_with_diagnostics(
pub fn span_lint_with_diagnostics(
&self,
lint: &'static Lint,
span: Option<impl Into<MultiSpan>>,
decorate: impl for<'a, 'b> FnOnce(&'b mut Diag<'a, ()>),
span: MultiSpan,
diagnostic: BuiltinLintDiag,
) {
// We first generate a blank diagnostic.
self.opt_span_lint(lint, span, diagnostics::builtin_message(&diagnostic), |db| {
// Now, set up surrounding context.
diagnostics::builtin(self.sess(), diagnostic, db);
// Rewrap `db`, and pass control to the user.
decorate(db)
});
diagnostics::emit_buffered_lint(self, lint, span, diagnostic)
}
}

pub trait LintContext {
fn sess(&self) -> &Session;

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

0 comments on commit 4edd58f

Please sign in to comment.