1use rustc_errors::codes::*;
2use rustc_errors::{DiagArgFromDisplay, MultiSpan};
3use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
4use rustc_span::{Span, Symbol};
5
6#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for FieldIsPrivate
where G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
FieldIsPrivate {
span: __binding_0,
struct_span: __binding_1,
field_names: __binding_2,
variant_descr: __binding_3,
def_path_str: __binding_4,
labels: __binding_5,
len: __binding_6 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$len ->\n [1] field\n *[other] fields\n} {$field_names} of {$variant_descr} `{$def_path_str}` {$len ->\n [1] is\n *[other] are\n} private")));
diag.code(E0451);
;
diag.arg("field_names", __binding_2);
diag.arg("variant_descr", __binding_3);
diag.arg("def_path_str", __binding_4);
diag.arg("len", __binding_6);
diag.span(__binding_0);
if let Some(__binding_1) = __binding_1 {
diag.span_label(__binding_1,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("in this type")));
}
for __binding_5 in __binding_5 {
diag.subdiagnostic(__binding_5);
}
diag
}
}
}
}
};Diagnostic)]
7#[diag("{$len ->
8 [1] field
9 *[other] fields
10} {$field_names} of {$variant_descr} `{$def_path_str}` {$len ->
11 [1] is
12 *[other] are
13} private", code = E0451)]
14pub(crate) struct FieldIsPrivate {
15 #[primary_span]
16 pub span: MultiSpan,
17 #[label("in this type")]
18 pub struct_span: Option<Span>,
19 pub field_names: String,
20 pub variant_descr: &'static str,
21 pub def_path_str: String,
22 #[subdiagnostic]
23 pub labels: Vec<FieldIsPrivateLabel>,
24 pub len: usize,
25}
26
27#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for FieldIsPrivateLabel {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
FieldIsPrivateLabel::IsUpdateSyntax {
span: __binding_0,
rest_field_names: __binding_1,
rest_len: __binding_2 } => {
diag.store_args();
diag.arg("rest_field_names", __binding_1);
diag.arg("rest_len", __binding_2);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$rest_len ->\n [1] field\n *[other] fields\n } {$rest_field_names} {$rest_len ->\n [1] is\n *[other] are\n } private")));
diag.span_label(__binding_0, __message);
diag.restore_args();
}
FieldIsPrivateLabel::Other { span: __binding_0 } => {
diag.store_args();
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("private field")));
diag.span_label(__binding_0, __message);
diag.restore_args();
}
}
}
}
};Subdiagnostic)]
28pub(crate) enum FieldIsPrivateLabel {
29 #[label(
30 "{$rest_len ->
31 [1] field
32 *[other] fields
33 } {$rest_field_names} {$rest_len ->
34 [1] is
35 *[other] are
36 } private"
37 )]
38 IsUpdateSyntax {
39 #[primary_span]
40 span: Span,
41 rest_field_names: String,
42 rest_len: usize,
43 },
44 #[label("private field")]
45 Other {
46 #[primary_span]
47 span: Span,
48 },
49}
50
51#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
ItemIsPrivate<'a> where G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
ItemIsPrivate {
span: __binding_0, kind: __binding_1, descr: __binding_2 }
=> {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$kind} `{$descr}` is private")));
;
diag.arg("kind", __binding_1);
diag.arg("descr", __binding_2);
diag.span(__binding_0);
diag.span_label(__binding_0,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("private {$kind}")));
diag
}
}
}
}
};Diagnostic)]
52#[diag("{$kind} `{$descr}` is private")]
53pub(crate) struct ItemIsPrivate<'a> {
54 #[primary_span]
55 #[label("private {$kind}")]
56 pub span: Span,
57 pub kind: &'a str,
58 pub descr: DiagArgFromDisplay<'a>,
59}
60
61#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
UnnamedItemIsPrivate where G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
UnnamedItemIsPrivate { span: __binding_0, kind: __binding_1
} => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$kind} is private")));
;
diag.arg("kind", __binding_1);
diag.span(__binding_0);
diag
}
}
}
}
};Diagnostic)]
62#[diag("{$kind} is private")]
63pub(crate) struct UnnamedItemIsPrivate {
64 #[primary_span]
65 pub span: Span,
66 pub kind: &'static str,
67}
68
69#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
InPublicInterface<'a> where G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
InPublicInterface {
span: __binding_0,
vis_descr: __binding_1,
kind: __binding_2,
descr: __binding_3,
vis_span: __binding_4 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$vis_descr} {$kind} `{$descr}` in public interface")));
diag.code(E0446);
;
diag.arg("vis_descr", __binding_1);
diag.arg("kind", __binding_2);
diag.arg("descr", __binding_3);
diag.span(__binding_0);
diag.span_label(__binding_0,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("can't leak {$vis_descr} {$kind}")));
diag.span_label(__binding_4,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`{$descr}` declared as {$vis_descr}")));
diag
}
}
}
}
};Diagnostic)]
70#[diag("{$vis_descr} {$kind} `{$descr}` in public interface", code = E0446)]
71pub(crate) struct InPublicInterface<'a> {
72 #[primary_span]
73 #[label("can't leak {$vis_descr} {$kind}")]
74 pub span: Span,
75 pub vis_descr: &'static str,
76 pub kind: &'a str,
77 pub descr: DiagArgFromDisplay<'a>,
78 #[label("`{$descr}` declared as {$vis_descr}")]
79 pub vis_span: Span,
80}
81
82#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
ReportEffectiveVisibility where G: rustc_errors::EmissionGuarantee
{
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
ReportEffectiveVisibility {
span: __binding_0, descr: __binding_1 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$descr}")));
;
diag.arg("descr", __binding_1);
diag.span(__binding_0);
diag
}
}
}
}
};Diagnostic)]
83#[diag("{$descr}")]
84pub(crate) struct ReportEffectiveVisibility {
85 #[primary_span]
86 pub span: Span,
87 pub descr: String,
88}
89
90#[derive(const _: () =
{
impl<'__a, 'a> rustc_errors::LintDiagnostic<'__a, ()> for
FromPrivateDependencyInPublicInterface<'a> {
#[track_caller]
fn decorate_lint<'__b>(self,
diag: &'__b mut rustc_errors::Diag<'__a, ()>) {
match self {
FromPrivateDependencyInPublicInterface {
kind: __binding_0, descr: __binding_1, krate: __binding_2 }
=> {
diag.primary_message(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$kind} `{$descr}` from private dependency '{$krate}' in public interface")));
;
diag.arg("kind", __binding_0);
diag.arg("descr", __binding_1);
diag.arg("krate", __binding_2);
diag
}
};
}
}
};LintDiagnostic)]
91#[diag("{$kind} `{$descr}` from private dependency '{$krate}' in public interface")]
92pub(crate) struct FromPrivateDependencyInPublicInterface<'a> {
93 pub kind: &'a str,
94 pub descr: DiagArgFromDisplay<'a>,
95 pub krate: Symbol,
96}
97
98#[derive(const _: () =
{
impl<'__a, 'a> rustc_errors::LintDiagnostic<'__a, ()> for
UnnameableTypesLint<'a> {
#[track_caller]
fn decorate_lint<'__b>(self,
diag: &'__b mut rustc_errors::Diag<'__a, ()>) {
match self {
UnnameableTypesLint {
span: __binding_0,
kind: __binding_1,
descr: __binding_2,
reachable_vis: __binding_3,
reexported_vis: __binding_4 } => {
diag.primary_message(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$kind} `{$descr}` is reachable but cannot be named")));
;
diag.arg("kind", __binding_1);
diag.arg("descr", __binding_2);
diag.arg("reachable_vis", __binding_3);
diag.arg("reexported_vis", __binding_4);
diag.span_label(__binding_0,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("reachable at visibility `{$reachable_vis}`, but can only be named at visibility `{$reexported_vis}`")));
diag
}
};
}
}
};LintDiagnostic)]
99#[diag("{$kind} `{$descr}` is reachable but cannot be named")]
100pub(crate) struct UnnameableTypesLint<'a> {
101 #[label(
102 "reachable at visibility `{$reachable_vis}`, but can only be named at visibility `{$reexported_vis}`"
103 )]
104 pub span: Span,
105 pub kind: &'a str,
106 pub descr: DiagArgFromDisplay<'a>,
107 pub reachable_vis: &'a str,
108 pub reexported_vis: &'a str,
109}
110
111#[derive(const _: () =
{
impl<'__a, 'a> rustc_errors::LintDiagnostic<'__a, ()> for
PrivateInterfacesOrBoundsLint<'a> {
#[track_caller]
fn decorate_lint<'__b>(self,
diag: &'__b mut rustc_errors::Diag<'__a, ()>) {
match self {
PrivateInterfacesOrBoundsLint {
item_span: __binding_0,
item_kind: __binding_1,
item_descr: __binding_2,
item_vis_descr: __binding_3,
ty_span: __binding_4,
ty_kind: __binding_5,
ty_descr: __binding_6,
ty_vis_descr: __binding_7 } => {
diag.primary_message(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$ty_kind} `{$ty_descr}` is more private than the item `{$item_descr}`")));
;
diag.arg("item_kind", __binding_1);
diag.arg("item_descr", __binding_2);
diag.arg("item_vis_descr", __binding_3);
diag.arg("ty_kind", __binding_5);
diag.arg("ty_descr", __binding_6);
diag.arg("ty_vis_descr", __binding_7);
diag.span_label(__binding_0,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$item_kind} `{$item_descr}` is reachable at visibility `{$item_vis_descr}`")));
diag.span_note(__binding_4,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("but {$ty_kind} `{$ty_descr}` is only usable at visibility `{$ty_vis_descr}`")));
diag
}
};
}
}
};LintDiagnostic)]
115#[diag("{$ty_kind} `{$ty_descr}` is more private than the item `{$item_descr}`")]
116pub(crate) struct PrivateInterfacesOrBoundsLint<'a> {
117 #[label("{$item_kind} `{$item_descr}` is reachable at visibility `{$item_vis_descr}`")]
118 pub item_span: Span,
119 pub item_kind: &'a str,
120 pub item_descr: DiagArgFromDisplay<'a>,
121 pub item_vis_descr: &'a str,
122 #[note("but {$ty_kind} `{$ty_descr}` is only usable at visibility `{$ty_vis_descr}`")]
123 pub ty_span: Span,
124 pub ty_kind: &'a str,
125 pub ty_descr: DiagArgFromDisplay<'a>,
126 pub ty_vis_descr: &'a str,
127}