1use std::borrow::Cow;
4
5use rustc_abi::ExternAbi;
6use rustc_ast::{AssignOpKind, Label};
7use rustc_errors::codes::*;
8use rustc_errors::{
9 Applicability, Diag, DiagArgValue, DiagCtxtHandle, DiagSymbolList, Diagnostic, IntoDiagArg,
10 Level, MultiSpan, Subdiagnostic, msg,
11};
12use rustc_hir as hir;
13use rustc_hir::ExprKind;
14use rustc_macros::{Diagnostic, Subdiagnostic};
15use rustc_middle::ty::Ty;
16use rustc_span::edition::{Edition, LATEST_STABLE_EDITION};
17use rustc_span::{Ident, Span, Spanned, Symbol};
18
19use crate::FnCtxt;
20
21#[derive(const _: () =
{
impl<'_sess> rustc_errors::Diagnostic<'_sess> for AsmConstPtrUnstable
{
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
match self {
AsmConstPtrUnstable { span: __binding_0 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("using pointers in asm `const` operand is experimental")));
;
diag.span(__binding_0);
diag
}
}
}
}
};Diagnostic)]
22#[diag("using pointers in asm `const` operand is experimental")]
23pub(crate) struct AsmConstPtrUnstable {
24 #[primary_span]
25 pub span: Span,
26}
27
28#[derive(const _: () =
{
impl<'_sess> rustc_errors::Diagnostic<'_sess> for
BaseExpressionDoubleDot {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
match self {
BaseExpressionDoubleDot {
span: __binding_0,
default_field_values_suggestion: __binding_1,
add_expr: __binding_2,
remove_dots: __binding_3 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("base expression required after `..`")));
let __code_0 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("#![feature(default_field_values)]\n"))
})].into_iter();
diag.code(E0797);
;
diag.span(__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 `#![feature(default_field_values)]` to the crate attributes to enable default values on `struct` fields")),
__code_0, rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::ShowAlways);
}
if let Some(__binding_2) = __binding_2 {
diag.subdiagnostic(__binding_2);
}
if let Some(__binding_3) = __binding_3 {
diag.subdiagnostic(__binding_3);
}
diag
}
}
}
}
};Diagnostic)]
29#[diag("base expression required after `..`", code = E0797)]
30pub(crate) struct BaseExpressionDoubleDot {
31 #[primary_span]
32 pub span: Span,
33 #[suggestion(
34 "add `#![feature(default_field_values)]` to the crate attributes to enable default values on `struct` fields",
35 code = "#![feature(default_field_values)]\n",
36 applicability = "machine-applicable",
37 style = "verbose"
38 )]
39 pub default_field_values_suggestion: Option<Span>,
40 #[subdiagnostic]
41 pub add_expr: Option<BaseExpressionDoubleDotAddExpr>,
42 #[subdiagnostic]
43 pub remove_dots: Option<BaseExpressionDoubleDotRemove>,
44}
45
46#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for BaseExpressionDoubleDotRemove {
fn add_to_diag(self, diag: &mut rustc_errors::Diag<'_>) {
match self {
BaseExpressionDoubleDotRemove { span: __binding_0 } => {
let __code_1 =
[::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("remove the `..` as all the fields are already present")),
&sub_args);
diag.span_suggestions_with_style(__binding_0, __message,
__code_1, rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::ShowAlways);
}
}
}
}
};Subdiagnostic)]
47#[suggestion(
48 "remove the `..` as all the fields are already present",
49 code = "",
50 applicability = "machine-applicable",
51 style = "verbose"
52)]
53pub(crate) struct BaseExpressionDoubleDotRemove {
54 #[primary_span]
55 pub span: Span,
56}
57
58#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for BaseExpressionDoubleDotAddExpr {
fn add_to_diag(self, diag: &mut rustc_errors::Diag<'_>) {
match self {
BaseExpressionDoubleDotAddExpr { span: __binding_0 } => {
let __code_2 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("/* expr */"))
})].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("add a base expression here")),
&sub_args);
diag.span_suggestions_with_style(__binding_0, __message,
__code_2, rustc_errors::Applicability::HasPlaceholders,
rustc_errors::SuggestionStyle::ShowAlways);
}
}
}
}
};Subdiagnostic)]
59#[suggestion(
60 "add a base expression here",
61 code = "/* expr */",
62 applicability = "has-placeholders",
63 style = "verbose"
64)]
65pub(crate) struct BaseExpressionDoubleDotAddExpr {
66 #[primary_span]
67 pub span: Span,
68}
69
70#[derive(const _: () =
{
impl<'_sess> rustc_errors::Diagnostic<'_sess> for
FieldMultiplySpecifiedInInitializer {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
match self {
FieldMultiplySpecifiedInInitializer {
span: __binding_0,
prev_span: __binding_1,
ident: __binding_2 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("field `{$ident}` specified more than once")));
diag.code(E0062);
;
diag.arg("ident", __binding_2);
diag.span(__binding_0);
diag.span_label(__binding_0,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("used more than once")));
diag.span_label(__binding_1,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("first use of `{$ident}`")));
diag
}
}
}
}
};Diagnostic)]
71#[diag("field `{$ident}` specified more than once", code = E0062)]
72pub(crate) struct FieldMultiplySpecifiedInInitializer {
73 #[primary_span]
74 #[label("used more than once")]
75 pub span: Span,
76 #[label("first use of `{$ident}`")]
77 pub prev_span: Span,
78 pub ident: Ident,
79}
80
81#[derive(const _: () =
{
impl<'_sess> rustc_errors::Diagnostic<'_sess> for
ReturnStmtOutsideOfFnBody {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
match self {
ReturnStmtOutsideOfFnBody {
span: __binding_0,
encl_body_span: __binding_1,
encl_fn_span: __binding_2,
statement_kind: __binding_3 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$statement_kind} statement outside of function body")));
diag.code(E0572);
;
diag.arg("statement_kind", __binding_3);
diag.span(__binding_0);
if let Some(__binding_1) = __binding_1 {
diag.span_label(__binding_1,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the {$statement_kind} is part of this body...")));
}
if let Some(__binding_2) = __binding_2 {
diag.span_label(__binding_2,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("...not the enclosing function body")));
}
diag
}
}
}
}
};Diagnostic)]
82#[diag("{$statement_kind} statement outside of function body", code = E0572)]
83pub(crate) struct ReturnStmtOutsideOfFnBody {
84 #[primary_span]
85 pub span: Span,
86 #[label("the {$statement_kind} is part of this body...")]
87 pub encl_body_span: Option<Span>,
88 #[label("...not the enclosing function body")]
89 pub encl_fn_span: Option<Span>,
90 pub statement_kind: ReturnLikeStatementKind,
91}
92
93pub(crate) enum ReturnLikeStatementKind {
94 Return,
95 Become,
96}
97
98impl IntoDiagArg for ReturnLikeStatementKind {
99 fn into_diag_arg(self, _: &mut Option<std::path::PathBuf>) -> DiagArgValue {
100 let kind = match self {
101 Self::Return => "return",
102 Self::Become => "become",
103 }
104 .into();
105
106 DiagArgValue::Str(kind)
107 }
108}
109
110#[derive(const _: () =
{
impl<'_sess> rustc_errors::Diagnostic<'_sess> for
RustCallIncorrectArgs {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
match self {
RustCallIncorrectArgs { span: __binding_0 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("functions with the \"rust-call\" ABI must take a single non-self tuple argument")));
;
diag.span(__binding_0);
diag
}
}
}
}
};Diagnostic)]
112#[diag("functions with the \"rust-call\" ABI must take a single non-self tuple argument")]
113pub(crate) struct RustCallIncorrectArgs {
114 #[primary_span]
115 pub span: Span,
116}
117
118#[derive(const _: () =
{
impl<'_sess> rustc_errors::Diagnostic<'_sess> for
YieldExprOutsideOfCoroutine {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
match self {
YieldExprOutsideOfCoroutine { span: __binding_0 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("yield expression outside of coroutine literal")));
diag.code(E0627);
;
diag.span(__binding_0);
diag
}
}
}
}
};Diagnostic)]
119#[diag("yield expression outside of coroutine literal", code = E0627)]
120pub(crate) struct YieldExprOutsideOfCoroutine {
121 #[primary_span]
122 pub span: Span,
123}
124
125#[derive(const _: () =
{
impl<'_sess> rustc_errors::Diagnostic<'_sess> for
StructExprNonExhaustive {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
match self {
StructExprNonExhaustive {
span: __binding_0, what: __binding_1 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("cannot create non-exhaustive {$what} using struct expression")));
diag.code(E0639);
;
diag.arg("what", __binding_1);
diag.span(__binding_0);
diag
}
}
}
}
};Diagnostic)]
126#[diag("cannot create non-exhaustive {$what} using struct expression", code = E0639)]
127pub(crate) struct StructExprNonExhaustive {
128 #[primary_span]
129 pub span: Span,
130 pub what: &'static str,
131}
132
133#[derive(const _: () =
{
impl<'_sess> rustc_errors::Diagnostic<'_sess> for
FunctionalRecordUpdateOnNonStruct {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
match self {
FunctionalRecordUpdateOnNonStruct { span: __binding_0 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("functional record update syntax requires a struct")));
diag.code(E0436);
;
diag.span(__binding_0);
diag
}
}
}
}
};Diagnostic)]
134#[diag("functional record update syntax requires a struct", code = E0436)]
135pub(crate) struct FunctionalRecordUpdateOnNonStruct {
136 #[primary_span]
137 pub span: Span,
138}
139
140#[derive(const _: () =
{
impl<'_sess> rustc_errors::Diagnostic<'_sess> for
AddressOfTemporaryTaken {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
match self {
AddressOfTemporaryTaken { span: __binding_0 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("cannot take address of a temporary")));
diag.code(E0745);
;
diag.span(__binding_0);
diag.span_label(__binding_0,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("temporary value")));
diag
}
}
}
}
};Diagnostic)]
141#[diag("cannot take address of a temporary", code = E0745)]
142pub(crate) struct AddressOfTemporaryTaken {
143 #[primary_span]
144 #[label("temporary value")]
145 pub span: Span,
146}
147
148#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for AddReturnTypeSuggestion {
fn add_to_diag(self, diag: &mut rustc_errors::Diag<'_>) {
match self {
AddReturnTypeSuggestion::Add {
span: __binding_0, found: __binding_1 } => {
let __code_3 =
[::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("try adding a return type")),
&sub_args);
diag.span_suggestions_with_style(__binding_0, __message,
__code_3, rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::ShowCode);
}
AddReturnTypeSuggestion::MissingHere { span: __binding_0 }
=> {
let __code_4 =
[::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("a return type might be missing here")),
&sub_args);
diag.span_suggestions_with_style(__binding_0, __message,
__code_4, rustc_errors::Applicability::HasPlaceholders,
rustc_errors::SuggestionStyle::ShowCode);
}
}
}
}
};Subdiagnostic)]
149pub(crate) enum AddReturnTypeSuggestion {
150 #[suggestion(
151 "try adding a return type",
152 code = " -> {found}",
153 applicability = "machine-applicable"
154 )]
155 Add {
156 #[primary_span]
157 span: Span,
158 found: String,
159 },
160 #[suggestion(
161 "a return type might be missing here",
162 code = " -> _",
163 applicability = "has-placeholders"
164 )]
165 MissingHere {
166 #[primary_span]
167 span: Span,
168 },
169}
170
171#[derive(const _: () =
{
impl<'tcx> rustc_errors::Subdiagnostic for
ExpectedReturnTypeLabel<'tcx> {
fn add_to_diag(self, diag: &mut rustc_errors::Diag<'_>) {
match self {
ExpectedReturnTypeLabel::Unit { 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("expected `()` because of default return type")),
&sub_args);
diag.span_label(__binding_0, __message);
}
ExpectedReturnTypeLabel::Other {
span: __binding_0, expected: __binding_1 } => {
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("expected".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("expected `{$expected}` because of return type")),
&sub_args);
diag.span_label(__binding_0, __message);
}
ExpectedReturnTypeLabel::ImplTrait {
span: __binding_0, trait_name: __binding_1 } => {
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("trait_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("expected a single type implementing `{$trait_name}` because of return type")),
&sub_args);
diag.span_label(__binding_0, __message);
}
}
}
}
};Subdiagnostic)]
172pub(crate) enum ExpectedReturnTypeLabel<'tcx> {
173 #[label("expected `()` because of default return type")]
174 Unit {
175 #[primary_span]
176 span: Span,
177 },
178 #[label("expected `{$expected}` because of return type")]
179 Other {
180 #[primary_span]
181 span: Span,
182 expected: Ty<'tcx>,
183 },
184 #[label("expected a single type implementing `{$trait_name}` because of return type")]
185 ImplTrait {
186 #[primary_span]
187 span: Span,
188 trait_name: String,
189 },
190}
191
192#[derive(const _: () =
{
impl<'_sess> rustc_errors::Diagnostic<'_sess> for
ExplicitDestructorCall {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
match self {
ExplicitDestructorCall {
span: __binding_0, sugg: __binding_1 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("explicit use of destructor method")));
diag.code(E0040);
;
diag.span(__binding_0);
diag.span_label(__binding_0,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("explicit destructor calls not allowed")));
diag.subdiagnostic(__binding_1);
diag
}
}
}
}
};Diagnostic)]
193#[diag("explicit use of destructor method", code = E0040)]
194pub(crate) struct ExplicitDestructorCall {
195 #[primary_span]
196 #[label("explicit destructor calls not allowed")]
197 pub span: Span,
198 #[subdiagnostic]
199 pub sugg: ExplicitDestructorCallSugg,
200}
201
202#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for ExplicitDestructorCallSugg {
fn add_to_diag(self, diag: &mut rustc_errors::Diag<'_>) {
match self {
ExplicitDestructorCallSugg::Empty(__binding_0) => {
let __code_5 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("drop"))
})].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 using `drop` function")),
&sub_args);
diag.span_suggestions_with_style(__binding_0, __message,
__code_5, rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowCode);
}
ExplicitDestructorCallSugg::Snippet {
lo: __binding_0, hi: __binding_1 } => {
let mut suggestions = Vec::new();
let __code_6 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("drop("))
});
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("consider using `drop` function")),
&sub_args);
diag.multipart_suggestion_with_style(__message, suggestions,
rustc_errors::Applicability::Unspecified,
rustc_errors::SuggestionStyle::HideCodeInline);
}
}
}
}
};Subdiagnostic)]
203pub(crate) enum ExplicitDestructorCallSugg {
204 #[suggestion(
205 "consider using `drop` function",
206 code = "drop",
207 applicability = "maybe-incorrect"
208 )]
209 Empty(#[primary_span] Span),
210 #[multipart_suggestion("consider using `drop` function", style = "short")]
211 Snippet {
212 #[suggestion_part(code = "drop(")]
213 lo: Span,
214 #[suggestion_part(code = ")")]
215 hi: Span,
216 },
217}
218
219#[derive(const _: () =
{
impl<'_sess, 'tcx> rustc_errors::Diagnostic<'_sess> for
MissingParenthesesInRange<'tcx> {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
match self {
MissingParenthesesInRange {
span: __binding_0,
ty: __binding_1,
method_name: __binding_2,
add_missing_parentheses: __binding_3 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("can't call method `{$method_name}` on type `{$ty}`")));
diag.code(E0689);
;
diag.arg("ty", __binding_1);
diag.arg("method_name", __binding_2);
diag.span(__binding_0);
diag.span_label(__binding_0,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("can't call method `{$method_name}` on type `{$ty}`")));
if let Some(__binding_3) = __binding_3 {
diag.subdiagnostic(__binding_3);
}
diag
}
}
}
}
};Diagnostic)]
220#[diag("can't call method `{$method_name}` on type `{$ty}`", code = E0689)]
221pub(crate) struct MissingParenthesesInRange<'tcx> {
222 #[primary_span]
223 #[label("can't call method `{$method_name}` on type `{$ty}`")]
224 pub span: Span,
225 pub ty: Ty<'tcx>,
226 pub method_name: String,
227 #[subdiagnostic]
228 pub add_missing_parentheses: Option<AddMissingParenthesesInRange>,
229}
230
231#[derive(const _: () =
{
impl<'_sess> rustc_errors::Diagnostic<'_sess> for
NeverTypeFallbackFlowingIntoUnsafe {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
match self {
NeverTypeFallbackFlowingIntoUnsafe::Call { sugg: __binding_0
} => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("never type fallback affects this call to an `unsafe` function")));
diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("specify the type explicitly")));
;
diag.subdiagnostic(__binding_0);
diag
}
NeverTypeFallbackFlowingIntoUnsafe::Method {
sugg: __binding_0 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("never type fallback affects this call to an `unsafe` method")));
diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("specify the type explicitly")));
;
diag.subdiagnostic(__binding_0);
diag
}
NeverTypeFallbackFlowingIntoUnsafe::Path { sugg: __binding_0
} => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("never type fallback affects this `unsafe` function")));
diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("specify the type explicitly")));
;
diag.subdiagnostic(__binding_0);
diag
}
NeverTypeFallbackFlowingIntoUnsafe::UnionField {
sugg: __binding_0 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("never type fallback affects this union access")));
diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("specify the type explicitly")));
;
diag.subdiagnostic(__binding_0);
diag
}
NeverTypeFallbackFlowingIntoUnsafe::Deref {
sugg: __binding_0 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("never type fallback affects this raw pointer dereference")));
diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("specify the type explicitly")));
;
diag.subdiagnostic(__binding_0);
diag
}
}
}
}
};Diagnostic)]
232pub(crate) enum NeverTypeFallbackFlowingIntoUnsafe {
233 #[help("specify the type explicitly")]
234 #[diag("never type fallback affects this call to an `unsafe` function")]
235 Call {
236 #[subdiagnostic]
237 sugg: SuggestAnnotations,
238 },
239 #[help("specify the type explicitly")]
240 #[diag("never type fallback affects this call to an `unsafe` method")]
241 Method {
242 #[subdiagnostic]
243 sugg: SuggestAnnotations,
244 },
245 #[help("specify the type explicitly")]
246 #[diag("never type fallback affects this `unsafe` function")]
247 Path {
248 #[subdiagnostic]
249 sugg: SuggestAnnotations,
250 },
251 #[help("specify the type explicitly")]
252 #[diag("never type fallback affects this union access")]
253 UnionField {
254 #[subdiagnostic]
255 sugg: SuggestAnnotations,
256 },
257 #[help("specify the type explicitly")]
258 #[diag("never type fallback affects this raw pointer dereference")]
259 Deref {
260 #[subdiagnostic]
261 sugg: SuggestAnnotations,
262 },
263}
264
265#[derive(#[automatically_derived]
impl ::core::clone::Clone for SuggestAnnotation {
#[inline]
fn clone(&self) -> Self {
match self {
Self::Unit(__self_0) =>
Self::Unit(::core::clone::Clone::clone(__self_0)),
Self::Path(__self_0) =>
Self::Path(::core::clone::Clone::clone(__self_0)),
Self::Local(__self_0) =>
Self::Local(::core::clone::Clone::clone(__self_0)),
Self::Turbo(__self_0, __self_1, __self_2) =>
Self::Turbo(::core::clone::Clone::clone(__self_0),
::core::clone::Clone::clone(__self_1),
::core::clone::Clone::clone(__self_2)),
}
}
}Clone)]
266pub(crate) enum SuggestAnnotation {
267 Unit(Span),
268 Path(Span),
269 Local(Span),
270 Turbo(Span, usize, usize),
271}
272
273#[derive(#[automatically_derived]
impl ::core::clone::Clone for SuggestAnnotations {
#[inline]
fn clone(&self) -> Self {
Self { suggestions: ::core::clone::Clone::clone(&self.suggestions) }
}
}Clone)]
274pub(crate) struct SuggestAnnotations {
275 pub suggestions: Vec<SuggestAnnotation>,
276}
277impl Subdiagnostic for SuggestAnnotations {
278 fn add_to_diag(self, diag: &mut Diag<'_>) {
279 if self.suggestions.is_empty() {
280 return;
281 }
282
283 let mut suggestions = ::alloc::vec::Vec::new()vec![];
284 for suggestion in self.suggestions {
285 match suggestion {
286 SuggestAnnotation::Unit(span) => {
287 suggestions.push((span, "()".to_string()));
288 }
289 SuggestAnnotation::Path(span) => {
290 suggestions.push((span.shrink_to_lo(), "<() as ".to_string()));
291 suggestions.push((span.shrink_to_hi(), ">".to_string()));
292 }
293 SuggestAnnotation::Local(span) => {
294 suggestions.push((span, ": ()".to_string()));
295 }
296 SuggestAnnotation::Turbo(span, n_args, idx) => suggestions.push((
297 span,
298 ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("::<{0}>",
(0..n_args).map(|i|
if i == idx {
"()"
} else { "_" }).collect::<Vec<_>>().join(", ")))
})format!(
299 "::<{}>",
300 (0..n_args)
301 .map(|i| if i == idx { "()" } else { "_" })
302 .collect::<Vec<_>>()
303 .join(", "),
304 ),
305 )),
306 }
307 }
308
309 diag.multipart_suggestion(
310 "use `()` annotations to avoid fallback changes",
311 suggestions,
312 Applicability::MachineApplicable,
313 );
314 }
315}
316
317#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for AddMissingParenthesesInRange {
fn add_to_diag(self, diag: &mut rustc_errors::Diag<'_>) {
match self {
AddMissingParenthesesInRange {
func_name: __binding_0,
left: __binding_1,
right: __binding_2 } => {
let mut suggestions = Vec::new();
let __code_8 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("("))
});
let __code_9 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!(")"))
});
suggestions.push((__binding_1, __code_8));
suggestions.push((__binding_2, __code_9));
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("func_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("you must surround the range in parentheses to call its `{$func_name}` function")),
&sub_args);
diag.multipart_suggestion_with_style(__message, suggestions,
rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowAlways);
}
}
}
}
};Subdiagnostic)]
318#[multipart_suggestion(
319 "you must surround the range in parentheses to call its `{$func_name}` function",
320 style = "verbose",
321 applicability = "maybe-incorrect"
322)]
323pub(crate) struct AddMissingParenthesesInRange {
324 pub func_name: String,
325 #[suggestion_part(code = "(")]
326 pub left: Span,
327 #[suggestion_part(code = ")")]
328 pub right: Span,
329}
330
331pub(crate) struct TypeMismatchFruTypo {
332 pub expr_span: Span,
334 pub fru_span: Span,
336 pub expr: Option<String>,
338}
339
340impl Subdiagnostic for TypeMismatchFruTypo {
341 fn add_to_diag(self, diag: &mut Diag<'_>) {
342 diag.arg("expr", self.expr.as_deref().unwrap_or("NONE"));
343
344 if self.expr_span.between(self.fru_span).is_empty() {
346 diag.span_note(
347 self.expr_span.to(self.fru_span),
348 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this expression may have been misinterpreted as a `..` range expression"))msg!("this expression may have been misinterpreted as a `..` range expression"),
349 );
350 } else {
351 let mut multispan: MultiSpan = ::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
[self.expr_span, self.fru_span]))vec![self.expr_span, self.fru_span].into();
352 multispan.push_span_label(
353 self.expr_span,
354 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this expression does not end in a comma..."))msg!("this expression does not end in a comma..."),
355 );
356 multispan.push_span_label(self.fru_span, rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("... so this is interpreted as a `..` range expression, instead of functional record update syntax"))msg!("... so this is interpreted as a `..` range expression, instead of functional record update syntax"));
357 diag.span_note(
358 multispan,
359 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this expression may have been misinterpreted as a `..` range expression"))msg!("this expression may have been misinterpreted as a `..` range expression"),
360 );
361 }
362
363 diag.span_suggestion_verbose(
364 self.expr_span.shrink_to_hi(),
365 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("to set the remaining fields{$expr ->\n [NONE]{\"\"}\n *[other] {\" \"}from `{$expr}`\n }, separate the last named field with a comma"))msg!(
366 "to set the remaining fields{$expr ->
367 [NONE]{\"\"}
368 *[other] {\" \"}from `{$expr}`
369 }, separate the last named field with a comma"
370 ),
371 ", ",
372 Applicability::MaybeIncorrect,
373 );
374 }
375}
376
377#[derive(const _: () =
{
impl<'_sess> rustc_errors::Diagnostic<'_sess> for
PtrCastAddAutoToObject {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
match self {
PtrCastAddAutoToObject {
span: __binding_0,
traits_len: __binding_1,
traits: __binding_2 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("cannot add {$traits_len ->\n [1] auto trait {$traits}\n *[other] auto traits {$traits}\n} to dyn bound via pointer cast")));
diag.code(E0804);
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this could allow UB elsewhere")));
diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("use `transmute` if you're sure this is sound")));
;
diag.arg("traits_len", __binding_1);
diag.arg("traits", __binding_2);
diag.span(__binding_0);
diag.span_label(__binding_0,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("unsupported cast")));
diag
}
}
}
}
};Diagnostic)]
378#[diag("cannot add {$traits_len ->
379 [1] auto trait {$traits}
380 *[other] auto traits {$traits}
381} to dyn bound via pointer cast", code = E0804)]
382#[note("this could allow UB elsewhere")]
383#[help("use `transmute` if you're sure this is sound")]
384pub(crate) struct PtrCastAddAutoToObject {
385 #[primary_span]
386 #[label("unsupported cast")]
387 pub span: Span,
388 pub traits_len: usize,
389 pub traits: DiagSymbolList<String>,
390}
391
392#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for HelpUseLatestEdition {
fn add_to_diag(self, diag: &mut rustc_errors::Diag<'_>) {
match self {
HelpUseLatestEdition::Cargo { edition: __binding_0 } => {
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("edition".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("set `edition = \"{$edition}\"` in `Cargo.toml`")),
&sub_args);
diag.help(__message);
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("for more on editions, read https://doc.rust-lang.org/edition-guide")),
&sub_args);
diag.note(__message);
}
HelpUseLatestEdition::Standalone { edition: __binding_0 } =>
{
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("edition".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("pass `--edition {$edition}` to `rustc`")),
&sub_args);
diag.help(__message);
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("for more on editions, read https://doc.rust-lang.org/edition-guide")),
&sub_args);
diag.note(__message);
}
}
}
}
};Subdiagnostic)]
393pub(crate) enum HelpUseLatestEdition {
394 #[help("set `edition = \"{$edition}\"` in `Cargo.toml`")]
395 #[note("for more on editions, read https://doc.rust-lang.org/edition-guide")]
396 Cargo { edition: Edition },
397 #[help("pass `--edition {$edition}` to `rustc`")]
398 #[note("for more on editions, read https://doc.rust-lang.org/edition-guide")]
399 Standalone { edition: Edition },
400}
401
402impl HelpUseLatestEdition {
403 pub(crate) fn new() -> Self {
404 let edition = LATEST_STABLE_EDITION;
405 if rustc_session::utils::was_invoked_from_cargo() {
406 Self::Cargo { edition }
407 } else {
408 Self::Standalone { edition }
409 }
410 }
411}
412
413#[derive(const _: () =
{
impl<'_sess, 'tcx> rustc_errors::Diagnostic<'_sess> for
NoFieldOnVariant<'tcx> {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
match self {
NoFieldOnVariant {
span: __binding_0,
container: __binding_1,
ident: __binding_2,
field: __binding_3,
enum_span: __binding_4,
field_span: __binding_5 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("no field named `{$field}` on enum variant `{$container}::{$ident}`")));
diag.code(E0609);
;
diag.arg("container", __binding_1);
diag.arg("ident", __binding_2);
diag.arg("field", __binding_3);
diag.span(__binding_0);
diag.span_label(__binding_4,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this enum variant...")));
diag.span_label(__binding_5,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("...does not have this field")));
diag
}
}
}
}
};Diagnostic)]
414#[diag("no field named `{$field}` on enum variant `{$container}::{$ident}`", code = E0609)]
415pub(crate) struct NoFieldOnVariant<'tcx> {
416 #[primary_span]
417 pub(crate) span: Span,
418 pub(crate) container: Ty<'tcx>,
419 pub(crate) ident: Ident,
420 pub(crate) field: Ident,
421 #[label("this enum variant...")]
422 pub(crate) enum_span: Span,
423 #[label("...does not have this field")]
424 pub(crate) field_span: Span,
425}
426
427#[derive(const _: () =
{
impl<'_sess, 'tcx> rustc_errors::Diagnostic<'_sess> for
CantDereference<'tcx> {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
match self {
CantDereference { span: __binding_0, ty: __binding_1 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("type `{$ty}` cannot be dereferenced")));
diag.code(E0614);
;
diag.arg("ty", __binding_1);
diag.span(__binding_0);
diag.span_label(__binding_0,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("can't be dereferenced")));
diag
}
}
}
}
};Diagnostic)]
428#[diag("type `{$ty}` cannot be dereferenced", code = E0614)]
429pub(crate) struct CantDereference<'tcx> {
430 #[primary_span]
431 #[label("can't be dereferenced")]
432 pub(crate) span: Span,
433 pub(crate) ty: Ty<'tcx>,
434}
435
436#[derive(const _: () =
{
impl<'_sess, 'tcx> rustc_errors::Diagnostic<'_sess> for
ExpectedArrayOrSlice<'tcx> {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
match self {
ExpectedArrayOrSlice {
span: __binding_0,
ty: __binding_1,
slice_pat_semantics: __binding_2,
as_deref: __binding_3,
slicing: __binding_4 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("expected an array or slice, found `{$ty}`")));
diag.code(E0529);
;
diag.arg("ty", __binding_1);
diag.span(__binding_0);
diag.span_label(__binding_0,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("pattern cannot match with input type `{$ty}`")));
if let Some(__binding_3) = __binding_3 {
diag.subdiagnostic(__binding_3);
}
if let Some(__binding_4) = __binding_4 {
diag.subdiagnostic(__binding_4);
}
diag
}
}
}
}
};Diagnostic)]
437#[diag("expected an array or slice, found `{$ty}`", code = E0529)]
438pub(crate) struct ExpectedArrayOrSlice<'tcx> {
439 #[primary_span]
440 #[label("pattern cannot match with input type `{$ty}`")]
441 pub(crate) span: Span,
442 pub(crate) ty: Ty<'tcx>,
443 pub(crate) slice_pat_semantics: bool,
444 #[subdiagnostic]
445 pub(crate) as_deref: Option<AsDerefSuggestion>,
446 #[subdiagnostic]
447 pub(crate) slicing: Option<SlicingSuggestion>,
448}
449
450#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for AsDerefSuggestion {
fn add_to_diag(self, diag: &mut rustc_errors::Diag<'_>) {
match self {
AsDerefSuggestion { span: __binding_0 } => {
let __code_10 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!(".as_deref()"))
})].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 using `as_deref` here")),
&sub_args);
diag.span_suggestions_with_style(__binding_0, __message,
__code_10, rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowAlways);
}
}
}
}
};Subdiagnostic)]
451#[suggestion(
452 "consider using `as_deref` here",
453 code = ".as_deref()",
454 style = "verbose",
455 applicability = "maybe-incorrect"
456)]
457pub(crate) struct AsDerefSuggestion {
458 #[primary_span]
459 pub(crate) span: Span,
460}
461
462#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for SlicingSuggestion {
fn add_to_diag(self, diag: &mut rustc_errors::Diag<'_>) {
match self {
SlicingSuggestion { span: __binding_0 } => {
let __code_11 =
[::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 slicing here")),
&sub_args);
diag.span_suggestions_with_style(__binding_0, __message,
__code_11, rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowAlways);
}
}
}
}
};Subdiagnostic)]
463#[suggestion(
464 "consider slicing here",
465 code = "[..]",
466 style = "verbose",
467 applicability = "maybe-incorrect"
468)]
469pub(crate) struct SlicingSuggestion {
470 #[primary_span]
471 pub(crate) span: Span,
472}
473
474#[derive(const _: () =
{
impl<'_sess> rustc_errors::Diagnostic<'_sess> for InvalidCallee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
match self {
InvalidCallee { span: __binding_0, found: __binding_1 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("expected function, found {$found}")));
diag.code(E0618);
;
diag.arg("found", __binding_1);
diag.span(__binding_0);
diag
}
}
}
}
};Diagnostic)]
475#[diag("expected function, found {$found}", code = E0618)]
476pub(crate) struct InvalidCallee {
477 #[primary_span]
478 pub span: Span,
479 pub found: String,
480}
481
482#[derive(const _: () =
{
impl<'_sess, 'tcx> rustc_errors::Diagnostic<'_sess> for
ScalableVectorCtor<'tcx> {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
match self {
ScalableVectorCtor { span: __binding_0, ty: __binding_1 } =>
{
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("scalable vector types cannot be initialised using their constructor")));
;
diag.span(__binding_0);
diag
}
}
}
}
};Diagnostic)]
483#[diag("scalable vector types cannot be initialised using their constructor")]
484pub(crate) struct ScalableVectorCtor<'tcx> {
485 #[primary_span]
486 pub span: Span,
487 pub ty: Ty<'tcx>,
488}
489
490#[derive(const _: () =
{
impl<'_sess, 'tcx> rustc_errors::Diagnostic<'_sess> for
IntToWide<'tcx> {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
match self {
IntToWide {
span: __binding_0,
metadata: __binding_1,
expr_ty: __binding_2,
cast_ty: __binding_3,
expr_if_nightly: __binding_4,
known_wide: __binding_5,
param_note: __binding_6 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("cannot cast `{$expr_ty}` to a pointer that {$known_wide ->\n [true] is\n *[false] may be\n} wide")));
diag.code(E0606);
;
diag.arg("metadata", __binding_1);
diag.arg("expr_ty", __binding_2);
diag.arg("cast_ty", __binding_3);
diag.arg("known_wide", __binding_5);
diag.span(__binding_0);
diag.span_label(__binding_0,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("creating a `{$cast_ty}` requires both an address and {$metadata}")));
if let Some(__binding_4) = __binding_4 {
diag.span_label(__binding_4,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider casting this expression to `*const ()`, then using `core::ptr::from_raw_parts`")));
}
if let Some(__binding_6) = __binding_6 {
diag.subdiagnostic(__binding_6);
}
diag
}
}
}
}
};Diagnostic)]
491#[diag("cannot cast `{$expr_ty}` to a pointer that {$known_wide ->
492 [true] is
493 *[false] may be
494} wide", code = E0606)]
495pub(crate) struct IntToWide<'tcx> {
496 #[primary_span]
497 #[label("creating a `{$cast_ty}` requires both an address and {$metadata}")]
498 pub span: Span,
499 pub metadata: &'tcx str,
500 pub expr_ty: Ty<'tcx>,
501 pub cast_ty: Ty<'tcx>,
502 #[label(
503 "consider casting this expression to `*const ()`, then using `core::ptr::from_raw_parts`"
504 )]
505 pub expr_if_nightly: Option<Span>,
506 pub known_wide: bool,
507 #[subdiagnostic]
508 pub param_note: Option<IntToWideParamNote>,
509}
510
511#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for IntToWideParamNote {
fn add_to_diag(self, diag: &mut rustc_errors::Diag<'_>) {
match self {
IntToWideParamNote { param: __binding_0 } => {
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("param".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("the type parameter `{$param}` is not known to be `Sized`, so this pointer may be wide")),
&sub_args);
diag.note(__message);
}
}
}
}
};Subdiagnostic)]
512#[note("the type parameter `{$param}` is not known to be `Sized`, so this pointer may be wide")]
513pub(crate) struct IntToWideParamNote {
514 pub param: Symbol,
515}
516
517#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for OptionResultRefMismatch {
fn add_to_diag(self, diag: &mut rustc_errors::Diag<'_>) {
match self {
OptionResultRefMismatch::Copied {
span: __binding_0, def_path: __binding_1 } => {
let __code_12 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!(".copied()"))
})].into_iter();
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("def_path".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 `{$def_path}::copied` to copy the value inside the `{$def_path}`")),
&sub_args);
diag.span_suggestions_with_style(__binding_0, __message,
__code_12, rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::ShowAlways);
}
OptionResultRefMismatch::Cloned {
span: __binding_0, def_path: __binding_1 } => {
let __code_13 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!(".cloned()"))
})].into_iter();
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("def_path".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 `{$def_path}::cloned` to clone the value inside the `{$def_path}`")),
&sub_args);
diag.span_suggestions_with_style(__binding_0, __message,
__code_13, rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::ShowAlways);
}
}
}
}
};Subdiagnostic)]
518pub(crate) enum OptionResultRefMismatch {
519 #[suggestion(
520 "use `{$def_path}::copied` to copy the value inside the `{$def_path}`",
521 code = ".copied()",
522 style = "verbose",
523 applicability = "machine-applicable"
524 )]
525 Copied {
526 #[primary_span]
527 span: Span,
528 def_path: String,
529 },
530 #[suggestion(
531 "use `{$def_path}::cloned` to clone the value inside the `{$def_path}`",
532 code = ".cloned()",
533 style = "verbose",
534 applicability = "machine-applicable"
535 )]
536 Cloned {
537 #[primary_span]
538 span: Span,
539 def_path: String,
540 },
541 }
556
557pub(crate) struct RemoveSemiForCoerce {
558 pub expr: Span,
559 pub ret: Span,
560 pub semi: Span,
561}
562
563impl Subdiagnostic for RemoveSemiForCoerce {
564 fn add_to_diag(self, diag: &mut Diag<'_>) {
565 let mut multispan: MultiSpan = self.semi.into();
566 multispan.push_span_label(
567 self.expr,
568 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this could be implicitly returned but it is a statement, not a tail expression"))msg!("this could be implicitly returned but it is a statement, not a tail expression"),
569 );
570 multispan
571 .push_span_label(self.ret, rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the `match` arms can conform to this return type"))msg!("the `match` arms can conform to this return type"));
572 multispan.push_span_label(
573 self.semi,
574 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the `match` is a statement because of this semicolon, consider removing it"))msg!("the `match` is a statement because of this semicolon, consider removing it"),
575 );
576 diag.span_note(multispan, rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("you might have meant to return the `match` expression"))msg!("you might have meant to return the `match` expression"));
577
578 diag.tool_only_span_suggestion(
579 self.semi,
580 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("remove this semicolon"))msg!("remove this semicolon"),
581 "",
582 Applicability::MaybeIncorrect,
583 );
584 }
585}
586
587#[derive(const _: () =
{
impl<'_sess> rustc_errors::Diagnostic<'_sess> for
NonConstPathInPattern {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
match self {
NonConstPathInPattern { spans: __binding_0 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("runtime values cannot be referenced in patterns")));
diag.code(E0080);
;
diag.span(__binding_0.clone());
for __binding_0 in __binding_0 {
diag.span_label(__binding_0,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("references a runtime value")));
}
diag
}
}
}
}
};Diagnostic)]
588#[diag("runtime values cannot be referenced in patterns", code = E0080)]
589pub(crate) struct NonConstPathInPattern {
590 #[primary_span]
591 #[label("references a runtime value")]
592 pub spans: Vec<Span>,
593}
594
595#[derive(const _: () =
{
impl<'_sess> rustc_errors::Diagnostic<'_sess> for
UnionPatMultipleFields {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
match self {
UnionPatMultipleFields { span: __binding_0 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("union patterns should have exactly one field")));
;
diag.span(__binding_0);
diag
}
}
}
}
};Diagnostic)]
596#[diag("union patterns should have exactly one field")]
597pub(crate) struct UnionPatMultipleFields {
598 #[primary_span]
599 pub span: Span,
600}
601
602#[derive(const _: () =
{
impl<'_sess> rustc_errors::Diagnostic<'_sess> for UnionPatDotDot {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
match self {
UnionPatDotDot { span: __binding_0 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`..` cannot be used in union patterns")));
;
diag.span(__binding_0);
diag
}
}
}
}
};Diagnostic)]
603#[diag("`..` cannot be used in union patterns")]
604pub(crate) struct UnionPatDotDot {
605 #[primary_span]
606 pub span: Span,
607}
608
609#[derive(const _: () =
{
impl<'tcx> rustc_errors::Subdiagnostic for UseIsEmpty<'tcx> {
fn add_to_diag(self, diag: &mut rustc_errors::Diag<'_>) {
match self {
UseIsEmpty {
lo: __binding_0, hi: __binding_1, expr_ty: __binding_2 } =>
{
let mut suggestions = Vec::new();
let __code_14 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("!"))
});
let __code_15 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!(".is_empty()"))
});
suggestions.push((__binding_0, __code_14));
suggestions.push((__binding_1, __code_15));
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("expr_ty".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 the `is_empty` method on `{$expr_ty}` to determine if it contains anything")),
&sub_args);
diag.multipart_suggestion_with_style(__message, suggestions,
rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowAlways);
}
}
}
}
};Subdiagnostic)]
610#[multipart_suggestion(
611 "consider using the `is_empty` method on `{$expr_ty}` to determine if it contains anything",
612 applicability = "maybe-incorrect",
613 style = "verbose"
614)]
615pub(crate) struct UseIsEmpty<'tcx> {
616 #[suggestion_part(code = "!")]
617 pub lo: Span,
618 #[suggestion_part(code = ".is_empty()")]
619 pub hi: Span,
620 pub expr_ty: Ty<'tcx>,
621}
622
623#[derive(const _: () =
{
impl<'_sess> rustc_errors::Diagnostic<'_sess> for
ArgMismatchIndeterminate {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
match self {
ArgMismatchIndeterminate { span: __binding_0 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("argument type mismatch was detected, but rustc had trouble determining where")));
;
diag.span(__binding_0);
diag
}
}
}
}
};Diagnostic)]
624#[diag("argument type mismatch was detected, but rustc had trouble determining where")]
625pub(crate) struct ArgMismatchIndeterminate {
626 #[primary_span]
627 pub span: Span,
628}
629
630#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for SuggestBoxing {
fn add_to_diag(self, diag: &mut rustc_errors::Diag<'_>) {
match self {
SuggestBoxing::Unit { start: __binding_0, end: __binding_1 }
=> {
let mut suggestions = Vec::new();
let __code_16 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("Box::new(())"))
});
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("for more on the distinction between the stack and the heap, read https://doc.rust-lang.org/book/ch15-01-box.html, https://doc.rust-lang.org/rust-by-example/std/box.html, and https://doc.rust-lang.org/std/boxed/index.html")),
&sub_args);
diag.note(__message);
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("store this in the heap by calling `Box::new`")),
&sub_args);
diag.multipart_suggestion_with_style(__message, suggestions,
rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::ShowCode);
}
SuggestBoxing::AsyncBody => {
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("for more on the distinction between the stack and the heap, read https://doc.rust-lang.org/book/ch15-01-box.html, https://doc.rust-lang.org/rust-by-example/std/box.html, and https://doc.rust-lang.org/std/boxed/index.html")),
&sub_args);
diag.note(__message);
}
SuggestBoxing::ExprFieldShorthand {
start: __binding_0, end: __binding_1, ident: __binding_2 }
=> {
let mut suggestions = Vec::new();
let __code_18 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0}: Box::new(",
__binding_2))
});
let __code_19 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!(")"))
});
suggestions.push((__binding_0, __code_18));
suggestions.push((__binding_1, __code_19));
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("for more on the distinction between the stack and the heap, read https://doc.rust-lang.org/book/ch15-01-box.html, https://doc.rust-lang.org/rust-by-example/std/box.html, and https://doc.rust-lang.org/std/boxed/index.html")),
&sub_args);
diag.note(__message);
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("store this in the heap by calling `Box::new`")),
&sub_args);
diag.multipart_suggestion_with_style(__message, suggestions,
rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::ShowCode);
}
SuggestBoxing::Other { start: __binding_0, end: __binding_1
} => {
let mut suggestions = Vec::new();
let __code_20 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("Box::new("))
});
let __code_21 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!(")"))
});
suggestions.push((__binding_0, __code_20));
suggestions.push((__binding_1, __code_21));
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("for more on the distinction between the stack and the heap, read https://doc.rust-lang.org/book/ch15-01-box.html, https://doc.rust-lang.org/rust-by-example/std/box.html, and https://doc.rust-lang.org/std/boxed/index.html")),
&sub_args);
diag.note(__message);
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("store this in the heap by calling `Box::new`")),
&sub_args);
diag.multipart_suggestion_with_style(__message, suggestions,
rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::ShowCode);
}
}
}
}
};Subdiagnostic)]
631pub(crate) enum SuggestBoxing {
632 #[note(
633 "for more on the distinction between the stack and the heap, read https://doc.rust-lang.org/book/ch15-01-box.html, https://doc.rust-lang.org/rust-by-example/std/box.html, and https://doc.rust-lang.org/std/boxed/index.html"
634 )]
635 #[multipart_suggestion(
636 "store this in the heap by calling `Box::new`",
637 applicability = "machine-applicable"
638 )]
639 Unit {
640 #[suggestion_part(code = "Box::new(())")]
641 start: Span,
642 #[suggestion_part(code = "")]
643 end: Span,
644 },
645 #[note(
646 "for more on the distinction between the stack and the heap, read https://doc.rust-lang.org/book/ch15-01-box.html, https://doc.rust-lang.org/rust-by-example/std/box.html, and https://doc.rust-lang.org/std/boxed/index.html"
647 )]
648 AsyncBody,
649 #[note(
650 "for more on the distinction between the stack and the heap, read https://doc.rust-lang.org/book/ch15-01-box.html, https://doc.rust-lang.org/rust-by-example/std/box.html, and https://doc.rust-lang.org/std/boxed/index.html"
651 )]
652 #[multipart_suggestion(
653 "store this in the heap by calling `Box::new`",
654 applicability = "machine-applicable"
655 )]
656 ExprFieldShorthand {
657 #[suggestion_part(code = "{ident}: Box::new(")]
658 start: Span,
659 #[suggestion_part(code = ")")]
660 end: Span,
661 ident: Ident,
662 },
663 #[note(
664 "for more on the distinction between the stack and the heap, read https://doc.rust-lang.org/book/ch15-01-box.html, https://doc.rust-lang.org/rust-by-example/std/box.html, and https://doc.rust-lang.org/std/boxed/index.html"
665 )]
666 #[multipart_suggestion(
667 "store this in the heap by calling `Box::new`",
668 applicability = "machine-applicable"
669 )]
670 Other {
671 #[suggestion_part(code = "Box::new(")]
672 start: Span,
673 #[suggestion_part(code = ")")]
674 end: Span,
675 },
676}
677
678#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for SuggestPtrNullMut {
fn add_to_diag(self, diag: &mut rustc_errors::Diag<'_>) {
match self {
SuggestPtrNullMut { span: __binding_0 } => {
let __code_22 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("core::ptr::null_mut()"))
})].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 using `core::ptr::null_mut` instead")),
&sub_args);
diag.span_suggestions_with_style(__binding_0, __message,
__code_22, rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowAlways);
}
}
}
}
};Subdiagnostic)]
679#[suggestion(
680 "consider using `core::ptr::null_mut` instead",
681 applicability = "maybe-incorrect",
682 style = "verbose",
683 code = "core::ptr::null_mut()"
684)]
685pub(crate) struct SuggestPtrNullMut {
686 #[primary_span]
687 pub span: Span,
688}
689
690#[derive(const _: () =
{
impl<'_sess, 'tcx> rustc_errors::Diagnostic<'_sess> for
TrivialCast<'tcx> {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
match self {
TrivialCast {
numeric: __binding_0,
expr_ty: __binding_1,
cast_ty: __binding_2 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("trivial {$numeric ->\n [true] numeric cast\n *[false] cast\n }: `{$expr_ty}` as `{$cast_ty}`")));
diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("cast can be replaced by coercion; this might require a temporary variable")));
;
diag.arg("numeric", __binding_0);
diag.arg("expr_ty", __binding_1);
diag.arg("cast_ty", __binding_2);
diag
}
}
}
}
};Diagnostic)]
691#[diag(
692 "trivial {$numeric ->
693 [true] numeric cast
694 *[false] cast
695 }: `{$expr_ty}` as `{$cast_ty}`"
696)]
697#[help("cast can be replaced by coercion; this might require a temporary variable")]
698pub(crate) struct TrivialCast<'tcx> {
699 pub numeric: bool,
700 pub expr_ty: Ty<'tcx>,
701 pub cast_ty: Ty<'tcx>,
702}
703
704pub(crate) struct BreakNonLoop<'a> {
705 pub span: Span,
706 pub head: Option<Span>,
707 pub kind: &'a str,
708 pub suggestion: String,
709 pub loop_label: Option<Label>,
710 pub break_label: Option<Label>,
711 pub break_expr_kind: &'a ExprKind<'a>,
712 pub break_expr_span: Span,
713}
714
715impl<'a> Diagnostic<'_> for BreakNonLoop<'a> {
716 #[track_caller]
717 fn into_diag(self, dcx: DiagCtxtHandle<'_>, level: Level) -> Diag<'_> {
718 let mut diag = Diag::new(dcx, level, rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`break` with value from a `{$kind}` loop"))msg!("`break` with value from a `{$kind}` loop"));
719 diag.span(self.span);
720 diag.code(E0571);
721 diag.arg("kind", self.kind);
722 diag.span_label(
723 self.span,
724 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("can only break with a value inside `loop` or breakable block"))msg!("can only break with a value inside `loop` or breakable block"),
725 );
726 if let Some(head) = self.head {
727 diag.span_label(head, rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("you can't `break` with a value in a `{$kind}` loop"))msg!("you can't `break` with a value in a `{$kind}` loop"));
728 }
729 diag.span_suggestion_verbose(
730 self.span,
731 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("use `break` on its own without a value inside this `{$kind}` loop"))msg!("use `break` on its own without a value inside this `{$kind}` loop"),
732 self.suggestion,
733 Applicability::MaybeIncorrect,
734 );
735 if let (Some(label), None) = (self.loop_label, self.break_label) {
736 match self.break_expr_kind {
737 ExprKind::Path(hir::QPath::Resolved(
738 None,
739 hir::Path { segments: [segment], res: hir::def::Res::Err, .. },
740 )) if label.ident.to_string() == ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("\'{0}", segment.ident))
})format!("'{}", segment.ident) => {
741 diag.downgrade_to_delayed_bug();
745 }
746 _ => {
747 diag.span_suggestion_verbose(
748 self.break_expr_span,
749 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("alternatively, you might have meant to use the available loop label"))msg!("alternatively, you might have meant to use the available loop label"),
750 label.ident,
751 Applicability::MaybeIncorrect,
752 );
753 }
754 }
755 }
756 diag
757 }
758}
759
760#[derive(const _: () =
{
impl<'_sess> rustc_errors::Diagnostic<'_sess> for ContinueLabeledBlock
{
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
match self {
ContinueLabeledBlock {
span: __binding_0, block_span: __binding_1 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`continue` pointing to a labeled block")));
diag.code(E0696);
;
diag.span(__binding_0);
diag.span_label(__binding_0,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("labeled blocks cannot be `continue`'d")));
diag.span_label(__binding_1,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("labeled block the `continue` points to")));
diag
}
}
}
}
};Diagnostic)]
761#[diag("`continue` pointing to a labeled block", code = E0696)]
762pub(crate) struct ContinueLabeledBlock {
763 #[primary_span]
764 #[label("labeled blocks cannot be `continue`'d")]
765 pub span: Span,
766 #[label("labeled block the `continue` points to")]
767 pub block_span: Span,
768}
769
770#[derive(const _: () =
{
impl<'_sess, 'a> rustc_errors::Diagnostic<'_sess> for
BreakInsideClosure<'a> {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
match self {
BreakInsideClosure {
span: __binding_0,
closure_span: __binding_1,
name: __binding_2 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`{$name}` inside of a closure")));
diag.code(E0267);
;
diag.arg("name", __binding_2);
diag.span(__binding_0);
diag.span_label(__binding_0,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("cannot `{$name}` inside of a closure")));
diag.span_label(__binding_1,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("enclosing closure")));
diag
}
}
}
}
};Diagnostic)]
771#[diag("`{$name}` inside of a closure", code = E0267)]
772pub(crate) struct BreakInsideClosure<'a> {
773 #[primary_span]
774 #[label("cannot `{$name}` inside of a closure")]
775 pub span: Span,
776 #[label("enclosing closure")]
777 pub closure_span: Span,
778 pub name: &'a str,
779}
780
781#[derive(const _: () =
{
impl<'_sess, 'a> rustc_errors::Diagnostic<'_sess> for
BreakInsideCoroutine<'a> {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
match self {
BreakInsideCoroutine {
span: __binding_0,
coroutine_span: __binding_1,
name: __binding_2,
kind: __binding_3,
source: __binding_4 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`{$name}` inside `{$kind}` {$source}")));
diag.code(E0267);
;
diag.arg("name", __binding_2);
diag.arg("kind", __binding_3);
diag.arg("source", __binding_4);
diag.span(__binding_0);
diag.span_label(__binding_0,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("cannot `{$name}` inside `{$kind}` {$source}")));
diag.span_label(__binding_1,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("enclosing `{$kind}` {$source}")));
diag
}
}
}
}
};Diagnostic)]
782#[diag("`{$name}` inside `{$kind}` {$source}", code = E0267)]
783pub(crate) struct BreakInsideCoroutine<'a> {
784 #[primary_span]
785 #[label("cannot `{$name}` inside `{$kind}` {$source}")]
786 pub span: Span,
787 #[label("enclosing `{$kind}` {$source}")]
788 pub coroutine_span: Span,
789 pub name: &'a str,
790 pub kind: &'a str,
791 pub source: &'a str,
792}
793
794#[derive(const _: () =
{
impl<'_sess, 'a> rustc_errors::Diagnostic<'_sess> for OutsideLoop<'a>
{
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
match self {
OutsideLoop {
spans: __binding_0,
name: __binding_1,
is_break: __binding_2,
suggestion: __binding_3 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`{$name}` outside of a loop{$is_break ->\n [true] {\" or labeled block\"}\n *[false] {\"\"}\n }")));
diag.code(E0268);
;
diag.arg("name", __binding_1);
diag.arg("is_break", __binding_2);
diag.span(__binding_0.clone());
for __binding_0 in __binding_0 {
diag.span_label(__binding_0,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("cannot `{$name}` outside of a loop{$is_break ->\n [true] {\" or labeled block\"}\n *[false] {\"\"}\n }")));
}
if let Some(__binding_3) = __binding_3 {
diag.subdiagnostic(__binding_3);
}
diag
}
}
}
}
};Diagnostic)]
795#[diag("`{$name}` outside of a loop{$is_break ->
796 [true] {\" or labeled block\"}
797 *[false] {\"\"}
798 }", code = E0268)]
799pub(crate) struct OutsideLoop<'a> {
800 #[primary_span]
801 #[label(
802 "cannot `{$name}` outside of a loop{$is_break ->
803 [true] {\" or labeled block\"}
804 *[false] {\"\"}
805 }"
806 )]
807 pub spans: Vec<Span>,
808 pub name: &'a str,
809 pub is_break: bool,
810 #[subdiagnostic]
811 pub suggestion: Option<OutsideLoopSuggestion>,
812}
813#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for OutsideLoopSuggestion {
fn add_to_diag(self, diag: &mut rustc_errors::Diag<'_>) {
match self {
OutsideLoopSuggestion {
block_span: __binding_0,
break_spans: __binding_1,
wrap_end: __binding_2,
block_prefix: __binding_3 } => {
let mut suggestions = Vec::new();
let __code_23 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0}", __binding_3))
});
let __code_24 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!(" \'block"))
});
let __code_25 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!(" }}"))
});
suggestions.push((__binding_0, __code_23));
for __binding_1 in __binding_1 {
suggestions.push((__binding_1, __code_24.clone()));
}
if let Some(__binding_2) = __binding_2 {
suggestions.push((__binding_2, __code_25));
}
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider labeling this block to be able to break within it")),
&sub_args);
diag.multipart_suggestion_with_style(__message, suggestions,
rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowCode);
}
}
}
}
};Subdiagnostic)]
814#[multipart_suggestion(
815 "consider labeling this block to be able to break within it",
816 applicability = "maybe-incorrect"
817)]
818pub(crate) struct OutsideLoopSuggestion {
819 #[suggestion_part(code = "{block_prefix}")]
820 pub block_span: Span,
821 #[suggestion_part(code = " 'block")]
822 pub break_spans: Vec<Span>,
823 #[suggestion_part(code = " }}")]
824 pub wrap_end: Option<Span>,
825 pub block_prefix: &'static str,
826}
827
828#[derive(const _: () =
{
impl<'_sess, 'a> rustc_errors::Diagnostic<'_sess> for
UnlabeledInLabeledBlock<'a> {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
match self {
UnlabeledInLabeledBlock {
span: __binding_0, cf_type: __binding_1 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("unlabeled `{$cf_type}` inside of a labeled block")));
diag.code(E0695);
;
diag.arg("cf_type", __binding_1);
diag.span(__binding_0);
diag.span_label(__binding_0,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`{$cf_type}` statements that would diverge to or through a labeled block need to bear a label")));
diag
}
}
}
}
};Diagnostic)]
829#[diag("unlabeled `{$cf_type}` inside of a labeled block", code = E0695)]
830pub(crate) struct UnlabeledInLabeledBlock<'a> {
831 #[primary_span]
832 #[label(
833 "`{$cf_type}` statements that would diverge to or through a labeled block need to bear a label"
834 )]
835 pub span: Span,
836 pub cf_type: &'a str,
837}
838
839#[derive(const _: () =
{
impl<'_sess, 'a> rustc_errors::Diagnostic<'_sess> for
UnlabeledCfInWhileCondition<'a> {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
match self {
UnlabeledCfInWhileCondition {
span: __binding_0, cf_type: __binding_1 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`break` or `continue` with no label in the condition of a `while` loop")));
diag.code(E0590);
;
diag.arg("cf_type", __binding_1);
diag.span(__binding_0);
diag.span_label(__binding_0,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("unlabeled `{$cf_type}` in the condition of a `while` loop")));
diag
}
}
}
}
};Diagnostic)]
840#[diag("`break` or `continue` with no label in the condition of a `while` loop", code = E0590)]
841pub(crate) struct UnlabeledCfInWhileCondition<'a> {
842 #[primary_span]
843 #[label("unlabeled `{$cf_type}` in the condition of a `while` loop")]
844 pub span: Span,
845 pub cf_type: &'a str,
846}
847
848#[derive(const _: () =
{
impl<'_sess, 'tcx> rustc_errors::Diagnostic<'_sess> for
NoAssociatedItem<'tcx> {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
match self {
NoAssociatedItem {
span: __binding_0,
item_kind: __binding_1,
item_ident: __binding_2,
ty_prefix: __binding_3,
ty: __binding_4,
trait_missing_method: __binding_5 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("no {$item_kind} named `{$item_ident}` found for {$ty_prefix} `{$ty}`{$trait_missing_method ->\n [true] {\"\"}\n *[other] {\" \"}in the current scope\n}")));
diag.code(E0599);
;
diag.arg("item_kind", __binding_1);
diag.arg("item_ident", __binding_2);
diag.arg("ty_prefix", __binding_3);
diag.arg("ty", __binding_4);
diag.arg("trait_missing_method", __binding_5);
diag.span(__binding_0);
diag
}
}
}
}
};Diagnostic)]
849#[diag("no {$item_kind} named `{$item_ident}` found for {$ty_prefix} `{$ty}`{$trait_missing_method ->
850 [true] {\"\"}
851 *[other] {\" \"}in the current scope
852}", code = E0599)]
853pub(crate) struct NoAssociatedItem<'tcx> {
854 #[primary_span]
855 pub span: Span,
856 pub item_kind: &'static str,
857 pub item_ident: Ident,
858 pub ty_prefix: Cow<'static, str>,
859 pub ty: Ty<'tcx>,
860 pub trait_missing_method: bool,
861}
862
863#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for CandidateTraitNote {
fn add_to_diag(self, diag: &mut rustc_errors::Diag<'_>) {
match self {
CandidateTraitNote {
span: __binding_0,
trait_name: __binding_1,
item_name: __binding_2,
action_or_ty: __binding_3 } => {
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("trait_name".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_1,
&mut diag.long_ty_path));
sub_args.insert("item_name".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_2,
&mut diag.long_ty_path));
sub_args.insert("action_or_ty".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("`{$trait_name}` defines an item `{$item_name}`{$action_or_ty ->\n [NONE] {\"\"}\n [implement] , perhaps you need to implement it\n *[other] , perhaps you need to restrict type parameter `{$action_or_ty}` with it\n }")),
&sub_args);
diag.span_note(__binding_0, __message);
}
}
}
}
};Subdiagnostic)]
864#[note(
865 "`{$trait_name}` defines an item `{$item_name}`{$action_or_ty ->
866 [NONE] {\"\"}
867 [implement] , perhaps you need to implement it
868 *[other] , perhaps you need to restrict type parameter `{$action_or_ty}` with it
869 }"
870)]
871pub(crate) struct CandidateTraitNote {
872 #[primary_span]
873 pub span: Span,
874 pub trait_name: String,
875 pub item_name: Ident,
876 pub action_or_ty: String,
877}
878
879#[derive(const _: () =
{
impl<'_sess, 'tcx> rustc_errors::Diagnostic<'_sess> for
CannotCastToBool<'tcx> {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
match self {
CannotCastToBool {
span: __binding_0, expr_ty: __binding_1, help: __binding_2 }
=> {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("cannot cast `{$expr_ty}` as `bool`")));
diag.code(E0054);
;
diag.arg("expr_ty", __binding_1);
diag.span(__binding_0);
diag.subdiagnostic(__binding_2);
diag
}
}
}
}
};Diagnostic)]
880#[diag("cannot cast `{$expr_ty}` as `bool`", code = E0054)]
881pub(crate) struct CannotCastToBool<'tcx> {
882 #[primary_span]
883 pub span: Span,
884 pub expr_ty: Ty<'tcx>,
885 #[subdiagnostic]
886 pub help: CannotCastToBoolHelp,
887}
888
889#[derive(const _: () =
{
impl<'_sess, 'tcx> rustc_errors::Diagnostic<'_sess> for
CastEnumDrop<'tcx> {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
match self {
CastEnumDrop {
span: __binding_0,
expr_ty: __binding_1,
cast_ty: __binding_2 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("cannot cast enum `{$expr_ty}` into integer `{$cast_ty}` because it implements `Drop`")));
;
diag.arg("expr_ty", __binding_1);
diag.arg("cast_ty", __binding_2);
diag.span(__binding_0);
diag
}
}
}
}
};Diagnostic)]
890#[diag("cannot cast enum `{$expr_ty}` into integer `{$cast_ty}` because it implements `Drop`")]
891pub(crate) struct CastEnumDrop<'tcx> {
892 #[primary_span]
893 pub span: Span,
894 pub expr_ty: Ty<'tcx>,
895 pub cast_ty: Ty<'tcx>,
896}
897
898#[derive(const _: () =
{
impl<'_sess> rustc_errors::Diagnostic<'_sess> for CastUnknownPointer {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
match self {
CastUnknownPointer {
span: __binding_0, to: __binding_1, sub: __binding_2 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("cannot cast {$to ->\n [true] to\n *[false] from\n} a pointer of an unknown kind")));
diag.code(E0641);
;
diag.arg("to", __binding_1);
diag.span(__binding_0);
diag.subdiagnostic(__binding_2);
diag
}
}
}
}
};Diagnostic)]
899#[diag("cannot cast {$to ->
900 [true] to
901 *[false] from
902} a pointer of an unknown kind", code = E0641)]
903pub(crate) struct CastUnknownPointer {
904 #[primary_span]
905 pub span: Span,
906 pub to: bool,
907 #[subdiagnostic]
908 pub sub: CastUnknownPointerSub,
909}
910
911pub(crate) enum CastUnknownPointerSub {
912 To(Span),
913 From(Span),
914}
915
916impl rustc_errors::Subdiagnostic for CastUnknownPointerSub {
917 fn add_to_diag(self, diag: &mut Diag<'_>) {
918 match self {
919 CastUnknownPointerSub::To(span) => {
920 let msg = rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("needs more type information"))msg!("needs more type information");
921 diag.span_label(span, msg);
922 let msg = rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the type information given here is insufficient to check whether the pointer cast is valid"))msg!(
923 "the type information given here is insufficient to check whether the pointer cast is valid"
924 );
925 diag.note(msg);
926 }
927 CastUnknownPointerSub::From(span) => {
928 let msg = rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the type information given here is insufficient to check whether the pointer cast is valid"))msg!(
929 "the type information given here is insufficient to check whether the pointer cast is valid"
930 );
931 diag.span_label(span, msg);
932 }
933 }
934 }
935}
936
937#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for CannotCastToBoolHelp {
fn add_to_diag(self, diag: &mut rustc_errors::Diag<'_>) {
match self {
CannotCastToBoolHelp::Numeric(__binding_0) => {
let __code_26 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!(" != 0"))
})].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("compare with zero instead")),
&sub_args);
diag.span_suggestions_with_style(__binding_0, __message,
__code_26, rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::ShowAlways);
}
CannotCastToBoolHelp::Unsupported(__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("unsupported cast")),
&sub_args);
diag.span_label(__binding_0, __message);
}
}
}
}
};Subdiagnostic)]
938pub(crate) enum CannotCastToBoolHelp {
939 #[suggestion(
940 "compare with zero instead",
941 applicability = "machine-applicable",
942 code = " != 0",
943 style = "verbose"
944 )]
945 Numeric(#[primary_span] Span),
946 #[label("unsupported cast")]
947 Unsupported(#[primary_span] Span),
948}
949
950#[derive(const _: () =
{
impl<'_sess> rustc_errors::Diagnostic<'_sess> for CtorIsPrivate {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
match self {
CtorIsPrivate { span: __binding_0, def: __binding_1 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("tuple struct constructor `{$def}` is private")));
diag.code(E0603);
;
diag.arg("def", __binding_1);
diag.span(__binding_0);
diag
}
}
}
}
};Diagnostic)]
951#[diag("tuple struct constructor `{$def}` is private", code = E0603)]
952pub(crate) struct CtorIsPrivate {
953 #[primary_span]
954 pub span: Span,
955 pub def: String,
956}
957
958#[derive(const _: () =
{
impl<'tcx> rustc_errors::Subdiagnostic for DerefImplsIsEmpty<'tcx> {
fn add_to_diag(self, diag: &mut rustc_errors::Diag<'_>) {
match self {
DerefImplsIsEmpty { span: __binding_0, deref_ty: __binding_1
} => {
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("deref_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("this expression `Deref`s to `{$deref_ty}` which implements `is_empty`")),
&sub_args);
diag.span_note(__binding_0, __message);
}
}
}
}
};Subdiagnostic)]
959#[note("this expression `Deref`s to `{$deref_ty}` which implements `is_empty`")]
960pub(crate) struct DerefImplsIsEmpty<'tcx> {
961 #[primary_span]
962 pub span: Span,
963 pub deref_ty: Ty<'tcx>,
964}
965
966#[derive(const _: () =
{
impl<'tcx> rustc_errors::Subdiagnostic for
SuggestConvertViaMethod<'tcx> {
fn add_to_diag(self, diag: &mut rustc_errors::Diag<'_>) {
match self {
SuggestConvertViaMethod {
span: __binding_0,
borrow_removal_span: __binding_1,
sugg: __binding_2,
expected: __binding_3,
found: __binding_4 } => {
let mut suggestions = Vec::new();
let __code_27 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0}", __binding_2))
});
let __code_28 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!(""))
});
suggestions.push((__binding_0, __code_27));
if let Some(__binding_1) = __binding_1 {
suggestions.push((__binding_1, __code_28));
}
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("sugg".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_2,
&mut diag.long_ty_path));
sub_args.insert("expected".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_3,
&mut diag.long_ty_path));
sub_args.insert("found".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("try using `{$sugg}` to convert `{$found}` to `{$expected}`")),
&sub_args);
diag.multipart_suggestion_with_style(__message, suggestions,
rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::ShowAlways);
}
}
}
}
};Subdiagnostic)]
967#[multipart_suggestion(
968 "try using `{$sugg}` to convert `{$found}` to `{$expected}`",
969 applicability = "machine-applicable",
970 style = "verbose"
971)]
972pub(crate) struct SuggestConvertViaMethod<'tcx> {
973 #[suggestion_part(code = "{sugg}")]
974 pub span: Span,
975 #[suggestion_part(code = "")]
976 pub borrow_removal_span: Option<Span>,
977 pub sugg: String,
978 pub expected: Ty<'tcx>,
979 pub found: Ty<'tcx>,
980}
981
982#[derive(const _: () =
{
impl<'tcx> rustc_errors::Subdiagnostic for
NoteCallerChoosesTyForTyParam<'tcx> {
fn add_to_diag(self, diag: &mut rustc_errors::Diag<'_>) {
match self {
NoteCallerChoosesTyForTyParam {
ty_param_name: __binding_0, found_ty: __binding_1 } => {
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("ty_param_name".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_0,
&mut diag.long_ty_path));
sub_args.insert("found_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("the caller chooses a type for `{$ty_param_name}` which can be different from `{$found_ty}`")),
&sub_args);
diag.note(__message);
}
}
}
}
};Subdiagnostic)]
983#[note(
984 "the caller chooses a type for `{$ty_param_name}` which can be different from `{$found_ty}`"
985)]
986pub(crate) struct NoteCallerChoosesTyForTyParam<'tcx> {
987 pub ty_param_name: Symbol,
988 pub found_ty: Ty<'tcx>,
989}
990
991#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for SuggestBoxingForReturnImplTrait {
fn add_to_diag(self, diag: &mut rustc_errors::Diag<'_>) {
match self {
SuggestBoxingForReturnImplTrait::ChangeReturnType {
start_sp: __binding_0, end_sp: __binding_1 } => {
let mut suggestions = Vec::new();
let __code_29 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("Box<dyn"))
});
let __code_30 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!(">"))
});
suggestions.push((__binding_0, __code_29));
suggestions.push((__binding_1, __code_30));
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("you could change the return type to be a boxed trait object")),
&sub_args);
diag.multipart_suggestion_with_style(__message, suggestions,
rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowCode);
}
SuggestBoxingForReturnImplTrait::BoxReturnExpr {
starts: __binding_0, ends: __binding_1 } => {
let mut suggestions = Vec::new();
let __code_31 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("Box::new("))
});
let __code_32 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!(")"))
});
for __binding_0 in __binding_0 {
suggestions.push((__binding_0, __code_31.clone()));
}
for __binding_1 in __binding_1 {
suggestions.push((__binding_1, __code_32.clone()));
}
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("if you change the return type to expect trait objects, box the returned expressions")),
&sub_args);
diag.multipart_suggestion_with_style(__message, suggestions,
rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowCode);
}
}
}
}
};Subdiagnostic)]
992pub(crate) enum SuggestBoxingForReturnImplTrait {
993 #[multipart_suggestion(
994 "you could change the return type to be a boxed trait object",
995 applicability = "maybe-incorrect"
996 )]
997 ChangeReturnType {
998 #[suggestion_part(code = "Box<dyn")]
999 start_sp: Span,
1000 #[suggestion_part(code = ">")]
1001 end_sp: Span,
1002 },
1003 #[multipart_suggestion(
1004 "if you change the return type to expect trait objects, box the returned expressions",
1005 applicability = "maybe-incorrect"
1006 )]
1007 BoxReturnExpr {
1008 #[suggestion_part(code = "Box::new(")]
1009 starts: Vec<Span>,
1010 #[suggestion_part(code = ")")]
1011 ends: Vec<Span>,
1012 },
1013}
1014
1015#[derive(const _: () =
{
impl<'_sess> rustc_errors::Diagnostic<'_sess> for
SelfCtorFromOuterItem {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
match self {
SelfCtorFromOuterItem {
span: __binding_0,
impl_span: __binding_1,
sugg: __binding_2,
item: __binding_3 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("can't reference `Self` constructor from outer item")));
diag.code(E0401);
;
diag.span(__binding_0);
diag.span_label(__binding_1,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the inner item doesn't inherit generics from this impl, so `Self` is invalid to reference")));
if let Some(__binding_2) = __binding_2 {
diag.subdiagnostic(__binding_2);
}
if let Some(__binding_3) = __binding_3 {
diag.subdiagnostic(__binding_3);
}
diag
}
}
}
}
};Diagnostic)]
1016#[diag("can't reference `Self` constructor from outer item", code = E0401)]
1017pub(crate) struct SelfCtorFromOuterItem {
1018 #[primary_span]
1019 pub span: Span,
1020 #[label(
1021 "the inner item doesn't inherit generics from this impl, so `Self` is invalid to reference"
1022 )]
1023 pub impl_span: Span,
1024 #[subdiagnostic]
1025 pub sugg: Option<ReplaceWithName>,
1026 #[subdiagnostic]
1027 pub item: Option<InnerItem>,
1028}
1029
1030#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for InnerItem {
fn add_to_diag(self, diag: &mut rustc_errors::Diag<'_>) {
match self {
InnerItem { 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("`Self` used in this inner item")),
&sub_args);
diag.span_label(__binding_0, __message);
}
}
}
}
};Subdiagnostic)]
1031#[label("`Self` used in this inner item")]
1032pub(crate) struct InnerItem {
1033 #[primary_span]
1034 pub span: Span,
1035}
1036
1037#[derive(const _: () =
{
impl<'_sess> rustc_errors::Diagnostic<'_sess> for
SelfCtorFromOuterItemLint {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
match self {
SelfCtorFromOuterItemLint {
impl_span: __binding_0, sugg: __binding_1, item: __binding_2
} => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("can't reference `Self` constructor from outer item")));
;
diag.span_label(__binding_0,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the inner item doesn't inherit generics from this impl, so `Self` is invalid to reference")));
if let Some(__binding_1) = __binding_1 {
diag.subdiagnostic(__binding_1);
}
if let Some(__binding_2) = __binding_2 {
diag.subdiagnostic(__binding_2);
}
diag
}
}
}
}
};Diagnostic)]
1038#[diag("can't reference `Self` constructor from outer item")]
1039pub(crate) struct SelfCtorFromOuterItemLint {
1040 #[label(
1041 "the inner item doesn't inherit generics from this impl, so `Self` is invalid to reference"
1042 )]
1043 pub impl_span: Span,
1044 #[subdiagnostic]
1045 pub sugg: Option<ReplaceWithName>,
1046 #[subdiagnostic]
1047 pub item: Option<InnerItem>,
1048}
1049
1050#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for ReplaceWithName {
fn add_to_diag(self, diag: &mut rustc_errors::Diag<'_>) {
match self {
ReplaceWithName { span: __binding_0, name: __binding_1 } =>
{
let __code_33 =
[::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("replace `Self` with the actual type")),
&sub_args);
diag.span_suggestions_with_style(__binding_0, __message,
__code_33, rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::ShowCode);
}
}
}
}
};Subdiagnostic)]
1051#[suggestion(
1052 "replace `Self` with the actual type",
1053 code = "{name}",
1054 applicability = "machine-applicable"
1055)]
1056pub(crate) struct ReplaceWithName {
1057 #[primary_span]
1058 pub span: Span,
1059 pub name: String,
1060}
1061
1062#[derive(const _: () =
{
impl<'_sess, 'tcx> rustc_errors::Diagnostic<'_sess> for
CastThinPointerToWidePointer<'tcx> {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
match self {
CastThinPointerToWidePointer {
span: __binding_0,
expr_ty: __binding_1,
cast_ty: __binding_2,
teach: __binding_3 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("cannot cast thin pointer `{$expr_ty}` to wide pointer `{$cast_ty}`")));
diag.code(E0607);
;
diag.arg("expr_ty", __binding_1);
diag.arg("cast_ty", __binding_2);
diag.span(__binding_0);
if __binding_3 {
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("thin pointers are \"simple\" pointers: they are purely a reference to a\n memory address.\n\n Wide pointers are pointers referencing \"Dynamically Sized Types\" (also\n called DST). DST don't have a statically known size, therefore they can\n only exist behind some kind of pointers that contain additional\n information. Slices and trait objects are DSTs. In the case of slices,\n the additional information the wide pointer holds is their size.\n\n To fix this error, don't try to cast directly between thin and wide\n pointers.\n\n For more information about casts, take a look at The Book:\n https://doc.rust-lang.org/reference/expressions/operator-expr.html#type-cast-expressions")));
}
diag
}
}
}
}
};Diagnostic)]
1063#[diag("cannot cast thin pointer `{$expr_ty}` to wide pointer `{$cast_ty}`", code = E0607)]
1064pub(crate) struct CastThinPointerToWidePointer<'tcx> {
1065 #[primary_span]
1066 pub span: Span,
1067 pub expr_ty: Ty<'tcx>,
1068 pub cast_ty: Ty<'tcx>,
1069 #[note(
1070 "thin pointers are \"simple\" pointers: they are purely a reference to a
1071 memory address.
1072
1073 Wide pointers are pointers referencing \"Dynamically Sized Types\" (also
1074 called DST). DST don't have a statically known size, therefore they can
1075 only exist behind some kind of pointers that contain additional
1076 information. Slices and trait objects are DSTs. In the case of slices,
1077 the additional information the wide pointer holds is their size.
1078
1079 To fix this error, don't try to cast directly between thin and wide
1080 pointers.
1081
1082 For more information about casts, take a look at The Book:
1083 https://doc.rust-lang.org/reference/expressions/operator-expr.html#type-cast-expressions"
1084 )]
1085 pub(crate) teach: bool,
1086}
1087
1088#[derive(const _: () =
{
impl<'_sess, 'a, 'tcx> rustc_errors::Diagnostic<'_sess> for
PassToVariadicFunction<'a, 'tcx> {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
match self {
PassToVariadicFunction {
span: __binding_0,
ty: __binding_1,
cast_ty: __binding_2,
sugg_span: __binding_3,
teach: __binding_4 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("can't pass `{$ty}` to variadic function")));
let __code_34 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!(" as {0}", __binding_2))
})].into_iter();
diag.code(E0617);
;
diag.arg("ty", __binding_1);
diag.arg("cast_ty", __binding_2);
diag.span(__binding_0);
diag.span_suggestions_with_style(__binding_3,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("cast the value to `{$cast_ty}`")),
__code_34, rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::ShowAlways);
if __binding_4 {
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("certain types, like `{$ty}`, must be cast before passing them to a variadic function to match the implicit cast that a C compiler would perform as part of C's numeric promotion rules")));
}
diag
}
}
}
}
};Diagnostic)]
1089#[diag("can't pass `{$ty}` to variadic function", code = E0617)]
1090pub(crate) struct PassToVariadicFunction<'a, 'tcx> {
1091 #[primary_span]
1092 pub span: Span,
1093 pub ty: Ty<'tcx>,
1094 pub cast_ty: &'a str,
1095 #[suggestion(
1096 "cast the value to `{$cast_ty}`",
1097 code = " as {cast_ty}",
1098 applicability = "machine-applicable",
1099 style = "verbose"
1100 )]
1101 pub sugg_span: Span,
1102 #[note(
1103 "certain types, like `{$ty}`, must be cast before passing them to a variadic function to match the implicit cast that a C compiler would perform as part of C's numeric promotion rules"
1104 )]
1105 pub(crate) teach: bool,
1106}
1107
1108#[derive(const _: () =
{
impl<'_sess> rustc_errors::Diagnostic<'_sess> for
PassFnItemToVariadicFunction {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
match self {
PassFnItemToVariadicFunction {
span: __binding_0,
sugg_span: __binding_1,
replace: __binding_2 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("can't pass a function item to a variadic function")));
let __code_35 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!(" as {0}", __binding_2))
})].into_iter();
diag.code(E0617);
diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("a function item is zero-sized and needs to be cast into a function pointer to be used in FFI")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("for more information on function items, visit https://doc.rust-lang.org/reference/types/function-item.html")));
;
diag.span(__binding_0);
diag.span_suggestions_with_style(__binding_1,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("use a function pointer instead")),
__code_35, rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::ShowAlways);
diag
}
}
}
}
};Diagnostic)]
1109#[diag("can't pass a function item to a variadic function", code = E0617)]
1110#[help(
1111 "a function item is zero-sized and needs to be cast into a function pointer to be used in FFI"
1112)]
1113#[note(
1114 "for more information on function items, visit https://doc.rust-lang.org/reference/types/function-item.html"
1115)]
1116pub(crate) struct PassFnItemToVariadicFunction {
1117 #[primary_span]
1118 pub span: Span,
1119 #[suggestion(
1120 "use a function pointer instead",
1121 code = " as {replace}",
1122 applicability = "machine-applicable",
1123 style = "verbose"
1124 )]
1125 pub sugg_span: Span,
1126 pub replace: String,
1127}
1128
1129#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for ReplaceCommaWithSemicolon {
fn add_to_diag(self, diag: &mut rustc_errors::Diag<'_>) {
match self {
ReplaceCommaWithSemicolon {
comma_span: __binding_0, descr: __binding_1 } => {
let __code_36 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("; "))
})].into_iter();
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("descr".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("replace the comma with a semicolon to create {$descr}")),
&sub_args);
diag.span_suggestions_with_style(__binding_0, __message,
__code_36, rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::ShowAlways);
}
}
}
}
};Subdiagnostic)]
1130#[suggestion(
1131 "replace the comma with a semicolon to create {$descr}",
1132 applicability = "machine-applicable",
1133 style = "verbose",
1134 code = "; "
1135)]
1136pub(crate) struct ReplaceCommaWithSemicolon {
1137 #[primary_span]
1138 pub comma_span: Span,
1139 pub descr: &'static str,
1140}
1141
1142#[derive(const _: () =
{
impl<'_sess> rustc_errors::Diagnostic<'_sess> for
SupertraitItemShadowing {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
match self {
SupertraitItemShadowing {
item: __binding_0,
subtrait: __binding_1,
shadower: __binding_2,
shadowee: __binding_3 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("trait item `{$item}` from `{$subtrait}` shadows identically named item from supertrait")));
;
diag.arg("item", __binding_0);
diag.arg("subtrait", __binding_1);
diag.subdiagnostic(__binding_2);
diag.subdiagnostic(__binding_3);
diag
}
}
}
}
};Diagnostic)]
1143#[diag("trait item `{$item}` from `{$subtrait}` shadows identically named item from supertrait")]
1144pub(crate) struct SupertraitItemShadowing {
1145 pub item: Symbol,
1146 pub subtrait: Symbol,
1147 #[subdiagnostic]
1148 pub shadower: SupertraitItemShadower,
1149 #[subdiagnostic]
1150 pub shadowee: SupertraitItemShadowee,
1151}
1152
1153#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for SupertraitItemShadower {
fn add_to_diag(self, diag: &mut rustc_errors::Diag<'_>) {
match self {
SupertraitItemShadower {
subtrait: __binding_0, span: __binding_1 } => {
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("subtrait".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("item from `{$subtrait}` shadows a supertrait item")),
&sub_args);
diag.span_note(__binding_1, __message);
}
}
}
}
};Subdiagnostic)]
1154#[note("item from `{$subtrait}` shadows a supertrait item")]
1155pub(crate) struct SupertraitItemShadower {
1156 pub subtrait: Symbol,
1157 #[primary_span]
1158 pub span: Span,
1159}
1160
1161#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for SupertraitItemShadowee {
fn add_to_diag(self, diag: &mut rustc_errors::Diag<'_>) {
match self {
SupertraitItemShadowee::Labeled {
span: __binding_0, supertrait: __binding_1 } => {
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("supertrait".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("item from `{$supertrait}` is shadowed by a subtrait item")),
&sub_args);
diag.span_note(__binding_0, __message);
}
SupertraitItemShadowee::Several {
spans: __binding_0, traits: __binding_1 } => {
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("traits".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("items from several supertraits are shadowed: {$traits}")),
&sub_args);
diag.span_note(__binding_0, __message);
}
}
}
}
};Subdiagnostic)]
1162pub(crate) enum SupertraitItemShadowee {
1163 #[note("item from `{$supertrait}` is shadowed by a subtrait item")]
1164 Labeled {
1165 #[primary_span]
1166 span: Span,
1167 supertrait: Symbol,
1168 },
1169 #[note("items from several supertraits are shadowed: {$traits}")]
1170 Several {
1171 #[primary_span]
1172 spans: MultiSpan,
1173 traits: DiagSymbolList,
1174 },
1175}
1176
1177#[derive(const _: () =
{
impl<'_sess, 'a> rustc_errors::Diagnostic<'_sess> for
RegisterTypeUnstable<'a> {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
match self {
RegisterTypeUnstable { span: __binding_0, ty: __binding_1 }
=> {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("type `{$ty}` cannot be used with this register class in stable")));
;
diag.arg("ty", __binding_1);
diag.span(__binding_0);
diag
}
}
}
}
};Diagnostic)]
1178#[diag("type `{$ty}` cannot be used with this register class in stable")]
1179pub(crate) struct RegisterTypeUnstable<'a> {
1180 #[primary_span]
1181 pub span: Span,
1182 pub ty: Ty<'a>,
1183}
1184
1185#[derive(const _: () =
{
impl<'_sess> rustc_errors::Diagnostic<'_sess> for
NakedAsmOutsideNakedFn {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
match self {
NakedAsmOutsideNakedFn { span: __binding_0 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the `naked_asm!` macro can only be used in functions marked with `#[unsafe(naked)]`")));
;
diag.span(__binding_0);
diag
}
}
}
}
};Diagnostic)]
1186#[diag("the `naked_asm!` macro can only be used in functions marked with `#[unsafe(naked)]`")]
1187pub(crate) struct NakedAsmOutsideNakedFn {
1188 #[primary_span]
1189 pub span: Span,
1190}
1191
1192#[derive(const _: () =
{
impl<'_sess> rustc_errors::Diagnostic<'_sess> for NoPatterns {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
match self {
NoPatterns { span: __binding_0 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("patterns not allowed in naked function parameters")));
;
diag.span(__binding_0);
diag
}
}
}
}
};Diagnostic)]
1193#[diag("patterns not allowed in naked function parameters")]
1194pub(crate) struct NoPatterns {
1195 #[primary_span]
1196 pub span: Span,
1197}
1198
1199#[derive(const _: () =
{
impl<'_sess> rustc_errors::Diagnostic<'_sess> for ParamsNotAllowed {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
match self {
ParamsNotAllowed { span: __binding_0 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("referencing function parameters is not allowed in naked functions")));
diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("follow the calling convention in asm block to use parameters")));
;
diag.span(__binding_0);
diag
}
}
}
}
};Diagnostic)]
1200#[diag("referencing function parameters is not allowed in naked functions")]
1201#[help("follow the calling convention in asm block to use parameters")]
1202pub(crate) struct ParamsNotAllowed {
1203 #[primary_span]
1204 pub span: Span,
1205}
1206
1207pub(crate) struct NakedFunctionsAsmBlock {
1208 pub span: Span,
1209 pub multiple_asms: Vec<Span>,
1210 pub non_asms: Vec<Span>,
1211}
1212
1213impl Diagnostic<'_> for NakedFunctionsAsmBlock {
1214 #[track_caller]
1215 fn into_diag(self, dcx: DiagCtxtHandle<'_>, level: Level) -> Diag<'_> {
1216 let mut diag = Diag::new(
1217 dcx,
1218 level,
1219 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("naked functions must contain a single `naked_asm!` invocation"))msg!("naked functions must contain a single `naked_asm!` invocation"),
1220 );
1221 diag.span(self.span);
1222 diag.code(E0787);
1223 for span in self.multiple_asms.iter() {
1224 diag.span_label(
1225 *span,
1226 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("multiple `naked_asm!` invocations are not allowed in naked functions"))msg!("multiple `naked_asm!` invocations are not allowed in naked functions"),
1227 );
1228 }
1229 for span in self.non_asms.iter() {
1230 diag.span_label(*span, rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("not allowed in naked functions"))msg!("not allowed in naked functions"));
1231 }
1232 diag
1233 }
1234}
1235
1236pub(crate) fn maybe_emit_plus_equals_diagnostic<'a>(
1237 fnctxt: &FnCtxt<'a, '_>,
1238 assign_op: Spanned<AssignOpKind>,
1239 lhs_expr: &hir::Expr<'_>,
1240) -> Result<(), Diag<'a>> {
1241 if assign_op.node == hir::AssignOpKind::AddAssign
1242 && let hir::ExprKind::Binary(bin_op, left, right) = &lhs_expr.kind
1243 && bin_op.node == hir::BinOpKind::And
1244 && crate::op::contains_let_in_chain(left)
1245 && let hir::ExprKind::Path(hir::QPath::Resolved(_, path)) = &right.kind
1246 && #[allow(non_exhaustive_omitted_patterns)] match path.res {
hir::def::Res::Local(_) => true,
_ => false,
}matches!(path.res, hir::def::Res::Local(_))
1247 {
1248 let mut err = fnctxt.dcx().struct_span_err(
1249 assign_op.span,
1250 "binary assignment operation `+=` cannot be used in a let chain",
1251 );
1252
1253 err.span_label(
1254 lhs_expr.span,
1255 "you are add-assigning the right-hand side expression to the result of this let-chain",
1256 );
1257
1258 err.span_label(assign_op.span, "cannot use `+=` in a let chain");
1259
1260 err.span_suggestion_short(
1261 assign_op.span,
1262 "you might have meant to compare with `==` instead of assigning with `+=`",
1263 "==",
1264 Applicability::MaybeIncorrect,
1265 );
1266
1267 return Err(err);
1268 }
1269 Ok(())
1270}
1271
1272#[derive(const _: () =
{
impl<'_sess> rustc_errors::Diagnostic<'_sess> for
NakedFunctionsMustNakedAsm {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
match self {
NakedFunctionsMustNakedAsm { span: __binding_0 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the `asm!` macro is not allowed in naked functions")));
diag.code(E0787);
;
diag.span(__binding_0);
diag.span_label(__binding_0,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider using the `naked_asm!` macro instead")));
diag
}
}
}
}
};Diagnostic)]
1273#[diag("the `asm!` macro is not allowed in naked functions", code = E0787)]
1274pub(crate) struct NakedFunctionsMustNakedAsm {
1275 #[primary_span]
1276 #[label("consider using the `naked_asm!` macro instead")]
1277 pub span: Span,
1278}
1279
1280#[derive(const _: () =
{
impl<'_sess> rustc_errors::Diagnostic<'_sess> for AbiCannotBeCalled {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
match self {
AbiCannotBeCalled { span: __binding_0, abi: __binding_1 } =>
{
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("functions with the {$abi} ABI cannot be called")));
;
diag.arg("abi", __binding_1);
diag.span(__binding_0);
diag.span_note(__binding_0,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("an `extern {$abi}` function can only be called using inline assembly")));
diag
}
}
}
}
};Diagnostic)]
1281#[diag("functions with the {$abi} ABI cannot be called")]
1282pub(crate) struct AbiCannotBeCalled {
1283 #[primary_span]
1284 #[note("an `extern {$abi}` function can only be called using inline assembly")]
1285 pub span: Span,
1286 pub abi: ExternAbi,
1287}
1288
1289#[derive(const _: () =
{
impl<'_sess> rustc_errors::Diagnostic<'_sess> for
GpuKernelAbiCannotBeCalled {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
match self {
GpuKernelAbiCannotBeCalled { span: __binding_0 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("functions with the \"gpu-kernel\" ABI cannot be called")));
;
diag.span(__binding_0);
diag.span_note(__binding_0,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("an `extern \"gpu-kernel\"` function must be launched on the GPU by the runtime")));
diag
}
}
}
}
};Diagnostic)]
1290#[diag("functions with the \"gpu-kernel\" ABI cannot be called")]
1291pub(crate) struct GpuKernelAbiCannotBeCalled {
1292 #[primary_span]
1293 #[note("an `extern \"gpu-kernel\"` function must be launched on the GPU by the runtime")]
1294 pub span: Span,
1295}
1296
1297#[derive(const _: () =
{
impl<'_sess> rustc_errors::Diagnostic<'_sess> for
ConstContinueBadLabel {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
match self {
ConstContinueBadLabel { span: __binding_0 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`#[const_continue]` must break to a labeled block that participates in a `#[loop_match]`")));
;
diag.span(__binding_0);
diag
}
}
}
}
};Diagnostic)]
1298#[diag("`#[const_continue]` must break to a labeled block that participates in a `#[loop_match]`")]
1299pub(crate) struct ConstContinueBadLabel {
1300 #[primary_span]
1301 pub span: Span,
1302}
1303
1304#[derive(const _: () =
{
impl<'_sess> rustc_errors::Diagnostic<'_sess> for
ProjectOnNonPinProjectType {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
match self {
ProjectOnNonPinProjectType {
span: __binding_0,
def_span: __binding_1,
sugg_span: __binding_2 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("cannot project on type that is not `#[pin_v2]`")));
let __code_37 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("#[pin_v2]\n"))
})].into_iter();
;
diag.span(__binding_0);
if let Some(__binding_1) = __binding_1 {
diag.span_note(__binding_1,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("type defined here")));
}
if let Some(__binding_2) = __binding_2 {
diag.span_suggestions_with_style(__binding_2,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("add `#[pin_v2]` here")),
__code_37, rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::ShowCode);
}
diag
}
}
}
}
};Diagnostic)]
1305#[diag("cannot project on type that is not `#[pin_v2]`")]
1306pub(crate) struct ProjectOnNonPinProjectType {
1307 #[primary_span]
1308 pub span: Span,
1309 #[note("type defined here")]
1310 pub def_span: Option<Span>,
1311 #[suggestion(
1312 "add `#[pin_v2]` here",
1313 code = "#[pin_v2]\n",
1314 applicability = "machine-applicable"
1315 )]
1316 pub sugg_span: Option<Span>,
1317}
1318
1319#[derive(const _: () =
{
impl<'_sess> rustc_errors::Diagnostic<'_sess> for
FloatLiteralF32Fallback {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
match self {
FloatLiteralF32Fallback {
literal: __binding_0, span: __binding_1 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("falling back to `f32` as the trait bound `f32: From<f64>` is not satisfied")));
let __code_38 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0}_f32", __binding_0))
})].into_iter();
;
if let Some(__binding_1) = __binding_1 {
diag.span_suggestions_with_style(__binding_1,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("explicitly specify the type as `f32`")),
__code_38, rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::ShowCode);
}
diag
}
}
}
}
};Diagnostic)]
1320#[diag("falling back to `f32` as the trait bound `f32: From<f64>` is not satisfied")]
1321pub(crate) struct FloatLiteralF32Fallback {
1322 pub literal: String,
1323 #[suggestion(
1324 "explicitly specify the type as `f32`",
1325 code = "{literal}_f32",
1326 applicability = "machine-applicable"
1327 )]
1328 pub span: Option<Span>,
1329}
1330
1331#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for ExprParenthesesNeeded {
fn add_to_diag(self, diag: &mut rustc_errors::Diag<'_>) {
match self {
ExprParenthesesNeeded {
left: __binding_0, right: __binding_1 } => {
let mut suggestions = Vec::new();
let __code_39 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("("))
});
let __code_40 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!(")"))
});
suggestions.push((__binding_0, __code_39));
suggestions.push((__binding_1, __code_40));
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("parentheses are required to parse this as an expression")),
&sub_args);
diag.multipart_suggestion_with_style(__message, suggestions,
rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::ShowCode);
}
}
}
}
};Subdiagnostic)]
1332#[multipart_suggestion(
1333 "parentheses are required to parse this as an expression",
1334 applicability = "machine-applicable"
1335)]
1336pub(crate) struct ExprParenthesesNeeded {
1337 #[suggestion_part(code = "(")]
1338 left: Span,
1339 #[suggestion_part(code = ")")]
1340 right: Span,
1341}
1342
1343impl ExprParenthesesNeeded {
1344 pub(crate) fn surrounding(s: Span) -> Self {
1345 ExprParenthesesNeeded { left: s.shrink_to_lo(), right: s.shrink_to_hi() }
1346 }
1347}
1348
1349#[derive(const _: () =
{
impl<'_sess> rustc_errors::Diagnostic<'_sess> for UnsafePanicHandlers
{
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
match self {
UnsafePanicHandlers => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`#[panic_handler]` functions can't be `unsafe`")));
;
diag
}
}
}
}
};Diagnostic)]
1350#[diag("`#[panic_handler]` functions can't be `unsafe`")]
1351pub(crate) struct UnsafePanicHandlers;