1use std::num::NonZero;
3
4use rustc_data_structures::fx::FxIndexMap;
5use rustc_errors::codes::*;
6use rustc_errors::formatting::DiagMessageAddArg;
7use rustc_errors::{
8 Applicability, Diag, DiagCtxtHandle, DiagMessage, DiagStyledString, Diagnostic,
9 EmissionGuarantee, Level, Subdiagnostic, SuggestionStyle, msg,
10};
11use rustc_hir as hir;
12use rustc_hir::def_id::DefId;
13use rustc_hir::intravisit::VisitorExt;
14use rustc_macros::{Diagnostic, Subdiagnostic};
15use rustc_middle::ty::inhabitedness::InhabitedPredicate;
16use rustc_middle::ty::{Clause, PolyExistentialTraitRef, Ty, TyCtxt};
17use rustc_session::Session;
18use rustc_span::edition::Edition;
19use rustc_span::{Ident, Span, Symbol, sym};
20
21use crate::LateContext;
22use crate::builtin::{InitError, ShorthandAssocTyCollector, TypeAliasBounds};
23use crate::lifetime_syntax::LifetimeSyntaxCategories;
24
25#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
OverruledAttribute<'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 {
OverruledAttribute {
span: __binding_0,
overruled: __binding_1,
lint_level: __binding_2,
lint_source: __binding_3,
sub: __binding_4 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$lint_level}({$lint_source}) incompatible with previous forbid")));
diag.code(E0453);
;
diag.arg("lint_level", __binding_2);
diag.arg("lint_source", __binding_3);
diag.span(__binding_0);
diag.span_label(__binding_1,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("overruled by previous forbid")));
diag.subdiagnostic(__binding_4);
diag
}
}
}
}
};Diagnostic)]
26#[diag("{$lint_level}({$lint_source}) incompatible with previous forbid", code = E0453)]
27pub(crate) struct OverruledAttribute<'a> {
28 #[primary_span]
29 pub span: Span,
30 #[label("overruled by previous forbid")]
31 pub overruled: Span,
32 pub lint_level: &'a str,
33 pub lint_source: Symbol,
34 #[subdiagnostic]
35 pub sub: OverruledAttributeSub,
36}
37
38pub(crate) enum OverruledAttributeSub {
39 DefaultSource { id: String },
40 NodeSource { span: Span, reason: Option<Symbol> },
41 CommandLineSource { id: Symbol },
42}
43
44impl Subdiagnostic for OverruledAttributeSub {
45 fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
46 match self {
47 OverruledAttributeSub::DefaultSource { id } => {
48 diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`forbid` lint level is the default for {$id}"))msg!("`forbid` lint level is the default for {$id}"));
49 diag.arg("id", id);
50 }
51 OverruledAttributeSub::NodeSource { span, reason } => {
52 diag.span_label(span, rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`forbid` level set here"))msg!("`forbid` level set here"));
53 if let Some(rationale) = reason {
54 diag.note(rationale.to_string());
55 }
56 }
57 OverruledAttributeSub::CommandLineSource { id } => {
58 diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`forbid` lint level was set on command line (`-F {$id}`)"))msg!("`forbid` lint level was set on command line (`-F {$id}`)"));
59 diag.arg("id", id);
60 }
61 }
62 }
63}
64
65#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
MalformedAttribute 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 {
MalformedAttribute { span: __binding_0, sub: __binding_1 }
=> {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("malformed lint attribute input")));
diag.code(E0452);
;
diag.span(__binding_0);
diag.subdiagnostic(__binding_1);
diag
}
}
}
}
};Diagnostic)]
66#[diag("malformed lint attribute input", code = E0452)]
67pub(crate) struct MalformedAttribute {
68 #[primary_span]
69 pub span: Span,
70 #[subdiagnostic]
71 pub sub: MalformedAttributeSub,
72}
73
74#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for MalformedAttributeSub {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
MalformedAttributeSub::BadAttributeArgument(__binding_0) =>
{
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("bad attribute argument")),
&sub_args);
diag.span_label(__binding_0, __message);
}
MalformedAttributeSub::ReasonMustBeStringLiteral(__binding_0)
=> {
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("reason must be a string literal")),
&sub_args);
diag.span_label(__binding_0, __message);
}
MalformedAttributeSub::ReasonMustComeLast(__binding_0) => {
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("reason in lint attribute must come last")),
&sub_args);
diag.span_label(__binding_0, __message);
}
}
}
}
};Subdiagnostic)]
75pub(crate) enum MalformedAttributeSub {
76 #[label("bad attribute argument")]
77 BadAttributeArgument(#[primary_span] Span),
78 #[label("reason must be a string literal")]
79 ReasonMustBeStringLiteral(#[primary_span] Span),
80 #[label("reason in lint attribute must come last")]
81 ReasonMustComeLast(#[primary_span] Span),
82}
83
84#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
UnknownToolInScopedLint 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 {
UnknownToolInScopedLint {
span: __binding_0,
tool_name: __binding_1,
lint_name: __binding_2,
is_nightly_build: __binding_3 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("unknown tool name `{$tool_name}` found in scoped lint: `{$tool_name}::{$lint_name}`")));
diag.code(E0710);
;
diag.arg("tool_name", __binding_1);
diag.arg("lint_name", __binding_2);
if let Some(__binding_0) = __binding_0 {
diag.span(__binding_0);
}
if __binding_3 {
diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("add `#![register_tool({$tool_name})]` to the crate root")));
}
diag
}
}
}
}
};Diagnostic)]
85#[diag("unknown tool name `{$tool_name}` found in scoped lint: `{$tool_name}::{$lint_name}`", code = E0710)]
86pub(crate) struct UnknownToolInScopedLint {
87 #[primary_span]
88 pub span: Option<Span>,
89 pub tool_name: Symbol,
90 pub lint_name: String,
91 #[help("add `#![register_tool({$tool_name})]` to the crate root")]
92 pub is_nightly_build: bool,
93}
94
95#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
BuiltinNoMangleGeneric 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 {
BuiltinNoMangleGeneric {
span: __binding_0, suggestion: __binding_1 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("functions generic over types or consts must be mangled")));
let __code_2 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!(""))
})].into_iter();
;
diag.span(__binding_0);
diag.span_suggestions_with_style(__binding_1,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("remove this attribute")),
__code_2, rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::HideCodeInline);
diag
}
}
}
}
};Diagnostic)]
96#[diag("functions generic over types or consts must be mangled")]
97pub(crate) struct BuiltinNoMangleGeneric {
98 #[primary_span]
99 pub span: Span,
100 #[suggestion(
103 "remove this attribute",
104 style = "short",
105 code = "",
106 applicability = "maybe-incorrect"
107 )]
108 pub suggestion: Span,
109}
110
111#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
BuiltinEllipsisInclusiveRangePatterns 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 {
BuiltinEllipsisInclusiveRangePatterns {
span: __binding_0,
suggestion: __binding_1,
replace: __binding_2 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`...` range patterns are deprecated")));
let __code_3 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0}", __binding_2))
})].into_iter();
diag.code(E0783);
;
diag.span(__binding_0);
diag.span_suggestions_with_style(__binding_1,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("use `..=` for an inclusive range")),
__code_3, rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::HideCodeInline);
diag
}
}
}
}
};Diagnostic)]
112#[diag("`...` range patterns are deprecated", code = E0783)]
113pub(crate) struct BuiltinEllipsisInclusiveRangePatterns {
114 #[primary_span]
115 pub span: Span,
116 #[suggestion(
117 "use `..=` for an inclusive range",
118 style = "short",
119 code = "{replace}",
120 applicability = "machine-applicable"
121 )]
122 pub suggestion: Span,
123 pub replace: String,
124}
125
126#[derive(const _: () =
{
impl<'a> rustc_errors::Subdiagnostic for RequestedLevel<'a> {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
RequestedLevel { level: __binding_0, lint_name: __binding_1
} => {
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("level".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_0,
&mut diag.long_ty_path));
sub_args.insert("lint_name".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_1,
&mut diag.long_ty_path));
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("requested on the command line with `{$level} {$lint_name}`")),
&sub_args);
diag.note(__message);
}
}
}
}
};Subdiagnostic)]
127#[note("requested on the command line with `{$level} {$lint_name}`")]
128pub(crate) struct RequestedLevel<'a> {
129 pub level: rustc_session::lint::Level,
130 pub lint_name: &'a str,
131}
132
133#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
UnsupportedGroup 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 {
UnsupportedGroup { lint_group: __binding_0 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`{$lint_group}` lint group is not supported with ´--force-warn´")));
diag.code(E0602);
;
diag.arg("lint_group", __binding_0);
diag
}
}
}
}
};Diagnostic)]
134#[diag("`{$lint_group}` lint group is not supported with ´--force-warn´", code = E0602)]
135pub(crate) struct UnsupportedGroup {
136 pub lint_group: String,
137}
138
139#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
CheckNameUnknownTool<'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 {
CheckNameUnknownTool {
tool_name: __binding_0, sub: __binding_1 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("unknown lint tool: `{$tool_name}`")));
diag.code(E0602);
;
diag.arg("tool_name", __binding_0);
diag.subdiagnostic(__binding_1);
diag
}
}
}
}
};Diagnostic)]
140#[diag("unknown lint tool: `{$tool_name}`", code = E0602)]
141pub(crate) struct CheckNameUnknownTool<'a> {
142 pub tool_name: Symbol,
143 #[subdiagnostic]
144 pub sub: RequestedLevel<'a>,
145}
146
147#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
ShadowedIntoIterDiag 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 {
ShadowedIntoIterDiag {
target: __binding_0,
edition: __binding_1,
suggestion: __binding_2,
sub: __binding_3 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this method call resolves to `<&{$target} as IntoIterator>::into_iter` (due to backwards compatibility), but will resolve to `<{$target} as IntoIterator>::into_iter` in Rust {$edition}")));
let __code_4 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("iter"))
})].into_iter();
;
diag.arg("target", __binding_0);
diag.arg("edition", __binding_1);
diag.span_suggestions_with_style(__binding_2,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("use `.iter()` instead of `.into_iter()` to avoid ambiguity")),
__code_4, rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::ShowCode);
if let Some(__binding_3) = __binding_3 {
diag.subdiagnostic(__binding_3);
}
diag
}
}
}
}
};Diagnostic)]
149#[diag(
150 "this method call resolves to `<&{$target} as IntoIterator>::into_iter` (due to backwards compatibility), but will resolve to `<{$target} as IntoIterator>::into_iter` in Rust {$edition}"
151)]
152pub(crate) struct ShadowedIntoIterDiag {
153 pub target: &'static str,
154 pub edition: &'static str,
155 #[suggestion(
156 "use `.iter()` instead of `.into_iter()` to avoid ambiguity",
157 code = "iter",
158 applicability = "machine-applicable"
159 )]
160 pub suggestion: Span,
161 #[subdiagnostic]
162 pub sub: Option<ShadowedIntoIterDiagSub>,
163}
164
165#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for ShadowedIntoIterDiagSub {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
ShadowedIntoIterDiagSub::RemoveIntoIter { span: __binding_0
} => {
let __code_5 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!(""))
})].into_iter();
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("or remove `.into_iter()` to iterate by value")),
&sub_args);
diag.span_suggestions_with_style(__binding_0, __message,
__code_5, rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowCode);
}
ShadowedIntoIterDiagSub::UseExplicitIntoIter {
start_span: __binding_0, end_span: __binding_1 } => {
let mut suggestions = Vec::new();
let __code_6 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("IntoIterator::into_iter("))
});
let __code_7 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!(")"))
});
suggestions.push((__binding_0, __code_6));
suggestions.push((__binding_1, __code_7));
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("or use `IntoIterator::into_iter(..)` instead of `.into_iter()` to explicitly iterate by value")),
&sub_args);
diag.multipart_suggestion_with_style(__message, suggestions,
rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowCode);
}
}
}
}
};Subdiagnostic)]
166pub(crate) enum ShadowedIntoIterDiagSub {
167 #[suggestion(
168 "or remove `.into_iter()` to iterate by value",
169 code = "",
170 applicability = "maybe-incorrect"
171 )]
172 RemoveIntoIter {
173 #[primary_span]
174 span: Span,
175 },
176 #[multipart_suggestion(
177 "or use `IntoIterator::into_iter(..)` instead of `.into_iter()` to explicitly iterate by value",
178 applicability = "maybe-incorrect"
179 )]
180 UseExplicitIntoIter {
181 #[suggestion_part(code = "IntoIterator::into_iter(")]
182 start_span: Span,
183 #[suggestion_part(code = ")")]
184 end_span: Span,
185 },
186}
187
188#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
ImplicitUnsafeAutorefsDiag<'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 {
ImplicitUnsafeAutorefsDiag {
raw_ptr_span: __binding_0,
raw_ptr_ty: __binding_1,
origin: __binding_2,
method: __binding_3,
suggestion: __binding_4 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("implicit autoref creates a reference to the dereference of a raw pointer")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("creating a reference requires the pointer target to be valid and imposes aliasing requirements")));
;
diag.arg("raw_ptr_ty", __binding_1);
diag.span_label(__binding_0,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this raw pointer has type `{$raw_ptr_ty}`")));
diag.subdiagnostic(__binding_2);
if let Some(__binding_3) = __binding_3 {
diag.subdiagnostic(__binding_3);
}
diag.subdiagnostic(__binding_4);
diag
}
}
}
}
};Diagnostic)]
190#[diag("implicit autoref creates a reference to the dereference of a raw pointer")]
191#[note(
192 "creating a reference requires the pointer target to be valid and imposes aliasing requirements"
193)]
194pub(crate) struct ImplicitUnsafeAutorefsDiag<'a> {
195 #[label("this raw pointer has type `{$raw_ptr_ty}`")]
196 pub raw_ptr_span: Span,
197 pub raw_ptr_ty: Ty<'a>,
198 #[subdiagnostic]
199 pub origin: ImplicitUnsafeAutorefsOrigin<'a>,
200 #[subdiagnostic]
201 pub method: Option<ImplicitUnsafeAutorefsMethodNote>,
202 #[subdiagnostic]
203 pub suggestion: ImplicitUnsafeAutorefsSuggestion,
204}
205
206#[derive(const _: () =
{
impl<'a> rustc_errors::Subdiagnostic for
ImplicitUnsafeAutorefsOrigin<'a> {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
ImplicitUnsafeAutorefsOrigin::Autoref {
autoref_span: __binding_0, autoref_ty: __binding_1 } => {
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("autoref_ty".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_1,
&mut diag.long_ty_path));
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("autoref is being applied to this expression, resulting in: `{$autoref_ty}`")),
&sub_args);
diag.span_note(__binding_0, __message);
}
ImplicitUnsafeAutorefsOrigin::OverloadedDeref => {
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("references are created through calls to explicit `Deref(Mut)::deref(_mut)` implementations")),
&sub_args);
diag.note(__message);
}
}
}
}
};Subdiagnostic)]
207pub(crate) enum ImplicitUnsafeAutorefsOrigin<'a> {
208 #[note("autoref is being applied to this expression, resulting in: `{$autoref_ty}`")]
209 Autoref {
210 #[primary_span]
211 autoref_span: Span,
212 autoref_ty: Ty<'a>,
213 },
214 #[note(
215 "references are created through calls to explicit `Deref(Mut)::deref(_mut)` implementations"
216 )]
217 OverloadedDeref,
218}
219
220#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for ImplicitUnsafeAutorefsMethodNote
{
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
ImplicitUnsafeAutorefsMethodNote {
def_span: __binding_0, method_name: __binding_1 } => {
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("method_name".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_1,
&mut diag.long_ty_path));
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("method calls to `{$method_name}` require a reference")),
&sub_args);
diag.span_note(__binding_0, __message);
}
}
}
}
};Subdiagnostic)]
221#[note("method calls to `{$method_name}` require a reference")]
222pub(crate) struct ImplicitUnsafeAutorefsMethodNote {
223 #[primary_span]
224 pub def_span: Span,
225 pub method_name: Symbol,
226}
227
228#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for ImplicitUnsafeAutorefsSuggestion
{
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
ImplicitUnsafeAutorefsSuggestion {
mutbl: __binding_0,
deref: __binding_1,
start_span: __binding_2,
end_span: __binding_3 } => {
let mut suggestions = Vec::new();
let __code_8 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("({1}{0}", __binding_1,
__binding_0))
});
let __code_9 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!(")"))
});
suggestions.push((__binding_2, __code_8));
suggestions.push((__binding_3, __code_9));
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("try using a raw pointer method instead; or if this reference is intentional, make it explicit")),
&sub_args);
diag.multipart_suggestion_with_style(__message, suggestions,
rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowCode);
}
}
}
}
};Subdiagnostic)]
229#[multipart_suggestion(
230 "try using a raw pointer method instead; or if this reference is intentional, make it explicit",
231 applicability = "maybe-incorrect"
232)]
233pub(crate) struct ImplicitUnsafeAutorefsSuggestion {
234 pub mutbl: &'static str,
235 pub deref: &'static str,
236 #[suggestion_part(code = "({mutbl}{deref}")]
237 pub start_span: Span,
238 #[suggestion_part(code = ")")]
239 pub end_span: Span,
240}
241
242#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
BuiltinWhileTrue 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 {
BuiltinWhileTrue {
suggestion: __binding_0, replace: __binding_1 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("denote infinite loops with `loop {\"{\"} ... {\"}\"}`")));
let __code_10 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0}", __binding_1))
})].into_iter();
;
diag.span_suggestions_with_style(__binding_0,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("use `loop`")),
__code_10, rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::HideCodeInline);
diag
}
}
}
}
};Diagnostic)]
244#[diag("denote infinite loops with `loop {\"{\"} ... {\"}\"}`")]
245pub(crate) struct BuiltinWhileTrue {
246 #[suggestion(
247 "use `loop`",
248 style = "short",
249 code = "{replace}",
250 applicability = "machine-applicable"
251 )]
252 pub suggestion: Span,
253 pub replace: String,
254}
255
256#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
BuiltinNonShorthandFieldPatterns 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 {
BuiltinNonShorthandFieldPatterns {
ident: __binding_0,
suggestion: __binding_1,
prefix: __binding_2 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the `{$ident}:` in this pattern is redundant")));
let __code_11 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{1}{0}", __binding_0,
__binding_2))
})].into_iter();
;
diag.arg("ident", __binding_0);
diag.span_suggestions_with_style(__binding_1,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("use shorthand field pattern")),
__code_11, rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::ShowCode);
diag
}
}
}
}
};Diagnostic)]
257#[diag("the `{$ident}:` in this pattern is redundant")]
258pub(crate) struct BuiltinNonShorthandFieldPatterns {
259 pub ident: Ident,
260 #[suggestion(
261 "use shorthand field pattern",
262 code = "{prefix}{ident}",
263 applicability = "machine-applicable"
264 )]
265 pub suggestion: Span,
266 pub prefix: &'static str,
267}
268
269#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for BuiltinUnsafe
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 {
BuiltinUnsafe::AllowInternalUnsafe => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`allow_internal_unsafe` allows defining macros using unsafe without triggering the `unsafe_code` lint at their call site")));
;
diag
}
BuiltinUnsafe::UnsafeBlock => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("usage of an `unsafe` block")));
;
diag
}
BuiltinUnsafe::UnsafeExternBlock => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("usage of an `unsafe extern` block")));
;
diag
}
BuiltinUnsafe::UnsafeTrait => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("declaration of an `unsafe` trait")));
;
diag
}
BuiltinUnsafe::UnsafeImpl => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("implementation of an `unsafe` trait")));
;
diag
}
BuiltinUnsafe::DeclUnsafeFn => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("declaration of an `unsafe` function")));
;
diag
}
BuiltinUnsafe::DeclUnsafeMethod => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("declaration of an `unsafe` method")));
;
diag
}
BuiltinUnsafe::ImplUnsafeMethod => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("implementation of an `unsafe` method")));
;
diag
}
BuiltinUnsafe::GlobalAsm => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("usage of `core::arch::global_asm`")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("using this macro is unsafe even though it does not need an `unsafe` block")));
;
diag
}
}
}
}
};Diagnostic)]
270pub(crate) enum BuiltinUnsafe {
271 #[diag(
272 "`allow_internal_unsafe` allows defining macros using unsafe without triggering the `unsafe_code` lint at their call site"
273 )]
274 AllowInternalUnsafe,
275 #[diag("usage of an `unsafe` block")]
276 UnsafeBlock,
277 #[diag("usage of an `unsafe extern` block")]
278 UnsafeExternBlock,
279 #[diag("declaration of an `unsafe` trait")]
280 UnsafeTrait,
281 #[diag("implementation of an `unsafe` trait")]
282 UnsafeImpl,
283 #[diag("declaration of an `unsafe` function")]
284 DeclUnsafeFn,
285 #[diag("declaration of an `unsafe` method")]
286 DeclUnsafeMethod,
287 #[diag("implementation of an `unsafe` method")]
288 ImplUnsafeMethod,
289 #[diag("usage of `core::arch::global_asm`")]
290 #[note("using this macro is unsafe even though it does not need an `unsafe` block")]
291 GlobalAsm,
292}
293
294#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
BuiltinMissingDoc<'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 {
BuiltinMissingDoc { article: __binding_0, desc: __binding_1
} => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("missing documentation for {$article} {$desc}")));
;
diag.arg("article", __binding_0);
diag.arg("desc", __binding_1);
diag
}
}
}
}
};Diagnostic)]
295#[diag("missing documentation for {$article} {$desc}")]
296pub(crate) struct BuiltinMissingDoc<'a> {
297 pub article: &'a str,
298 pub desc: &'a str,
299}
300
301#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
BuiltinMissingCopyImpl 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 {
BuiltinMissingCopyImpl => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("type could implement `Copy`; consider adding `impl Copy`")));
;
diag
}
}
}
}
};Diagnostic)]
302#[diag("type could implement `Copy`; consider adding `impl Copy`")]
303pub(crate) struct BuiltinMissingCopyImpl;
304
305pub(crate) struct BuiltinMissingDebugImpl<'a> {
306 pub tcx: TyCtxt<'a>,
307 pub def_id: DefId,
308}
309
310impl<'a> Diagnostic<'a, ()> for BuiltinMissingDebugImpl<'_> {
312 fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, ()> {
313 let Self { tcx, def_id } = self;
314 Diag::new(
315 dcx,
316 level,
317 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("type does not implement `{$debug}`; consider adding `#[derive(Debug)]` or a manual implementation"))msg!("type does not implement `{$debug}`; consider adding `#[derive(Debug)]` or a manual implementation"),
318 ).with_arg("debug", tcx.def_path_str(def_id))
319 }
320}
321
322#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
BuiltinAnonymousParams<'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 {
BuiltinAnonymousParams {
suggestion: __binding_0, ty_snip: __binding_1 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("anonymous parameters are deprecated and will be removed in the next edition")));
let __code_12 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("_: {0}", __binding_1))
})].into_iter();
;
diag.span_suggestions_with_style(__binding_0.0,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("try naming the parameter or explicitly ignoring it")),
__code_12, __binding_0.1,
rustc_errors::SuggestionStyle::ShowCode);
diag
}
}
}
}
};Diagnostic)]
323#[diag("anonymous parameters are deprecated and will be removed in the next edition")]
324pub(crate) struct BuiltinAnonymousParams<'a> {
325 #[suggestion("try naming the parameter or explicitly ignoring it", code = "_: {ty_snip}")]
326 pub suggestion: (Span, Applicability),
327 pub ty_snip: &'a str,
328}
329
330#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
BuiltinUnusedDocComment<'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 {
BuiltinUnusedDocComment {
kind: __binding_0, label: __binding_1, sub: __binding_2 } =>
{
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("unused doc comment")));
;
diag.arg("kind", __binding_0);
diag.span_label(__binding_1,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("rustdoc does not generate documentation for {$kind}")));
diag.subdiagnostic(__binding_2);
diag
}
}
}
}
};Diagnostic)]
331#[diag("unused doc comment")]
332pub(crate) struct BuiltinUnusedDocComment<'a> {
333 pub kind: &'a str,
334 #[label("rustdoc does not generate documentation for {$kind}")]
335 pub label: Span,
336 #[subdiagnostic]
337 pub sub: BuiltinUnusedDocCommentSub,
338}
339
340#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for BuiltinUnusedDocCommentSub {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
BuiltinUnusedDocCommentSub::PlainHelp => {
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("use `//` for a plain comment")),
&sub_args);
diag.help(__message);
}
BuiltinUnusedDocCommentSub::BlockHelp => {
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("use `/* */` for a plain comment")),
&sub_args);
diag.help(__message);
}
}
}
}
};Subdiagnostic)]
341pub(crate) enum BuiltinUnusedDocCommentSub {
342 #[help("use `//` for a plain comment")]
343 PlainHelp,
344 #[help("use `/* */` for a plain comment")]
345 BlockHelp,
346}
347
348#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
BuiltinConstNoMangle 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 {
BuiltinConstNoMangle { suggestion: __binding_0 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("const items should never be `#[no_mangle]`")));
let __code_13 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("pub static "))
})].into_iter();
;
if let Some(__binding_0) = __binding_0 {
diag.span_suggestions_with_style(__binding_0,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("try a static value")),
__code_13, rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::ShowCode);
}
diag
}
}
}
}
};Diagnostic)]
349#[diag("const items should never be `#[no_mangle]`")]
350pub(crate) struct BuiltinConstNoMangle {
351 #[suggestion("try a static value", code = "pub static ", applicability = "machine-applicable")]
352 pub suggestion: Option<Span>,
353}
354
355#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
BuiltinMutablesTransmutes 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 {
BuiltinMutablesTransmutes => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("transmuting &T to &mut T is undefined behavior, even if the reference is unused, consider instead using an UnsafeCell")));
;
diag
}
}
}
}
};Diagnostic)]
356#[diag(
357 "transmuting &T to &mut T is undefined behavior, even if the reference is unused, consider instead using an UnsafeCell"
358)]
359pub(crate) struct BuiltinMutablesTransmutes;
360
361#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
BuiltinUnstableFeatures 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 {
BuiltinUnstableFeatures => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("use of an unstable feature")));
;
diag
}
}
}
}
};Diagnostic)]
362#[diag("use of an unstable feature")]
363pub(crate) struct BuiltinUnstableFeatures;
364
365pub(crate) struct BuiltinUngatedAsyncFnTrackCaller<'a> {
367 pub label: Span,
368 pub session: &'a Session,
369}
370
371impl<'a> Diagnostic<'a, ()> for BuiltinUngatedAsyncFnTrackCaller<'_> {
372 fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, ()> {
373 let mut diag = Diag::new(dcx, level, "`#[track_caller]` on async functions is a no-op")
374 .with_span_label(self.label, "this function will not propagate the caller location");
375 rustc_session::diagnostics::add_feature_diagnostics(
376 &mut diag,
377 self.session,
378 sym::async_fn_track_caller,
379 );
380 diag
381 }
382}
383
384#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
BuiltinUnreachablePub<'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 {
BuiltinUnreachablePub {
what: __binding_0,
new_vis: __binding_1,
suggestion: __binding_2,
help: __binding_3 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("unreachable `pub` {$what}")));
let __code_14 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0}", __binding_1))
})].into_iter();
;
diag.arg("what", __binding_0);
diag.span_suggestions_with_style(__binding_2.0,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider restricting its visibility")),
__code_14, __binding_2.1,
rustc_errors::SuggestionStyle::ShowCode);
if __binding_3 {
diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("or consider exporting it for use by other crates")));
}
diag
}
}
}
}
};Diagnostic)]
385#[diag("unreachable `pub` {$what}")]
386pub(crate) struct BuiltinUnreachablePub<'a> {
387 pub what: &'a str,
388 pub new_vis: &'a str,
389 #[suggestion("consider restricting its visibility", code = "{new_vis}")]
390 pub suggestion: (Span, Applicability),
391 #[help("or consider exporting it for use by other crates")]
392 pub help: bool,
393}
394
395#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
MacroExprFragment2024 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 {
MacroExprFragment2024 { suggestion: __binding_0 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the `expr` fragment specifier will accept more expressions in the 2024 edition")));
let __code_15 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("expr_2021"))
})].into_iter();
;
diag.span_suggestions_with_style(__binding_0,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("to keep the existing behavior, use the `expr_2021` fragment specifier")),
__code_15, rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::ShowCode);
diag
}
}
}
}
};Diagnostic)]
396#[diag("the `expr` fragment specifier will accept more expressions in the 2024 edition")]
397pub(crate) struct MacroExprFragment2024 {
398 #[suggestion(
399 "to keep the existing behavior, use the `expr_2021` fragment specifier",
400 code = "expr_2021",
401 applicability = "machine-applicable"
402 )]
403 pub suggestion: Span,
404}
405
406pub(crate) struct BuiltinTypeAliasBounds<'hir> {
407 pub in_where_clause: bool,
408 pub label: Span,
409 pub enable_feat_help: bool,
410 pub suggestions: Vec<(Span, String)>,
411 pub preds: &'hir [hir::WherePredicate<'hir>],
412 pub ty: Option<&'hir hir::Ty<'hir>>,
413}
414
415impl<'a> Diagnostic<'a, ()> for BuiltinTypeAliasBounds<'_> {
416 fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, ()> {
417 let mut diag = Diag::new(dcx, level, if self.in_where_clause {
418 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("where clauses on type aliases are not enforced"))msg!("where clauses on type aliases are not enforced")
419 } else {
420 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("bounds on generic parameters in type aliases are not enforced"))msg!("bounds on generic parameters in type aliases are not enforced")
421 })
422 .with_span_label(self.label, rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("will not be checked at usage sites of the type alias"))msg!("will not be checked at usage sites of the type alias"))
423 .with_note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this is a known limitation of the type checker that may be lifted in a future edition.\n see issue #112792 <https://github.com/rust-lang/rust/issues/112792> for more information"))msg!(
424 "this is a known limitation of the type checker that may be lifted in a future edition.
425 see issue #112792 <https://github.com/rust-lang/rust/issues/112792> for more information"
426 ));
427 if self.enable_feat_help {
428 diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("add `#![feature(checked_type_aliases)]` to the crate attributes to enable the desired semantics"))msg!("add `#![feature(checked_type_aliases)]` to the crate attributes to enable the desired semantics"));
429 }
430
431 let mut collector = ShorthandAssocTyCollector { qselves: Vec::new() };
434 if let Some(ty) = self.ty {
435 collector.visit_ty_unambig(ty);
436 }
437
438 let affect_object_lifetime_defaults = self
439 .preds
440 .iter()
441 .filter(|pred| pred.kind.in_where_clause() == self.in_where_clause)
442 .any(|pred| TypeAliasBounds::affects_object_lifetime_defaults(pred));
443
444 let applicability = if !collector.qselves.is_empty() || affect_object_lifetime_defaults {
447 Applicability::MaybeIncorrect
448 } else {
449 Applicability::MachineApplicable
450 };
451
452 diag.arg("count", self.suggestions.len());
453 diag.multipart_suggestion(
454 if self.in_where_clause {
455 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("remove this where clause"))msg!("remove this where clause")
456 } else {
457 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("remove {$count ->\n [one] this bound\n *[other] these bounds\n }"))msg!(
458 "remove {$count ->
459 [one] this bound
460 *[other] these bounds
461 }"
462 )
463 },
464 self.suggestions,
465 applicability,
466 );
467
468 for qself in collector.qselves {
479 diag.multipart_suggestion(
480 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("fully qualify this associated type"))msg!("fully qualify this associated type"),
481 ::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
[(qself.shrink_to_lo(), "<".into()),
(qself.shrink_to_hi(), " as /* Trait */>".into())]))vec![
482 (qself.shrink_to_lo(), "<".into()),
483 (qself.shrink_to_hi(), " as /* Trait */>".into()),
484 ],
485 Applicability::HasPlaceholders,
486 );
487 }
488 diag
489 }
490}
491
492#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
BuiltinTrivialBounds<'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 {
BuiltinTrivialBounds {
clause_kind_name: __binding_0, clause: __binding_1 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$clause_kind_name} bound {$clause} does not depend on any type or lifetime parameters")));
;
diag.arg("clause_kind_name", __binding_0);
diag.arg("clause", __binding_1);
diag
}
}
}
}
};Diagnostic)]
493#[diag("{$clause_kind_name} bound {$clause} does not depend on any type or lifetime parameters")]
494pub(crate) struct BuiltinTrivialBounds<'a> {
495 pub clause_kind_name: &'a str,
496 pub clause: Clause<'a>,
497}
498
499#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
BuiltinDoubleNegations 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 {
BuiltinDoubleNegations { add_parens: __binding_0 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("use of a double negation")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the prefix `--` could be misinterpreted as a decrement operator which exists in other languages")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("use `-= 1` if you meant to decrement the value")));
;
diag.subdiagnostic(__binding_0);
diag
}
}
}
}
};Diagnostic)]
500#[diag("use of a double negation")]
501#[note(
502 "the prefix `--` could be misinterpreted as a decrement operator which exists in other languages"
503)]
504#[note("use `-= 1` if you meant to decrement the value")]
505pub(crate) struct BuiltinDoubleNegations {
506 #[subdiagnostic]
507 pub add_parens: BuiltinDoubleNegationsAddParens,
508}
509
510#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for BuiltinDoubleNegationsAddParens {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
BuiltinDoubleNegationsAddParens {
start_span: __binding_0, end_span: __binding_1 } => {
let mut suggestions = Vec::new();
let __code_16 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("("))
});
let __code_17 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!(")"))
});
suggestions.push((__binding_0, __code_16));
suggestions.push((__binding_1, __code_17));
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("add parentheses for clarity")),
&sub_args);
diag.multipart_suggestion_with_style(__message, suggestions,
rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowCode);
}
}
}
}
};Subdiagnostic)]
511#[multipart_suggestion("add parentheses for clarity", applicability = "maybe-incorrect")]
512pub(crate) struct BuiltinDoubleNegationsAddParens {
513 #[suggestion_part(code = "(")]
514 pub start_span: Span,
515 #[suggestion_part(code = ")")]
516 pub end_span: Span,
517}
518
519#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
BuiltinEllipsisInclusiveRangePatternsLint 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 {
BuiltinEllipsisInclusiveRangePatternsLint::Parenthesise {
suggestion: __binding_0, replace: __binding_1 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`...` range patterns are deprecated")));
let __code_18 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0}", __binding_1))
})].into_iter();
;
diag.span_suggestions_with_style(__binding_0,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("use `..=` for an inclusive range")),
__code_18, rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::ShowCode);
diag
}
BuiltinEllipsisInclusiveRangePatternsLint::NonParenthesise {
suggestion: __binding_0 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`...` range patterns are deprecated")));
let __code_19 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("..="))
})].into_iter();
;
diag.span_suggestions_with_style(__binding_0,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("use `..=` for an inclusive range")),
__code_19, rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::HideCodeInline);
diag
}
}
}
}
};Diagnostic)]
520pub(crate) enum BuiltinEllipsisInclusiveRangePatternsLint {
521 #[diag("`...` range patterns are deprecated")]
522 Parenthesise {
523 #[suggestion(
524 "use `..=` for an inclusive range",
525 code = "{replace}",
526 applicability = "machine-applicable"
527 )]
528 suggestion: Span,
529 replace: String,
530 },
531 #[diag("`...` range patterns are deprecated")]
532 NonParenthesise {
533 #[suggestion(
534 "use `..=` for an inclusive range",
535 style = "short",
536 code = "..=",
537 applicability = "machine-applicable"
538 )]
539 suggestion: Span,
540 },
541}
542
543#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
BuiltinKeywordIdents 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 {
BuiltinKeywordIdents {
kw: __binding_0,
next: __binding_1,
suggestion: __binding_2,
prefix: __binding_3 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`{$kw}` is a keyword in the {$next} edition")));
let __code_20 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{1}r#{0}", __binding_0,
__binding_3))
})].into_iter();
;
diag.arg("kw", __binding_0);
diag.arg("next", __binding_1);
diag.span_suggestions_with_style(__binding_2,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("you can use a raw identifier to stay compatible")),
__code_20, rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::ShowCode);
diag
}
}
}
}
};Diagnostic)]
544#[diag("`{$kw}` is a keyword in the {$next} edition")]
545pub(crate) struct BuiltinKeywordIdents {
546 pub kw: Ident,
547 pub next: Edition,
548 #[suggestion(
549 "you can use a raw identifier to stay compatible",
550 code = "{prefix}r#{kw}",
551 applicability = "machine-applicable"
552 )]
553 pub suggestion: Span,
554 pub prefix: &'static str,
555}
556
557#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
BuiltinExplicitOutlives 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 {
BuiltinExplicitOutlives { suggestion: __binding_0 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("outlives requirements can be inferred")));
;
diag.subdiagnostic(__binding_0);
diag
}
}
}
}
};Diagnostic)]
558#[diag("outlives requirements can be inferred")]
559pub(crate) struct BuiltinExplicitOutlives {
560 #[subdiagnostic]
561 pub suggestion: BuiltinExplicitOutlivesSuggestion,
562}
563
564#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for BuiltinExplicitOutlivesSuggestion
{
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
BuiltinExplicitOutlivesSuggestion {
spans: __binding_0,
applicability: __binding_1,
count: __binding_2 } => {
let mut suggestions = Vec::new();
let __code_21 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!(""))
});
for __binding_0 in __binding_0 {
suggestions.push((__binding_0, __code_21.clone()));
}
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("count".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_2,
&mut diag.long_ty_path));
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("remove {$count ->\n [one] this bound\n *[other] these bounds\n }")),
&sub_args);
diag.multipart_suggestion_with_style(__message, suggestions,
__binding_1, rustc_errors::SuggestionStyle::ShowCode);
}
}
}
}
};Subdiagnostic)]
565#[multipart_suggestion(
566 "remove {$count ->
567 [one] this bound
568 *[other] these bounds
569 }"
570)]
571pub(crate) struct BuiltinExplicitOutlivesSuggestion {
572 #[suggestion_part(code = "")]
573 pub spans: Vec<Span>,
574 #[applicability]
575 pub applicability: Applicability,
576 pub count: usize,
577}
578
579#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
BuiltinIncompleteFeatures 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 {
BuiltinIncompleteFeatures {
name: __binding_0, note: __binding_1, help: __binding_2 } =>
{
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the feature `{$name}` is incomplete and may not be safe to use and/or cause compiler crashes")));
;
diag.arg("name", __binding_0);
if let Some(__binding_1) = __binding_1 {
diag.subdiagnostic(__binding_1);
}
if let Some(__binding_2) = __binding_2 {
diag.subdiagnostic(__binding_2);
}
diag
}
}
}
}
};Diagnostic)]
580#[diag(
581 "the feature `{$name}` is incomplete and may not be safe to use and/or cause compiler crashes"
582)]
583pub(crate) struct BuiltinIncompleteFeatures {
584 pub name: Symbol,
585 #[subdiagnostic]
586 pub note: Option<BuiltinFeatureIssueNote>,
587 #[subdiagnostic]
588 pub help: Option<BuiltinIncompleteFeaturesHelp>,
589}
590
591#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
BuiltinInternalFeatures 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 {
BuiltinInternalFeatures { name: __binding_0 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the feature `{$name}` is internal to the compiler or standard library")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("using it is strongly discouraged")));
;
diag.arg("name", __binding_0);
diag
}
}
}
}
};Diagnostic)]
592#[diag("the feature `{$name}` is internal to the compiler or standard library")]
593#[note("using it is strongly discouraged")]
594pub(crate) struct BuiltinInternalFeatures {
595 pub name: Symbol,
596}
597
598#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for BuiltinIncompleteFeaturesHelp {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
BuiltinIncompleteFeaturesHelp { name: __binding_0 } => {
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("name".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_0,
&mut diag.long_ty_path));
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider using `min_{$name}` instead, which is more stable and complete")),
&sub_args);
diag.help(__message);
}
}
}
}
};Subdiagnostic)]
599#[help("consider using `min_{$name}` instead, which is more stable and complete")]
600pub(crate) struct BuiltinIncompleteFeaturesHelp {
601 pub name: Symbol,
602}
603
604#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for BuiltinFeatureIssueNote {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
BuiltinFeatureIssueNote { n: __binding_0 } => {
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("n".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_0,
&mut diag.long_ty_path));
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("see issue #{$n} <https://github.com/rust-lang/rust/issues/{$n}> for more information")),
&sub_args);
diag.note(__message);
}
}
}
}
};Subdiagnostic)]
605#[note("see issue #{$n} <https://github.com/rust-lang/rust/issues/{$n}> for more information")]
606pub(crate) struct BuiltinFeatureIssueNote {
607 pub n: NonZero<u32>,
608}
609
610pub(crate) struct BuiltinUnpermittedTypeInit<'a> {
611 pub msg: DiagMessage,
612 pub ty: Ty<'a>,
613 pub label: Span,
614 pub sub: BuiltinUnpermittedTypeInitSub,
615 pub tcx: TyCtxt<'a>,
616}
617
618impl<'a> Diagnostic<'a, ()> for BuiltinUnpermittedTypeInit<'_> {
619 fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, ()> {
620 let mut diag = Diag::new(dcx, level, self.msg)
621 .with_arg("ty", self.ty)
622 .with_span_label(self.label, rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this code causes undefined behavior when executed"))msg!("this code causes undefined behavior when executed"));
623 if let InhabitedPredicate::True = self.ty.inhabited_predicate(self.tcx) {
624 diag.span_label(
626 self.label,
627 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done"))msg!("help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done"),
628 );
629 }
630 self.sub.add_to_diag(&mut diag);
631 diag
632 }
633}
634
635pub(crate) struct BuiltinUnpermittedTypeInitSub {
637 pub err: InitError,
638}
639
640impl Subdiagnostic for BuiltinUnpermittedTypeInitSub {
641 fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
642 let mut err = self.err;
643 loop {
644 if let Some(span) = err.span {
645 diag.span_note(span, err.message);
646 } else {
647 diag.note(err.message);
648 }
649 if let Some(e) = err.nested {
650 err = *e;
651 } else {
652 break;
653 }
654 }
655 }
656}
657
658#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
BuiltinClashingExtern<'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 {
BuiltinClashingExtern::SameName {
this: __binding_0,
orig: __binding_1,
previous_decl_label: __binding_2,
mismatch_label: __binding_3,
sub: __binding_4 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`{$this}` redeclared with a different signature")));
;
diag.arg("this", __binding_0);
diag.arg("orig", __binding_1);
diag.span_label(__binding_2,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`{$orig}` previously declared here")));
diag.span_label(__binding_3,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this signature doesn't match the previous declaration")));
diag.subdiagnostic(__binding_4);
diag
}
BuiltinClashingExtern::DiffName {
this: __binding_0,
orig: __binding_1,
previous_decl_label: __binding_2,
mismatch_label: __binding_3,
sub: __binding_4 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`{$this}` redeclares `{$orig}` with a different signature")));
;
diag.arg("this", __binding_0);
diag.arg("orig", __binding_1);
diag.span_label(__binding_2,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`{$orig}` previously declared here")));
diag.span_label(__binding_3,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this signature doesn't match the previous declaration")));
diag.subdiagnostic(__binding_4);
diag
}
}
}
}
};Diagnostic)]
659pub(crate) enum BuiltinClashingExtern<'a> {
660 #[diag("`{$this}` redeclared with a different signature")]
661 SameName {
662 this: Symbol,
663 orig: Symbol,
664 #[label("`{$orig}` previously declared here")]
665 previous_decl_label: Span,
666 #[label("this signature doesn't match the previous declaration")]
667 mismatch_label: Span,
668 #[subdiagnostic]
669 sub: BuiltinClashingExternSub<'a>,
670 },
671 #[diag("`{$this}` redeclares `{$orig}` with a different signature")]
672 DiffName {
673 this: Symbol,
674 orig: Symbol,
675 #[label("`{$orig}` previously declared here")]
676 previous_decl_label: Span,
677 #[label("this signature doesn't match the previous declaration")]
678 mismatch_label: Span,
679 #[subdiagnostic]
680 sub: BuiltinClashingExternSub<'a>,
681 },
682}
683
684pub(crate) struct BuiltinClashingExternSub<'a> {
686 pub tcx: TyCtxt<'a>,
687 pub expected: Ty<'a>,
688 pub found: Ty<'a>,
689}
690
691impl Subdiagnostic for BuiltinClashingExternSub<'_> {
692 fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
693 let mut expected_str = DiagStyledString::new();
694 expected_str.push(self.expected.fn_sig(self.tcx).to_string(), false);
695 let mut found_str = DiagStyledString::new();
696 found_str.push(self.found.fn_sig(self.tcx).to_string(), true);
697 diag.note_expected_found("", expected_str, "", found_str);
698 }
699}
700
701#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
BuiltinDerefNullptr 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 {
BuiltinDerefNullptr { label: __binding_0 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("dereferencing a null pointer")));
;
diag.span_label(__binding_0,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this code causes undefined behavior when executed")));
diag
}
}
}
}
};Diagnostic)]
702#[diag("dereferencing a null pointer")]
703pub(crate) struct BuiltinDerefNullptr {
704 #[label("this code causes undefined behavior when executed")]
705 pub label: Span,
706}
707
708#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
BuiltinSpecialModuleNameUsed 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 {
BuiltinSpecialModuleNameUsed::Lib => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("found module declaration for lib.rs")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("lib.rs is the root of this crate's library target")));
diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("to refer to it from other targets, use the library's name as the path")));
;
diag
}
BuiltinSpecialModuleNameUsed::Main => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("found module declaration for main.rs")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("a binary crate cannot be used as library")));
;
diag
}
}
}
}
};Diagnostic)]
709pub(crate) enum BuiltinSpecialModuleNameUsed {
710 #[diag("found module declaration for lib.rs")]
711 #[note("lib.rs is the root of this crate's library target")]
712 #[help("to refer to it from other targets, use the library's name as the path")]
713 Lib,
714 #[diag("found module declaration for main.rs")]
715 #[note("a binary crate cannot be used as library")]
716 Main,
717}
718
719#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for CVoidReturn
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 {
CVoidReturn { suggestion: __binding_0 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`c_void` should not be used as a return type")));
let __code_22 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!(""))
})].into_iter();
diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("returning `()` in Rust is equivalent to returning `void` in C")));
;
diag.span_suggestions_with_style(__binding_0,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("remove the return type to implicitly return `()`")),
__code_22, rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowCode);
diag
}
}
}
}
};Diagnostic)]
721#[diag("`c_void` should not be used as a return type")]
722#[help("returning `()` in Rust is equivalent to returning `void` in C")]
723pub(crate) struct CVoidReturn {
724 #[suggestion(
725 "remove the return type to implicitly return `()`",
726 code = "",
727 applicability = "maybe-incorrect"
728 )]
729 pub suggestion: Span,
730}
731
732#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
ExternCVoidReturn 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 {
ExternCVoidReturn { suggestion: __binding_0 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("declarations returning `c_void` are not compatible with C functions returning `void`")));
let __code_23 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!(""))
})].into_iter();
diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("returning `()` in Rust is equivalent to returning `void` in C")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`c_void` is only used through raw pointers for compatibility with `void` pointers")));
;
diag.span_suggestions_with_style(__binding_0,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("remove the return type to implicitly return `()`")),
__code_23, rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowCode);
diag
}
}
}
}
};Diagnostic)]
734#[diag("declarations returning `c_void` are not compatible with C functions returning `void`")]
735#[help("returning `()` in Rust is equivalent to returning `void` in C")]
736#[note("`c_void` is only used through raw pointers for compatibility with `void` pointers")]
737pub(crate) struct ExternCVoidReturn {
738 #[suggestion(
739 "remove the return type to implicitly return `()`",
740 code = "",
741 applicability = "maybe-incorrect"
742 )]
743 pub suggestion: Span,
744}
745
746#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
SupertraitAsDerefTarget<'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 {
SupertraitAsDerefTarget {
self_ty: __binding_0,
supertrait_principal: __binding_1,
target_principal: __binding_2,
label: __binding_3,
label2: __binding_4 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this `Deref` implementation is covered by an implicit supertrait coercion")));
;
diag.arg("self_ty", __binding_0);
diag.arg("supertrait_principal", __binding_1);
diag.arg("target_principal", __binding_2);
diag.span_label(__binding_3,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`{$self_ty}` implements `Deref<Target = dyn {$target_principal}>` which conflicts with supertrait `{$supertrait_principal}`")));
if let Some(__binding_4) = __binding_4 {
diag.subdiagnostic(__binding_4);
}
diag
}
}
}
}
};Diagnostic)]
748#[diag("this `Deref` implementation is covered by an implicit supertrait coercion")]
749pub(crate) struct SupertraitAsDerefTarget<'a> {
750 pub self_ty: Ty<'a>,
751 pub supertrait_principal: PolyExistentialTraitRef<'a>,
752 pub target_principal: PolyExistentialTraitRef<'a>,
753 #[label(
754 "`{$self_ty}` implements `Deref<Target = dyn {$target_principal}>` which conflicts with supertrait `{$supertrait_principal}`"
755 )]
756 pub label: Span,
757 #[subdiagnostic]
758 pub label2: Option<SupertraitAsDerefTargetLabel<'a>>,
759}
760
761#[derive(const _: () =
{
impl<'a> rustc_errors::Subdiagnostic for
SupertraitAsDerefTargetLabel<'a> {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
SupertraitAsDerefTargetLabel {
label: __binding_0, self_ty: __binding_1 } => {
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("self_ty".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_1,
&mut diag.long_ty_path));
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("target type is a supertrait of `{$self_ty}`")),
&sub_args);
diag.span_label(__binding_0, __message);
}
}
}
}
};Subdiagnostic)]
762#[label("target type is a supertrait of `{$self_ty}`")]
763pub(crate) struct SupertraitAsDerefTargetLabel<'a> {
764 #[primary_span]
765 pub label: Span,
766 pub self_ty: Ty<'a>,
767}
768
769#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
EnumIntrinsicsMemDiscriminate<'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 {
EnumIntrinsicsMemDiscriminate {
ty_param: __binding_0, note: __binding_1 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the return value of `mem::discriminant` is unspecified when called with a non-enum type")));
;
diag.arg("ty_param", __binding_0);
diag.span_note(__binding_1,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the argument to `discriminant` should be a reference to an enum, but it was passed a reference to a `{$ty_param}`, which is not an enum")));
diag
}
}
}
}
};Diagnostic)]
771#[diag("the return value of `mem::discriminant` is unspecified when called with a non-enum type")]
772pub(crate) struct EnumIntrinsicsMemDiscriminate<'a> {
773 pub ty_param: Ty<'a>,
774 #[note(
775 "the argument to `discriminant` should be a reference to an enum, but it was passed a reference to a `{$ty_param}`, which is not an enum"
776 )]
777 pub note: Span,
778}
779
780#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
EnumIntrinsicsMemVariant<'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 {
EnumIntrinsicsMemVariant { ty_param: __binding_0 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the return value of `mem::variant_count` is unspecified when called with a non-enum type")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the type parameter of `variant_count` should be an enum, but it was instantiated with the type `{$ty_param}`, which is not an enum")));
;
diag.arg("ty_param", __binding_0);
diag
}
}
}
}
};Diagnostic)]
781#[diag("the return value of `mem::variant_count` is unspecified when called with a non-enum type")]
782#[note(
783 "the type parameter of `variant_count` should be an enum, but it was instantiated with the type `{$ty_param}`, which is not an enum"
784)]
785pub(crate) struct EnumIntrinsicsMemVariant<'a> {
786 pub ty_param: Ty<'a>,
787}
788
789#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for Expectation
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 {
Expectation { rationale: __binding_0, note: __binding_1 } =>
{
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this lint expectation is unfulfilled")));
;
if let Some(__binding_0) = __binding_0 {
diag.subdiagnostic(__binding_0);
}
if __binding_1 {
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the `unfulfilled_lint_expectations` lint can't be expected and will always produce this message")));
}
diag
}
}
}
}
};Diagnostic)]
791#[diag("this lint expectation is unfulfilled")]
792pub(crate) struct Expectation {
793 #[subdiagnostic]
794 pub rationale: Option<ExpectationNote>,
795 #[note(
796 "the `unfulfilled_lint_expectations` lint can't be expected and will always produce this message"
797 )]
798 pub note: bool,
799}
800
801#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for ExpectationNote {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
ExpectationNote { rationale: __binding_0 } => {
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("rationale".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_0,
&mut diag.long_ty_path));
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$rationale}")),
&sub_args);
diag.note(__message);
}
}
}
}
};Subdiagnostic)]
802#[note("{$rationale}")]
803pub(crate) struct ExpectationNote {
804 pub rationale: Symbol,
805}
806
807#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
UselessPtrNullChecksDiag<'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 {
UselessPtrNullChecksDiag::FnPtr {
orig_ty: __binding_0, label: __binding_1 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("function pointers are not nullable, so checking them for null will always return false")));
diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("wrap the function pointer inside an `Option` and use `Option::is_none` to check for null pointer value")));
;
diag.arg("orig_ty", __binding_0);
diag.span_label(__binding_1,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("expression has type `{$orig_ty}`")));
diag
}
UselessPtrNullChecksDiag::Ref {
orig_ty: __binding_0, label: __binding_1 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("references are not nullable, so checking them for null will always return false")));
;
diag.arg("orig_ty", __binding_0);
diag.span_label(__binding_1,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("expression has type `{$orig_ty}`")));
diag
}
UselessPtrNullChecksDiag::FnRet { fn_name: __binding_0 } =>
{
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("returned pointer of `{$fn_name}` call is never null, so checking it for null will always return false")));
;
diag.arg("fn_name", __binding_0);
diag
}
}
}
}
};Diagnostic)]
809pub(crate) enum UselessPtrNullChecksDiag<'a> {
810 #[diag(
811 "function pointers are not nullable, so checking them for null will always return false"
812 )]
813 #[help(
814 "wrap the function pointer inside an `Option` and use `Option::is_none` to check for null pointer value"
815 )]
816 FnPtr {
817 orig_ty: Ty<'a>,
818 #[label("expression has type `{$orig_ty}`")]
819 label: Span,
820 },
821 #[diag("references are not nullable, so checking them for null will always return false")]
822 Ref {
823 orig_ty: Ty<'a>,
824 #[label("expression has type `{$orig_ty}`")]
825 label: Span,
826 },
827 #[diag(
828 "returned pointer of `{$fn_name}` call is never null, so checking it for null will always return false"
829 )]
830 FnRet { fn_name: Ident },
831}
832
833#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
InvalidNullArgumentsDiag 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 {
InvalidNullArgumentsDiag::NullPtrInline {
null_span: __binding_0 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("calling this function with a null pointer is undefined behavior, even if the result of the function is unused")));
diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("for more information, visit <https://doc.rust-lang.org/std/ptr/index.html> and <https://doc.rust-lang.org/reference/behavior-considered-undefined.html>")));
;
diag.span_label(__binding_0,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("null pointer originates from here")));
diag
}
InvalidNullArgumentsDiag::NullPtrThroughBinding {
null_span: __binding_0 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("calling this function with a null pointer is undefined behavior, even if the result of the function is unused")));
diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("for more information, visit <https://doc.rust-lang.org/std/ptr/index.html> and <https://doc.rust-lang.org/reference/behavior-considered-undefined.html>")));
;
diag.span_note(__binding_0,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("null pointer originates from here")));
diag
}
}
}
}
};Diagnostic)]
834pub(crate) enum InvalidNullArgumentsDiag {
835 #[diag(
836 "calling this function with a null pointer is undefined behavior, even if the result of the function is unused"
837 )]
838 #[help(
839 "for more information, visit <https://doc.rust-lang.org/std/ptr/index.html> and <https://doc.rust-lang.org/reference/behavior-considered-undefined.html>"
840 )]
841 NullPtrInline {
842 #[label("null pointer originates from here")]
843 null_span: Span,
844 },
845 #[diag(
846 "calling this function with a null pointer is undefined behavior, even if the result of the function is unused"
847 )]
848 #[help(
849 "for more information, visit <https://doc.rust-lang.org/std/ptr/index.html> and <https://doc.rust-lang.org/reference/behavior-considered-undefined.html>"
850 )]
851 NullPtrThroughBinding {
852 #[note("null pointer originates from here")]
853 null_span: Span,
854 },
855}
856
857#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
ForLoopsOverFalliblesDiag<'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 {
ForLoopsOverFalliblesDiag {
article: __binding_0,
ref_prefix: __binding_1,
ty: __binding_2,
sub: __binding_3,
question_mark: __binding_4,
suggestion: __binding_5 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("for loop over {$article} `{$ref_prefix}{$ty}`. This is more readably written as an `if let` statement")));
;
diag.arg("article", __binding_0);
diag.arg("ref_prefix", __binding_1);
diag.arg("ty", __binding_2);
diag.subdiagnostic(__binding_3);
if let Some(__binding_4) = __binding_4 {
diag.subdiagnostic(__binding_4);
}
diag.subdiagnostic(__binding_5);
diag
}
}
}
}
};Diagnostic)]
859#[diag(
860 "for loop over {$article} `{$ref_prefix}{$ty}`. This is more readably written as an `if let` statement"
861)]
862pub(crate) struct ForLoopsOverFalliblesDiag<'a> {
863 pub article: &'static str,
864 pub ref_prefix: &'static str,
865 pub ty: &'static str,
866 #[subdiagnostic]
867 pub sub: ForLoopsOverFalliblesLoopSub<'a>,
868 #[subdiagnostic]
869 pub question_mark: Option<ForLoopsOverFalliblesQuestionMark>,
870 #[subdiagnostic]
871 pub suggestion: ForLoopsOverFalliblesSuggestion<'a>,
872}
873
874#[derive(const _: () =
{
impl<'a> rustc_errors::Subdiagnostic for
ForLoopsOverFalliblesLoopSub<'a> {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
ForLoopsOverFalliblesLoopSub::RemoveNext {
suggestion: __binding_0, recv_snip: __binding_1 } => {
let __code_24 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!(".by_ref()"))
})].into_iter();
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("recv_snip".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_1,
&mut diag.long_ty_path));
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("to iterate over `{$recv_snip}` remove the call to `next`")),
&sub_args);
diag.span_suggestions_with_style(__binding_0, __message,
__code_24, rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowCode);
}
ForLoopsOverFalliblesLoopSub::UseWhileLet {
start_span: __binding_0,
end_span: __binding_1,
var: __binding_2 } => {
let mut suggestions = Vec::new();
let __code_25 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("while let {0}(",
__binding_2))
});
let __code_26 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!(") = "))
});
suggestions.push((__binding_0, __code_25));
suggestions.push((__binding_1, __code_26));
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("to check pattern in a loop use `while let`")),
&sub_args);
diag.multipart_suggestion_with_style(__message, suggestions,
rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowCode);
}
}
}
}
};Subdiagnostic)]
875pub(crate) enum ForLoopsOverFalliblesLoopSub<'a> {
876 #[suggestion(
877 "to iterate over `{$recv_snip}` remove the call to `next`",
878 code = ".by_ref()",
879 applicability = "maybe-incorrect"
880 )]
881 RemoveNext {
882 #[primary_span]
883 suggestion: Span,
884 recv_snip: String,
885 },
886 #[multipart_suggestion(
887 "to check pattern in a loop use `while let`",
888 applicability = "maybe-incorrect"
889 )]
890 UseWhileLet {
891 #[suggestion_part(code = "while let {var}(")]
892 start_span: Span,
893 #[suggestion_part(code = ") = ")]
894 end_span: Span,
895 var: &'a str,
896 },
897}
898
899#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for ForLoopsOverFalliblesQuestionMark
{
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
ForLoopsOverFalliblesQuestionMark { suggestion: __binding_0
} => {
let __code_27 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("?"))
})].into_iter();
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider unwrapping the `Result` with `?` to iterate over its contents")),
&sub_args);
diag.span_suggestions_with_style(__binding_0, __message,
__code_27, rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowCode);
}
}
}
}
};Subdiagnostic)]
900#[suggestion(
901 "consider unwrapping the `Result` with `?` to iterate over its contents",
902 code = "?",
903 applicability = "maybe-incorrect"
904)]
905pub(crate) struct ForLoopsOverFalliblesQuestionMark {
906 #[primary_span]
907 pub suggestion: Span,
908}
909
910#[derive(const _: () =
{
impl<'a> rustc_errors::Subdiagnostic for
ForLoopsOverFalliblesSuggestion<'a> {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
ForLoopsOverFalliblesSuggestion {
var: __binding_0,
start_span: __binding_1,
end_span: __binding_2 } => {
let mut suggestions = Vec::new();
let __code_28 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("if let {0}(",
__binding_0))
});
let __code_29 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!(") = "))
});
suggestions.push((__binding_1, __code_28));
suggestions.push((__binding_2, __code_29));
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider using `if let` to clear intent")),
&sub_args);
diag.multipart_suggestion_with_style(__message, suggestions,
rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowCode);
}
}
}
}
};Subdiagnostic)]
911#[multipart_suggestion(
912 "consider using `if let` to clear intent",
913 applicability = "maybe-incorrect"
914)]
915pub(crate) struct ForLoopsOverFalliblesSuggestion<'a> {
916 pub var: &'a str,
917 #[suggestion_part(code = "if let {var}(")]
918 pub start_span: Span,
919 #[suggestion_part(code = ") = ")]
920 pub end_span: Span,
921}
922
923#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for UseLetUnderscoreIgnoreSuggestion
{
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
UseLetUnderscoreIgnoreSuggestion::Note => {
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("use `let _ = ...` to ignore the expression or result")),
&sub_args);
diag.note(__message);
}
UseLetUnderscoreIgnoreSuggestion::Suggestion {
start_span: __binding_0, end_span: __binding_1 } => {
let mut suggestions = Vec::new();
let __code_30 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("let _ = "))
});
let __code_31 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!(""))
});
suggestions.push((__binding_0, __code_30));
suggestions.push((__binding_1, __code_31));
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("use `let _ = ...` to ignore the expression or result")),
&sub_args);
diag.multipart_suggestion_with_style(__message, suggestions,
rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowAlways);
}
}
}
}
};Subdiagnostic)]
924pub(crate) enum UseLetUnderscoreIgnoreSuggestion {
925 #[note("use `let _ = ...` to ignore the expression or result")]
926 Note,
927 #[multipart_suggestion(
928 "use `let _ = ...` to ignore the expression or result",
929 style = "verbose",
930 applicability = "maybe-incorrect"
931 )]
932 Suggestion {
933 #[suggestion_part(code = "let _ = ")]
934 start_span: Span,
935 #[suggestion_part(code = "")]
936 end_span: Span,
937 },
938}
939
940#[derive(const _: () =
{
impl<'_sess, 'tcx, G> rustc_errors::Diagnostic<'_sess, G> for
RedefiningRuntimeSymbolsDiag<'tcx> 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 {
RedefiningRuntimeSymbolsDiag::Invalid {
symbol_name: __binding_0,
expected_fn_sig: __binding_1,
found_fn_sig: __binding_2 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("invalid definition of the runtime `{$symbol_name}` symbol used by the standard library")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("expected `{$expected_fn_sig}` (for the current target)\n found `{$found_fn_sig}`")));
diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("either fix the signature or remove any attributes like `#[unsafe(no_mangle)]`, `#[unsafe(export_name = \"{$symbol_name}\")]`, or `#[link_name = \"{$symbol_name}\"]`")));
;
diag.arg("symbol_name", __binding_0);
diag.arg("expected_fn_sig", __binding_1);
diag.arg("found_fn_sig", __binding_2);
diag
}
RedefiningRuntimeSymbolsDiag::Suspicious {
symbol_name: __binding_0,
expected_fn_sig: __binding_1,
found_fn_sig: __binding_2 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("suspicious definition of the runtime `{$symbol_name}` symbol used by the standard library")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("expected `{$expected_fn_sig}` (for the current target)\n found `{$found_fn_sig}`")));
diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("either fix the signature or remove any attributes like `#[unsafe(no_mangle)]`, `#[unsafe(export_name = \"{$symbol_name}\")]`, or `#[link_name = \"{$symbol_name}\"]`")));
diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("allow this lint if the signature is compatible")));
;
diag.arg("symbol_name", __binding_0);
diag.arg("expected_fn_sig", __binding_1);
diag.arg("found_fn_sig", __binding_2);
diag
}
}
}
}
};Diagnostic)]
942pub(crate) enum RedefiningRuntimeSymbolsDiag<'tcx> {
943 #[diag(
944 "invalid definition of the runtime `{$symbol_name}` symbol used by the standard library"
945 )]
946 #[note(
947 "expected `{$expected_fn_sig}` (for the current target)
948 found `{$found_fn_sig}`"
949 )]
950 #[help(
951 "either fix the signature or remove any attributes like `#[unsafe(no_mangle)]`, `#[unsafe(export_name = \"{$symbol_name}\")]`, or `#[link_name = \"{$symbol_name}\"]`"
952 )]
953 Invalid { symbol_name: String, expected_fn_sig: Ty<'tcx>, found_fn_sig: Ty<'tcx> },
954 #[diag(
955 "suspicious definition of the runtime `{$symbol_name}` symbol used by the standard library"
956 )]
957 #[note(
958 "expected `{$expected_fn_sig}` (for the current target)
959 found `{$found_fn_sig}`"
960 )]
961 #[help(
962 "either fix the signature or remove any attributes like `#[unsafe(no_mangle)]`, `#[unsafe(export_name = \"{$symbol_name}\")]`, or `#[link_name = \"{$symbol_name}\"]`"
963 )]
964 #[help("allow this lint if the signature is compatible")]
965 Suspicious { symbol_name: String, expected_fn_sig: Ty<'tcx>, found_fn_sig: Ty<'tcx> },
966}
967
968#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
DropRefDiag<'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 {
DropRefDiag {
arg_ty: __binding_0, label: __binding_1, sugg: __binding_2 }
=> {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("calls to `std::mem::drop` with a reference instead of an owned value does nothing")));
;
diag.arg("arg_ty", __binding_0);
diag.span_label(__binding_1,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("argument has type `{$arg_ty}`")));
diag.subdiagnostic(__binding_2);
diag
}
}
}
}
};Diagnostic)]
970#[diag("calls to `std::mem::drop` with a reference instead of an owned value does nothing")]
971pub(crate) struct DropRefDiag<'a> {
972 pub arg_ty: Ty<'a>,
973 #[label("argument has type `{$arg_ty}`")]
974 pub label: Span,
975 #[subdiagnostic]
976 pub sugg: UseLetUnderscoreIgnoreSuggestion,
977}
978
979#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
DropCopyDiag<'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 {
DropCopyDiag {
arg_ty: __binding_0, label: __binding_1, sugg: __binding_2 }
=> {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("calls to `std::mem::drop` with a value that implements `Copy` does nothing")));
;
diag.arg("arg_ty", __binding_0);
diag.span_label(__binding_1,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("argument has type `{$arg_ty}`")));
diag.subdiagnostic(__binding_2);
diag
}
}
}
}
};Diagnostic)]
980#[diag("calls to `std::mem::drop` with a value that implements `Copy` does nothing")]
981pub(crate) struct DropCopyDiag<'a> {
982 pub arg_ty: Ty<'a>,
983 #[label("argument has type `{$arg_ty}`")]
984 pub label: Span,
985 #[subdiagnostic]
986 pub sugg: UseLetUnderscoreIgnoreSuggestion,
987}
988
989#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
ForgetRefDiag<'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 {
ForgetRefDiag {
arg_ty: __binding_0, label: __binding_1, sugg: __binding_2 }
=> {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("calls to `std::mem::forget` with a reference instead of an owned value does nothing")));
;
diag.arg("arg_ty", __binding_0);
diag.span_label(__binding_1,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("argument has type `{$arg_ty}`")));
diag.subdiagnostic(__binding_2);
diag
}
}
}
}
};Diagnostic)]
990#[diag("calls to `std::mem::forget` with a reference instead of an owned value does nothing")]
991pub(crate) struct ForgetRefDiag<'a> {
992 pub arg_ty: Ty<'a>,
993 #[label("argument has type `{$arg_ty}`")]
994 pub label: Span,
995 #[subdiagnostic]
996 pub sugg: UseLetUnderscoreIgnoreSuggestion,
997}
998
999#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
ForgetCopyDiag<'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 {
ForgetCopyDiag {
arg_ty: __binding_0, label: __binding_1, sugg: __binding_2 }
=> {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("calls to `std::mem::forget` with a value that implements `Copy` does nothing")));
;
diag.arg("arg_ty", __binding_0);
diag.span_label(__binding_1,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("argument has type `{$arg_ty}`")));
diag.subdiagnostic(__binding_2);
diag
}
}
}
}
};Diagnostic)]
1000#[diag("calls to `std::mem::forget` with a value that implements `Copy` does nothing")]
1001pub(crate) struct ForgetCopyDiag<'a> {
1002 pub arg_ty: Ty<'a>,
1003 #[label("argument has type `{$arg_ty}`")]
1004 pub label: Span,
1005 #[subdiagnostic]
1006 pub sugg: UseLetUnderscoreIgnoreSuggestion,
1007}
1008
1009#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
UndroppedManuallyDropsDiag<'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 {
UndroppedManuallyDropsDiag {
arg_ty: __binding_0,
label: __binding_1,
suggestion: __binding_2 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("calls to `std::mem::drop` with `std::mem::ManuallyDrop` instead of the inner value does nothing")));
;
diag.arg("arg_ty", __binding_0);
diag.span_label(__binding_1,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("argument has type `{$arg_ty}`")));
diag.subdiagnostic(__binding_2);
diag
}
}
}
}
};Diagnostic)]
1010#[diag(
1011 "calls to `std::mem::drop` with `std::mem::ManuallyDrop` instead of the inner value does nothing"
1012)]
1013pub(crate) struct UndroppedManuallyDropsDiag<'a> {
1014 pub arg_ty: Ty<'a>,
1015 #[label("argument has type `{$arg_ty}`")]
1016 pub label: Span,
1017 #[subdiagnostic]
1018 pub suggestion: UndroppedManuallyDropsSuggestion,
1019}
1020
1021#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for UndroppedManuallyDropsSuggestion
{
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
UndroppedManuallyDropsSuggestion {
start_span: __binding_0, end_span: __binding_1 } => {
let mut suggestions = Vec::new();
let __code_32 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("std::mem::ManuallyDrop::into_inner("))
});
let __code_33 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!(")"))
});
suggestions.push((__binding_0, __code_32));
suggestions.push((__binding_1, __code_33));
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("use `std::mem::ManuallyDrop::into_inner` to get the inner value")),
&sub_args);
diag.multipart_suggestion_with_style(__message, suggestions,
rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::ShowCode);
}
}
}
}
};Subdiagnostic)]
1022#[multipart_suggestion(
1023 "use `std::mem::ManuallyDrop::into_inner` to get the inner value",
1024 applicability = "machine-applicable"
1025)]
1026pub(crate) struct UndroppedManuallyDropsSuggestion {
1027 #[suggestion_part(code = "std::mem::ManuallyDrop::into_inner(")]
1028 pub start_span: Span,
1029 #[suggestion_part(code = ")")]
1030 pub end_span: Span,
1031}
1032
1033#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
InvalidFromUtf8Diag 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 {
InvalidFromUtf8Diag::Unchecked {
method: __binding_0,
valid_up_to: __binding_1,
label: __binding_2 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("calls to `{$method}` with an invalid literal are undefined behavior")));
;
diag.arg("method", __binding_0);
diag.arg("valid_up_to", __binding_1);
diag.span_label(__binding_2,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the literal was valid UTF-8 up to the {$valid_up_to} bytes")));
diag
}
InvalidFromUtf8Diag::Checked {
method: __binding_0,
valid_up_to: __binding_1,
label: __binding_2 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("calls to `{$method}` with an invalid literal always return an error")));
;
diag.arg("method", __binding_0);
diag.arg("valid_up_to", __binding_1);
diag.span_label(__binding_2,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the literal was valid UTF-8 up to the {$valid_up_to} bytes")));
diag
}
}
}
}
};Diagnostic)]
1035pub(crate) enum InvalidFromUtf8Diag {
1036 #[diag("calls to `{$method}` with an invalid literal are undefined behavior")]
1037 Unchecked {
1038 method: String,
1039 valid_up_to: usize,
1040 #[label("the literal was valid UTF-8 up to the {$valid_up_to} bytes")]
1041 label: Span,
1042 },
1043 #[diag("calls to `{$method}` with an invalid literal always return an error")]
1044 Checked {
1045 method: String,
1046 valid_up_to: usize,
1047 #[label("the literal was valid UTF-8 up to the {$valid_up_to} bytes")]
1048 label: Span,
1049 },
1050}
1051
1052#[derive(const _: () =
{
impl<'_sess, 'tcx, G> rustc_errors::Diagnostic<'_sess, G> for
ConstItemInteriorMutationsDiag<'tcx> 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 {
ConstItemInteriorMutationsDiag {
method_name: __binding_0,
const_name: __binding_1,
const_ty: __binding_2,
receiver_span: __binding_3,
sugg_static: __binding_4 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("mutation of an interior mutable `const` item with call to `{$method_name}`")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("each usage of a `const` item creates a new temporary")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("only the temporaries and never the original `const {$const_name}` will be modified")));
diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("for more details on interior mutability see <https://doc.rust-lang.org/reference/interior-mutability.html>")));
;
diag.arg("method_name", __binding_0);
diag.arg("const_name", __binding_1);
diag.arg("const_ty", __binding_2);
diag.span_label(__binding_3,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`{$const_name}` is a interior mutable `const` item of type `{$const_ty}`")));
if let Some(__binding_4) = __binding_4 {
diag.subdiagnostic(__binding_4);
}
diag
}
}
}
}
};Diagnostic)]
1054#[diag("mutation of an interior mutable `const` item with call to `{$method_name}`")]
1055#[note("each usage of a `const` item creates a new temporary")]
1056#[note("only the temporaries and never the original `const {$const_name}` will be modified")]
1057#[help(
1058 "for more details on interior mutability see <https://doc.rust-lang.org/reference/interior-mutability.html>"
1059)]
1060pub(crate) struct ConstItemInteriorMutationsDiag<'tcx> {
1061 pub method_name: Ident,
1062 pub const_name: Ident,
1063 pub const_ty: Ty<'tcx>,
1064 #[label("`{$const_name}` is a interior mutable `const` item of type `{$const_ty}`")]
1065 pub receiver_span: Span,
1066 #[subdiagnostic]
1067 pub sugg_static: Option<ConstItemInteriorMutationsSuggestionStatic>,
1068}
1069
1070#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for
ConstItemInteriorMutationsSuggestionStatic {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
ConstItemInteriorMutationsSuggestionStatic::Spanful {
const_: __binding_0,
before: __binding_1,
const_name: __binding_2 } => {
let __code_34 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0}static ",
__binding_1))
})].into_iter();
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("const_name".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_2,
&mut diag.long_ty_path));
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("for a shared instance of `{$const_name}`, consider making it a `static` item instead")),
&sub_args);
diag.span_suggestions_with_style(__binding_0, __message,
__code_34, rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowAlways);
}
ConstItemInteriorMutationsSuggestionStatic::Spanless {
const_name: __binding_0 } => {
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("const_name".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_0,
&mut diag.long_ty_path));
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("for a shared instance of `{$const_name}`, consider making it a `static` item instead")),
&sub_args);
diag.help(__message);
}
}
}
}
};Subdiagnostic)]
1071pub(crate) enum ConstItemInteriorMutationsSuggestionStatic {
1072 #[suggestion(
1073 "for a shared instance of `{$const_name}`, consider making it a `static` item instead",
1074 code = "{before}static ",
1075 style = "verbose",
1076 applicability = "maybe-incorrect"
1077 )]
1078 Spanful {
1079 #[primary_span]
1080 const_: Span,
1081 before: &'static str,
1082 const_name: Ident,
1083 },
1084 #[help("for a shared instance of `{$const_name}`, consider making it a `static` item instead")]
1085 Spanless { const_name: Ident },
1086}
1087
1088#[derive(const _: () =
{
impl<'_sess, 'tcx, G> rustc_errors::Diagnostic<'_sess, G> for
InvalidReferenceCastingDiag<'tcx> 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 {
InvalidReferenceCastingDiag::BorrowAsMut {
orig_cast: __binding_0 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>")));
;
if let Some(__binding_0) = __binding_0 {
diag.span_label(__binding_0,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("casting happened here")));
}
diag
}
InvalidReferenceCastingDiag::AssignToRef {
orig_cast: __binding_0 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("assigning to `&T` is undefined behavior, consider using an `UnsafeCell`")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>")));
;
if let Some(__binding_0) = __binding_0 {
diag.span_label(__binding_0,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("casting happened here")));
}
diag
}
InvalidReferenceCastingDiag::BiggerLayout {
orig_cast: __binding_0,
alloc: __binding_1,
from_ty: __binding_2,
from_size: __binding_3,
to_ty: __binding_4,
to_size: __binding_5 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("casting references to a bigger memory layout than the backing allocation is undefined behavior, even if the reference is unused")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("casting from `{$from_ty}` ({$from_size} bytes) to `{$to_ty}` ({$to_size} bytes)")));
;
diag.arg("from_ty", __binding_2);
diag.arg("from_size", __binding_3);
diag.arg("to_ty", __binding_4);
diag.arg("to_size", __binding_5);
if let Some(__binding_0) = __binding_0 {
diag.span_label(__binding_0,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("casting happened here")));
}
diag.span_label(__binding_1,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("backing allocation comes from here")));
diag
}
}
}
}
};Diagnostic)]
1090pub(crate) enum InvalidReferenceCastingDiag<'tcx> {
1091 #[diag(
1092 "casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`"
1093 )]
1094 #[note(
1095 "for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>"
1096 )]
1097 BorrowAsMut {
1098 #[label("casting happened here")]
1099 orig_cast: Option<Span>,
1100 },
1101 #[diag("assigning to `&T` is undefined behavior, consider using an `UnsafeCell`")]
1102 #[note(
1103 "for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>"
1104 )]
1105 AssignToRef {
1106 #[label("casting happened here")]
1107 orig_cast: Option<Span>,
1108 },
1109 #[diag(
1110 "casting references to a bigger memory layout than the backing allocation is undefined behavior, even if the reference is unused"
1111 )]
1112 #[note("casting from `{$from_ty}` ({$from_size} bytes) to `{$to_ty}` ({$to_size} bytes)")]
1113 BiggerLayout {
1114 #[label("casting happened here")]
1115 orig_cast: Option<Span>,
1116 #[label("backing allocation comes from here")]
1117 alloc: Span,
1118 from_ty: Ty<'tcx>,
1119 from_size: u64,
1120 to_ty: Ty<'tcx>,
1121 to_size: u64,
1122 },
1123}
1124
1125#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for MappingToUnit
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 {
MappingToUnit {
function_label: __binding_0,
argument_label: __binding_1,
map_label: __binding_2,
suggestion: __binding_3 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`Iterator::map` call that discard the iterator's values")));
let __code_35 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("for_each"))
})].into_iter();
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`Iterator::map`, like many of the methods on `Iterator`, gets executed lazily, meaning that its effects won't be visible until it is iterated")));
;
diag.span_label(__binding_0,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this function returns `()`, which is likely not what you wanted")));
diag.span_label(__binding_1,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("called `Iterator::map` with callable that returns `()`")));
diag.span_label(__binding_2,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("after this call to map, the resulting iterator is `impl Iterator<Item = ()>`, which means the only information carried by the iterator is the number of items")));
diag.span_suggestions_with_style(__binding_3,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("you might have meant to use `Iterator::for_each`")),
__code_35, rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowAlways);
diag
}
}
}
}
};Diagnostic)]
1127#[diag("`Iterator::map` call that discard the iterator's values")]
1128#[note(
1129 "`Iterator::map`, like many of the methods on `Iterator`, gets executed lazily, meaning that its effects won't be visible until it is iterated"
1130)]
1131pub(crate) struct MappingToUnit {
1132 #[label("this function returns `()`, which is likely not what you wanted")]
1133 pub function_label: Span,
1134 #[label("called `Iterator::map` with callable that returns `()`")]
1135 pub argument_label: Span,
1136 #[label(
1137 "after this call to map, the resulting iterator is `impl Iterator<Item = ()>`, which means the only information carried by the iterator is the number of items"
1138 )]
1139 pub map_label: Span,
1140 #[suggestion(
1141 "you might have meant to use `Iterator::for_each`",
1142 style = "verbose",
1143 code = "for_each",
1144 applicability = "maybe-incorrect"
1145 )]
1146 pub suggestion: Span,
1147}
1148
1149#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
DefaultHashTypesDiag<'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 {
DefaultHashTypesDiag {
preferred: __binding_0, used: __binding_1 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("prefer `{$preferred}` over `{$used}`, it has better performance")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("a `use rustc_data_structures::fx::{$preferred}` may be necessary")));
;
diag.arg("preferred", __binding_0);
diag.arg("used", __binding_1);
diag
}
}
}
}
};Diagnostic)]
1151#[diag("prefer `{$preferred}` over `{$used}`, it has better performance")]
1152#[note("a `use rustc_data_structures::fx::{$preferred}` may be necessary")]
1153pub(crate) struct DefaultHashTypesDiag<'a> {
1154 pub preferred: &'a str,
1155 pub used: Symbol,
1156}
1157
1158#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
QueryInstability 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 {
QueryInstability { query: __binding_0 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("using `{$query}` can result in unstable query results")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("if you believe this case to be fine, allow this lint and add a comment explaining your rationale")));
;
diag.arg("query", __binding_0);
diag
}
}
}
}
};Diagnostic)]
1159#[diag("using `{$query}` can result in unstable query results")]
1160#[note(
1161 "if you believe this case to be fine, allow this lint and add a comment explaining your rationale"
1162)]
1163pub(crate) struct QueryInstability {
1164 pub query: Symbol,
1165}
1166
1167#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for QueryUntracked
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 {
QueryUntracked { method: __binding_0 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`{$method}` accesses information that is not tracked by the query system")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("if you believe this case to be fine, allow this lint and add a comment explaining your rationale")));
;
diag.arg("method", __binding_0);
diag
}
}
}
}
};Diagnostic)]
1168#[diag("`{$method}` accesses information that is not tracked by the query system")]
1169#[note(
1170 "if you believe this case to be fine, allow this lint and add a comment explaining your rationale"
1171)]
1172pub(crate) struct QueryUntracked {
1173 pub method: Symbol,
1174}
1175
1176#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
SpanUseEqCtxtDiag 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 {
SpanUseEqCtxtDiag => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("use `.eq_ctxt()` instead of `.ctxt() == .ctxt()`")));
;
diag
}
}
}
}
};Diagnostic)]
1177#[diag("use `.eq_ctxt()` instead of `.ctxt() == .ctxt()`")]
1178pub(crate) struct SpanUseEqCtxtDiag;
1179
1180#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
SymbolInternStringLiteralDiag 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 {
SymbolInternStringLiteralDiag => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("using `Symbol::intern` on a string literal")));
diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider adding the symbol to `compiler/rustc_span/src/symbol.rs`")));
;
diag
}
}
}
}
};Diagnostic)]
1181#[diag("using `Symbol::intern` on a string literal")]
1182#[help("consider adding the symbol to `compiler/rustc_span/src/symbol.rs`")]
1183pub(crate) struct SymbolInternStringLiteralDiag;
1184
1185#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for TykindKind
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 {
TykindKind { suggestion: __binding_0 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("usage of `ty::TyKind::<kind>`")));
let __code_36 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("ty"))
})].into_iter();
;
diag.span_suggestions_with_style(__binding_0,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("try using `ty::<kind>` directly")),
__code_36, rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowCode);
diag
}
}
}
}
};Diagnostic)]
1186#[diag("usage of `ty::TyKind::<kind>`")]
1187pub(crate) struct TykindKind {
1188 #[suggestion(
1189 "try using `ty::<kind>` directly",
1190 code = "ty",
1191 applicability = "maybe-incorrect"
1192 )]
1193 pub suggestion: Span,
1194}
1195
1196#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for TykindDiag
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 {
TykindDiag => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("usage of `ty::TyKind`")));
diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("try using `Ty` instead")));
;
diag
}
}
}
}
};Diagnostic)]
1197#[diag("usage of `ty::TyKind`")]
1198#[help("try using `Ty` instead")]
1199pub(crate) struct TykindDiag;
1200
1201#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for TyQualified
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 {
TyQualified { ty: __binding_0, suggestion: __binding_1 } =>
{
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("usage of qualified `ty::{$ty}`")));
let __code_37 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0}", __binding_0))
})].into_iter();
;
diag.arg("ty", __binding_0);
diag.span_suggestions_with_style(__binding_1,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("try importing it and using it unqualified")),
__code_37, rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowCode);
diag
}
}
}
}
};Diagnostic)]
1202#[diag("usage of qualified `ty::{$ty}`")]
1203pub(crate) struct TyQualified {
1204 pub ty: String,
1205 #[suggestion(
1206 "try importing it and using it unqualified",
1207 code = "{ty}",
1208 applicability = "maybe-incorrect"
1209 )]
1210 pub suggestion: Span,
1211}
1212
1213#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
TypeIrInherentUsage 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 {
TypeIrInherentUsage => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("do not use `rustc_type_ir::inherent` unless you're inside of the trait solver")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the method or struct you're looking for is likely defined somewhere else downstream in the compiler")));
;
diag
}
}
}
}
};Diagnostic)]
1214#[diag("do not use `rustc_type_ir::inherent` unless you're inside of the trait solver")]
1215#[note(
1216 "the method or struct you're looking for is likely defined somewhere else downstream in the compiler"
1217)]
1218pub(crate) struct TypeIrInherentUsage;
1219
1220#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
TypeIrTraitUsage 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 {
TypeIrTraitUsage => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("do not use `rustc_type_ir::Interner` or `rustc_type_ir::InferCtxtLike` unless you're inside of the trait solver")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the method or struct you're looking for is likely defined somewhere else downstream in the compiler")));
;
diag
}
}
}
}
};Diagnostic)]
1221#[diag(
1222 "do not use `rustc_type_ir::Interner` or `rustc_type_ir::InferCtxtLike` unless you're inside of the trait solver"
1223)]
1224#[note(
1225 "the method or struct you're looking for is likely defined somewhere else downstream in the compiler"
1226)]
1227pub(crate) struct TypeIrTraitUsage;
1228
1229#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
TypeIrDirectUse 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 {
TypeIrDirectUse => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("do not use `rustc_type_ir` unless you are implementing type system internals")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("use `rustc_middle::ty` instead")));
;
diag
}
}
}
}
};Diagnostic)]
1230#[diag("do not use `rustc_type_ir` unless you are implementing type system internals")]
1231#[note("use `rustc_middle::ty` instead")]
1232pub(crate) struct TypeIrDirectUse;
1233
1234#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
NonGlobImportTypeIrInherent 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 {
NonGlobImportTypeIrInherent {
suggestion: __binding_0, snippet: __binding_1 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("non-glob import of `rustc_type_ir::inherent`")));
let __code_38 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0}", __binding_1))
})].into_iter();
;
if let Some(__binding_0) = __binding_0 {
diag.span_suggestions_with_style(__binding_0,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("try using a glob import instead")),
__code_38, rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowCode);
}
diag
}
}
}
}
};Diagnostic)]
1235#[diag("non-glob import of `rustc_type_ir::inherent`")]
1236pub(crate) struct NonGlobImportTypeIrInherent {
1237 #[suggestion(
1238 "try using a glob import instead",
1239 code = "{snippet}",
1240 applicability = "maybe-incorrect"
1241 )]
1242 pub suggestion: Option<Span>,
1243 pub snippet: &'static str,
1244}
1245
1246#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for LintPassByHand
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 {
LintPassByHand => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("implementing `LintPass` by hand")));
diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("try using `declare_lint_pass!` or `impl_lint_pass!` instead")));
;
diag
}
}
}
}
};Diagnostic)]
1247#[diag("implementing `LintPass` by hand")]
1248#[help("try using `declare_lint_pass!` or `impl_lint_pass!` instead")]
1249pub(crate) struct LintPassByHand;
1250
1251#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
BadOptAccessDiag<'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 {
BadOptAccessDiag { msg: __binding_0 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$msg}")));
;
diag.arg("msg", __binding_0);
diag
}
}
}
}
};Diagnostic)]
1252#[diag("{$msg}")]
1253pub(crate) struct BadOptAccessDiag<'a> {
1254 pub msg: &'a str,
1255}
1256
1257#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
ImplicitSysrootCrateImportDiag<'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 {
ImplicitSysrootCrateImportDiag { name: __binding_0 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("dangerous use of `extern crate {$name}` which is not guaranteed to exist exactly once in the sysroot")));
diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("try using a cargo dependency or using a re-export of the dependency provided by a rustc_* crate")));
;
diag.arg("name", __binding_0);
diag
}
}
}
}
};Diagnostic)]
1258#[diag(
1259 "dangerous use of `extern crate {$name}` which is not guaranteed to exist exactly once in the sysroot"
1260)]
1261#[help(
1262 "try using a cargo dependency or using a re-export of the dependency provided by a rustc_* crate"
1263)]
1264pub(crate) struct ImplicitSysrootCrateImportDiag<'a> {
1265 pub name: &'a str,
1266}
1267
1268#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
AttributeKindInFindAttr 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 {
AttributeKindInFindAttr => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("use of `AttributeKind` in `find_attr!(...)` invocation")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`find_attr!(...)` already imports `AttributeKind::*`")));
diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("remove `AttributeKind`")));
;
diag
}
}
}
}
};Diagnostic)]
1269#[diag("use of `AttributeKind` in `find_attr!(...)` invocation")]
1270#[note("`find_attr!(...)` already imports `AttributeKind::*`")]
1271#[help("remove `AttributeKind`")]
1272pub(crate) struct AttributeKindInFindAttr;
1273
1274#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
RustcMustMatchExhaustivelyNotExhaustive 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 {
RustcMustMatchExhaustivelyNotExhaustive {
attr_span: __binding_0,
pat_span: __binding_1,
message: __binding_2 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("match is not exhaustive")));
diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("explicitly list all variants of the enum in a `match`")));
;
diag.arg("message", __binding_2);
diag.span_label(__binding_0,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("required because of this attribute")));
diag.span_note(__binding_1,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$message}")));
diag
}
}
}
}
};Diagnostic)]
1275#[diag("match is not exhaustive")]
1276#[help("explicitly list all variants of the enum in a `match`")]
1277pub(crate) struct RustcMustMatchExhaustivelyNotExhaustive {
1278 #[label("required because of this attribute")]
1279 pub attr_span: Span,
1280
1281 #[note("{$message}")]
1282 pub pat_span: Span,
1283 pub message: &'static str,
1284}
1285
1286#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for NonBindingLet
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 {
NonBindingLet::SyncLock { pat: __binding_0, sub: __binding_1
} => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("non-binding let on a synchronization lock")));
;
diag.span_label(__binding_0,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this lock is not assigned to a binding and is immediately dropped")));
diag.subdiagnostic(__binding_1);
diag
}
NonBindingLet::DropType { sub: __binding_0 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("non-binding let on a type that has a destructor")));
;
diag.subdiagnostic(__binding_0);
diag
}
}
}
}
};Diagnostic)]
1288pub(crate) enum NonBindingLet {
1289 #[diag("non-binding let on a synchronization lock")]
1290 SyncLock {
1291 #[label("this lock is not assigned to a binding and is immediately dropped")]
1292 pat: Span,
1293 #[subdiagnostic]
1294 sub: NonBindingLetSub,
1295 },
1296 #[diag("non-binding let on a type that has a destructor")]
1297 DropType {
1298 #[subdiagnostic]
1299 sub: NonBindingLetSub,
1300 },
1301}
1302
1303pub(crate) struct NonBindingLetSub {
1304 pub suggestion: Span,
1305 pub drop_fn_start_end: Option<(Span, Span)>,
1306 pub is_assign_desugar: bool,
1307}
1308
1309impl Subdiagnostic for NonBindingLetSub {
1310 fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
1311 let can_suggest_binding = self.drop_fn_start_end.is_some() || !self.is_assign_desugar;
1312
1313 if can_suggest_binding {
1314 let prefix = if self.is_assign_desugar { "let " } else { "" };
1315 diag.span_suggestion_verbose(
1316 self.suggestion,
1317 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider binding to an unused variable to avoid immediately dropping the value"))msg!(
1318 "consider binding to an unused variable to avoid immediately dropping the value"
1319 ),
1320 ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0}_unused", prefix))
})format!("{prefix}_unused"),
1321 Applicability::MachineApplicable,
1322 );
1323 } else {
1324 diag.span_help(
1325 self.suggestion,
1326 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider binding to an unused variable to avoid immediately dropping the value"))msg!(
1327 "consider binding to an unused variable to avoid immediately dropping the value"
1328 ),
1329 );
1330 }
1331 if let Some(drop_fn_start_end) = self.drop_fn_start_end {
1332 diag.multipart_suggestion(
1333 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider immediately dropping the value"))msg!("consider immediately dropping the value"),
1334 ::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
[(drop_fn_start_end.0, "drop(".to_string()),
(drop_fn_start_end.1, ")".to_string())]))vec![
1335 (drop_fn_start_end.0, "drop(".to_string()),
1336 (drop_fn_start_end.1, ")".to_string()),
1337 ],
1338 Applicability::MachineApplicable,
1339 );
1340 } else {
1341 diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider immediately dropping the value using `drop(..)` after the `let` statement"))msg!(
1342 "consider immediately dropping the value using `drop(..)` after the `let` statement"
1343 ));
1344 }
1345 }
1346}
1347
1348#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
OverruledAttributeLint<'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 {
OverruledAttributeLint {
overruled: __binding_0,
lint_level: __binding_1,
lint_source: __binding_2,
sub: __binding_3 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$lint_level}({$lint_source}) incompatible with previous forbid")));
;
diag.arg("lint_level", __binding_1);
diag.arg("lint_source", __binding_2);
diag.span_label(__binding_0,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("overruled by previous forbid")));
diag.subdiagnostic(__binding_3);
diag
}
}
}
}
};Diagnostic)]
1350#[diag("{$lint_level}({$lint_source}) incompatible with previous forbid")]
1351pub(crate) struct OverruledAttributeLint<'a> {
1352 #[label("overruled by previous forbid")]
1353 pub overruled: Span,
1354 pub lint_level: &'a str,
1355 pub lint_source: Symbol,
1356 #[subdiagnostic]
1357 pub sub: OverruledAttributeSub,
1358}
1359
1360#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
DeprecatedLintName<'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 {
DeprecatedLintName {
name: __binding_0,
suggestion: __binding_1,
replace: __binding_2 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("lint name `{$name}` is deprecated and may not have an effect in the future")));
let __code_39 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0}", __binding_2))
})].into_iter();
;
diag.arg("name", __binding_0);
diag.span_suggestions_with_style(__binding_1,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("change it to")),
__code_39, rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::ShowCode);
diag
}
}
}
}
};Diagnostic)]
1361#[diag("lint name `{$name}` is deprecated and may not have an effect in the future")]
1362pub(crate) struct DeprecatedLintName<'a> {
1363 pub name: String,
1364 #[suggestion("change it to", code = "{replace}", applicability = "machine-applicable")]
1365 pub suggestion: Span,
1366 pub replace: &'a str,
1367}
1368
1369#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
DeprecatedLintNameFromCommandLine<'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 {
DeprecatedLintNameFromCommandLine {
name: __binding_0,
replace: __binding_1,
requested_level: __binding_2 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("lint name `{$name}` is deprecated and may not have an effect in the future")));
diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("change it to {$replace}")));
;
diag.arg("name", __binding_0);
diag.arg("replace", __binding_1);
diag.subdiagnostic(__binding_2);
diag
}
}
}
}
};Diagnostic)]
1370#[diag("lint name `{$name}` is deprecated and may not have an effect in the future")]
1371#[help("change it to {$replace}")]
1372pub(crate) struct DeprecatedLintNameFromCommandLine<'a> {
1373 pub name: String,
1374 pub replace: &'a str,
1375 #[subdiagnostic]
1376 pub requested_level: RequestedLevel<'a>,
1377}
1378
1379#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
RenamedLint<'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 {
RenamedLint {
name: __binding_0,
replace: __binding_1,
suggestion: __binding_2 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("lint `{$name}` has been renamed to `{$replace}`")));
;
diag.arg("name", __binding_0);
diag.arg("replace", __binding_1);
diag.subdiagnostic(__binding_2);
diag
}
}
}
}
};Diagnostic)]
1380#[diag("lint `{$name}` has been renamed to `{$replace}`")]
1381pub(crate) struct RenamedLint<'a> {
1382 pub name: &'a str,
1383 pub replace: &'a str,
1384 #[subdiagnostic]
1385 pub suggestion: RenamedLintSuggestion<'a>,
1386}
1387
1388#[derive(const _: () =
{
impl<'a> rustc_errors::Subdiagnostic for RenamedLintSuggestion<'a> {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
RenamedLintSuggestion::WithSpan {
suggestion: __binding_0, replace: __binding_1 } => {
let __code_40 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0}", __binding_1))
})].into_iter();
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("use the new name")),
&sub_args);
diag.span_suggestions_with_style(__binding_0, __message,
__code_40, rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::ShowCode);
}
RenamedLintSuggestion::WithoutSpan { replace: __binding_0 }
=> {
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("replace".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_0,
&mut diag.long_ty_path));
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("use the new name `{$replace}`")),
&sub_args);
diag.help(__message);
}
}
}
}
};Subdiagnostic)]
1389pub(crate) enum RenamedLintSuggestion<'a> {
1390 #[suggestion("use the new name", code = "{replace}", applicability = "machine-applicable")]
1391 WithSpan {
1392 #[primary_span]
1393 suggestion: Span,
1394 replace: &'a str,
1395 },
1396 #[help("use the new name `{$replace}`")]
1397 WithoutSpan { replace: &'a str },
1398}
1399
1400#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
RenamedLintFromCommandLine<'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 {
RenamedLintFromCommandLine {
name: __binding_0,
replace: __binding_1,
suggestion: __binding_2,
requested_level: __binding_3 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("lint `{$name}` has been renamed to `{$replace}`")));
;
diag.arg("name", __binding_0);
diag.arg("replace", __binding_1);
diag.subdiagnostic(__binding_2);
diag.subdiagnostic(__binding_3);
diag
}
}
}
}
};Diagnostic)]
1401#[diag("lint `{$name}` has been renamed to `{$replace}`")]
1402pub(crate) struct RenamedLintFromCommandLine<'a> {
1403 pub name: &'a str,
1404 pub replace: &'a str,
1405 #[subdiagnostic]
1406 pub suggestion: RenamedLintSuggestion<'a>,
1407 #[subdiagnostic]
1408 pub requested_level: RequestedLevel<'a>,
1409}
1410
1411#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
RemovedLint<'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 {
RemovedLint { name: __binding_0, reason: __binding_1 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("lint `{$name}` has been removed: {$reason}")));
;
diag.arg("name", __binding_0);
diag.arg("reason", __binding_1);
diag
}
}
}
}
};Diagnostic)]
1412#[diag("lint `{$name}` has been removed: {$reason}")]
1413pub(crate) struct RemovedLint<'a> {
1414 pub name: &'a str,
1415 pub reason: &'a str,
1416}
1417
1418#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
RemovedLintFromCommandLine<'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 {
RemovedLintFromCommandLine {
name: __binding_0,
reason: __binding_1,
requested_level: __binding_2 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("lint `{$name}` has been removed: {$reason}")));
;
diag.arg("name", __binding_0);
diag.arg("reason", __binding_1);
diag.subdiagnostic(__binding_2);
diag
}
}
}
}
};Diagnostic)]
1419#[diag("lint `{$name}` has been removed: {$reason}")]
1420pub(crate) struct RemovedLintFromCommandLine<'a> {
1421 pub name: &'a str,
1422 pub reason: &'a str,
1423 #[subdiagnostic]
1424 pub requested_level: RequestedLevel<'a>,
1425}
1426
1427#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for UnknownLint
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 {
UnknownLint { name: __binding_0, suggestion: __binding_1 }
=> {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("unknown lint: `{$name}`")));
;
diag.arg("name", __binding_0);
if let Some(__binding_1) = __binding_1 {
diag.subdiagnostic(__binding_1);
}
diag
}
}
}
}
};Diagnostic)]
1428#[diag("unknown lint: `{$name}`")]
1429pub(crate) struct UnknownLint {
1430 pub name: String,
1431 #[subdiagnostic]
1432 pub suggestion: Option<UnknownLintSuggestion>,
1433}
1434
1435#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for UnknownLintSuggestion {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
UnknownLintSuggestion::WithSpan {
suggestion: __binding_0,
replace: __binding_1,
from_rustc: __binding_2 } => {
let __code_41 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0}", __binding_1))
})].into_iter();
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("from_rustc".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_2,
&mut diag.long_ty_path));
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$from_rustc ->\n [true] a lint with a similar name exists in `rustc` lints\n *[false] did you mean\n }")),
&sub_args);
diag.span_suggestions_with_style(__binding_0, __message,
__code_41, rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowCode);
}
UnknownLintSuggestion::WithoutSpan {
replace: __binding_0, from_rustc: __binding_1 } => {
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("replace".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_0,
&mut diag.long_ty_path));
sub_args.insert("from_rustc".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_1,
&mut diag.long_ty_path));
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$from_rustc ->\n [true] a lint with a similar name exists in `rustc` lints: `{$replace}`\n *[false] did you mean: `{$replace}`\n }")),
&sub_args);
diag.help(__message);
}
}
}
}
};Subdiagnostic)]
1436pub(crate) enum UnknownLintSuggestion {
1437 #[suggestion(
1438 "{$from_rustc ->
1439 [true] a lint with a similar name exists in `rustc` lints
1440 *[false] did you mean
1441 }",
1442 code = "{replace}",
1443 applicability = "maybe-incorrect"
1444 )]
1445 WithSpan {
1446 #[primary_span]
1447 suggestion: Span,
1448 replace: Symbol,
1449 from_rustc: bool,
1450 },
1451 #[help(
1452 "{$from_rustc ->
1453 [true] a lint with a similar name exists in `rustc` lints: `{$replace}`
1454 *[false] did you mean: `{$replace}`
1455 }"
1456 )]
1457 WithoutSpan { replace: Symbol, from_rustc: bool },
1458}
1459
1460#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
UnknownLintFromCommandLine<'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 {
UnknownLintFromCommandLine {
name: __binding_0,
suggestion: __binding_1,
requested_level: __binding_2 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("unknown lint: `{$name}`")));
diag.code(E0602);
;
diag.arg("name", __binding_0);
if let Some(__binding_1) = __binding_1 {
diag.subdiagnostic(__binding_1);
}
diag.subdiagnostic(__binding_2);
diag
}
}
}
}
};Diagnostic)]
1461#[diag("unknown lint: `{$name}`", code = E0602)]
1462pub(crate) struct UnknownLintFromCommandLine<'a> {
1463 pub name: String,
1464 #[subdiagnostic]
1465 pub suggestion: Option<UnknownLintSuggestion>,
1466 #[subdiagnostic]
1467 pub requested_level: RequestedLevel<'a>,
1468}
1469
1470#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
IgnoredUnlessCrateSpecified<'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 {
IgnoredUnlessCrateSpecified {
level: __binding_0, name: __binding_1 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$level}({$name}) is ignored unless specified at crate level")));
;
diag.arg("level", __binding_0);
diag.arg("name", __binding_1);
diag
}
}
}
}
};Diagnostic)]
1471#[diag("{$level}({$name}) is ignored unless specified at crate level")]
1472pub(crate) struct IgnoredUnlessCrateSpecified<'a> {
1473 pub level: &'a str,
1474 pub name: Symbol,
1475}
1476
1477#[derive(const _: () =
{
impl<'_sess, 'tcx, G> rustc_errors::Diagnostic<'_sess, G> for
DanglingPointersFromTemporaries<'tcx> 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 {
DanglingPointersFromTemporaries {
callee: __binding_0,
ty: __binding_1,
ptr_span: __binding_2,
temporary_span: __binding_3 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this creates a dangling pointer because temporary `{$ty}` is dropped at end of statement")));
diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("bind the `{$ty}` to a variable such that it outlives the pointer returned by `{$callee}`")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("a dangling pointer is safe, but dereferencing one is undefined behavior")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("returning a pointer to a local variable will always result in a dangling pointer")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("for more information, see <https://doc.rust-lang.org/reference/destructors.html>")));
;
diag.arg("callee", __binding_0);
diag.arg("ty", __binding_1);
diag.span_label(__binding_2,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("pointer created here")));
diag.span_label(__binding_3,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this `{$ty}` is dropped at end of statement")));
diag
}
}
}
}
};Diagnostic)]
1479#[diag("this creates a dangling pointer because temporary `{$ty}` is dropped at end of statement")]
1480#[help("bind the `{$ty}` to a variable such that it outlives the pointer returned by `{$callee}`")]
1481#[note("a dangling pointer is safe, but dereferencing one is undefined behavior")]
1482#[note("returning a pointer to a local variable will always result in a dangling pointer")]
1483#[note("for more information, see <https://doc.rust-lang.org/reference/destructors.html>")]
1484pub(crate) struct DanglingPointersFromTemporaries<'tcx> {
1486 pub callee: Ident,
1487 pub ty: Ty<'tcx>,
1488 #[label("pointer created here")]
1489 pub ptr_span: Span,
1490 #[label("this `{$ty}` is dropped at end of statement")]
1491 pub temporary_span: Span,
1492}
1493
1494#[derive(const _: () =
{
impl<'_sess, 'tcx, G> rustc_errors::Diagnostic<'_sess, G> for
DanglingPointersFromLocals<'tcx> 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 {
DanglingPointersFromLocals {
ret_ty: __binding_0,
ret_ty_span: __binding_1,
fn_kind: __binding_2,
local_var: __binding_3,
local_var_name: __binding_4,
local_var_ty: __binding_5,
created_at: __binding_6 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$fn_kind} returns a dangling pointer to dropped local variable `{$local_var_name}`")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("a dangling pointer is safe, but dereferencing one is undefined behavior")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("for more information, see <https://doc.rust-lang.org/reference/destructors.html>")));
;
diag.arg("ret_ty", __binding_0);
diag.arg("fn_kind", __binding_2);
diag.arg("local_var_name", __binding_4);
diag.span_label(__binding_1,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("return type is `{$ret_ty}`")));
diag.span_label(__binding_3,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("local variable `{$local_var_name}` is dropped at the end of the {$fn_kind}")));
if let Some(__binding_6) = __binding_6 {
diag.span_label(__binding_6,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("dangling pointer created here")));
}
diag
}
}
}
}
};Diagnostic)]
1495#[diag("{$fn_kind} returns a dangling pointer to dropped local variable `{$local_var_name}`")]
1496#[note("a dangling pointer is safe, but dereferencing one is undefined behavior")]
1497#[note("for more information, see <https://doc.rust-lang.org/reference/destructors.html>")]
1498pub(crate) struct DanglingPointersFromLocals<'tcx> {
1499 pub ret_ty: Ty<'tcx>,
1500 #[label("return type is `{$ret_ty}`")]
1501 pub ret_ty_span: Span,
1502 pub fn_kind: &'static str,
1503 #[label("local variable `{$local_var_name}` is dropped at the end of the {$fn_kind}")]
1504 pub local_var: Span,
1505 pub local_var_name: Ident,
1506 pub local_var_ty: Ty<'tcx>,
1507 #[label("dangling pointer created here")]
1508 pub created_at: Option<Span>,
1509}
1510
1511#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
MultipleSupertraitUpcastable 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 {
MultipleSupertraitUpcastable { ident: __binding_0 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`{$ident}` is dyn-compatible and has multiple supertraits")));
;
diag.arg("ident", __binding_0);
diag
}
}
}
}
};Diagnostic)]
1513#[diag("`{$ident}` is dyn-compatible and has multiple supertraits")]
1514pub(crate) struct MultipleSupertraitUpcastable {
1515 pub ident: Ident,
1516}
1517
1518#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
IdentifierNonAsciiChar 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 {
IdentifierNonAsciiChar => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("identifier contains non-ASCII characters")));
;
diag
}
}
}
}
};Diagnostic)]
1520#[diag("identifier contains non-ASCII characters")]
1521pub(crate) struct IdentifierNonAsciiChar;
1522
1523#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
IdentifierUncommonCodepoints 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 {
IdentifierUncommonCodepoints {
codepoints: __binding_0,
codepoints_len: __binding_1,
identifier_type: __binding_2 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("identifier contains {$codepoints_len ->\n [one] { $identifier_type ->\n [Exclusion] a character from an archaic script\n [Technical] a character that is for non-linguistic, specialized usage\n [Limited_Use] a character from a script in limited use\n [Not_NFKC] a non normalized (NFKC) character\n *[other] an uncommon character\n }\n *[other] { $identifier_type ->\n [Exclusion] {$codepoints_len} characters from archaic scripts\n [Technical] {$codepoints_len} characters that are for non-linguistic, specialized usage\n [Limited_Use] {$codepoints_len} characters from scripts in limited use\n [Not_NFKC] {$codepoints_len} non normalized (NFKC) characters\n *[other] uncommon characters\n }\n }: {$codepoints}")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$codepoints_len ->\n [one] this character is\n *[other] these characters are\n } included in the{$identifier_type ->\n [Restricted] {\"\"}\n *[other] {\" \"}{$identifier_type}\n } Unicode general security profile")));
;
diag.arg("codepoints", __binding_0);
diag.arg("codepoints_len", __binding_1);
diag.arg("identifier_type", __binding_2);
diag
}
}
}
}
};Diagnostic)]
1524#[diag(
1525 "identifier contains {$codepoints_len ->
1526 [one] { $identifier_type ->
1527 [Exclusion] a character from an archaic script
1528 [Technical] a character that is for non-linguistic, specialized usage
1529 [Limited_Use] a character from a script in limited use
1530 [Not_NFKC] a non normalized (NFKC) character
1531 *[other] an uncommon character
1532 }
1533 *[other] { $identifier_type ->
1534 [Exclusion] {$codepoints_len} characters from archaic scripts
1535 [Technical] {$codepoints_len} characters that are for non-linguistic, specialized usage
1536 [Limited_Use] {$codepoints_len} characters from scripts in limited use
1537 [Not_NFKC] {$codepoints_len} non normalized (NFKC) characters
1538 *[other] uncommon characters
1539 }
1540 }: {$codepoints}"
1541)]
1542#[note(
1543 r#"{$codepoints_len ->
1544 [one] this character is
1545 *[other] these characters are
1546 } included in the{$identifier_type ->
1547 [Restricted] {""}
1548 *[other] {" "}{$identifier_type}
1549 } Unicode general security profile"#
1550)]
1551pub(crate) struct IdentifierUncommonCodepoints {
1552 pub codepoints: Vec<char>,
1553 pub codepoints_len: usize,
1554 pub identifier_type: &'static str,
1555}
1556
1557#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
ConfusableIdentifierPair 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 {
ConfusableIdentifierPair {
existing_sym: __binding_0,
sym: __binding_1,
label: __binding_2,
main_label: __binding_3 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("found both `{$existing_sym}` and `{$sym}` as identifiers, which look alike")));
;
diag.arg("existing_sym", __binding_0);
diag.arg("sym", __binding_1);
diag.span_label(__binding_2,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("other identifier used here")));
diag.span_label(__binding_3,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this identifier can be confused with `{$existing_sym}`")));
diag
}
}
}
}
};Diagnostic)]
1558#[diag("found both `{$existing_sym}` and `{$sym}` as identifiers, which look alike")]
1559pub(crate) struct ConfusableIdentifierPair {
1560 pub existing_sym: Symbol,
1561 pub sym: Symbol,
1562 #[label("other identifier used here")]
1563 pub label: Span,
1564 #[label("this identifier can be confused with `{$existing_sym}`")]
1565 pub main_label: Span,
1566}
1567
1568#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
MixedScriptConfusables 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 {
MixedScriptConfusables {
set: __binding_0, includes: __binding_1 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the usage of Script Group `{$set}` in this crate consists solely of mixed script confusables")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the usage includes {$includes}")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("please recheck to make sure their usages are indeed what you want")));
;
diag.arg("set", __binding_0);
diag.arg("includes", __binding_1);
diag
}
}
}
}
};Diagnostic)]
1569#[diag(
1570 "the usage of Script Group `{$set}` in this crate consists solely of mixed script confusables"
1571)]
1572#[note("the usage includes {$includes}")]
1573#[note("please recheck to make sure their usages are indeed what you want")]
1574pub(crate) struct MixedScriptConfusables {
1575 pub set: String,
1576 pub includes: String,
1577}
1578
1579pub(crate) struct NonFmtPanicUnused {
1581 pub count: usize,
1582 pub suggestion: Option<Span>,
1583}
1584
1585impl<'a> Diagnostic<'a, ()> for NonFmtPanicUnused {
1587 fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, ()> {
1588 let mut diag = Diag::new(dcx, level, rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("panic message contains {$count ->\n [one] an unused\n *[other] unused\n } formatting {$count ->\n [one] placeholder\n *[other] placeholders\n }"))msg!(
1589 "panic message contains {$count ->
1590 [one] an unused
1591 *[other] unused
1592 } formatting {$count ->
1593 [one] placeholder
1594 *[other] placeholders
1595 }"
1596 ))
1597 .with_arg("count", self.count)
1598 .with_note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this message is not used as a format string when given without arguments, but will be in Rust 2021"))msg!("this message is not used as a format string when given without arguments, but will be in Rust 2021"));
1599 if let Some(span) = self.suggestion {
1600 diag.span_suggestion(
1601 span.shrink_to_hi(),
1602 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("add the missing {$count ->\n [one] argument\n *[other] arguments\n }"))msg!(
1603 "add the missing {$count ->
1604 [one] argument
1605 *[other] arguments
1606 }"
1607 ),
1608 ", ...",
1609 Applicability::HasPlaceholders,
1610 );
1611 diag.span_suggestion(
1612 span.shrink_to_lo(),
1613 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("or add a \"{\"{\"}{\"}\"}\" format string to use the message literally"))msg!(r#"or add a "{"{"}{"}"}" format string to use the message literally"#),
1614 "\"{}\", ",
1615 Applicability::MachineApplicable,
1616 );
1617 }
1618 diag
1619 }
1620}
1621
1622#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
NonFmtPanicBraces 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 {
NonFmtPanicBraces {
count: __binding_0, suggestion: __binding_1 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("panic message contains {$count ->\n [one] a brace\n *[other] braces\n }")));
let __code_42 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("\"{{}}\", "))
})].into_iter();
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this message is not used as a format string, but will be in Rust 2021")));
;
diag.arg("count", __binding_0);
if let Some(__binding_1) = __binding_1 {
diag.span_suggestions_with_style(__binding_1,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("add a \"{\"{\"}{\"}\"}\" format string to use the message literally")),
__code_42, rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::ShowCode);
}
diag
}
}
}
}
};Diagnostic)]
1623#[diag(
1624 "panic message contains {$count ->
1625 [one] a brace
1626 *[other] braces
1627 }"
1628)]
1629#[note("this message is not used as a format string, but will be in Rust 2021")]
1630pub(crate) struct NonFmtPanicBraces {
1631 pub count: usize,
1632 #[suggestion(
1633 "add a \"{\"{\"}{\"}\"}\" format string to use the message literally",
1634 code = "\"{{}}\", ",
1635 applicability = "machine-applicable"
1636 )]
1637 pub suggestion: Option<Span>,
1638}
1639
1640#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
NonCamelCaseType<'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 {
NonCamelCaseType {
sort: __binding_0, name: __binding_1, sub: __binding_2 } =>
{
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$sort} `{$name}` should have an upper camel case name")));
;
diag.arg("sort", __binding_0);
diag.arg("name", __binding_1);
diag.subdiagnostic(__binding_2);
diag
}
}
}
}
};Diagnostic)]
1642#[diag("{$sort} `{$name}` should have an upper camel case name")]
1643pub(crate) struct NonCamelCaseType<'a> {
1644 pub sort: &'a str,
1645 pub name: &'a str,
1646 #[subdiagnostic]
1647 pub sub: NonCamelCaseTypeSub,
1648}
1649
1650#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for NonCamelCaseTypeSub {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
NonCamelCaseTypeSub::Label { span: __binding_0 } => {
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("should have an UpperCamelCase name")),
&sub_args);
diag.span_label(__binding_0, __message);
}
NonCamelCaseTypeSub::Suggestion {
span: __binding_0, replace: __binding_1 } => {
let __code_43 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0}", __binding_1))
})].into_iter();
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("convert the identifier to upper camel case")),
&sub_args);
diag.span_suggestions_with_style(__binding_0, __message,
__code_43, rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowCode);
}
}
}
}
};Subdiagnostic)]
1651pub(crate) enum NonCamelCaseTypeSub {
1652 #[label("should have an UpperCamelCase name")]
1653 Label {
1654 #[primary_span]
1655 span: Span,
1656 },
1657 #[suggestion(
1658 "convert the identifier to upper camel case",
1659 code = "{replace}",
1660 applicability = "maybe-incorrect"
1661 )]
1662 Suggestion {
1663 #[primary_span]
1664 span: Span,
1665 replace: String,
1666 },
1667}
1668
1669#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
NonSnakeCaseDiag<'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 {
NonSnakeCaseDiag {
sort: __binding_0, name: __binding_1, sub: __binding_2 } =>
{
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$sort} `{$name}` should have a snake case name")));
;
diag.arg("sort", __binding_0);
diag.arg("name", __binding_1);
diag.subdiagnostic(__binding_2);
diag
}
}
}
}
};Diagnostic)]
1670#[diag("{$sort} `{$name}` should have a snake case name")]
1671pub(crate) struct NonSnakeCaseDiag<'a> {
1672 pub sort: &'a str,
1673 pub name: &'a str,
1674 #[subdiagnostic]
1675 pub sub: NonSnakeCaseDiagSub,
1676}
1677
1678pub(crate) enum NonSnakeCaseDiagSub {
1679 Label { span: Span },
1680 Help { sc: String },
1681 RenameOrConvertSuggestion { span: Span, suggestion: Ident },
1682 ConvertSuggestion { span: Span, suggestion: String },
1683 SuggestionAndNote { sc: String, span: Span },
1684}
1685
1686impl Subdiagnostic for NonSnakeCaseDiagSub {
1687 fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
1688 match self {
1689 NonSnakeCaseDiagSub::Label { span } => {
1690 diag.span_label(span, rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("should have a snake_case name"))msg!("should have a snake_case name"));
1691 }
1692 NonSnakeCaseDiagSub::Help { sc } => {
1693 diag.arg("sc", sc);
1694 diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("convert the identifier to snake case: `{$sc}`"))msg!("convert the identifier to snake case: `{$sc}`"));
1695 }
1696 NonSnakeCaseDiagSub::ConvertSuggestion { span, suggestion } => {
1697 diag.span_suggestion(
1698 span,
1699 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("convert the identifier to snake case"))msg!("convert the identifier to snake case"),
1700 suggestion,
1701 Applicability::MaybeIncorrect,
1702 );
1703 }
1704 NonSnakeCaseDiagSub::RenameOrConvertSuggestion { span, suggestion } => {
1705 diag.span_suggestion(
1706 span,
1707 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("rename the identifier or convert it to a snake case raw identifier"))msg!("rename the identifier or convert it to a snake case raw identifier"),
1708 suggestion,
1709 Applicability::MaybeIncorrect,
1710 );
1711 }
1712 NonSnakeCaseDiagSub::SuggestionAndNote { sc, span } => {
1713 diag.arg("sc", sc);
1714 diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`{$sc}` cannot be used as a raw identifier"))msg!("`{$sc}` cannot be used as a raw identifier"));
1715 diag.span_suggestion(
1716 span,
1717 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("rename the identifier"))msg!("rename the identifier"),
1718 "",
1719 Applicability::MaybeIncorrect,
1720 );
1721 }
1722 }
1723 }
1724}
1725
1726#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
NonUpperCaseGlobal<'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 {
NonUpperCaseGlobal {
sort: __binding_0,
name: __binding_1,
sub: __binding_2,
usages: __binding_3 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$sort} `{$name}` should have an upper case name")));
;
diag.arg("sort", __binding_0);
diag.arg("name", __binding_1);
diag.subdiagnostic(__binding_2);
for __binding_3 in __binding_3 {
diag.subdiagnostic(__binding_3);
}
diag
}
}
}
}
};Diagnostic)]
1727#[diag("{$sort} `{$name}` should have an upper case name")]
1728pub(crate) struct NonUpperCaseGlobal<'a> {
1729 pub sort: &'a str,
1730 pub name: &'a str,
1731 #[subdiagnostic]
1732 pub sub: NonUpperCaseGlobalSub,
1733 #[subdiagnostic]
1734 pub usages: Vec<NonUpperCaseGlobalSubTool>,
1735}
1736
1737#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for NonUpperCaseGlobalSub {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
NonUpperCaseGlobalSub::Label { span: __binding_0 } => {
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("should have an UPPER_CASE name")),
&sub_args);
diag.span_label(__binding_0, __message);
}
NonUpperCaseGlobalSub::Suggestion {
span: __binding_0,
applicability: __binding_1,
replace: __binding_2 } => {
let __code_44 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0}", __binding_2))
})].into_iter();
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("convert the identifier to upper case")),
&sub_args);
diag.span_suggestions_with_style(__binding_0, __message,
__code_44, __binding_1,
rustc_errors::SuggestionStyle::ShowCode);
}
}
}
}
};Subdiagnostic)]
1738pub(crate) enum NonUpperCaseGlobalSub {
1739 #[label("should have an UPPER_CASE name")]
1740 Label {
1741 #[primary_span]
1742 span: Span,
1743 },
1744 #[suggestion("convert the identifier to upper case", code = "{replace}")]
1745 Suggestion {
1746 #[primary_span]
1747 span: Span,
1748 #[applicability]
1749 applicability: Applicability,
1750 replace: String,
1751 },
1752}
1753
1754#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for NonUpperCaseGlobalSubTool {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
NonUpperCaseGlobalSubTool {
span: __binding_0, replace: __binding_1 } => {
let __code_45 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0}", __binding_1))
})].into_iter();
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("convert the identifier to upper case")),
&sub_args);
diag.span_suggestions_with_style(__binding_0, __message,
__code_45, rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::CompletelyHidden);
}
}
}
}
};Subdiagnostic)]
1755#[suggestion(
1756 "convert the identifier to upper case",
1757 code = "{replace}",
1758 applicability = "machine-applicable",
1759 style = "tool-only"
1760)]
1761pub(crate) struct NonUpperCaseGlobalSubTool {
1762 #[primary_span]
1763 pub(crate) span: Span,
1764 pub(crate) replace: String,
1765}
1766
1767#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
NoopMethodCallDiag<'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 {
NoopMethodCallDiag {
method: __binding_0,
orig_ty: __binding_1,
trait_: __binding_2,
label: __binding_3,
suggest_derive: __binding_4 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("call to `.{$method}()` on a reference in this situation does nothing")));
let __code_46 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!(""))
})].into_iter();
let __code_47 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("#[derive(Clone)]\n"))
})].into_iter();
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the type `{$orig_ty}` does not implement `{$trait_}`, so calling `{$method}` on `&{$orig_ty}` copies the reference, which does not do anything and can be removed")));
;
diag.arg("method", __binding_0);
diag.arg("orig_ty", __binding_1);
diag.arg("trait_", __binding_2);
diag.span_suggestions_with_style(__binding_3,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("remove this redundant call")),
__code_46, rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::ShowCode);
if let Some(__binding_4) = __binding_4 {
diag.span_suggestions_with_style(__binding_4,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("if you meant to clone `{$orig_ty}`, implement `Clone` for it")),
__code_47, rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowCode);
}
diag
}
}
}
}
};Diagnostic)]
1769#[diag("call to `.{$method}()` on a reference in this situation does nothing")]
1770#[note(
1771 "the type `{$orig_ty}` does not implement `{$trait_}`, so calling `{$method}` on `&{$orig_ty}` copies the reference, which does not do anything and can be removed"
1772)]
1773pub(crate) struct NoopMethodCallDiag<'a> {
1774 pub method: Ident,
1775 pub orig_ty: Ty<'a>,
1776 pub trait_: Symbol,
1777 #[suggestion("remove this redundant call", code = "", applicability = "machine-applicable")]
1778 pub label: Span,
1779 #[suggestion(
1780 "if you meant to clone `{$orig_ty}`, implement `Clone` for it",
1781 code = "#[derive(Clone)]\n",
1782 applicability = "maybe-incorrect"
1783 )]
1784 pub suggest_derive: Option<Span>,
1785}
1786
1787#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
SuspiciousDoubleRefDerefDiag<'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 {
SuspiciousDoubleRefDerefDiag { ty: __binding_0 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("using `.deref()` on a double reference, which returns `{$ty}` instead of dereferencing the inner type")));
;
diag.arg("ty", __binding_0);
diag
}
}
}
}
};Diagnostic)]
1788#[diag(
1789 "using `.deref()` on a double reference, which returns `{$ty}` instead of dereferencing the inner type"
1790)]
1791pub(crate) struct SuspiciousDoubleRefDerefDiag<'a> {
1792 pub ty: Ty<'a>,
1793}
1794
1795#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
SuspiciousDoubleRefCloneDiag<'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 {
SuspiciousDoubleRefCloneDiag { ty: __binding_0 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("using `.clone()` on a double reference, which returns `{$ty}` instead of cloning the inner type")));
;
diag.arg("ty", __binding_0);
diag
}
}
}
}
};Diagnostic)]
1796#[diag(
1797 "using `.clone()` on a double reference, which returns `{$ty}` instead of cloning the inner type"
1798)]
1799pub(crate) struct SuspiciousDoubleRefCloneDiag<'a> {
1800 pub ty: Ty<'a>,
1801}
1802
1803pub(crate) enum NonLocalDefinitionsDiag {
1805 Impl {
1806 depth: u32,
1807 body_kind_descr: &'static str,
1808 body_name: String,
1809 cargo_update: Option<NonLocalDefinitionsCargoUpdateNote>,
1810 const_anon: Option<Option<Span>>,
1811 doctest: bool,
1812 macro_to_change: Option<(String, &'static str)>,
1813 },
1814 MacroRules {
1815 depth: u32,
1816 body_kind_descr: &'static str,
1817 body_name: String,
1818 doctest: bool,
1819 cargo_update: Option<NonLocalDefinitionsCargoUpdateNote>,
1820 },
1821}
1822
1823impl<'a> Diagnostic<'a, ()> for NonLocalDefinitionsDiag {
1824 fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, ()> {
1825 let mut diag = Diag::new(dcx, level, "");
1826 match self {
1827 NonLocalDefinitionsDiag::Impl {
1828 depth,
1829 body_kind_descr,
1830 body_name,
1831 cargo_update,
1832 const_anon,
1833 doctest,
1834 macro_to_change,
1835 } => {
1836 diag.primary_message(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("non-local `impl` definition, `impl` blocks should be written at the same level as their item"))msg!("non-local `impl` definition, `impl` blocks should be written at the same level as their item"));
1837 diag.arg("depth", depth);
1838 diag.arg("body_kind_descr", body_kind_descr);
1839 diag.arg("body_name", body_name);
1840
1841 if let Some((macro_to_change, macro_kind)) = macro_to_change {
1842 diag.arg("macro_to_change", macro_to_change);
1843 diag.arg("macro_kind", macro_kind);
1844 diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the {$macro_kind} `{$macro_to_change}` defines the non-local `impl`, and may need to be changed"))msg!("the {$macro_kind} `{$macro_to_change}` defines the non-local `impl`, and may need to be changed"));
1845 }
1846 if let Some(cargo_update) = cargo_update {
1847 diag.subdiagnostic(cargo_update);
1848 }
1849
1850 diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl`"))msg!("an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl`"));
1851
1852 if doctest {
1853 diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("make this doc-test a standalone test with its own `fn main() {\"{\"} ... {\"}\"}`"))msg!("make this doc-test a standalone test with its own `fn main() {\"{\"} ... {\"}\"}`"));
1854 }
1855
1856 if let Some(const_anon) = const_anon {
1857 diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("items in an anonymous const item (`const _: () = {\"{\"} ... {\"}\"}`) are treated as in the same scope as the anonymous const's declaration for the purpose of this lint"))msg!("items in an anonymous const item (`const _: () = {\"{\"} ... {\"}\"}`) are treated as in the same scope as the anonymous const's declaration for the purpose of this lint"));
1858 if let Some(const_anon) = const_anon {
1859 diag.span_suggestion(
1860 const_anon,
1861 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("use a const-anon item to suppress this lint"))msg!("use a const-anon item to suppress this lint"),
1862 "_",
1863 Applicability::MachineApplicable,
1864 );
1865 }
1866 }
1867 }
1868 NonLocalDefinitionsDiag::MacroRules {
1869 depth,
1870 body_kind_descr,
1871 body_name,
1872 doctest,
1873 cargo_update,
1874 } => {
1875 diag.primary_message(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("non-local `macro_rules!` definition, `#[macro_export]` macro should be written at top level module"))msg!("non-local `macro_rules!` definition, `#[macro_export]` macro should be written at top level module"));
1876 diag.arg("depth", depth);
1877 diag.arg("body_kind_descr", body_kind_descr);
1878 diag.arg("body_name", body_name);
1879
1880 if doctest {
1881 diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("remove the `#[macro_export]` or make this doc-test a standalone test with its own `fn main() {\"{\"} ... {\"}\"}`"))msg!(r#"remove the `#[macro_export]` or make this doc-test a standalone test with its own `fn main() {"{"} ... {"}"}`"#));
1882 } else {
1883 diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("remove the `#[macro_export]` or move this `macro_rules!` outside the of the current {$body_kind_descr} {$depth ->\n [one] `{$body_name}`\n *[other] `{$body_name}` and up {$depth} bodies\n }"))msg!(
1884 "remove the `#[macro_export]` or move this `macro_rules!` outside the of the current {$body_kind_descr} {$depth ->
1885 [one] `{$body_name}`
1886 *[other] `{$body_name}` and up {$depth} bodies
1887 }"
1888 ));
1889 }
1890
1891 diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("a `macro_rules!` definition is non-local if it is nested inside an item and has a `#[macro_export]` attribute"))msg!("a `macro_rules!` definition is non-local if it is nested inside an item and has a `#[macro_export]` attribute"));
1892
1893 if let Some(cargo_update) = cargo_update {
1894 diag.subdiagnostic(cargo_update);
1895 }
1896 }
1897 }
1898 diag
1899 }
1900}
1901
1902#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for
NonLocalDefinitionsCargoUpdateNote {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
NonLocalDefinitionsCargoUpdateNote {
macro_kind: __binding_0,
macro_name: __binding_1,
crate_name: __binding_2 } => {
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("macro_kind".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_0,
&mut diag.long_ty_path));
sub_args.insert("macro_name".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_1,
&mut diag.long_ty_path));
sub_args.insert("crate_name".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_2,
&mut diag.long_ty_path));
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the {$macro_kind} `{$macro_name}` may come from an old version of the `{$crate_name}` crate, try updating your dependency with `cargo update -p {$crate_name}`")),
&sub_args);
diag.note(__message);
}
}
}
}
};Subdiagnostic)]
1903#[note(
1904 "the {$macro_kind} `{$macro_name}` may come from an old version of the `{$crate_name}` crate, try updating your dependency with `cargo update -p {$crate_name}`"
1905)]
1906pub(crate) struct NonLocalDefinitionsCargoUpdateNote {
1907 pub macro_kind: &'static str,
1908 pub macro_name: Symbol,
1909 pub crate_name: Symbol,
1910}
1911
1912#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
AmbiguousNegativeLiteralsDiag 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 {
AmbiguousNegativeLiteralsDiag {
negative_literal: __binding_0, current_behavior: __binding_1
} => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`-` has lower precedence than method calls, which might be unexpected")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("e.g. `-4.abs()` equals `-4`; while `(-4).abs()` equals `4`")));
;
diag.subdiagnostic(__binding_0);
diag.subdiagnostic(__binding_1);
diag
}
}
}
}
};Diagnostic)]
1914#[diag("`-` has lower precedence than method calls, which might be unexpected")]
1915#[note("e.g. `-4.abs()` equals `-4`; while `(-4).abs()` equals `4`")]
1916pub(crate) struct AmbiguousNegativeLiteralsDiag {
1917 #[subdiagnostic]
1918 pub negative_literal: AmbiguousNegativeLiteralsNegativeLiteralSuggestion,
1919 #[subdiagnostic]
1920 pub current_behavior: AmbiguousNegativeLiteralsCurrentBehaviorSuggestion,
1921}
1922
1923#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for
AmbiguousNegativeLiteralsNegativeLiteralSuggestion {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
AmbiguousNegativeLiteralsNegativeLiteralSuggestion {
start_span: __binding_0, end_span: __binding_1 } => {
let mut suggestions = Vec::new();
let __code_48 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("("))
});
let __code_49 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!(")"))
});
suggestions.push((__binding_0, __code_48));
suggestions.push((__binding_1, __code_49));
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("add parentheses around the `-` and the literal to call the method on a negative literal")),
&sub_args);
diag.multipart_suggestion_with_style(__message, suggestions,
rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowCode);
}
}
}
}
};Subdiagnostic)]
1924#[multipart_suggestion(
1925 "add parentheses around the `-` and the literal to call the method on a negative literal",
1926 applicability = "maybe-incorrect"
1927)]
1928pub(crate) struct AmbiguousNegativeLiteralsNegativeLiteralSuggestion {
1929 #[suggestion_part(code = "(")]
1930 pub start_span: Span,
1931 #[suggestion_part(code = ")")]
1932 pub end_span: Span,
1933}
1934
1935#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for
AmbiguousNegativeLiteralsCurrentBehaviorSuggestion {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
AmbiguousNegativeLiteralsCurrentBehaviorSuggestion {
start_span: __binding_0, end_span: __binding_1 } => {
let mut suggestions = Vec::new();
let __code_50 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("("))
});
let __code_51 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!(")"))
});
suggestions.push((__binding_0, __code_50));
suggestions.push((__binding_1, __code_51));
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("add parentheses around the literal and the method call to keep the current behavior")),
&sub_args);
diag.multipart_suggestion_with_style(__message, suggestions,
rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowCode);
}
}
}
}
};Subdiagnostic)]
1936#[multipart_suggestion(
1937 "add parentheses around the literal and the method call to keep the current behavior",
1938 applicability = "maybe-incorrect"
1939)]
1940pub(crate) struct AmbiguousNegativeLiteralsCurrentBehaviorSuggestion {
1941 #[suggestion_part(code = "(")]
1942 pub start_span: Span,
1943 #[suggestion_part(code = ")")]
1944 pub end_span: Span,
1945}
1946
1947#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
DisallowedPassByRefDiag 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 {
DisallowedPassByRefDiag {
ty: __binding_0, suggestion: __binding_1 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("passing `{$ty}` by reference")));
let __code_52 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0}", __binding_0))
})].into_iter();
;
diag.arg("ty", __binding_0);
diag.span_suggestions_with_style(__binding_1,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("try passing by value")),
__code_52, rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowCode);
diag
}
}
}
}
};Diagnostic)]
1949#[diag("passing `{$ty}` by reference")]
1950pub(crate) struct DisallowedPassByRefDiag {
1951 pub ty: String,
1952 #[suggestion("try passing by value", code = "{ty}", applicability = "maybe-incorrect")]
1953 pub suggestion: Span,
1954}
1955
1956#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
RedundantSemicolonsDiag 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 {
RedundantSemicolonsDiag {
multiple: __binding_0, suggestion: __binding_1 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("unnecessary trailing {$multiple ->\n [true] semicolons\n *[false] semicolon\n }")));
;
diag.arg("multiple", __binding_0);
if let Some(__binding_1) = __binding_1 {
diag.subdiagnostic(__binding_1);
}
diag
}
}
}
}
};Diagnostic)]
1958#[diag(
1959 "unnecessary trailing {$multiple ->
1960 [true] semicolons
1961 *[false] semicolon
1962 }"
1963)]
1964pub(crate) struct RedundantSemicolonsDiag {
1965 pub multiple: bool,
1966 #[subdiagnostic]
1967 pub suggestion: Option<RedundantSemicolonsSuggestion>,
1968}
1969
1970#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for RedundantSemicolonsSuggestion {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
RedundantSemicolonsSuggestion {
multiple_semicolons: __binding_0, span: __binding_1 } => {
let __code_53 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!(""))
})].into_iter();
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("multiple_semicolons".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_0,
&mut diag.long_ty_path));
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("remove {$multiple_semicolons ->\n [true] these semicolons\n *[false] this semicolon\n }")),
&sub_args);
diag.span_suggestions_with_style(__binding_1, __message,
__code_53, rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowCode);
}
}
}
}
};Subdiagnostic)]
1971#[suggestion(
1972 "remove {$multiple_semicolons ->
1973 [true] these semicolons
1974 *[false] this semicolon
1975 }",
1976 code = "",
1977 applicability = "maybe-incorrect"
1978)]
1979pub(crate) struct RedundantSemicolonsSuggestion {
1980 pub multiple_semicolons: bool,
1981 #[primary_span]
1982 pub span: Span,
1983}
1984
1985pub(crate) struct DropTraitConstraintsDiag<'a> {
1987 pub clause: Clause<'a>,
1988 pub tcx: TyCtxt<'a>,
1989 pub def_id: DefId,
1990}
1991
1992impl<'a> Diagnostic<'a, ()> for DropTraitConstraintsDiag<'_> {
1994 fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, ()> {
1995 Diag::new(dcx, level, rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("bounds on `{$clause}` are most likely incorrect, consider instead using `{$needs_drop}` to detect whether a type can be trivially dropped"))msg!("bounds on `{$clause}` are most likely incorrect, consider instead using `{$needs_drop}` to detect whether a type can be trivially dropped"))
1996 .with_arg("clause", self.clause)
1997 .with_arg("needs_drop", self.tcx.def_path_str(self.def_id))
1998 }
1999}
2000
2001pub(crate) struct DropGlue<'a> {
2002 pub tcx: TyCtxt<'a>,
2003 pub def_id: DefId,
2004}
2005
2006impl<'a> Diagnostic<'a, ()> for DropGlue<'_> {
2008 fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, ()> {
2009 Diag::new(dcx, level, rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("types that do not implement `Drop` can still have drop glue, consider instead using `{$needs_drop}` to detect whether a type is trivially dropped"))msg!("types that do not implement `Drop` can still have drop glue, consider instead using `{$needs_drop}` to detect whether a type is trivially dropped"))
2010 .with_arg("needs_drop", self.tcx.def_path_str(self.def_id))
2011 }
2012}
2013
2014#[derive(const _: () =
{
impl<'_sess, 'tcx, G> rustc_errors::Diagnostic<'_sess, G> for
IntegerToPtrTransmutes<'tcx> 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 {
IntegerToPtrTransmutes { suggestion: __binding_0 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("transmuting an integer to a pointer creates a pointer without provenance")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this is dangerous because dereferencing the resulting pointer is undefined behavior")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("exposed provenance semantics can be used to create a pointer based on some previously exposed provenance")));
diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("if you truly mean to create a pointer without provenance, use `std::ptr::without_provenance_mut`")));
diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("for more information about transmute, see <https://doc.rust-lang.org/std/mem/fn.transmute.html#transmutation-between-pointers-and-integers>")));
diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("for more information about exposed provenance, see <https://doc.rust-lang.org/std/ptr/index.html#exposed-provenance>")));
;
if let Some(__binding_0) = __binding_0 {
diag.subdiagnostic(__binding_0);
}
diag
}
}
}
}
};Diagnostic)]
2016#[diag("transmuting an integer to a pointer creates a pointer without provenance")]
2017#[note("this is dangerous because dereferencing the resulting pointer is undefined behavior")]
2018#[note(
2019 "exposed provenance semantics can be used to create a pointer based on some previously exposed provenance"
2020)]
2021#[help(
2022 "if you truly mean to create a pointer without provenance, use `std::ptr::without_provenance_mut`"
2023)]
2024#[help(
2025 "for more information about transmute, see <https://doc.rust-lang.org/std/mem/fn.transmute.html#transmutation-between-pointers-and-integers>"
2026)]
2027#[help(
2028 "for more information about exposed provenance, see <https://doc.rust-lang.org/std/ptr/index.html#exposed-provenance>"
2029)]
2030pub(crate) struct IntegerToPtrTransmutes<'tcx> {
2031 #[subdiagnostic]
2032 pub suggestion: Option<IntegerToPtrTransmutesSuggestion<'tcx>>,
2033}
2034
2035#[derive(const _: () =
{
impl<'tcx> rustc_errors::Subdiagnostic for
IntegerToPtrTransmutesSuggestion<'tcx> {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
IntegerToPtrTransmutesSuggestion::ToPtr {
dst: __binding_0,
suffix: __binding_1,
start_call: __binding_2 } => {
let mut suggestions = Vec::new();
let __code_54 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("std::ptr::with_exposed_provenance{1}::<{0}>(",
__binding_0, __binding_1))
});
suggestions.push((__binding_2, __code_54));
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("suffix".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_1,
&mut diag.long_ty_path));
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("use `std::ptr::with_exposed_provenance{$suffix}` instead to use a previously exposed provenance")),
&sub_args);
diag.multipart_suggestion_with_style(__message, suggestions,
rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::ShowAlways);
}
IntegerToPtrTransmutesSuggestion::ToRef {
dst: __binding_0,
suffix: __binding_1,
ref_mutbl: __binding_2,
start_call: __binding_3 } => {
let mut suggestions = Vec::new();
let __code_55 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("&{1}*std::ptr::with_exposed_provenance{2}::<{0}>(",
__binding_0, __binding_2, __binding_1))
});
suggestions.push((__binding_3, __code_55));
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("suffix".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_1,
&mut diag.long_ty_path));
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("use `std::ptr::with_exposed_provenance{$suffix}` instead to use a previously exposed provenance")),
&sub_args);
diag.multipart_suggestion_with_style(__message, suggestions,
rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::ShowAlways);
}
}
}
}
};Subdiagnostic)]
2036pub(crate) enum IntegerToPtrTransmutesSuggestion<'tcx> {
2037 #[multipart_suggestion(
2038 "use `std::ptr::with_exposed_provenance{$suffix}` instead to use a previously exposed provenance",
2039 applicability = "machine-applicable",
2040 style = "verbose"
2041 )]
2042 ToPtr {
2043 dst: Ty<'tcx>,
2044 suffix: &'static str,
2045 #[suggestion_part(code = "std::ptr::with_exposed_provenance{suffix}::<{dst}>(")]
2046 start_call: Span,
2047 },
2048 #[multipart_suggestion(
2049 "use `std::ptr::with_exposed_provenance{$suffix}` instead to use a previously exposed provenance",
2050 applicability = "machine-applicable",
2051 style = "verbose"
2052 )]
2053 ToRef {
2054 dst: Ty<'tcx>,
2055 suffix: &'static str,
2056 ref_mutbl: &'static str,
2057 #[suggestion_part(
2058 code = "&{ref_mutbl}*std::ptr::with_exposed_provenance{suffix}::<{dst}>("
2059 )]
2060 start_call: Span,
2061 },
2062}
2063
2064#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
RangeEndpointOutOfRange<'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 {
RangeEndpointOutOfRange { ty: __binding_0, sub: __binding_1
} => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("range endpoint is out of range for `{$ty}`")));
;
diag.arg("ty", __binding_0);
diag.subdiagnostic(__binding_1);
diag
}
}
}
}
};Diagnostic)]
2066#[diag("range endpoint is out of range for `{$ty}`")]
2067pub(crate) struct RangeEndpointOutOfRange<'a> {
2068 pub ty: &'a str,
2069 #[subdiagnostic]
2070 pub sub: UseInclusiveRange<'a>,
2071}
2072
2073#[derive(const _: () =
{
impl<'a> rustc_errors::Subdiagnostic for UseInclusiveRange<'a> {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
UseInclusiveRange::WithoutParen {
sugg: __binding_0,
start: __binding_1,
literal: __binding_2,
suffix: __binding_3 } => {
let __code_56 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{1}..={0}{2}",
__binding_2, __binding_1, __binding_3))
})].into_iter();
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("use an inclusive range instead")),
&sub_args);
diag.span_suggestions_with_style(__binding_0, __message,
__code_56, rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::ShowCode);
}
UseInclusiveRange::WithParen {
eq_sugg: __binding_0,
lit_sugg: __binding_1,
literal: __binding_2,
suffix: __binding_3 } => {
let mut suggestions = Vec::new();
let __code_57 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("="))
});
let __code_58 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0}{1}", __binding_2,
__binding_3))
});
suggestions.push((__binding_0, __code_57));
suggestions.push((__binding_1, __code_58));
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("use an inclusive range instead")),
&sub_args);
diag.multipart_suggestion_with_style(__message, suggestions,
rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::ShowCode);
}
}
}
}
};Subdiagnostic)]
2074pub(crate) enum UseInclusiveRange<'a> {
2075 #[suggestion(
2076 "use an inclusive range instead",
2077 code = "{start}..={literal}{suffix}",
2078 applicability = "machine-applicable"
2079 )]
2080 WithoutParen {
2081 #[primary_span]
2082 sugg: Span,
2083 start: String,
2084 literal: u128,
2085 suffix: &'a str,
2086 },
2087 #[multipart_suggestion("use an inclusive range instead", applicability = "machine-applicable")]
2088 WithParen {
2089 #[suggestion_part(code = "=")]
2090 eq_sugg: Span,
2091 #[suggestion_part(code = "{literal}{suffix}")]
2092 lit_sugg: Span,
2093 literal: u128,
2094 suffix: &'a str,
2095 },
2096}
2097
2098#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
OverflowingBinHex<'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 {
OverflowingBinHex {
ty: __binding_0,
sign: __binding_1,
sub: __binding_2,
sign_bit_sub: __binding_3 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("literal out of range for `{$ty}`")));
;
diag.arg("ty", __binding_0);
diag.subdiagnostic(__binding_1);
if let Some(__binding_2) = __binding_2 {
diag.subdiagnostic(__binding_2);
}
if let Some(__binding_3) = __binding_3 {
diag.subdiagnostic(__binding_3);
}
diag
}
}
}
}
};Diagnostic)]
2099#[diag("literal out of range for `{$ty}`")]
2100pub(crate) struct OverflowingBinHex<'a> {
2101 pub ty: &'a str,
2102 #[subdiagnostic]
2103 pub sign: OverflowingBinHexSign<'a>,
2104 #[subdiagnostic]
2105 pub sub: Option<OverflowingBinHexSub<'a>>,
2106 #[subdiagnostic]
2107 pub sign_bit_sub: Option<OverflowingBinHexSignBitSub<'a>>,
2108}
2109
2110#[derive(const _: () =
{
impl<'a> rustc_errors::Subdiagnostic for OverflowingBinHexSign<'a> {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
OverflowingBinHexSign::Positive {
lit: __binding_0,
ty: __binding_1,
actually: __binding_2,
dec: __binding_3 } => {
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("lit".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_0,
&mut diag.long_ty_path));
sub_args.insert("ty".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_1,
&mut diag.long_ty_path));
sub_args.insert("actually".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_2,
&mut diag.long_ty_path));
sub_args.insert("dec".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_3,
&mut diag.long_ty_path));
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the literal `{$lit}` (decimal `{$dec}`) does not fit into the type `{$ty}` and will become `{$actually}{$ty}`")),
&sub_args);
diag.note(__message);
}
OverflowingBinHexSign::Negative {
lit: __binding_0,
ty: __binding_1,
actually: __binding_2,
dec: __binding_3 } => {
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("lit".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_0,
&mut diag.long_ty_path));
sub_args.insert("ty".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_1,
&mut diag.long_ty_path));
sub_args.insert("actually".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_2,
&mut diag.long_ty_path));
sub_args.insert("dec".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_3,
&mut diag.long_ty_path));
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the literal `{$lit}` (decimal `{$dec}`) does not fit into the type `{$ty}`")),
&sub_args);
diag.note(__message);
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("and the value `-{$lit}` will become `{$actually}{$ty}`")),
&sub_args);
diag.note(__message);
}
}
}
}
};Subdiagnostic)]
2111pub(crate) enum OverflowingBinHexSign<'a> {
2112 #[note(
2113 "the literal `{$lit}` (decimal `{$dec}`) does not fit into the type `{$ty}` and will become `{$actually}{$ty}`"
2114 )]
2115 Positive { lit: String, ty: &'a str, actually: String, dec: u128 },
2116 #[note("the literal `{$lit}` (decimal `{$dec}`) does not fit into the type `{$ty}`")]
2117 #[note("and the value `-{$lit}` will become `{$actually}{$ty}`")]
2118 Negative { lit: String, ty: &'a str, actually: String, dec: u128 },
2119}
2120
2121#[derive(const _: () =
{
impl<'a> rustc_errors::Subdiagnostic for OverflowingBinHexSub<'a> {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
OverflowingBinHexSub::Suggestion {
span: __binding_0,
suggestion_ty: __binding_1,
sans_suffix: __binding_2 } => {
let __code_59 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0}{1}", __binding_2,
__binding_1))
})].into_iter();
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("suggestion_ty".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_1,
&mut diag.long_ty_path));
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider using the type `{$suggestion_ty}` instead")),
&sub_args);
diag.span_suggestions_with_style(__binding_0, __message,
__code_59, rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::ShowCode);
}
OverflowingBinHexSub::Help { suggestion_ty: __binding_0 } =>
{
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("suggestion_ty".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_0,
&mut diag.long_ty_path));
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider using the type `{$suggestion_ty}` instead")),
&sub_args);
diag.help(__message);
}
}
}
}
};Subdiagnostic)]
2122pub(crate) enum OverflowingBinHexSub<'a> {
2123 #[suggestion(
2124 "consider using the type `{$suggestion_ty}` instead",
2125 code = "{sans_suffix}{suggestion_ty}",
2126 applicability = "machine-applicable"
2127 )]
2128 Suggestion {
2129 #[primary_span]
2130 span: Span,
2131 suggestion_ty: &'a str,
2132 sans_suffix: &'a str,
2133 },
2134 #[help("consider using the type `{$suggestion_ty}` instead")]
2135 Help { suggestion_ty: &'a str },
2136}
2137
2138#[derive(const _: () =
{
impl<'a> rustc_errors::Subdiagnostic for
OverflowingBinHexSignBitSub<'a> {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
OverflowingBinHexSignBitSub::CastSigned {
span: __binding_0,
lit_no_suffix: __binding_1,
negative_val: __binding_2,
uint_ty: __binding_3,
int_ty: __binding_4 } => {
let __code_60 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0}{1}.cast_signed()",
__binding_1, __binding_3))
})].into_iter();
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("negative_val".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_2,
&mut diag.long_ty_path));
sub_args.insert("uint_ty".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_3,
&mut diag.long_ty_path));
sub_args.insert("int_ty".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_4,
&mut diag.long_ty_path));
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("to use as a negative number (decimal `{$negative_val}`), consider using the type `{$uint_ty}` for the literal and cast it to `{$int_ty}`")),
&sub_args);
diag.span_suggestions_with_style(__binding_0, __message,
__code_60, rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowCode);
}
OverflowingBinHexSignBitSub::AsCast {
span: __binding_0,
lit_no_suffix: __binding_1,
negative_val: __binding_2,
uint_ty: __binding_3,
int_ty: __binding_4 } => {
let __code_61 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{1}{2} as {0}",
__binding_4, __binding_1, __binding_3))
})].into_iter();
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("negative_val".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_2,
&mut diag.long_ty_path));
sub_args.insert("uint_ty".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_3,
&mut diag.long_ty_path));
sub_args.insert("int_ty".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_4,
&mut diag.long_ty_path));
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("to use as a negative number (decimal `{$negative_val}`), consider using the type `{$uint_ty}` for the literal and cast it to `{$int_ty}`")),
&sub_args);
diag.span_suggestions_with_style(__binding_0, __message,
__code_61, rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowCode);
}
}
}
}
};Subdiagnostic)]
2139pub(crate) enum OverflowingBinHexSignBitSub<'a> {
2140 #[suggestion(
2141 "to use as a negative number (decimal `{$negative_val}`), consider using the type `{$uint_ty}` for the literal and cast it to `{$int_ty}`",
2142 code = "{lit_no_suffix}{uint_ty}.cast_signed()",
2143 applicability = "maybe-incorrect"
2144 )]
2145 CastSigned {
2146 #[primary_span]
2147 span: Span,
2148 lit_no_suffix: &'a str,
2149 negative_val: String,
2150 uint_ty: &'a str,
2151 int_ty: &'a str,
2152 },
2153 #[suggestion(
2154 "to use as a negative number (decimal `{$negative_val}`), consider using the type `{$uint_ty}` for the literal and cast it to `{$int_ty}`",
2155 code = "{lit_no_suffix}{uint_ty} as {int_ty}",
2156 applicability = "maybe-incorrect"
2157 )]
2158 AsCast {
2159 #[primary_span]
2160 span: Span,
2161 lit_no_suffix: &'a str,
2162 negative_val: String,
2163 uint_ty: &'a str,
2164 int_ty: &'a str,
2165 },
2166}
2167
2168#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
OverflowingInt<'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 {
OverflowingInt {
ty: __binding_0,
lit: __binding_1,
min: __binding_2,
max: __binding_3,
help: __binding_4 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("literal out of range for `{$ty}`")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the literal `{$lit}` does not fit into the type `{$ty}` whose range is `{$min}..={$max}`")));
;
diag.arg("ty", __binding_0);
diag.arg("lit", __binding_1);
diag.arg("min", __binding_2);
diag.arg("max", __binding_3);
if let Some(__binding_4) = __binding_4 {
diag.subdiagnostic(__binding_4);
}
diag
}
}
}
}
};Diagnostic)]
2169#[diag("literal out of range for `{$ty}`")]
2170#[note("the literal `{$lit}` does not fit into the type `{$ty}` whose range is `{$min}..={$max}`")]
2171pub(crate) struct OverflowingInt<'a> {
2172 pub ty: &'a str,
2173 pub lit: String,
2174 pub min: i128,
2175 pub max: u128,
2176 #[subdiagnostic]
2177 pub help: Option<OverflowingIntHelp<'a>>,
2178}
2179
2180#[derive(const _: () =
{
impl<'a> rustc_errors::Subdiagnostic for OverflowingIntHelp<'a> {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
OverflowingIntHelp { suggestion_ty: __binding_0 } => {
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("suggestion_ty".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_0,
&mut diag.long_ty_path));
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider using the type `{$suggestion_ty}` instead")),
&sub_args);
diag.help(__message);
}
}
}
}
};Subdiagnostic)]
2181#[help("consider using the type `{$suggestion_ty}` instead")]
2182pub(crate) struct OverflowingIntHelp<'a> {
2183 pub suggestion_ty: &'a str,
2184}
2185
2186#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
OnlyCastu8ToChar 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 {
OnlyCastu8ToChar { span: __binding_0, literal: __binding_1 }
=> {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("only `u8` can be cast into `char`")));
let __code_62 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("\'\\u{{{0:X}}}\'",
__binding_1))
})].into_iter();
;
diag.span_suggestions_with_style(__binding_0,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("use a `char` literal instead")),
__code_62, rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::ShowCode);
diag
}
}
}
}
};Diagnostic)]
2187#[diag("only `u8` can be cast into `char`")]
2188pub(crate) struct OnlyCastu8ToChar {
2189 #[suggestion(
2190 "use a `char` literal instead",
2191 code = "'\\u{{{literal:X}}}'",
2192 applicability = "machine-applicable"
2193 )]
2194 pub span: Span,
2195 pub literal: u128,
2196}
2197
2198#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
OverflowingUInt<'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 {
OverflowingUInt {
ty: __binding_0,
lit: __binding_1,
min: __binding_2,
max: __binding_3 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("literal out of range for `{$ty}`")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the literal `{$lit}` does not fit into the type `{$ty}` whose range is `{$min}..={$max}`")));
;
diag.arg("ty", __binding_0);
diag.arg("lit", __binding_1);
diag.arg("min", __binding_2);
diag.arg("max", __binding_3);
diag
}
}
}
}
};Diagnostic)]
2199#[diag("literal out of range for `{$ty}`")]
2200#[note("the literal `{$lit}` does not fit into the type `{$ty}` whose range is `{$min}..={$max}`")]
2201pub(crate) struct OverflowingUInt<'a> {
2202 pub ty: &'a str,
2203 pub lit: String,
2204 pub min: u128,
2205 pub max: u128,
2206}
2207
2208#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
OverflowingLiteral<'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 {
OverflowingLiteral { ty: __binding_0, lit: __binding_1 } =>
{
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("literal out of range for `{$ty}`")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the literal `{$lit}` does not fit into the type `{$ty}` and will be converted to `{$ty}::INFINITY`")));
;
diag.arg("ty", __binding_0);
diag.arg("lit", __binding_1);
diag
}
}
}
}
};Diagnostic)]
2209#[diag("literal out of range for `{$ty}`")]
2210#[note(
2211 "the literal `{$lit}` does not fit into the type `{$ty}` and will be converted to `{$ty}::INFINITY`"
2212)]
2213pub(crate) struct OverflowingLiteral<'a> {
2214 pub ty: &'a str,
2215 pub lit: String,
2216}
2217
2218#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
SurrogateCharCast 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 {
SurrogateCharCast { literal: __binding_0 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("surrogate values are not valid for `char`")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`0xD800..=0xDFFF` are reserved for Unicode surrogates and are not valid `char` values")));
;
diag
}
}
}
}
};Diagnostic)]
2219#[diag("surrogate values are not valid for `char`")]
2220#[note("`0xD800..=0xDFFF` are reserved for Unicode surrogates and are not valid `char` values")]
2221pub(crate) struct SurrogateCharCast {
2222 pub literal: u128,
2223}
2224
2225#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
TooLargeCharCast 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 {
TooLargeCharCast { literal: __binding_0 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("value exceeds maximum `char` value")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("maximum valid `char` value is `0x10FFFF`")));
;
diag
}
}
}
}
};Diagnostic)]
2226#[diag("value exceeds maximum `char` value")]
2227#[note("maximum valid `char` value is `0x10FFFF`")]
2228pub(crate) struct TooLargeCharCast {
2229 pub literal: u128,
2230}
2231
2232#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
UsesPowerAlignment 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 {
UsesPowerAlignment => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("repr(C) does not follow the power alignment rule. This may affect platform C ABI compatibility for this type")));
;
diag
}
}
}
}
};Diagnostic)]
2233#[diag(
2234 "repr(C) does not follow the power alignment rule. This may affect platform C ABI compatibility for this type"
2235)]
2236pub(crate) struct UsesPowerAlignment;
2237
2238#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
UnusedComparisons 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 {
UnusedComparisons => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("comparison is useless due to type limits")));
;
diag
}
}
}
}
};Diagnostic)]
2239#[diag("comparison is useless due to type limits")]
2240pub(crate) struct UnusedComparisons;
2241
2242#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
InvalidNanComparisons 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 {
InvalidNanComparisons::EqNe { suggestion: __binding_0 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("incorrect NaN comparison, NaN cannot be directly compared to itself")));
;
diag.subdiagnostic(__binding_0);
diag
}
InvalidNanComparisons::LtLeGtGe => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("incorrect NaN comparison, NaN is not orderable")));
;
diag
}
}
}
}
};Diagnostic)]
2243pub(crate) enum InvalidNanComparisons {
2244 #[diag("incorrect NaN comparison, NaN cannot be directly compared to itself")]
2245 EqNe {
2246 #[subdiagnostic]
2247 suggestion: InvalidNanComparisonsSuggestion,
2248 },
2249 #[diag("incorrect NaN comparison, NaN is not orderable")]
2250 LtLeGtGe,
2251}
2252
2253#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for InvalidNanComparisonsSuggestion {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
InvalidNanComparisonsSuggestion::Spanful {
neg: __binding_0,
float: __binding_1,
nan_plus_binop: __binding_2 } => {
let mut suggestions = Vec::new();
let __code_63 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("!"))
});
let __code_64 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!(".is_nan()"))
});
let __code_65 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!(""))
});
if let Some(__binding_0) = __binding_0 {
suggestions.push((__binding_0, __code_63));
}
suggestions.push((__binding_1, __code_64));
suggestions.push((__binding_2, __code_65));
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("use `f32::is_nan()` or `f64::is_nan()` instead")),
&sub_args);
diag.multipart_suggestion_with_style(__message, suggestions,
rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::ShowAlways);
}
InvalidNanComparisonsSuggestion::Spanless => {
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("use `f32::is_nan()` or `f64::is_nan()` instead")),
&sub_args);
diag.help(__message);
}
}
}
}
};Subdiagnostic)]
2254pub(crate) enum InvalidNanComparisonsSuggestion {
2255 #[multipart_suggestion(
2256 "use `f32::is_nan()` or `f64::is_nan()` instead",
2257 style = "verbose",
2258 applicability = "machine-applicable"
2259 )]
2260 Spanful {
2261 #[suggestion_part(code = "!")]
2262 neg: Option<Span>,
2263 #[suggestion_part(code = ".is_nan()")]
2264 float: Span,
2265 #[suggestion_part(code = "")]
2266 nan_plus_binop: Span,
2267 },
2268 #[help("use `f32::is_nan()` or `f64::is_nan()` instead")]
2269 Spanless,
2270}
2271
2272#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
AmbiguousWidePointerComparisons<'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 {
AmbiguousWidePointerComparisons::SpanfulEq {
addr_suggestion: __binding_0,
addr_metadata_suggestion: __binding_1 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("ambiguous wide pointer comparison, the comparison includes metadata which may not be expected")));
;
diag.subdiagnostic(__binding_0);
if let Some(__binding_1) = __binding_1 {
diag.subdiagnostic(__binding_1);
}
diag
}
AmbiguousWidePointerComparisons::SpanfulCmp {
cast_suggestion: __binding_0, expect_suggestion: __binding_1
} => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("ambiguous wide pointer comparison, the comparison includes metadata which may not be expected")));
;
diag.subdiagnostic(__binding_0);
diag.subdiagnostic(__binding_1);
diag
}
AmbiguousWidePointerComparisons::Spanless => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("ambiguous wide pointer comparison, the comparison includes metadata which may not be expected")));
diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("use explicit `std::ptr::eq` method to compare metadata and addresses")));
diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("use `std::ptr::addr_eq` or untyped pointers to only compare their addresses")));
;
diag
}
}
}
}
};Diagnostic)]
2273pub(crate) enum AmbiguousWidePointerComparisons<'a> {
2274 #[diag(
2275 "ambiguous wide pointer comparison, the comparison includes metadata which may not be expected"
2276 )]
2277 SpanfulEq {
2278 #[subdiagnostic]
2279 addr_suggestion: AmbiguousWidePointerComparisonsAddrSuggestion<'a>,
2280 #[subdiagnostic]
2281 addr_metadata_suggestion: Option<AmbiguousWidePointerComparisonsAddrMetadataSuggestion<'a>>,
2282 },
2283 #[diag(
2284 "ambiguous wide pointer comparison, the comparison includes metadata which may not be expected"
2285 )]
2286 SpanfulCmp {
2287 #[subdiagnostic]
2288 cast_suggestion: AmbiguousWidePointerComparisonsCastSuggestion<'a>,
2289 #[subdiagnostic]
2290 expect_suggestion: AmbiguousWidePointerComparisonsExpectSuggestion<'a>,
2291 },
2292 #[diag(
2293 "ambiguous wide pointer comparison, the comparison includes metadata which may not be expected"
2294 )]
2295 #[help("use explicit `std::ptr::eq` method to compare metadata and addresses")]
2296 #[help("use `std::ptr::addr_eq` or untyped pointers to only compare their addresses")]
2297 Spanless,
2298}
2299
2300#[derive(const _: () =
{
impl<'a> rustc_errors::Subdiagnostic for
AmbiguousWidePointerComparisonsAddrMetadataSuggestion<'a> {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
AmbiguousWidePointerComparisonsAddrMetadataSuggestion {
ne: __binding_0,
deref_left: __binding_1,
deref_right: __binding_2,
l_modifiers: __binding_3,
r_modifiers: __binding_4,
left: __binding_5,
middle: __binding_6,
right: __binding_7 } => {
let mut suggestions = Vec::new();
let __code_66 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{1}std::ptr::eq({0}",
__binding_1, __binding_0))
});
let __code_67 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{1}, {0}", __binding_2,
__binding_3))
});
let __code_68 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0})", __binding_4))
});
suggestions.push((__binding_5, __code_66));
suggestions.push((__binding_6, __code_67));
suggestions.push((__binding_7, __code_68));
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("use explicit `std::ptr::eq` method to compare metadata and addresses")),
&sub_args);
diag.multipart_suggestion_with_style(__message, suggestions,
rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowAlways);
}
}
}
}
};Subdiagnostic)]
2301#[multipart_suggestion(
2302 "use explicit `std::ptr::eq` method to compare metadata and addresses",
2303 style = "verbose",
2304 applicability = "maybe-incorrect"
2306)]
2307pub(crate) struct AmbiguousWidePointerComparisonsAddrMetadataSuggestion<'a> {
2308 pub ne: &'a str,
2309 pub deref_left: &'a str,
2310 pub deref_right: &'a str,
2311 pub l_modifiers: &'a str,
2312 pub r_modifiers: &'a str,
2313 #[suggestion_part(code = "{ne}std::ptr::eq({deref_left}")]
2314 pub left: Span,
2315 #[suggestion_part(code = "{l_modifiers}, {deref_right}")]
2316 pub middle: Span,
2317 #[suggestion_part(code = "{r_modifiers})")]
2318 pub right: Span,
2319}
2320
2321#[derive(const _: () =
{
impl<'a> rustc_errors::Subdiagnostic for
AmbiguousWidePointerComparisonsAddrSuggestion<'a> {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
AmbiguousWidePointerComparisonsAddrSuggestion {
ne: __binding_0,
deref_left: __binding_1,
deref_right: __binding_2,
l_modifiers: __binding_3,
r_modifiers: __binding_4,
left: __binding_5,
middle: __binding_6,
right: __binding_7 } => {
let mut suggestions = Vec::new();
let __code_69 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{1}std::ptr::addr_eq({0}",
__binding_1, __binding_0))
});
let __code_70 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{1}, {0}", __binding_2,
__binding_3))
});
let __code_71 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0})", __binding_4))
});
suggestions.push((__binding_5, __code_69));
suggestions.push((__binding_6, __code_70));
suggestions.push((__binding_7, __code_71));
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("use `std::ptr::addr_eq` or untyped pointers to only compare their addresses")),
&sub_args);
diag.multipart_suggestion_with_style(__message, suggestions,
rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowAlways);
}
}
}
}
};Subdiagnostic)]
2322#[multipart_suggestion(
2323 "use `std::ptr::addr_eq` or untyped pointers to only compare their addresses",
2324 style = "verbose",
2325 applicability = "maybe-incorrect"
2327)]
2328pub(crate) struct AmbiguousWidePointerComparisonsAddrSuggestion<'a> {
2329 pub(crate) ne: &'a str,
2330 pub(crate) deref_left: &'a str,
2331 pub(crate) deref_right: &'a str,
2332 pub(crate) l_modifiers: &'a str,
2333 pub(crate) r_modifiers: &'a str,
2334 #[suggestion_part(code = "{ne}std::ptr::addr_eq({deref_left}")]
2335 pub(crate) left: Span,
2336 #[suggestion_part(code = "{l_modifiers}, {deref_right}")]
2337 pub(crate) middle: Span,
2338 #[suggestion_part(code = "{r_modifiers})")]
2339 pub(crate) right: Span,
2340}
2341
2342#[derive(const _: () =
{
impl<'a> rustc_errors::Subdiagnostic for
AmbiguousWidePointerComparisonsCastSuggestion<'a> {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
AmbiguousWidePointerComparisonsCastSuggestion {
deref_left: __binding_0,
deref_right: __binding_1,
paren_left: __binding_2,
paren_right: __binding_3,
l_modifiers: __binding_4,
r_modifiers: __binding_5,
left_before: __binding_6,
left_after: __binding_7,
right_before: __binding_8,
right_after: __binding_9 } => {
let mut suggestions = Vec::new();
let __code_72 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("({0}", __binding_0))
});
let __code_73 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0}{1}.cast::<()>()",
__binding_4, __binding_2))
});
let __code_74 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("({0}", __binding_1))
});
let __code_75 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{1}{0}.cast::<()>()",
__binding_3, __binding_5))
});
if let Some(__binding_6) = __binding_6 {
suggestions.push((__binding_6, __code_72));
}
suggestions.push((__binding_7, __code_73));
if let Some(__binding_8) = __binding_8 {
suggestions.push((__binding_8, __code_74));
}
suggestions.push((__binding_9, __code_75));
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("use untyped pointers to only compare their addresses")),
&sub_args);
diag.multipart_suggestion_with_style(__message, suggestions,
rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowAlways);
}
}
}
}
};Subdiagnostic)]
2343#[multipart_suggestion(
2344 "use untyped pointers to only compare their addresses",
2345 style = "verbose",
2346 applicability = "maybe-incorrect"
2348)]
2349pub(crate) struct AmbiguousWidePointerComparisonsCastSuggestion<'a> {
2350 pub(crate) deref_left: &'a str,
2351 pub(crate) deref_right: &'a str,
2352 pub(crate) paren_left: &'a str,
2353 pub(crate) paren_right: &'a str,
2354 pub(crate) l_modifiers: &'a str,
2355 pub(crate) r_modifiers: &'a str,
2356 #[suggestion_part(code = "({deref_left}")]
2357 pub(crate) left_before: Option<Span>,
2358 #[suggestion_part(code = "{l_modifiers}{paren_left}.cast::<()>()")]
2359 pub(crate) left_after: Span,
2360 #[suggestion_part(code = "({deref_right}")]
2361 pub(crate) right_before: Option<Span>,
2362 #[suggestion_part(code = "{r_modifiers}{paren_right}.cast::<()>()")]
2363 pub(crate) right_after: Span,
2364}
2365
2366#[derive(const _: () =
{
impl<'a> rustc_errors::Subdiagnostic for
AmbiguousWidePointerComparisonsExpectSuggestion<'a> {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
AmbiguousWidePointerComparisonsExpectSuggestion {
paren_left: __binding_0,
paren_right: __binding_1,
before: __binding_2,
after: __binding_3 } => {
let mut suggestions = Vec::new();
let __code_76 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{{ #[expect(ambiguous_wide_pointer_comparisons, reason = \"...\")] {0}",
__binding_0))
});
let __code_77 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0} }}", __binding_1))
});
suggestions.push((__binding_2, __code_76));
suggestions.push((__binding_3, __code_77));
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("or expect the lint to compare the pointers metadata and addresses")),
&sub_args);
diag.multipart_suggestion_with_style(__message, suggestions,
rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowAlways);
}
}
}
}
};Subdiagnostic)]
2367#[multipart_suggestion(
2368 "or expect the lint to compare the pointers metadata and addresses",
2369 style = "verbose",
2370 applicability = "maybe-incorrect"
2372)]
2373pub(crate) struct AmbiguousWidePointerComparisonsExpectSuggestion<'a> {
2374 pub(crate) paren_left: &'a str,
2375 pub(crate) paren_right: &'a str,
2376 #[suggestion_part(
2378 code = r#"{{ #[expect(ambiguous_wide_pointer_comparisons, reason = "...")] {paren_left}"#
2379 )]
2380 pub(crate) before: Span,
2381 #[suggestion_part(code = "{paren_right} }}")]
2382 pub(crate) after: Span,
2383}
2384
2385#[derive(const _: () =
{
impl<'_sess, 'a, 'tcx, G> rustc_errors::Diagnostic<'_sess, G> for
UnpredictableFunctionPointerComparisons<'a, 'tcx> 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 {
UnpredictableFunctionPointerComparisons::Suggestion {
sugg: __binding_0 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("function pointer comparisons do not produce meaningful results since their addresses are not guaranteed to be unique")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the address of the same function can vary between different codegen units")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("furthermore, different functions could have the same address after being merged together")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("for more information visit <https://doc.rust-lang.org/nightly/core/ptr/fn.fn_addr_eq.html>")));
;
diag.subdiagnostic(__binding_0);
diag
}
UnpredictableFunctionPointerComparisons::Warn => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("function pointer comparisons do not produce meaningful results since their addresses are not guaranteed to be unique")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the address of the same function can vary between different codegen units")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("furthermore, different functions could have the same address after being merged together")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("for more information visit <https://doc.rust-lang.org/nightly/core/ptr/fn.fn_addr_eq.html>")));
;
diag
}
}
}
}
};Diagnostic)]
2386pub(crate) enum UnpredictableFunctionPointerComparisons<'a, 'tcx> {
2387 #[diag(
2388 "function pointer comparisons do not produce meaningful results since their addresses are not guaranteed to be unique"
2389 )]
2390 #[note("the address of the same function can vary between different codegen units")]
2391 #[note(
2392 "furthermore, different functions could have the same address after being merged together"
2393 )]
2394 #[note(
2395 "for more information visit <https://doc.rust-lang.org/nightly/core/ptr/fn.fn_addr_eq.html>"
2396 )]
2397 Suggestion {
2398 #[subdiagnostic]
2399 sugg: UnpredictableFunctionPointerComparisonsSuggestion<'a, 'tcx>,
2400 },
2401 #[diag(
2402 "function pointer comparisons do not produce meaningful results since their addresses are not guaranteed to be unique"
2403 )]
2404 #[note("the address of the same function can vary between different codegen units")]
2405 #[note(
2406 "furthermore, different functions could have the same address after being merged together"
2407 )]
2408 #[note(
2409 "for more information visit <https://doc.rust-lang.org/nightly/core/ptr/fn.fn_addr_eq.html>"
2410 )]
2411 Warn,
2412}
2413
2414#[derive(const _: () =
{
impl<'a, 'tcx> rustc_errors::Subdiagnostic for
UnpredictableFunctionPointerComparisonsSuggestion<'a, 'tcx> {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
UnpredictableFunctionPointerComparisonsSuggestion::FnAddrEq {
ne: __binding_0,
deref_left: __binding_1,
deref_right: __binding_2,
left: __binding_3,
middle: __binding_4,
right: __binding_5 } => {
let mut suggestions = Vec::new();
let __code_78 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{1}std::ptr::fn_addr_eq({0}",
__binding_1, __binding_0))
});
let __code_79 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!(", {0}", __binding_2))
});
let __code_80 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!(")"))
});
suggestions.push((__binding_3, __code_78));
suggestions.push((__binding_4, __code_79));
suggestions.push((__binding_5, __code_80));
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("refactor your code, or use `std::ptr::fn_addr_eq` to suppress the lint")),
&sub_args);
diag.multipart_suggestion_with_style(__message, suggestions,
rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowAlways);
}
UnpredictableFunctionPointerComparisonsSuggestion::FnAddrEqWithCast {
ne: __binding_0,
deref_left: __binding_1,
deref_right: __binding_2,
fn_sig: __binding_3,
left: __binding_4,
middle: __binding_5,
right: __binding_6 } => {
let mut suggestions = Vec::new();
let __code_81 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{1}std::ptr::fn_addr_eq({0}",
__binding_1, __binding_0))
});
let __code_82 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!(", {0}", __binding_2))
});
let __code_83 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!(" as {0})", __binding_3))
});
suggestions.push((__binding_4, __code_81));
suggestions.push((__binding_5, __code_82));
suggestions.push((__binding_6, __code_83));
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("refactor your code, or use `std::ptr::fn_addr_eq` to suppress the lint")),
&sub_args);
diag.multipart_suggestion_with_style(__message, suggestions,
rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowAlways);
}
}
}
}
};Subdiagnostic)]
2415pub(crate) enum UnpredictableFunctionPointerComparisonsSuggestion<'a, 'tcx> {
2416 #[multipart_suggestion(
2417 "refactor your code, or use `std::ptr::fn_addr_eq` to suppress the lint",
2418 style = "verbose",
2419 applicability = "maybe-incorrect"
2420 )]
2421 FnAddrEq {
2422 ne: &'a str,
2423 deref_left: &'a str,
2424 deref_right: &'a str,
2425 #[suggestion_part(code = "{ne}std::ptr::fn_addr_eq({deref_left}")]
2426 left: Span,
2427 #[suggestion_part(code = ", {deref_right}")]
2428 middle: Span,
2429 #[suggestion_part(code = ")")]
2430 right: Span,
2431 },
2432 #[multipart_suggestion(
2433 "refactor your code, or use `std::ptr::fn_addr_eq` to suppress the lint",
2434 style = "verbose",
2435 applicability = "maybe-incorrect"
2436 )]
2437 FnAddrEqWithCast {
2438 ne: &'a str,
2439 deref_left: &'a str,
2440 deref_right: &'a str,
2441 fn_sig: rustc_middle::ty::PolyFnSig<'tcx>,
2442 #[suggestion_part(code = "{ne}std::ptr::fn_addr_eq({deref_left}")]
2443 left: Span,
2444 #[suggestion_part(code = ", {deref_right}")]
2445 middle: Span,
2446 #[suggestion_part(code = " as {fn_sig})")]
2447 right: Span,
2448 },
2449}
2450
2451pub(crate) struct ImproperCTypes<'a> {
2452 pub ty: Ty<'a>,
2453 pub desc: &'a str,
2454 pub label: Span,
2455 pub help: Option<DiagMessage>,
2456 pub note: DiagMessage,
2457 pub span_note: Option<Span>,
2458}
2459
2460impl<'a> Diagnostic<'a, ()> for ImproperCTypes<'_> {
2462 fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, ()> {
2463 let mut diag = Diag::new(
2464 dcx,
2465 level,
2466 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`extern` {$desc} uses type `{$ty}`, which is not FFI-safe"))msg!("`extern` {$desc} uses type `{$ty}`, which is not FFI-safe"),
2467 )
2468 .with_arg("ty", self.ty)
2469 .with_arg("desc", self.desc)
2470 .with_span_label(self.label, rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("not FFI-safe"))msg!("not FFI-safe"));
2471 if let Some(help) = self.help {
2472 diag.help(help);
2473 }
2474 diag.note(self.note);
2475 if let Some(note) = self.span_note {
2476 diag.span_note(note, rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the type is defined here"))msg!("the type is defined here"));
2477 }
2478 diag
2479 }
2480}
2481
2482#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
ImproperGpuKernelArg<'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 {
ImproperGpuKernelArg { ty: __binding_0 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("passing type `{$ty}` to a function with \"gpu-kernel\" ABI may have unexpected behavior")));
diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("use primitive types and raw pointers to get reliable behavior")));
;
diag.arg("ty", __binding_0);
diag
}
}
}
}
};Diagnostic)]
2483#[diag("passing type `{$ty}` to a function with \"gpu-kernel\" ABI may have unexpected behavior")]
2484#[help("use primitive types and raw pointers to get reliable behavior")]
2485pub(crate) struct ImproperGpuKernelArg<'a> {
2486 pub ty: Ty<'a>,
2487}
2488
2489#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
MissingGpuKernelExportName 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 {
MissingGpuKernelExportName => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("function with the \"gpu-kernel\" ABI has a mangled name")));
diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("use `unsafe(no_mangle)` or `unsafe(export_name = \"<name>\")`")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("mangled names make it hard to find the kernel, this is usually not intended")));
;
diag
}
}
}
}
};Diagnostic)]
2490#[diag("function with the \"gpu-kernel\" ABI has a mangled name")]
2491#[help("use `unsafe(no_mangle)` or `unsafe(export_name = \"<name>\")`")]
2492#[note("mangled names make it hard to find the kernel, this is usually not intended")]
2493pub(crate) struct MissingGpuKernelExportName;
2494
2495#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
VariantSizeDifferencesDiag 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 {
VariantSizeDifferencesDiag { largest: __binding_0 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("enum variant is more than three times larger ({$largest} bytes) than the next largest")));
;
diag.arg("largest", __binding_0);
diag
}
}
}
}
};Diagnostic)]
2496#[diag("enum variant is more than three times larger ({$largest} bytes) than the next largest")]
2497pub(crate) struct VariantSizeDifferencesDiag {
2498 pub largest: u64,
2499}
2500
2501#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
AtomicOrderingLoad 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 {
AtomicOrderingLoad => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("atomic loads cannot have `Release` or `AcqRel` ordering")));
diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider using ordering modes `Acquire`, `SeqCst` or `Relaxed`")));
;
diag
}
}
}
}
};Diagnostic)]
2502#[diag("atomic loads cannot have `Release` or `AcqRel` ordering")]
2503#[help("consider using ordering modes `Acquire`, `SeqCst` or `Relaxed`")]
2504pub(crate) struct AtomicOrderingLoad;
2505
2506#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
AtomicOrderingStore 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 {
AtomicOrderingStore => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("atomic stores cannot have `Acquire` or `AcqRel` ordering")));
diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider using ordering modes `Release`, `SeqCst` or `Relaxed`")));
;
diag
}
}
}
}
};Diagnostic)]
2507#[diag("atomic stores cannot have `Acquire` or `AcqRel` ordering")]
2508#[help("consider using ordering modes `Release`, `SeqCst` or `Relaxed`")]
2509pub(crate) struct AtomicOrderingStore;
2510
2511#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
AtomicOrderingFence 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 {
AtomicOrderingFence => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("memory fences cannot have `Relaxed` ordering")));
diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider using ordering modes `Acquire`, `Release`, `AcqRel` or `SeqCst`")));
;
diag
}
}
}
}
};Diagnostic)]
2512#[diag("memory fences cannot have `Relaxed` ordering")]
2513#[help("consider using ordering modes `Acquire`, `Release`, `AcqRel` or `SeqCst`")]
2514pub(crate) struct AtomicOrderingFence;
2515
2516#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
InvalidAtomicOrderingDiag 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 {
InvalidAtomicOrderingDiag {
method: __binding_0, fail_order_arg_span: __binding_1 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`{$method}`'s failure ordering may not be `Release` or `AcqRel`, since a failed `{$method}` does not result in a write")));
diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider using `Acquire` or `Relaxed` failure ordering instead")));
;
diag.arg("method", __binding_0);
diag.span_label(__binding_1,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("invalid failure ordering")));
diag
}
}
}
}
};Diagnostic)]
2517#[diag(
2518 "`{$method}`'s failure ordering may not be `Release` or `AcqRel`, since a failed `{$method}` does not result in a write"
2519)]
2520#[help("consider using `Acquire` or `Relaxed` failure ordering instead")]
2521pub(crate) struct InvalidAtomicOrderingDiag {
2522 pub method: Symbol,
2523 #[label("invalid failure ordering")]
2524 pub fail_order_arg_span: Span,
2525}
2526
2527#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
UnusedOp<'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 {
UnusedOp {
op: __binding_0, label: __binding_1, suggestion: __binding_2
} => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("unused {$op} that must be used")));
;
diag.arg("op", __binding_0);
diag.span_label(__binding_1,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the {$op} produces a value")));
diag.subdiagnostic(__binding_2);
diag
}
}
}
}
};Diagnostic)]
2529#[diag("unused {$op} that must be used")]
2530pub(crate) struct UnusedOp<'a> {
2531 pub op: &'a str,
2532 #[label("the {$op} produces a value")]
2533 pub label: Span,
2534 #[subdiagnostic]
2535 pub suggestion: UnusedOpSuggestion,
2536}
2537
2538#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for UnusedOpSuggestion {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
UnusedOpSuggestion::NormalExpr { span: __binding_0 } => {
let __code_84 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("let _ = "))
})].into_iter();
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("use `let _ = ...` to ignore the resulting value")),
&sub_args);
diag.span_suggestions_with_style(__binding_0, __message,
__code_84, rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowAlways);
}
UnusedOpSuggestion::BlockTailExpr {
before_span: __binding_0, after_span: __binding_1 } => {
let mut suggestions = Vec::new();
let __code_85 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("let _ = "))
});
let __code_86 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!(";"))
});
suggestions.push((__binding_0, __code_85));
suggestions.push((__binding_1, __code_86));
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("use `let _ = ...` to ignore the resulting value")),
&sub_args);
diag.multipart_suggestion_with_style(__message, suggestions,
rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowAlways);
}
}
}
}
};Subdiagnostic)]
2539pub(crate) enum UnusedOpSuggestion {
2540 #[suggestion(
2541 "use `let _ = ...` to ignore the resulting value",
2542 style = "verbose",
2543 code = "let _ = ",
2544 applicability = "maybe-incorrect"
2545 )]
2546 NormalExpr {
2547 #[primary_span]
2548 span: Span,
2549 },
2550 #[multipart_suggestion(
2551 "use `let _ = ...` to ignore the resulting value",
2552 style = "verbose",
2553 applicability = "maybe-incorrect"
2554 )]
2555 BlockTailExpr {
2556 #[suggestion_part(code = "let _ = ")]
2557 before_span: Span,
2558 #[suggestion_part(code = ";")]
2559 after_span: Span,
2560 },
2561}
2562
2563#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
UnusedResult<'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 {
UnusedResult { ty: __binding_0 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("unused result of type `{$ty}`")));
;
diag.arg("ty", __binding_0);
diag
}
}
}
}
};Diagnostic)]
2564#[diag("unused result of type `{$ty}`")]
2565pub(crate) struct UnusedResult<'a> {
2566 pub ty: Ty<'a>,
2567}
2568
2569#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
UnusedClosure<'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 {
UnusedClosure {
count: __binding_0, pre: __binding_1, post: __binding_2 } =>
{
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("unused {$pre}{$count ->\n [one] closure\n *[other] closures\n }{$post} that must be used")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("closures are lazy and do nothing unless called")));
;
diag.arg("count", __binding_0);
diag.arg("pre", __binding_1);
diag.arg("post", __binding_2);
diag
}
}
}
}
};Diagnostic)]
2572#[diag(
2573 "unused {$pre}{$count ->
2574 [one] closure
2575 *[other] closures
2576 }{$post} that must be used"
2577)]
2578#[note("closures are lazy and do nothing unless called")]
2579pub(crate) struct UnusedClosure<'a> {
2580 pub count: usize,
2581 pub pre: &'a str,
2582 pub post: &'a str,
2583}
2584
2585#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
UnusedCoroutine<'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 {
UnusedCoroutine {
count: __binding_0, pre: __binding_1, post: __binding_2 } =>
{
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("unused {$pre}{$count ->\n [one] coroutine\n *[other] coroutine\n }{$post} that must be used")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("coroutines are lazy and do nothing unless resumed")));
;
diag.arg("count", __binding_0);
diag.arg("pre", __binding_1);
diag.arg("post", __binding_2);
diag
}
}
}
}
};Diagnostic)]
2588#[diag(
2589 "unused {$pre}{$count ->
2590 [one] coroutine
2591 *[other] coroutine
2592 }{$post} that must be used"
2593)]
2594#[note("coroutines are lazy and do nothing unless resumed")]
2595pub(crate) struct UnusedCoroutine<'a> {
2596 pub count: usize,
2597 pub pre: &'a str,
2598 pub post: &'a str,
2599}
2600
2601pub(crate) struct UnusedDef<'a, 'b> {
2604 pub pre: &'a str,
2605 pub post: &'a str,
2606 pub cx: &'a LateContext<'b>,
2607 pub def_id: DefId,
2608 pub note: Option<Symbol>,
2609 pub suggestion: Option<UnusedDefSuggestion>,
2610}
2611
2612#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for UnusedDefSuggestion {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
UnusedDefSuggestion::NormalExpr { span: __binding_0 } => {
let __code_87 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("let _ = "))
})].into_iter();
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("use `let _ = ...` to ignore the resulting value")),
&sub_args);
diag.span_suggestions_with_style(__binding_0, __message,
__code_87, rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowAlways);
}
UnusedDefSuggestion::BlockTailExpr {
before_span: __binding_0, after_span: __binding_1 } => {
let mut suggestions = Vec::new();
let __code_88 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("let _ = "))
});
let __code_89 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!(";"))
});
suggestions.push((__binding_0, __code_88));
suggestions.push((__binding_1, __code_89));
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("use `let _ = ...` to ignore the resulting value")),
&sub_args);
diag.multipart_suggestion_with_style(__message, suggestions,
rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowAlways);
}
}
}
}
};Subdiagnostic)]
2613pub(crate) enum UnusedDefSuggestion {
2614 #[suggestion(
2615 "use `let _ = ...` to ignore the resulting value",
2616 style = "verbose",
2617 code = "let _ = ",
2618 applicability = "maybe-incorrect"
2619 )]
2620 NormalExpr {
2621 #[primary_span]
2622 span: Span,
2623 },
2624 #[multipart_suggestion(
2625 "use `let _ = ...` to ignore the resulting value",
2626 style = "verbose",
2627 applicability = "maybe-incorrect"
2628 )]
2629 BlockTailExpr {
2630 #[suggestion_part(code = "let _ = ")]
2631 before_span: Span,
2632 #[suggestion_part(code = ";")]
2633 after_span: Span,
2634 },
2635}
2636
2637impl<'a> Diagnostic<'a, ()> for UnusedDef<'_, '_> {
2639 fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, ()> {
2640 let mut diag =
2641 Diag::new(dcx, level, rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("unused {$pre}`{$def}`{$post} that must be used"))msg!("unused {$pre}`{$def}`{$post} that must be used"))
2642 .with_arg("pre", self.pre)
2643 .with_arg("post", self.post)
2644 .with_arg("def", self.cx.tcx.def_path_str(self.def_id));
2645 if let Some(note) = self.note {
2647 diag.note(note.to_string());
2648 }
2649 if let Some(sugg) = self.suggestion {
2650 diag.subdiagnostic(sugg);
2651 }
2652 diag
2653 }
2654}
2655
2656#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
PathStatementDrop 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 {
PathStatementDrop { sub: __binding_0 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("path statement drops value")));
;
diag.subdiagnostic(__binding_0);
diag
}
}
}
}
};Diagnostic)]
2657#[diag("path statement drops value")]
2658pub(crate) struct PathStatementDrop {
2659 #[subdiagnostic]
2660 pub sub: PathStatementDropSub,
2661}
2662
2663#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for PathStatementDropSub {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
PathStatementDropSub::Suggestion {
span: __binding_0, snippet: __binding_1 } => {
let __code_90 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("drop({0});",
__binding_1))
})].into_iter();
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("use `drop` to clarify the intent")),
&sub_args);
diag.span_suggestions_with_style(__binding_0, __message,
__code_90, rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::ShowCode);
}
PathStatementDropSub::Help { span: __binding_0 } => {
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("use `drop` to clarify the intent")),
&sub_args);
diag.span_help(__binding_0, __message);
}
}
}
}
};Subdiagnostic)]
2664pub(crate) enum PathStatementDropSub {
2665 #[suggestion(
2666 "use `drop` to clarify the intent",
2667 code = "drop({snippet});",
2668 applicability = "machine-applicable"
2669 )]
2670 Suggestion {
2671 #[primary_span]
2672 span: Span,
2673 snippet: String,
2674 },
2675 #[help("use `drop` to clarify the intent")]
2676 Help {
2677 #[primary_span]
2678 span: Span,
2679 },
2680}
2681
2682#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
PathStatementNoEffect 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 {
PathStatementNoEffect => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("path statement with no effect")));
;
diag
}
}
}
}
};Diagnostic)]
2683#[diag("path statement with no effect")]
2684pub(crate) struct PathStatementNoEffect;
2685
2686#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
UnusedDelim<'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 {
UnusedDelim {
delim: __binding_0,
item: __binding_1,
suggestion: __binding_2 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("unnecessary {$delim} around {$item}")));
;
diag.arg("delim", __binding_0);
diag.arg("item", __binding_1);
if let Some(__binding_2) = __binding_2 {
diag.subdiagnostic(__binding_2);
}
diag
}
}
}
}
};Diagnostic)]
2687#[diag("unnecessary {$delim} around {$item}")]
2688pub(crate) struct UnusedDelim<'a> {
2689 pub delim: &'static str,
2690 pub item: &'a str,
2691 #[subdiagnostic]
2692 pub suggestion: Option<UnusedDelimSuggestion>,
2693}
2694
2695#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for UnusedDelimSuggestion {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
UnusedDelimSuggestion {
start_span: __binding_0,
start_replace: __binding_1,
end_span: __binding_2,
end_replace: __binding_3,
delim: __binding_4 } => {
let mut suggestions = Vec::new();
let __code_91 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0}", __binding_1))
});
let __code_92 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0}", __binding_3))
});
suggestions.push((__binding_0, __code_91));
suggestions.push((__binding_2, __code_92));
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("delim".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_4,
&mut diag.long_ty_path));
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("remove these {$delim}")),
&sub_args);
diag.multipart_suggestion_with_style(__message, suggestions,
rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::ShowCode);
}
}
}
}
};Subdiagnostic)]
2696#[multipart_suggestion("remove these {$delim}", applicability = "machine-applicable")]
2697pub(crate) struct UnusedDelimSuggestion {
2698 #[suggestion_part(code = "{start_replace}")]
2699 pub start_span: Span,
2700 pub start_replace: &'static str,
2701 #[suggestion_part(code = "{end_replace}")]
2702 pub end_span: Span,
2703 pub end_replace: &'static str,
2704 pub delim: &'static str,
2705}
2706
2707#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
UnusedImportBracesDiag 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 {
UnusedImportBracesDiag { node: __binding_0 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("braces around {$node} is unnecessary")));
;
diag.arg("node", __binding_0);
diag
}
}
}
}
};Diagnostic)]
2708#[diag("braces around {$node} is unnecessary")]
2709pub(crate) struct UnusedImportBracesDiag {
2710 pub node: Symbol,
2711}
2712
2713#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
UnusedAllocationDiag 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 {
UnusedAllocationDiag => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("unnecessary allocation, use `&` instead")));
;
diag
}
}
}
}
};Diagnostic)]
2714#[diag("unnecessary allocation, use `&` instead")]
2715pub(crate) struct UnusedAllocationDiag;
2716
2717#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
UnusedAllocationMutDiag 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 {
UnusedAllocationMutDiag => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("unnecessary allocation, use `&mut` instead")));
;
diag
}
}
}
}
};Diagnostic)]
2718#[diag("unnecessary allocation, use `&mut` instead")]
2719pub(crate) struct UnusedAllocationMutDiag;
2720
2721pub(crate) struct AsyncFnInTraitDiag {
2722 pub sugg: Option<Vec<(Span, String)>>,
2723}
2724
2725impl<'a> Diagnostic<'a, ()> for AsyncFnInTraitDiag {
2726 fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, ()> {
2727 let mut diag = Diag::new(
2728 dcx,
2729 level,
2730 "use of `async fn` in public traits is discouraged as auto trait bounds cannot be specified",
2731 );
2732 diag.note("you can suppress this lint if you plan to use the trait only in your own code, or do not care about auto traits like `Send` on the `Future`");
2733 if let Some(sugg) = self.sugg {
2734 diag.multipart_suggestion("you can alternatively desugar to a normal `fn` that returns `impl Future` and add any desired bounds such as `Send`, but these cannot be relaxed without a breaking API change", sugg, Applicability::MaybeIncorrect);
2735 }
2736 diag
2737 }
2738}
2739
2740#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
UnitBindingsDiag 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 {
UnitBindingsDiag { label: __binding_0 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("binding has unit type `()`")));
;
diag.span_label(__binding_0,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this pattern is inferred to be the unit type `()`")));
diag
}
}
}
}
};Diagnostic)]
2741#[diag("binding has unit type `()`")]
2742pub(crate) struct UnitBindingsDiag {
2743 #[label("this pattern is inferred to be the unit type `()`")]
2744 pub label: Span,
2745}
2746
2747#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
InvalidAsmLabel 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 {
InvalidAsmLabel::Named { missing_precise_span: __binding_0 }
=> {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("avoid using named labels in inline assembly")));
diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("only local labels of the form `<number>:` should be used in inline asm")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("see the asm section of Rust By Example <https://doc.rust-lang.org/nightly/rust-by-example/unsafe/asm.html#labels> for more information")));
;
if __binding_0 {
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the label may be declared in the expansion of a macro")));
}
diag
}
InvalidAsmLabel::FormatArg {
missing_precise_span: __binding_0 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("avoid using named labels in inline assembly")));
diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("only local labels of the form `<number>:` should be used in inline asm")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("format arguments may expand to a non-numeric value")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("see the asm section of Rust By Example <https://doc.rust-lang.org/nightly/rust-by-example/unsafe/asm.html#labels> for more information")));
;
if __binding_0 {
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the label may be declared in the expansion of a macro")));
}
diag
}
InvalidAsmLabel::Binary {
missing_precise_span: __binding_0, span: __binding_1 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("avoid using labels containing only the digits `0` and `1` in inline assembly")));
diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("start numbering with `2` instead")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("an LLVM bug makes these labels ambiguous with a binary literal number on x86")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("see <https://github.com/llvm/llvm-project/issues/99547> for more information")));
;
if __binding_0 {
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the label may be declared in the expansion of a macro")));
}
diag.span_label(__binding_1,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("use a different label that doesn't start with `0` or `1`")));
diag
}
}
}
}
};Diagnostic)]
2748pub(crate) enum InvalidAsmLabel {
2749 #[diag("avoid using named labels in inline assembly")]
2750 #[help("only local labels of the form `<number>:` should be used in inline asm")]
2751 #[note(
2752 "see the asm section of Rust By Example <https://doc.rust-lang.org/nightly/rust-by-example/unsafe/asm.html#labels> for more information"
2753 )]
2754 Named {
2755 #[note("the label may be declared in the expansion of a macro")]
2756 missing_precise_span: bool,
2757 },
2758 #[diag("avoid using named labels in inline assembly")]
2759 #[help("only local labels of the form `<number>:` should be used in inline asm")]
2760 #[note("format arguments may expand to a non-numeric value")]
2761 #[note(
2762 "see the asm section of Rust By Example <https://doc.rust-lang.org/nightly/rust-by-example/unsafe/asm.html#labels> for more information"
2763 )]
2764 FormatArg {
2765 #[note("the label may be declared in the expansion of a macro")]
2766 missing_precise_span: bool,
2767 },
2768 #[diag("avoid using labels containing only the digits `0` and `1` in inline assembly")]
2769 #[help("start numbering with `2` instead")]
2770 #[note("an LLVM bug makes these labels ambiguous with a binary literal number on x86")]
2771 #[note("see <https://github.com/llvm/llvm-project/issues/99547> for more information")]
2772 Binary {
2773 #[note("the label may be declared in the expansion of a macro")]
2774 missing_precise_span: bool,
2775 #[label("use a different label that doesn't start with `0` or `1`")]
2777 span: Span,
2778 },
2779}
2780
2781#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
RefOfMutStatic<'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 {
RefOfMutStatic {
span: __binding_0,
sugg: __binding_1,
shared_label: __binding_2,
shared_note: __binding_3,
mut_note: __binding_4,
interior_mutability_help: __binding_5,
interior_mutability_sugg: __binding_6 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("creating a {$shared_label}reference to mutable static")));
;
diag.arg("shared_label", __binding_2);
diag.span_label(__binding_0,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$shared_label}reference to mutable static")));
if let Some(__binding_1) = __binding_1 {
diag.subdiagnostic(__binding_1);
}
if __binding_3 {
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("shared references to mutable statics are dangerous; it's undefined behavior if the static is mutated or if a mutable reference is created for it while the shared reference lives")));
}
if __binding_4 {
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("mutable references to mutable statics are dangerous; it's undefined behavior if any other pointer to the static is used or if any other reference is created for the static while the mutable reference lives")));
}
if __binding_5 {
diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("use a type that relies on \"interior mutability\" instead; to read more on this, visit <https://doc.rust-lang.org/reference/interior-mutability.html>")));
}
if let Some(__binding_6) = __binding_6 {
diag.subdiagnostic(__binding_6);
}
diag
}
}
}
}
};Diagnostic)]
2782#[diag("creating a {$shared_label}reference to mutable static")]
2783pub(crate) struct RefOfMutStatic<'a> {
2784 #[label("{$shared_label}reference to mutable static")]
2785 pub span: Span,
2786 #[subdiagnostic]
2787 pub sugg: Option<MutRefSugg>,
2788 pub shared_label: &'a str,
2789 #[note(
2790 "shared references to mutable statics are dangerous; it's undefined behavior if the static is mutated or if a mutable reference is created for it while the shared reference lives"
2791 )]
2792 pub shared_note: bool,
2793 #[note(
2794 "mutable references to mutable statics are dangerous; it's undefined behavior if any other pointer to the static is used or if any other reference is created for the static while the mutable reference lives"
2795 )]
2796 pub mut_note: bool,
2797 #[help(
2798 "use a type that relies on \"interior mutability\" instead; to read more on this, visit <https://doc.rust-lang.org/reference/interior-mutability.html>"
2799 )]
2800 pub interior_mutability_help: bool,
2801 #[subdiagnostic]
2802 pub interior_mutability_sugg: Option<StaticMutRefsInteriorMutabilitySugg>,
2803}
2804
2805#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for MutRefSugg {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
MutRefSugg::Shared { span: __binding_0 } => {
let mut suggestions = Vec::new();
let __code_93 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("&raw const "))
});
suggestions.push((__binding_0, __code_93));
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("use `&raw const` instead to create a raw pointer")),
&sub_args);
diag.multipart_suggestion_with_style(__message, suggestions,
rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowAlways);
}
MutRefSugg::Mut { span: __binding_0 } => {
let mut suggestions = Vec::new();
let __code_94 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("&raw mut "))
});
suggestions.push((__binding_0, __code_94));
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("use `&raw mut` instead to create a raw pointer")),
&sub_args);
diag.multipart_suggestion_with_style(__message, suggestions,
rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowAlways);
}
}
}
}
};Subdiagnostic)]
2806pub(crate) enum MutRefSugg {
2807 #[multipart_suggestion(
2808 "use `&raw const` instead to create a raw pointer",
2809 style = "verbose",
2810 applicability = "maybe-incorrect"
2811 )]
2812 Shared {
2813 #[suggestion_part(code = "&raw const ")]
2814 span: Span,
2815 },
2816 #[multipart_suggestion(
2817 "use `&raw mut` instead to create a raw pointer",
2818 style = "verbose",
2819 applicability = "maybe-incorrect"
2820 )]
2821 Mut {
2822 #[suggestion_part(code = "&raw mut ")]
2823 span: Span,
2824 },
2825}
2826
2827#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for
StaticMutRefsInteriorMutabilitySugg {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
StaticMutRefsInteriorMutabilitySugg { span: __binding_0 } =>
{
let __code_95 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!(""))
})].into_iter();
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this type already provides \"interior mutability\", so its binding doesn't need to be declared as mutable when borrowed with a shared reference")),
&sub_args);
diag.span_suggestions_with_style(__binding_0, __message,
__code_95, rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowAlways);
}
}
}
}
};Subdiagnostic)]
2828#[suggestion(
2829 "this type already provides \"interior mutability\", so its binding doesn't need to be declared as mutable when borrowed with a shared reference",
2830 style = "verbose",
2831 applicability = "maybe-incorrect",
2832 code = ""
2833)]
2834pub(crate) struct StaticMutRefsInteriorMutabilitySugg {
2835 #[primary_span]
2836 pub span: Span,
2837}
2838
2839#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
UnqualifiedLocalImportsDiag 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 {
UnqualifiedLocalImportsDiag => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`use` of a local item without leading `self::`, `super::`, or `crate::`")));
;
diag
}
}
}
}
};Diagnostic)]
2840#[diag("`use` of a local item without leading `self::`, `super::`, or `crate::`")]
2841pub(crate) struct UnqualifiedLocalImportsDiag;
2842
2843#[derive(const _: () =
{
impl<'_sess, 'tcx, G> rustc_errors::Diagnostic<'_sess, G> for
FunctionCastsAsIntegerDiag<'tcx> 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 {
FunctionCastsAsIntegerDiag { sugg: __binding_0 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("direct cast of function item into an integer")));
;
diag.subdiagnostic(__binding_0);
diag
}
}
}
}
};Diagnostic)]
2844#[diag("direct cast of function item into an integer")]
2845pub(crate) struct FunctionCastsAsIntegerDiag<'tcx> {
2846 #[subdiagnostic]
2847 pub(crate) sugg: FunctionCastsAsIntegerSugg<'tcx>,
2848}
2849
2850#[derive(const _: () =
{
impl<'tcx> rustc_errors::Subdiagnostic for
FunctionCastsAsIntegerSugg<'tcx> {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
FunctionCastsAsIntegerSugg {
suggestion: __binding_0, cast_to_ty: __binding_1 } => {
let __code_96 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!(" as *const ()"))
})].into_iter();
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("first cast to a pointer `as *const ()`")),
&sub_args);
diag.span_suggestions_with_style(__binding_0, __message,
__code_96, rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::ShowAlways);
}
}
}
}
};Subdiagnostic)]
2851#[suggestion(
2852 "first cast to a pointer `as *const ()`",
2853 code = " as *const ()",
2854 applicability = "machine-applicable",
2855 style = "verbose"
2856)]
2857pub(crate) struct FunctionCastsAsIntegerSugg<'tcx> {
2858 #[primary_span]
2859 pub suggestion: Span,
2860 pub cast_to_ty: Ty<'tcx>,
2861}
2862
2863#[derive(#[automatically_derived]
impl ::core::fmt::Debug for MismatchedLifetimeSyntaxes {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field3_finish(f,
"MismatchedLifetimeSyntaxes", "inputs", &self.inputs, "outputs",
&self.outputs, "suggestions", &&self.suggestions)
}
}Debug)]
2864pub(crate) struct MismatchedLifetimeSyntaxes {
2865 pub inputs: LifetimeSyntaxCategories<Vec<Span>>,
2866 pub outputs: LifetimeSyntaxCategories<Vec<Span>>,
2867
2868 pub suggestions: Vec<MismatchedLifetimeSyntaxesSuggestion>,
2869}
2870
2871impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for MismatchedLifetimeSyntaxes {
2872 fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, G> {
2873 let counts = self.inputs.len() + self.outputs.len();
2874 let message = match counts {
2875 LifetimeSyntaxCategories { hidden: 0, elided: 0, named: 0 } => {
2876 {
::core::panicking::panic_fmt(format_args!("No lifetime mismatch detected"));
}panic!("No lifetime mismatch detected")
2877 }
2878
2879 LifetimeSyntaxCategories { hidden: _, elided: _, named: 0 } => {
2880 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("hiding a lifetime that's elided elsewhere is confusing"))msg!("hiding a lifetime that's elided elsewhere is confusing")
2881 }
2882
2883 LifetimeSyntaxCategories { hidden: _, elided: 0, named: _ } => {
2884 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("hiding a lifetime that's named elsewhere is confusing"))msg!("hiding a lifetime that's named elsewhere is confusing")
2885 }
2886
2887 LifetimeSyntaxCategories { hidden: 0, elided: _, named: _ } => {
2888 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("eliding a lifetime that's named elsewhere is confusing"))msg!("eliding a lifetime that's named elsewhere is confusing")
2889 }
2890
2891 LifetimeSyntaxCategories { hidden: _, elided: _, named: _ } => {
2892 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("hiding or eliding a lifetime that's named elsewhere is confusing"))msg!("hiding or eliding a lifetime that's named elsewhere is confusing")
2893 }
2894 };
2895 let mut diag = Diag::new(dcx, level, message);
2896
2897 for s in self.inputs.hidden {
2898 diag.span_label(s, rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the lifetime is hidden here"))msg!("the lifetime is hidden here"));
2899 }
2900 for s in self.inputs.elided {
2901 diag.span_label(s, rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the lifetime is elided here"))msg!("the lifetime is elided here"));
2902 }
2903 for s in self.inputs.named {
2904 diag.span_label(s, rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the lifetime is named here"))msg!("the lifetime is named here"));
2905 }
2906
2907 let mut hidden_output_counts: FxIndexMap<Span, usize> = FxIndexMap::default();
2908 for s in self.outputs.hidden {
2909 *hidden_output_counts.entry(s).or_insert(0) += 1;
2910 }
2911 for (span, count) in hidden_output_counts {
2912 let label = rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the same {$count ->\n [one] lifetime\n *[other] lifetimes\n } {$count ->\n [one] is\n *[other] are\n } hidden here"))msg!(
2913 "the same {$count ->
2914 [one] lifetime
2915 *[other] lifetimes
2916 } {$count ->
2917 [one] is
2918 *[other] are
2919 } hidden here"
2920 )
2921 .arg("count", count)
2922 .format();
2923 diag.span_label(span, label);
2924 }
2925 for s in self.outputs.elided {
2926 diag.span_label(s, rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the same lifetime is elided here"))msg!("the same lifetime is elided here"));
2927 }
2928 for s in self.outputs.named {
2929 diag.span_label(s, rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the same lifetime is named here"))msg!("the same lifetime is named here"));
2930 }
2931
2932 diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the same lifetime is referred to in inconsistent ways, making the signature confusing"))msg!(
2933 "the same lifetime is referred to in inconsistent ways, making the signature confusing"
2934 ));
2935
2936 let mut suggestions = self.suggestions.into_iter();
2937 if let Some(s) = suggestions.next() {
2938 diag.subdiagnostic(s);
2939
2940 for mut s in suggestions {
2941 s.make_optional_alternative();
2942 diag.subdiagnostic(s);
2943 }
2944 }
2945 diag
2946 }
2947}
2948
2949#[derive(#[automatically_derived]
impl ::core::fmt::Debug for MismatchedLifetimeSyntaxesSuggestion {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
MismatchedLifetimeSyntaxesSuggestion::Implicit {
suggestions: __self_0, optional_alternative: __self_1 } =>
::core::fmt::Formatter::debug_struct_field2_finish(f,
"Implicit", "suggestions", __self_0, "optional_alternative",
&__self_1),
MismatchedLifetimeSyntaxesSuggestion::Mixed {
implicit_suggestions: __self_0,
explicit_anonymous_suggestions: __self_1,
optional_alternative: __self_2 } =>
::core::fmt::Formatter::debug_struct_field3_finish(f, "Mixed",
"implicit_suggestions", __self_0,
"explicit_anonymous_suggestions", __self_1,
"optional_alternative", &__self_2),
MismatchedLifetimeSyntaxesSuggestion::Explicit {
lifetime_name: __self_0,
suggestions: __self_1,
optional_alternative: __self_2 } =>
::core::fmt::Formatter::debug_struct_field3_finish(f,
"Explicit", "lifetime_name", __self_0, "suggestions",
__self_1, "optional_alternative", &__self_2),
}
}
}Debug)]
2950pub(crate) enum MismatchedLifetimeSyntaxesSuggestion {
2951 Implicit {
2952 suggestions: Vec<Span>,
2953 optional_alternative: bool,
2954 },
2955
2956 Mixed {
2957 implicit_suggestions: Vec<Span>,
2958 explicit_anonymous_suggestions: Vec<(Span, String)>,
2959 optional_alternative: bool,
2960 },
2961
2962 Explicit {
2963 lifetime_name: String,
2964 suggestions: Vec<(Span, String)>,
2965 optional_alternative: bool,
2966 },
2967}
2968
2969impl MismatchedLifetimeSyntaxesSuggestion {
2970 fn make_optional_alternative(&mut self) {
2971 use MismatchedLifetimeSyntaxesSuggestion::*;
2972
2973 let optional_alternative = match self {
2974 Implicit { optional_alternative, .. }
2975 | Mixed { optional_alternative, .. }
2976 | Explicit { optional_alternative, .. } => optional_alternative,
2977 };
2978
2979 *optional_alternative = true;
2980 }
2981}
2982
2983impl Subdiagnostic for MismatchedLifetimeSyntaxesSuggestion {
2984 fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
2985 use MismatchedLifetimeSyntaxesSuggestion::*;
2986
2987 let style = |optional_alternative| {
2988 if optional_alternative {
2989 SuggestionStyle::CompletelyHidden
2990 } else {
2991 SuggestionStyle::ShowAlways
2992 }
2993 };
2994
2995 let applicability = |optional_alternative| {
2996 if optional_alternative {
2999 Applicability::MaybeIncorrect
3000 } else {
3001 Applicability::MachineApplicable
3002 }
3003 };
3004
3005 match self {
3006 Implicit { suggestions, optional_alternative } => {
3007 let suggestions = suggestions.into_iter().map(|s| (s, String::new())).collect();
3008 diag.multipart_suggestion_with_style(
3009 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("remove the lifetime name from references"))msg!("remove the lifetime name from references"),
3010 suggestions,
3011 applicability(optional_alternative),
3012 style(optional_alternative),
3013 );
3014 }
3015
3016 Mixed {
3017 implicit_suggestions,
3018 explicit_anonymous_suggestions,
3019 optional_alternative,
3020 } => {
3021 let message = if implicit_suggestions.is_empty() {
3022 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("use `'_` for type paths"))msg!("use `'_` for type paths")
3023 } else {
3024 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("remove the lifetime name from references and use `'_` for type paths"))msg!("remove the lifetime name from references and use `'_` for type paths")
3025 };
3026
3027 let implicit_suggestions =
3028 implicit_suggestions.into_iter().map(|s| (s, String::new()));
3029
3030 let suggestions =
3031 implicit_suggestions.chain(explicit_anonymous_suggestions).collect();
3032
3033 diag.multipart_suggestion_with_style(
3034 message,
3035 suggestions,
3036 applicability(optional_alternative),
3037 style(optional_alternative),
3038 );
3039 }
3040
3041 Explicit { lifetime_name, suggestions, optional_alternative } => {
3042 let msg = rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consistently use `{$lifetime_name}`"))msg!("consistently use `{$lifetime_name}`")
3043 .arg("lifetime_name", lifetime_name)
3044 .format();
3045 diag.multipart_suggestion_with_style(
3046 msg,
3047 suggestions,
3048 applicability(optional_alternative),
3049 style(optional_alternative),
3050 );
3051 }
3052 }
3053 }
3054}
3055
3056#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
EqInternalMethodImplemented 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 {
EqInternalMethodImplemented => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`Eq::assert_receiver_is_total_eq` should never be implemented by hand")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this method was used to add checks to the `Eq` derive macro")));
;
diag
}
}
}
}
};Diagnostic)]
3057#[diag("`Eq::assert_receiver_is_total_eq` should never be implemented by hand")]
3058#[note("this method was used to add checks to the `Eq` derive macro")]
3059pub(crate) struct EqInternalMethodImplemented;
3060
3061#[derive(const _: () =
{
impl<'_sess, 'tcx, G> rustc_errors::Diagnostic<'_sess, G> for
ImplicitProvenanceCastsInt2Ptr<'tcx> 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 {
ImplicitProvenanceCastsInt2Ptr {
expr_ty: __binding_0,
cast_ty: __binding_1,
sugg: __binding_2 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("cast from `{$expr_ty}` to `{$cast_ty}` implicitly relies on exposed provenance")));
diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("if conforming to strict provenance is not possible, use `std::ptr::with_exposed_provenance()`")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("for more information, visit <https://doc.rust-lang.org/std/ptr/index.html#provenance>")));
;
diag.arg("expr_ty", __binding_0);
diag.arg("cast_ty", __binding_1);
if let Some(__binding_2) = __binding_2 {
diag.subdiagnostic(__binding_2);
}
diag
}
}
}
}
};Diagnostic)]
3062#[diag("cast from `{$expr_ty}` to `{$cast_ty}` implicitly relies on exposed provenance")]
3063#[help(
3064 "if conforming to strict provenance is not possible, use `std::ptr::with_exposed_provenance()`"
3065)]
3066#[note("for more information, visit <https://doc.rust-lang.org/std/ptr/index.html#provenance>")]
3067pub(crate) struct ImplicitProvenanceCastsInt2Ptr<'tcx> {
3068 pub expr_ty: Ty<'tcx>,
3069 pub cast_ty: Ty<'tcx>,
3070 #[subdiagnostic]
3071 pub sugg: Option<Int2PtrSuggestion>,
3072}
3073
3074#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for Int2PtrSuggestion {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
Int2PtrSuggestion { lo: __binding_0, hi: __binding_1 } => {
let mut suggestions = Vec::new();
let __code_97 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("(...).with_addr("))
});
let __code_98 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!(")"))
});
suggestions.push((__binding_0, __code_97));
suggestions.push((__binding_1, __code_98));
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("use `.with_addr()` to adjust the address of a valid pointer in the same allocation")),
&sub_args);
diag.multipart_suggestion_with_style(__message, suggestions,
rustc_errors::Applicability::HasPlaceholders,
rustc_errors::SuggestionStyle::ShowCode);
}
}
}
}
};Subdiagnostic)]
3075#[multipart_suggestion(
3076 "use `.with_addr()` to adjust the address of a valid pointer in the same allocation",
3077 applicability = "has-placeholders"
3078)]
3079pub(crate) struct Int2PtrSuggestion {
3080 #[suggestion_part(code = "(...).with_addr(")]
3081 pub lo: Span,
3082 #[suggestion_part(code = ")")]
3083 pub hi: Span,
3084}
3085
3086#[derive(const _: () =
{
impl<'_sess, 'tcx, G> rustc_errors::Diagnostic<'_sess, G> for
ImplicitProvenanceCastsPtr2Int<'tcx> 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 {
ImplicitProvenanceCastsPtr2Int {
cast_from_ty: __binding_0,
cast_to_ty: __binding_1,
sugg: __binding_2 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("cast from `{$cast_from_ty}` to `{$cast_to_ty}` implicitly exposes pointer provenance")));
diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("if conforming to strict provenance is not possible, use `.expose_provenance()`")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("for more information, visit <https://doc.rust-lang.org/std/ptr/index.html#provenance>")));
;
diag.arg("cast_from_ty", __binding_0);
diag.arg("cast_to_ty", __binding_1);
if let Some(__binding_2) = __binding_2 {
diag.subdiagnostic(__binding_2);
}
diag
}
}
}
}
};Diagnostic)]
3087#[diag("cast from `{$cast_from_ty}` to `{$cast_to_ty}` implicitly exposes pointer provenance")]
3088#[help("if conforming to strict provenance is not possible, use `.expose_provenance()`")]
3089#[note("for more information, visit <https://doc.rust-lang.org/std/ptr/index.html#provenance>")]
3090pub(crate) struct ImplicitProvenanceCastsPtr2Int<'tcx> {
3091 pub cast_from_ty: Ty<'tcx>,
3092 pub cast_to_ty: Ty<'tcx>,
3093 #[subdiagnostic]
3094 pub sugg: Option<Ptr2IntSuggestion<'tcx>>,
3095}
3096
3097#[derive(const _: () =
{
impl<'tcx> rustc_errors::Subdiagnostic for Ptr2IntSuggestion<'tcx> {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
Ptr2IntSuggestion::NeedsParensCast {
expr_span: __binding_0,
cast_span: __binding_1,
cast_to_ty: __binding_2 } => {
let mut suggestions = Vec::new();
let __code_99 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("("))
});
let __code_100 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!(").addr() as {0}",
__binding_2))
});
suggestions.push((__binding_0, __code_99));
suggestions.push((__binding_1, __code_100));
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("use `.addr()` to obtain the address of a pointer")),
&sub_args);
diag.multipart_suggestion_with_style(__message, suggestions,
rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowCode);
}
Ptr2IntSuggestion::NeedsParens {
expr_span: __binding_0, cast_span: __binding_1 } => {
let mut suggestions = Vec::new();
let __code_101 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("("))
});
let __code_102 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!(").addr()"))
});
suggestions.push((__binding_0, __code_101));
suggestions.push((__binding_1, __code_102));
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("use `.addr()` to obtain the address of a pointer")),
&sub_args);
diag.multipart_suggestion_with_style(__message, suggestions,
rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowCode);
}
Ptr2IntSuggestion::NeedsCast {
cast_span: __binding_0, cast_to_ty: __binding_1 } => {
let __code_103 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!(".addr() as {0}",
__binding_1))
})].into_iter();
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("use `.addr()` to obtain the address of a pointer")),
&sub_args);
diag.span_suggestions_with_style(__binding_0, __message,
__code_103, rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowCode);
}
Ptr2IntSuggestion::Other { cast_span: __binding_0 } => {
let __code_104 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!(".addr()"))
})].into_iter();
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("use `.addr()` to obtain the address of a pointer")),
&sub_args);
diag.span_suggestions_with_style(__binding_0, __message,
__code_104, rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowCode);
}
}
}
}
};Subdiagnostic)]
3098pub(crate) enum Ptr2IntSuggestion<'tcx> {
3099 #[multipart_suggestion(
3100 "use `.addr()` to obtain the address of a pointer",
3101 applicability = "maybe-incorrect"
3102 )]
3103 NeedsParensCast {
3104 #[suggestion_part(code = "(")]
3105 expr_span: Span,
3106 #[suggestion_part(code = ").addr() as {cast_to_ty}")]
3107 cast_span: Span,
3108 cast_to_ty: Ty<'tcx>,
3109 },
3110 #[multipart_suggestion(
3111 "use `.addr()` to obtain the address of a pointer",
3112 applicability = "maybe-incorrect"
3113 )]
3114 NeedsParens {
3115 #[suggestion_part(code = "(")]
3116 expr_span: Span,
3117 #[suggestion_part(code = ").addr()")]
3118 cast_span: Span,
3119 },
3120 #[suggestion(
3121 "use `.addr()` to obtain the address of a pointer",
3122 code = ".addr() as {cast_to_ty}",
3123 applicability = "maybe-incorrect"
3124 )]
3125 NeedsCast {
3126 #[primary_span]
3127 cast_span: Span,
3128 cast_to_ty: Ty<'tcx>,
3129 },
3130 #[suggestion(
3131 "use `.addr()` to obtain the address of a pointer",
3132 code = ".addr()",
3133 applicability = "maybe-incorrect"
3134 )]
3135 Other {
3136 #[primary_span]
3137 cast_span: Span,
3138 },
3139}
3140
3141#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
RawBorrowViaReference<'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 {
RawBorrowViaReference { suggestion: __binding_0 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("creating an intermediate reference implies aliasing requirements even when immediately cast to a raw pointers")));
;
diag.subdiagnostic(__binding_0);
diag
}
}
}
}
};Diagnostic)]
3142#[diag(
3143 "creating an intermediate reference implies aliasing requirements even when immediately cast to a raw pointers"
3144)]
3145pub(crate) struct RawBorrowViaReference<'a> {
3146 #[subdiagnostic]
3147 pub suggestion: RawBorrowViaReferenceSuggestion<'a>,
3148}
3149
3150#[derive(const _: () =
{
impl<'a> rustc_errors::Subdiagnostic for
RawBorrowViaReferenceSuggestion<'a> {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
RawBorrowViaReferenceSuggestion::Spanful {
left: __binding_0, right: __binding_1, mutbl: __binding_2 }
=> {
let mut suggestions = Vec::new();
let __code_105 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("&raw {0} ", __binding_2))
});
let __code_106 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!(""))
});
suggestions.push((__binding_0, __code_105));
suggestions.push((__binding_1, __code_106));
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("mutbl".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_2,
&mut diag.long_ty_path));
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider using `&raw {$mutbl}` for a safer and more explicit raw pointer")),
&sub_args);
diag.multipart_suggestion_with_style(__message, suggestions,
rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::ShowCode);
}
RawBorrowViaReferenceSuggestion::Spanless {
mutbl: __binding_0 } => {
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("mutbl".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_0,
&mut diag.long_ty_path));
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider using `&raw {$mutbl}` for a safer and more explicit raw pointer")),
&sub_args);
diag.help(__message);
}
}
}
}
};Subdiagnostic)]
3151pub(crate) enum RawBorrowViaReferenceSuggestion<'a> {
3152 #[multipart_suggestion(
3153 "consider using `&raw {$mutbl}` for a safer and more explicit raw pointer",
3154 applicability = "machine-applicable"
3155 )]
3156 Spanful {
3157 #[suggestion_part(code = "&raw {mutbl} ")]
3158 left: Span,
3159 #[suggestion_part(code = "")]
3160 right: Span,
3161 mutbl: &'a str,
3162 },
3163 #[help("consider using `&raw {$mutbl}` for a safer and more explicit raw pointer")]
3164 Spanless { mutbl: &'a str },
3165}