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,
10 EmissionGuarantee, IntoDiagArg, Level, MultiSpan, Subdiagnostic, msg,
11};
12use rustc_hir as hir;
13use rustc_hir::ExprKind;
14use rustc_macros::{Diagnostic, Subdiagnostic};
15use rustc_middle::ty::{self, 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, G> rustc_errors::Diagnostic<'_sess, G> for
AsmConstPtrUnstable where G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
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, G> rustc_errors::Diagnostic<'_sess, G> for
BaseExpressionDoubleDot where G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
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<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
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<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
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, G> rustc_errors::Diagnostic<'_sess, G> for
FieldMultiplySpecifiedInInitializer where
G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
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, G> rustc_errors::Diagnostic<'_sess, G> for
ReturnStmtOutsideOfFnBody where G: rustc_errors::EmissionGuarantee
{
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
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, G> rustc_errors::Diagnostic<'_sess, G> for
RustCallIncorrectArgs where G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
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, G> rustc_errors::Diagnostic<'_sess, G> for
YieldExprOutsideOfCoroutine where
G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
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, G> rustc_errors::Diagnostic<'_sess, G> for
StructExprNonExhaustive where G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
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, G> rustc_errors::Diagnostic<'_sess, G> for
FunctionalRecordUpdateOnNonStruct where
G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
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, G> rustc_errors::Diagnostic<'_sess, G> for
AddressOfTemporaryTaken where G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
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<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
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<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
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, G> rustc_errors::Diagnostic<'_sess, G> for
ExplicitDestructorCall where G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
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<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
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, G> rustc_errors::Diagnostic<'_sess, G> for
MissingParenthesesInRange<'tcx> where
G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
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, G> rustc_errors::Diagnostic<'_sess, G> for
NeverTypeFallbackFlowingIntoUnsafe where
G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
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(const _: () =
{
impl<'_sess, 'tcx, G> rustc_errors::Diagnostic<'_sess, G> for
DependencyOnUnitNeverTypeFallback<'tcx> where
G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
DependencyOnUnitNeverTypeFallback {
obligation_span: __binding_0,
obligation: __binding_1,
sugg: __binding_2 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this function depends on never type fallback being `()`")));
diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("specify the types explicitly")));
;
diag.arg("obligation", __binding_1);
diag.span_note(__binding_0,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("in edition 2024, the requirement `{$obligation}` will fail")));
diag.subdiagnostic(__binding_2);
diag
}
}
}
}
};Diagnostic)]
266#[help("specify the types explicitly")]
267#[diag("this function depends on never type fallback being `()`")]
268pub(crate) struct DependencyOnUnitNeverTypeFallback<'tcx> {
269 #[note("in edition 2024, the requirement `{$obligation}` will fail")]
270 pub obligation_span: Span,
271 pub obligation: ty::Predicate<'tcx>,
272 #[subdiagnostic]
273 pub sugg: SuggestAnnotations,
274}
275
276#[derive(#[automatically_derived]
impl ::core::clone::Clone for SuggestAnnotation {
#[inline]
fn clone(&self) -> SuggestAnnotation {
match self {
SuggestAnnotation::Unit(__self_0) =>
SuggestAnnotation::Unit(::core::clone::Clone::clone(__self_0)),
SuggestAnnotation::Path(__self_0) =>
SuggestAnnotation::Path(::core::clone::Clone::clone(__self_0)),
SuggestAnnotation::Local(__self_0) =>
SuggestAnnotation::Local(::core::clone::Clone::clone(__self_0)),
SuggestAnnotation::Turbo(__self_0, __self_1, __self_2) =>
SuggestAnnotation::Turbo(::core::clone::Clone::clone(__self_0),
::core::clone::Clone::clone(__self_1),
::core::clone::Clone::clone(__self_2)),
}
}
}Clone)]
277pub(crate) enum SuggestAnnotation {
278 Unit(Span),
279 Path(Span),
280 Local(Span),
281 Turbo(Span, usize, usize),
282}
283
284#[derive(#[automatically_derived]
impl ::core::clone::Clone for SuggestAnnotations {
#[inline]
fn clone(&self) -> SuggestAnnotations {
SuggestAnnotations {
suggestions: ::core::clone::Clone::clone(&self.suggestions),
}
}
}Clone)]
285pub(crate) struct SuggestAnnotations {
286 pub suggestions: Vec<SuggestAnnotation>,
287}
288impl Subdiagnostic for SuggestAnnotations {
289 fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
290 if self.suggestions.is_empty() {
291 return;
292 }
293
294 let mut suggestions = ::alloc::vec::Vec::new()vec![];
295 for suggestion in self.suggestions {
296 match suggestion {
297 SuggestAnnotation::Unit(span) => {
298 suggestions.push((span, "()".to_string()));
299 }
300 SuggestAnnotation::Path(span) => {
301 suggestions.push((span.shrink_to_lo(), "<() as ".to_string()));
302 suggestions.push((span.shrink_to_hi(), ">".to_string()));
303 }
304 SuggestAnnotation::Local(span) => {
305 suggestions.push((span, ": ()".to_string()));
306 }
307 SuggestAnnotation::Turbo(span, n_args, idx) => suggestions.push((
308 span,
309 ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("::<{0}>",
(0..n_args).map(|i|
if i == idx {
"()"
} else { "_" }).collect::<Vec<_>>().join(", ")))
})format!(
310 "::<{}>",
311 (0..n_args)
312 .map(|i| if i == idx { "()" } else { "_" })
313 .collect::<Vec<_>>()
314 .join(", "),
315 ),
316 )),
317 }
318 }
319
320 diag.multipart_suggestion(
321 "use `()` annotations to avoid fallback changes",
322 suggestions,
323 Applicability::MachineApplicable,
324 );
325 }
326}
327
328#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for AddMissingParenthesesInRange {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
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)]
329#[multipart_suggestion(
330 "you must surround the range in parentheses to call its `{$func_name}` function",
331 style = "verbose",
332 applicability = "maybe-incorrect"
333)]
334pub(crate) struct AddMissingParenthesesInRange {
335 pub func_name: String,
336 #[suggestion_part(code = "(")]
337 pub left: Span,
338 #[suggestion_part(code = ")")]
339 pub right: Span,
340}
341
342pub(crate) struct TypeMismatchFruTypo {
343 pub expr_span: Span,
345 pub fru_span: Span,
347 pub expr: Option<String>,
349}
350
351impl Subdiagnostic for TypeMismatchFruTypo {
352 fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
353 diag.arg("expr", self.expr.as_deref().unwrap_or("NONE"));
354
355 if self.expr_span.between(self.fru_span).is_empty() {
357 diag.span_note(
358 self.expr_span.to(self.fru_span),
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 } else {
362 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();
363 multispan.push_span_label(
364 self.expr_span,
365 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..."),
366 );
367 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"));
368 diag.span_note(
369 multispan,
370 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"),
371 );
372 }
373
374 diag.span_suggestion(
375 self.expr_span.shrink_to_hi(),
376 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!(
377 "to set the remaining fields{$expr ->
378 [NONE]{\"\"}
379 *[other] {\" \"}from `{$expr}`
380 }, separate the last named field with a comma"
381 ),
382 ", ",
383 Applicability::MaybeIncorrect,
384 );
385 }
386}
387
388#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
PtrCastAddAutoToObject where G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
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)]
389#[diag("cannot add {$traits_len ->
390 [1] auto trait {$traits}
391 *[other] auto traits {$traits}
392} to dyn bound via pointer cast", code = E0804)]
393#[note("this could allow UB elsewhere")]
394#[help("use `transmute` if you're sure this is sound")]
395pub(crate) struct PtrCastAddAutoToObject {
396 #[primary_span]
397 #[label("unsupported cast")]
398 pub span: Span,
399 pub traits_len: usize,
400 pub traits: DiagSymbolList<String>,
401}
402
403#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for HelpUseLatestEdition {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
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)]
404pub(crate) enum HelpUseLatestEdition {
405 #[help("set `edition = \"{$edition}\"` in `Cargo.toml`")]
406 #[note("for more on editions, read https://doc.rust-lang.org/edition-guide")]
407 Cargo { edition: Edition },
408 #[help("pass `--edition {$edition}` to `rustc`")]
409 #[note("for more on editions, read https://doc.rust-lang.org/edition-guide")]
410 Standalone { edition: Edition },
411}
412
413impl HelpUseLatestEdition {
414 pub(crate) fn new() -> Self {
415 let edition = LATEST_STABLE_EDITION;
416 if rustc_session::utils::was_invoked_from_cargo() {
417 Self::Cargo { edition }
418 } else {
419 Self::Standalone { edition }
420 }
421 }
422}
423
424#[derive(const _: () =
{
impl<'_sess, 'tcx, G> rustc_errors::Diagnostic<'_sess, G> for
NoFieldOnVariant<'tcx> where G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
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)]
425#[diag("no field named `{$field}` on enum variant `{$container}::{$ident}`", code = E0609)]
426pub(crate) struct NoFieldOnVariant<'tcx> {
427 #[primary_span]
428 pub(crate) span: Span,
429 pub(crate) container: Ty<'tcx>,
430 pub(crate) ident: Ident,
431 pub(crate) field: Ident,
432 #[label("this enum variant...")]
433 pub(crate) enum_span: Span,
434 #[label("...does not have this field")]
435 pub(crate) field_span: Span,
436}
437
438#[derive(const _: () =
{
impl<'_sess, 'tcx, G> rustc_errors::Diagnostic<'_sess, G> for
CantDereference<'tcx> where G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
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)]
439#[diag("type `{$ty}` cannot be dereferenced", code = E0614)]
440pub(crate) struct CantDereference<'tcx> {
441 #[primary_span]
442 #[label("can't be dereferenced")]
443 pub(crate) span: Span,
444 pub(crate) ty: Ty<'tcx>,
445}
446
447#[derive(const _: () =
{
impl<'_sess, 'tcx, G> rustc_errors::Diagnostic<'_sess, G> for
ExpectedArrayOrSlice<'tcx> where
G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
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)]
448#[diag("expected an array or slice, found `{$ty}`", code = E0529)]
449pub(crate) struct ExpectedArrayOrSlice<'tcx> {
450 #[primary_span]
451 #[label("pattern cannot match with input type `{$ty}`")]
452 pub(crate) span: Span,
453 pub(crate) ty: Ty<'tcx>,
454 pub(crate) slice_pat_semantics: bool,
455 #[subdiagnostic]
456 pub(crate) as_deref: Option<AsDerefSuggestion>,
457 #[subdiagnostic]
458 pub(crate) slicing: Option<SlicingSuggestion>,
459}
460
461#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for AsDerefSuggestion {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
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)]
462#[suggestion(
463 "consider using `as_deref` here",
464 code = ".as_deref()",
465 style = "verbose",
466 applicability = "maybe-incorrect"
467)]
468pub(crate) struct AsDerefSuggestion {
469 #[primary_span]
470 pub(crate) span: Span,
471}
472
473#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for SlicingSuggestion {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
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)]
474#[suggestion(
475 "consider slicing here",
476 code = "[..]",
477 style = "verbose",
478 applicability = "maybe-incorrect"
479)]
480pub(crate) struct SlicingSuggestion {
481 #[primary_span]
482 pub(crate) span: Span,
483}
484
485#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for InvalidCallee
where G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
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)]
486#[diag("expected function, found {$found}", code = E0618)]
487pub(crate) struct InvalidCallee {
488 #[primary_span]
489 pub span: Span,
490 pub found: String,
491}
492
493#[derive(const _: () =
{
impl<'_sess, 'tcx, G> rustc_errors::Diagnostic<'_sess, G> for
ScalableVectorCtor<'tcx> where G: rustc_errors::EmissionGuarantee
{
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
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)]
494#[diag("scalable vector types cannot be initialised using their constructor")]
495pub(crate) struct ScalableVectorCtor<'tcx> {
496 #[primary_span]
497 pub span: Span,
498 pub ty: Ty<'tcx>,
499}
500
501#[derive(const _: () =
{
impl<'_sess, 'tcx, G> rustc_errors::Diagnostic<'_sess, G> for
IntToWide<'tcx> where G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
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)]
502#[diag("cannot cast `{$expr_ty}` to a pointer that {$known_wide ->
503 [true] is
504 *[false] may be
505} wide", code = E0606)]
506pub(crate) struct IntToWide<'tcx> {
507 #[primary_span]
508 #[label("creating a `{$cast_ty}` requires both an address and {$metadata}")]
509 pub span: Span,
510 pub metadata: &'tcx str,
511 pub expr_ty: Ty<'tcx>,
512 pub cast_ty: Ty<'tcx>,
513 #[label(
514 "consider casting this expression to `*const ()`, then using `core::ptr::from_raw_parts`"
515 )]
516 pub expr_if_nightly: Option<Span>,
517 pub known_wide: bool,
518 #[subdiagnostic]
519 pub param_note: Option<IntToWideParamNote>,
520}
521
522#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for IntToWideParamNote {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
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)]
523#[note("the type parameter `{$param}` is not known to be `Sized`, so this pointer may be wide")]
524pub(crate) struct IntToWideParamNote {
525 pub param: Symbol,
526}
527
528#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for OptionResultRefMismatch {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
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)]
529pub(crate) enum OptionResultRefMismatch {
530 #[suggestion(
531 "use `{$def_path}::copied` to copy the value inside the `{$def_path}`",
532 code = ".copied()",
533 style = "verbose",
534 applicability = "machine-applicable"
535 )]
536 Copied {
537 #[primary_span]
538 span: Span,
539 def_path: String,
540 },
541 #[suggestion(
542 "use `{$def_path}::cloned` to clone the value inside the `{$def_path}`",
543 code = ".cloned()",
544 style = "verbose",
545 applicability = "machine-applicable"
546 )]
547 Cloned {
548 #[primary_span]
549 span: Span,
550 def_path: String,
551 },
552 }
567
568pub(crate) struct RemoveSemiForCoerce {
569 pub expr: Span,
570 pub ret: Span,
571 pub semi: Span,
572}
573
574impl Subdiagnostic for RemoveSemiForCoerce {
575 fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
576 let mut multispan: MultiSpan = self.semi.into();
577 multispan.push_span_label(
578 self.expr,
579 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"),
580 );
581 multispan
582 .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"));
583 multispan.push_span_label(
584 self.semi,
585 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"),
586 );
587 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"));
588
589 diag.tool_only_span_suggestion(
590 self.semi,
591 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("remove this semicolon"))msg!("remove this semicolon"),
592 "",
593 Applicability::MaybeIncorrect,
594 );
595 }
596}
597
598#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
UnionPatMultipleFields where G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
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)]
599#[diag("union patterns should have exactly one field")]
600pub(crate) struct UnionPatMultipleFields {
601 #[primary_span]
602 pub span: Span,
603}
604
605#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for UnionPatDotDot
where G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
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)]
606#[diag("`..` cannot be used in union patterns")]
607pub(crate) struct UnionPatDotDot {
608 #[primary_span]
609 pub span: Span,
610}
611
612#[derive(const _: () =
{
impl<'tcx> rustc_errors::Subdiagnostic for UseIsEmpty<'tcx> {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
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)]
613#[multipart_suggestion(
614 "consider using the `is_empty` method on `{$expr_ty}` to determine if it contains anything",
615 applicability = "maybe-incorrect",
616 style = "verbose"
617)]
618pub(crate) struct UseIsEmpty<'tcx> {
619 #[suggestion_part(code = "!")]
620 pub lo: Span,
621 #[suggestion_part(code = ".is_empty()")]
622 pub hi: Span,
623 pub expr_ty: Ty<'tcx>,
624}
625
626#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
ArgMismatchIndeterminate where G: rustc_errors::EmissionGuarantee
{
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
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)]
627#[diag("argument type mismatch was detected, but rustc had trouble determining where")]
628pub(crate) struct ArgMismatchIndeterminate {
629 #[primary_span]
630 pub span: Span,
631}
632
633#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for SuggestBoxing {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
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)]
634pub(crate) enum SuggestBoxing {
635 #[note(
636 "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"
637 )]
638 #[multipart_suggestion(
639 "store this in the heap by calling `Box::new`",
640 applicability = "machine-applicable"
641 )]
642 Unit {
643 #[suggestion_part(code = "Box::new(())")]
644 start: Span,
645 #[suggestion_part(code = "")]
646 end: Span,
647 },
648 #[note(
649 "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"
650 )]
651 AsyncBody,
652 #[note(
653 "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"
654 )]
655 #[multipart_suggestion(
656 "store this in the heap by calling `Box::new`",
657 applicability = "machine-applicable"
658 )]
659 ExprFieldShorthand {
660 #[suggestion_part(code = "{ident}: Box::new(")]
661 start: Span,
662 #[suggestion_part(code = ")")]
663 end: Span,
664 ident: Ident,
665 },
666 #[note(
667 "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"
668 )]
669 #[multipart_suggestion(
670 "store this in the heap by calling `Box::new`",
671 applicability = "machine-applicable"
672 )]
673 Other {
674 #[suggestion_part(code = "Box::new(")]
675 start: Span,
676 #[suggestion_part(code = ")")]
677 end: Span,
678 },
679}
680
681#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for SuggestPtrNullMut {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
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)]
682#[suggestion(
683 "consider using `core::ptr::null_mut` instead",
684 applicability = "maybe-incorrect",
685 style = "verbose",
686 code = "core::ptr::null_mut()"
687)]
688pub(crate) struct SuggestPtrNullMut {
689 #[primary_span]
690 pub span: Span,
691}
692
693#[derive(const _: () =
{
impl<'_sess, 'tcx, G> rustc_errors::Diagnostic<'_sess, G> for
TrivialCast<'tcx> where G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
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)]
694#[diag(
695 "trivial {$numeric ->
696 [true] numeric cast
697 *[false] cast
698 }: `{$expr_ty}` as `{$cast_ty}`"
699)]
700#[help("cast can be replaced by coercion; this might require a temporary variable")]
701pub(crate) struct TrivialCast<'tcx> {
702 pub numeric: bool,
703 pub expr_ty: Ty<'tcx>,
704 pub cast_ty: Ty<'tcx>,
705}
706
707pub(crate) struct BreakNonLoop<'a> {
708 pub span: Span,
709 pub head: Option<Span>,
710 pub kind: &'a str,
711 pub suggestion: String,
712 pub loop_label: Option<Label>,
713 pub break_label: Option<Label>,
714 pub break_expr_kind: &'a ExprKind<'a>,
715 pub break_expr_span: Span,
716}
717
718impl<'a, G: EmissionGuarantee> Diagnostic<'_, G> for BreakNonLoop<'a> {
719 #[track_caller]
720 fn into_diag(self, dcx: DiagCtxtHandle<'_>, level: Level) -> Diag<'_, G> {
721 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"));
722 diag.span(self.span);
723 diag.code(E0571);
724 diag.arg("kind", self.kind);
725 diag.span_label(
726 self.span,
727 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"),
728 );
729 if let Some(head) = self.head {
730 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"));
731 }
732 diag.span_suggestion(
733 self.span,
734 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"),
735 self.suggestion,
736 Applicability::MaybeIncorrect,
737 );
738 if let (Some(label), None) = (self.loop_label, self.break_label) {
739 match self.break_expr_kind {
740 ExprKind::Path(hir::QPath::Resolved(
741 None,
742 hir::Path { segments: [segment], res: hir::def::Res::Err, .. },
743 )) if label.ident.to_string() == ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("\'{0}", segment.ident))
})format!("'{}", segment.ident) => {
744 diag.downgrade_to_delayed_bug();
748 }
749 _ => {
750 diag.span_suggestion(
751 self.break_expr_span,
752 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"),
753 label.ident,
754 Applicability::MaybeIncorrect,
755 );
756 }
757 }
758 }
759 diag
760 }
761}
762
763#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
ContinueLabeledBlock where G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
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)]
764#[diag("`continue` pointing to a labeled block", code = E0696)]
765pub(crate) struct ContinueLabeledBlock {
766 #[primary_span]
767 #[label("labeled blocks cannot be `continue`'d")]
768 pub span: Span,
769 #[label("labeled block the `continue` points to")]
770 pub block_span: Span,
771}
772
773#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
BreakInsideClosure<'a> where G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
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)]
774#[diag("`{$name}` inside of a closure", code = E0267)]
775pub(crate) struct BreakInsideClosure<'a> {
776 #[primary_span]
777 #[label("cannot `{$name}` inside of a closure")]
778 pub span: Span,
779 #[label("enclosing closure")]
780 pub closure_span: Span,
781 pub name: &'a str,
782}
783
784#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
BreakInsideCoroutine<'a> where G: rustc_errors::EmissionGuarantee
{
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
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)]
785#[diag("`{$name}` inside `{$kind}` {$source}", code = E0267)]
786pub(crate) struct BreakInsideCoroutine<'a> {
787 #[primary_span]
788 #[label("cannot `{$name}` inside `{$kind}` {$source}")]
789 pub span: Span,
790 #[label("enclosing `{$kind}` {$source}")]
791 pub coroutine_span: Span,
792 pub name: &'a str,
793 pub kind: &'a str,
794 pub source: &'a str,
795}
796
797#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
OutsideLoop<'a> where G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
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)]
798#[diag("`{$name}` outside of a loop{$is_break ->
799 [true] {\" or labeled block\"}
800 *[false] {\"\"}
801 }", code = E0268)]
802pub(crate) struct OutsideLoop<'a> {
803 #[primary_span]
804 #[label(
805 "cannot `{$name}` outside of a loop{$is_break ->
806 [true] {\" or labeled block\"}
807 *[false] {\"\"}
808 }"
809 )]
810 pub spans: Vec<Span>,
811 pub name: &'a str,
812 pub is_break: bool,
813 #[subdiagnostic]
814 pub suggestion: Option<OutsideLoopSuggestion>,
815}
816#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for OutsideLoopSuggestion {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
OutsideLoopSuggestion {
block_span: __binding_0, break_spans: __binding_1 } => {
let mut suggestions = Vec::new();
let __code_23 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("\'block: "))
});
let __code_24 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!(" \'block"))
});
suggestions.push((__binding_0, __code_23));
for __binding_1 in __binding_1 {
suggestions.push((__binding_1, __code_24.clone()));
}
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)]
817#[multipart_suggestion(
818 "consider labeling this block to be able to break within it",
819 applicability = "maybe-incorrect"
820)]
821pub(crate) struct OutsideLoopSuggestion {
822 #[suggestion_part(code = "'block: ")]
823 pub block_span: Span,
824 #[suggestion_part(code = " 'block")]
825 pub break_spans: Vec<Span>,
826}
827
828#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
UnlabeledInLabeledBlock<'a> where
G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
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, G> rustc_errors::Diagnostic<'_sess, G> for
UnlabeledCfInWhileCondition<'a> where
G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
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, G> rustc_errors::Diagnostic<'_sess, G> for
NoAssociatedItem<'tcx> where G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
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<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
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, G> rustc_errors::Diagnostic<'_sess, G> for
CannotCastToBool<'tcx> where G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
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, G> rustc_errors::Diagnostic<'_sess, G> for
CastEnumDrop<'tcx> where G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
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, G> rustc_errors::Diagnostic<'_sess, G> for
CastUnknownPointer where G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
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<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
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<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
CannotCastToBoolHelp::Numeric(__binding_0) => {
let __code_25 =
[::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_25, 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, G> rustc_errors::Diagnostic<'_sess, G> for CtorIsPrivate
where G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
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<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
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<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
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_26 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0}", __binding_2))
});
let __code_27 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!(""))
});
suggestions.push((__binding_0, __code_26));
if let Some(__binding_1) = __binding_1 {
suggestions.push((__binding_1, __code_27));
}
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<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
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<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
SuggestBoxingForReturnImplTrait::ChangeReturnType {
start_sp: __binding_0, end_sp: __binding_1 } => {
let mut suggestions = Vec::new();
let __code_28 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("Box<dyn"))
});
let __code_29 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!(">"))
});
suggestions.push((__binding_0, __code_28));
suggestions.push((__binding_1, __code_29));
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("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_30 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("Box::new("))
});
let __code_31 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!(")"))
});
for __binding_0 in __binding_0 {
suggestions.push((__binding_0, __code_30.clone()));
}
for __binding_1 in __binding_1 {
suggestions.push((__binding_1, __code_31.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, G> rustc_errors::Diagnostic<'_sess, G> for
SelfCtorFromOuterItem where G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
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<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
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, G> rustc_errors::Diagnostic<'_sess, G> for
SelfCtorFromOuterItemLint where G: rustc_errors::EmissionGuarantee
{
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
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<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
ReplaceWithName { span: __binding_0, name: __binding_1 } =>
{
let __code_32 =
[::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_32, 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, G> rustc_errors::Diagnostic<'_sess, G> for
CastThinPointerToWidePointer<'tcx> where
G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
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, G> rustc_errors::Diagnostic<'_sess, G> for
PassToVariadicFunction<'a, 'tcx> where
G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
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_33 =
[::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_33, 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, G> rustc_errors::Diagnostic<'_sess, G> for
PassFnItemToVariadicFunction where
G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
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_34 =
[::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_34, 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<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
ReplaceCommaWithSemicolon {
comma_span: __binding_0, descr: __binding_1 } => {
let __code_35 =
[::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_35, 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, G> rustc_errors::Diagnostic<'_sess, G> for
SupertraitItemShadowing where G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
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<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
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<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
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, G> rustc_errors::Diagnostic<'_sess, G> for
RegisterTypeUnstable<'a> where G: rustc_errors::EmissionGuarantee
{
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
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, G> rustc_errors::Diagnostic<'_sess, G> for
NakedAsmOutsideNakedFn where G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
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, G> rustc_errors::Diagnostic<'_sess, G> for NoPatterns
where G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
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, G> rustc_errors::Diagnostic<'_sess, G> for
ParamsNotAllowed where G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
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<G: EmissionGuarantee> Diagnostic<'_, G> for NakedFunctionsAsmBlock {
1214 #[track_caller]
1215 fn into_diag(self, dcx: DiagCtxtHandle<'_>, level: Level) -> Diag<'_, G> {
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(
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, G> rustc_errors::Diagnostic<'_sess, G> for
NakedFunctionsMustNakedAsm where
G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
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, G> rustc_errors::Diagnostic<'_sess, G> for
AbiCannotBeCalled where G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
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, G> rustc_errors::Diagnostic<'_sess, G> for
GpuKernelAbiCannotBeCalled where
G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
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, G> rustc_errors::Diagnostic<'_sess, G> for
ConstContinueBadLabel where G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
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, G> rustc_errors::Diagnostic<'_sess, G> for
ProjectOnNonPinProjectType where
G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
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_36 =
[::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_36, 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, G> rustc_errors::Diagnostic<'_sess, G> for
FloatLiteralF32Fallback where G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
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_37 =
[::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_37, 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}