Skip to content

Commit a0a5cff

Browse files
authored
Rollup merge of rust-lang#98420 - davidtwco:translation-lint-fixes-and-more-migration, r=compiler-errors
translation: lint fix + more migration - Unfortunately, the diagnostic lints are very broken and trigger much more often than they should. This PR corrects the conditional which checks if the function call being made is to a diagnostic function so that it returns in every intended case. - The `rustc_lint_diagnostics` attribute is used by the diagnostic translation/struct migration lints to identify calls where non-translatable diagnostics or diagnostics outwith impls are being created. Any function used in creating a diagnostic should be annotated with this attribute so this PR adds the attribute to many more functions. - Port the diagnostics from the `rustc_privacy` crate and enable the lints for that crate. r? `@compiler-errors`
2 parents cfda49b + 15d61d7 commit a0a5cff

File tree

14 files changed

+188
-47
lines changed

14 files changed

+188
-47
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4280,6 +4280,7 @@ dependencies = [
42804280
"rustc_data_structures",
42814281
"rustc_errors",
42824282
"rustc_hir",
4283+
"rustc_macros",
42834284
"rustc_middle",
42844285
"rustc_session",
42854286
"rustc_span",

compiler/rustc_borrowck/src/borrowck_errors.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
use rustc_errors::{struct_span_err, DiagnosticBuilder, DiagnosticId, ErrorGuaranteed, MultiSpan};
1+
use rustc_errors::{
2+
struct_span_err, DiagnosticBuilder, DiagnosticId, DiagnosticMessage, ErrorGuaranteed, MultiSpan,
3+
};
24
use rustc_middle::ty::{self, Ty, TyCtxt};
35
use rustc_span::Span;
46

@@ -476,10 +478,11 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
476478
struct_span_err!(self, span, E0716, "temporary value dropped while borrowed",)
477479
}
478480

481+
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
479482
fn struct_span_err_with_code<S: Into<MultiSpan>>(
480483
&self,
481484
sp: S,
482-
msg: &str,
485+
msg: impl Into<DiagnosticMessage>,
483486
code: DiagnosticId,
484487
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
485488
self.infcx.tcx.sess.struct_span_err_with_code(sp, msg, code)

compiler/rustc_borrowck/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#![feature(let_else)]
77
#![feature(min_specialization)]
88
#![feature(never_type)]
9+
#![feature(rustc_attrs)]
910
#![feature(stmt_expr_attributes)]
1011
#![feature(trusted_step)]
1112
#![feature(try_blocks)]
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
privacy-field-is-private = field `{$field_name}` of {$variant_descr} `{$def_path_str}` is private
2+
privacy-field-is-private-is-update-syntax-label = field `{$field_name}` is private
3+
privacy-field-is-private-label = private field
4+
5+
privacy-item-is-private = {$kind} `{$descr}` is private
6+
.label = private {$kind}
7+
privacy-unnamed-item-is-private = {$kind} is private
8+
.label = private {$kind}
9+
10+
privacy-in-public-interface = {$vis_descr} {$kind} `{$descr}` in public interface
11+
.label = can't leak {$vis_descr} {$kind}
12+
.visibility-label = `{$descr}` declared as {$vis_descr}

compiler/rustc_error_messages/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ pub use unic_langid::{langid, LanguageIdentifier};
3232
// Generates `DEFAULT_LOCALE_RESOURCES` static and `fluent_generated` module.
3333
fluent_messages! {
3434
parser => "../locales/en-US/parser.ftl",
35+
privacy => "../locales/en-US/privacy.ftl",
3536
typeck => "../locales/en-US/typeck.ftl",
3637
builtin_macros => "../locales/en-US/builtin_macros.ftl",
3738
}

compiler/rustc_expand/src/base.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,6 +1077,7 @@ impl<'a> ExtCtxt<'a> {
10771077
self.current_expansion.id.expansion_cause()
10781078
}
10791079

1080+
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
10801081
pub fn struct_span_err<S: Into<MultiSpan>>(
10811082
&self,
10821083
sp: S,
@@ -1101,9 +1102,11 @@ impl<'a> ExtCtxt<'a> {
11011102
///
11021103
/// Compilation will be stopped in the near future (at the end of
11031104
/// the macro expansion phase).
1105+
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
11041106
pub fn span_err<S: Into<MultiSpan>>(&self, sp: S, msg: &str) {
11051107
self.sess.parse_sess.span_diagnostic.span_err(sp, msg);
11061108
}
1109+
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
11071110
pub fn span_warn<S: Into<MultiSpan>>(&self, sp: S, msg: &str) {
11081111
self.sess.parse_sess.span_diagnostic.span_warn(sp, msg);
11091112
}

compiler/rustc_expand/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#![feature(proc_macro_diagnostic)]
1010
#![feature(proc_macro_internals)]
1111
#![feature(proc_macro_span)]
12+
#![feature(rustc_attrs)]
1213
#![feature(try_blocks)]
1314
#![recursion_limit = "256"]
1415

compiler/rustc_lint/src/internal.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -406,9 +406,12 @@ impl LateLintPass<'_> for Diagnostics {
406406
fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) {
407407
let Some((span, def_id, substs)) = typeck_results_of_method_fn(cx, expr) else { return };
408408
debug!(?span, ?def_id, ?substs);
409-
if let Ok(Some(instance)) = ty::Instance::resolve(cx.tcx, cx.param_env, def_id, substs) &&
410-
!cx.tcx.has_attr(instance.def_id(), sym::rustc_lint_diagnostics)
411-
{
409+
let has_attr = ty::Instance::resolve(cx.tcx, cx.param_env, def_id, substs)
410+
.ok()
411+
.and_then(|inst| inst)
412+
.map(|inst| cx.tcx.has_attr(inst.def_id(), sym::rustc_lint_diagnostics))
413+
.unwrap_or(false);
414+
if !has_attr {
412415
return;
413416
}
414417

compiler/rustc_parse/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#![feature(let_chains)]
77
#![feature(let_else)]
88
#![feature(never_type)]
9+
#![feature(rustc_attrs)]
910
#![recursion_limit = "256"]
1011

1112
#[macro_use]

compiler/rustc_parse/src/parser/diagnostics.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,7 @@ impl<'a> DerefMut for SnapshotParser<'a> {
357357
}
358358

359359
impl<'a> Parser<'a> {
360+
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
360361
pub(super) fn span_err<S: Into<MultiSpan>>(
361362
&self,
362363
sp: S,
@@ -365,6 +366,7 @@ impl<'a> Parser<'a> {
365366
err.span_err(sp, self.diagnostic())
366367
}
367368

369+
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
368370
pub fn struct_span_err<S: Into<MultiSpan>>(
369371
&self,
370372
sp: S,

0 commit comments

Comments
 (0)