Rollup merge of #152069 - JonathanBrouwer:convert_privacy, r=lqd

Convert to inline diagnostics in `rustc_privacy`

For https://github.com/rust-lang/rust/issues/151366

r? @jdonszelmann
This commit is contained in:
Jonathan Brouwer 2026-02-04 14:39:25 +01:00 committed by GitHub
commit ecafacdeb7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 33 additions and 63 deletions

View file

@ -3803,7 +3803,6 @@ dependencies = [
"rustc_parse",
"rustc_passes",
"rustc_pattern_analysis",
"rustc_privacy",
"rustc_public",
"rustc_resolve",
"rustc_session",
@ -4485,7 +4484,6 @@ dependencies = [
"rustc_ast",
"rustc_data_structures",
"rustc_errors",
"rustc_fluent_macro",
"rustc_hir",
"rustc_macros",
"rustc_middle",

View file

@ -37,7 +37,6 @@ rustc_monomorphize = { path = "../rustc_monomorphize" }
rustc_parse = { path = "../rustc_parse" }
rustc_passes = { path = "../rustc_passes" }
rustc_pattern_analysis = { path = "../rustc_pattern_analysis" }
rustc_privacy = { path = "../rustc_privacy" }
rustc_public = { path = "../rustc_public", features = ["rustc_internal"] }
rustc_resolve = { path = "../rustc_resolve" }
rustc_session = { path = "../rustc_session" }

View file

@ -133,7 +133,6 @@ pub static DEFAULT_LOCALE_RESOURCES: &[&str] = &[
rustc_parse::DEFAULT_LOCALE_RESOURCE,
rustc_passes::DEFAULT_LOCALE_RESOURCE,
rustc_pattern_analysis::DEFAULT_LOCALE_RESOURCE,
rustc_privacy::DEFAULT_LOCALE_RESOURCE,
rustc_resolve::DEFAULT_LOCALE_RESOURCE,
rustc_trait_selection::DEFAULT_LOCALE_RESOURCE,
// tidy-alphabetical-end

View file

@ -8,7 +8,6 @@ edition = "2024"
rustc_ast = { path = "../rustc_ast" }
rustc_data_structures = { path = "../rustc_data_structures" }
rustc_errors = { path = "../rustc_errors" }
rustc_fluent_macro = { path = "../rustc_fluent_macro" }
rustc_hir = { path = "../rustc_hir" }
rustc_macros = { path = "../rustc_macros" }
rustc_middle = { path = "../rustc_middle" }

View file

@ -1,39 +0,0 @@
privacy_field_is_private =
{$len ->
[1] field
*[other] fields
} {$field_names} of {$variant_descr} `{$def_path_str}` {$len ->
[1] is
*[other] are
} private
.label = in this type
privacy_field_is_private_is_update_syntax_label = {$rest_len ->
[1] field
*[other] fields
} {$rest_field_names} {$rest_len ->
[1] is
*[other] are
} private
privacy_field_is_private_label = private field
privacy_from_private_dep_in_public_interface =
{$kind} `{$descr}` from private dependency '{$krate}' in public interface
privacy_in_public_interface = {$vis_descr} {$kind} `{$descr}` in public interface
.label = can't leak {$vis_descr} {$kind}
.visibility_label = `{$descr}` declared as {$vis_descr}
privacy_item_is_private = {$kind} `{$descr}` is private
.label = private {$kind}
privacy_private_interface_or_bounds_lint = {$ty_kind} `{$ty_descr}` is more private than the item `{$item_descr}`
.item_label = {$item_kind} `{$item_descr}` is reachable at visibility `{$item_vis_descr}`
.ty_note = but {$ty_kind} `{$ty_descr}` is only usable at visibility `{$ty_vis_descr}`
privacy_report_effective_visibility = {$descr}
privacy_unnameable_types_lint = {$kind} `{$descr}` is reachable but cannot be named
.label = reachable at visibility `{$reachable_vis}`, but can only be named at visibility `{$reexported_vis}`
privacy_unnamed_item_is_private = {$kind} is private
.label = private {$kind}

View file

@ -4,11 +4,17 @@ use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
use rustc_span::{Span, Symbol};
#[derive(Diagnostic)]
#[diag(privacy_field_is_private, code = E0451)]
#[diag("{$len ->
[1] field
*[other] fields
} {$field_names} of {$variant_descr} `{$def_path_str}` {$len ->
[1] is
*[other] are
} private", code = E0451)]
pub(crate) struct FieldIsPrivate {
#[primary_span]
pub span: MultiSpan,
#[label]
#[label("in this type")]
pub struct_span: Option<Span>,
pub field_names: String,
pub variant_descr: &'static str,
@ -20,14 +26,22 @@ pub(crate) struct FieldIsPrivate {
#[derive(Subdiagnostic)]
pub(crate) enum FieldIsPrivateLabel {
#[label(privacy_field_is_private_is_update_syntax_label)]
#[label(
"{$rest_len ->
[1] field
*[other] fields
} {$rest_field_names} {$rest_len ->
[1] is
*[other] are
} private"
)]
IsUpdateSyntax {
#[primary_span]
span: Span,
rest_field_names: String,
rest_len: usize,
},
#[label(privacy_field_is_private_label)]
#[label("private field")]
Other {
#[primary_span]
span: Span,
@ -35,17 +49,17 @@ pub(crate) enum FieldIsPrivateLabel {
}
#[derive(Diagnostic)]
#[diag(privacy_item_is_private)]
#[diag("{$kind} `{$descr}` is private")]
pub(crate) struct ItemIsPrivate<'a> {
#[primary_span]
#[label]
#[label("private {$kind}")]
pub span: Span,
pub kind: &'a str,
pub descr: DiagArgFromDisplay<'a>,
}
#[derive(Diagnostic)]
#[diag(privacy_unnamed_item_is_private)]
#[diag("{$kind} is private")]
pub(crate) struct UnnamedItemIsPrivate {
#[primary_span]
pub span: Span,
@ -53,20 +67,20 @@ pub(crate) struct UnnamedItemIsPrivate {
}
#[derive(Diagnostic)]
#[diag(privacy_in_public_interface, code = E0446)]
#[diag("{$vis_descr} {$kind} `{$descr}` in public interface", code = E0446)]
pub(crate) struct InPublicInterface<'a> {
#[primary_span]
#[label]
#[label("can't leak {$vis_descr} {$kind}")]
pub span: Span,
pub vis_descr: &'static str,
pub kind: &'a str,
pub descr: DiagArgFromDisplay<'a>,
#[label(privacy_visibility_label)]
#[label("`{$descr}` declared as {$vis_descr}")]
pub vis_span: Span,
}
#[derive(Diagnostic)]
#[diag(privacy_report_effective_visibility)]
#[diag("{$descr}")]
pub(crate) struct ReportEffectiveVisibility {
#[primary_span]
pub span: Span,
@ -74,7 +88,7 @@ pub(crate) struct ReportEffectiveVisibility {
}
#[derive(LintDiagnostic)]
#[diag(privacy_from_private_dep_in_public_interface)]
#[diag("{$kind} `{$descr}` from private dependency '{$krate}' in public interface")]
pub(crate) struct FromPrivateDependencyInPublicInterface<'a> {
pub kind: &'a str,
pub descr: DiagArgFromDisplay<'a>,
@ -82,9 +96,11 @@ pub(crate) struct FromPrivateDependencyInPublicInterface<'a> {
}
#[derive(LintDiagnostic)]
#[diag(privacy_unnameable_types_lint)]
#[diag("{$kind} `{$descr}` is reachable but cannot be named")]
pub(crate) struct UnnameableTypesLint<'a> {
#[label]
#[label(
"reachable at visibility `{$reachable_vis}`, but can only be named at visibility `{$reexported_vis}`"
)]
pub span: Span,
pub kind: &'a str,
pub descr: DiagArgFromDisplay<'a>,
@ -96,14 +112,14 @@ pub(crate) struct UnnameableTypesLint<'a> {
// They will replace private-in-public errors and compatibility lints in future.
// See https://rust-lang.github.io/rfcs/2145-type-privacy.html for more details.
#[derive(LintDiagnostic)]
#[diag(privacy_private_interface_or_bounds_lint)]
#[diag("{$ty_kind} `{$ty_descr}` is more private than the item `{$item_descr}`")]
pub(crate) struct PrivateInterfacesOrBoundsLint<'a> {
#[label(privacy_item_label)]
#[label("{$item_kind} `{$item_descr}` is reachable at visibility `{$item_vis_descr}`")]
pub item_span: Span,
pub item_kind: &'a str,
pub item_descr: DiagArgFromDisplay<'a>,
pub item_vis_descr: &'a str,
#[note(privacy_ty_note)]
#[note("but {$ty_kind} `{$ty_descr}` is only usable at visibility `{$ty_vis_descr}`")]
pub ty_span: Span,
pub ty_kind: &'a str,
pub ty_descr: DiagArgFromDisplay<'a>,

View file

@ -39,8 +39,6 @@ use rustc_span::hygiene::Transparency;
use rustc_span::{Ident, Span, Symbol, sym};
use tracing::debug;
rustc_fluent_macro::fluent_messages! { "../messages.ftl" }
////////////////////////////////////////////////////////////////////////////////
// Generic infrastructure used to implement specific visitors below.
////////////////////////////////////////////////////////////////////////////////