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