1use rustc_errors::codes::*;
2use rustc_errors::{Applicability, Diag, EmissionGuarantee, LintDiagnostic, Subdiagnostic, msg};
3use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
4use rustc_middle::mir::AssertKind;
5use rustc_middle::query::Key;
6use rustc_middle::ty::TyCtxt;
7use rustc_session::lint::{self, Lint};
8use rustc_span::def_id::DefId;
9use rustc_span::{Ident, Span, Symbol};
10
11pub(crate) fn emit_inline_always_target_feature_diagnostic<'a, 'tcx>(
14 tcx: TyCtxt<'tcx>,
15 call_span: Span,
16 callee_def_id: DefId,
17 caller_def_id: DefId,
18 callee_only: &[&'a str],
19) {
20 tcx.node_span_lint(
21 lint::builtin::INLINE_ALWAYS_MISMATCHING_TARGET_FEATURES,
22 tcx.local_def_id_to_hir_id(caller_def_id.as_local().unwrap()),
23 call_span,
24 |lint| {
25 let callee = tcx.def_path_str(callee_def_id);
26 let caller = tcx.def_path_str(caller_def_id);
27
28 lint.primary_message(::alloc::__export::must_use({
::alloc::fmt::format(format_args!("call to `#[inline(always)]`-annotated `{0}` requires the same target features to be inlined",
callee))
})format!(
29 "call to `#[inline(always)]`-annotated `{callee}` \
30 requires the same target features to be inlined"
31 ));
32 lint.note("function will not be inlined");
33
34 lint.note(::alloc::__export::must_use({
::alloc::fmt::format(format_args!("the following target features are on `{1}` but missing from `{2}`: {0}",
callee_only.join(", "), callee, caller))
})format!(
35 "the following target features are on `{callee}` but missing from `{caller}`: {}",
36 callee_only.join(", ")
37 ));
38 lint.span_note(callee_def_id.default_span(tcx), ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("`{0}` is defined here", callee))
})format!("`{callee}` is defined here"));
39
40 let feats = callee_only.join(",");
41 lint.span_suggestion(
42 tcx.def_span(caller_def_id).shrink_to_lo(),
43 ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("add `#[target_feature]` attribute to `{0}`",
caller))
})format!("add `#[target_feature]` attribute to `{caller}`"),
44 ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("#[target_feature(enable = \"{0}\")]\n",
feats))
})format!("#[target_feature(enable = \"{feats}\")]\n"),
45 lint::Applicability::MaybeIncorrect,
46 );
47 },
48 );
49}
50
51#[derive(const _: () =
{
impl<'__a> rustc_errors::LintDiagnostic<'__a, ()> for
UnconditionalRecursion {
#[track_caller]
fn decorate_lint<'__b>(self,
diag: &'__b mut rustc_errors::Diag<'__a, ()>) {
match self {
UnconditionalRecursion {
span: __binding_0, call_sites: __binding_1 } => {
diag.primary_message(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("function cannot return without recursing")));
diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("a `loop` may express intention better if this is on purpose")));
;
diag.span_label(__binding_0,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("cannot return without recursing")));
for __binding_1 in __binding_1 {
diag.span_label(__binding_1,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("recursive call site")));
}
diag
}
};
}
}
};LintDiagnostic)]
52#[diag("function cannot return without recursing")]
53#[help("a `loop` may express intention better if this is on purpose")]
54pub(crate) struct UnconditionalRecursion {
55 #[label("cannot return without recursing")]
56 pub(crate) span: Span,
57 #[label("recursive call site")]
58 pub(crate) call_sites: Vec<Span>,
59}
60
61#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
InvalidForceInline 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 {
InvalidForceInline {
attr_span: __binding_0,
callee_span: __binding_1,
callee: __binding_2,
reason: __binding_3 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`{$callee}` is incompatible with `#[rustc_force_inline]`")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("incompatible due to: {$reason}")));
;
diag.arg("callee", __binding_2);
diag.arg("reason", __binding_3);
diag.span(__binding_0);
diag.span_label(__binding_1,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`{$callee}` defined here")));
diag
}
}
}
}
};Diagnostic)]
62#[diag("`{$callee}` is incompatible with `#[rustc_force_inline]`")]
63#[note("incompatible due to: {$reason}")]
64pub(crate) struct InvalidForceInline {
65 #[primary_span]
66 pub attr_span: Span,
67 #[label("`{$callee}` defined here")]
68 pub callee_span: Span,
69 pub callee: String,
70 pub reason: &'static str,
71}
72
73#[derive(const _: () =
{
impl<'__a> rustc_errors::LintDiagnostic<'__a, ()> for ConstMutate {
#[track_caller]
fn decorate_lint<'__b>(self,
diag: &'__b mut rustc_errors::Diag<'__a, ()>) {
match self {
ConstMutate::Modify { konst: __binding_0 } => {
diag.primary_message(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("attempting to modify a `const` item")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("each usage of a `const` item creates a new temporary; the original `const` item will not be modified")));
;
diag.span_note(__binding_0,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`const` item defined here")));
diag
}
ConstMutate::MutBorrow {
method_call: __binding_0, konst: __binding_1 } => {
diag.primary_message(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("taking a mutable reference to a `const` item")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("each usage of a `const` item creates a new temporary")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the mutable reference will refer to this temporary, not the original `const` item")));
;
if let Some(__binding_0) = __binding_0 {
diag.span_note(__binding_0,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("mutable reference created due to call to this method")));
}
diag.span_note(__binding_1,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`const` item defined here")));
diag
}
};
}
}
};LintDiagnostic)]
74pub(crate) enum ConstMutate {
75 #[diag("attempting to modify a `const` item")]
76 #[note(
77 "each usage of a `const` item creates a new temporary; the original `const` item will not be modified"
78 )]
79 Modify {
80 #[note("`const` item defined here")]
81 konst: Span,
82 },
83 #[diag("taking a mutable reference to a `const` item")]
84 #[note("each usage of a `const` item creates a new temporary")]
85 #[note("the mutable reference will refer to this temporary, not the original `const` item")]
86 MutBorrow {
87 #[note("mutable reference created due to call to this method")]
88 method_call: Option<Span>,
89 #[note("`const` item defined here")]
90 konst: Span,
91 },
92}
93
94#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
UnalignedPackedRef 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 {
UnalignedPackedRef {
span: __binding_0, ty_descr: __binding_1, align: __binding_2
} => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("reference to field of packed {$ty_descr} is unaligned")));
diag.code(E0793);
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this {$ty_descr} is {$align ->\n [one] {\"\"}\n *[other] {\"at most \"}\n }{$align}-byte aligned, but the type of this field may require higher alignment")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)")));
diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)")));
;
diag.arg("ty_descr", __binding_1);
diag.arg("align", __binding_2);
diag.span(__binding_0);
diag
}
}
}
}
};Diagnostic)]
95#[diag("reference to field of packed {$ty_descr} is unaligned", code = E0793)]
96#[note(
97 "this {$ty_descr} is {$align ->
98 [one] {\"\"}
99 *[other] {\"at most \"}
100 }{$align}-byte aligned, but the type of this field may require higher alignment"
101)]
102#[note(
103 "creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)"
104)]
105#[help(
106 "copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)"
107)]
108pub(crate) struct UnalignedPackedRef {
109 #[primary_span]
110 pub span: Span,
111 pub ty_descr: &'static str,
112 pub align: u64,
113}
114
115#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
UnknownPassName<'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 {
UnknownPassName { name: __binding_0 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("MIR pass `{$name}` is unknown and will be ignored")));
;
diag.arg("name", __binding_0);
diag
}
}
}
}
};Diagnostic)]
116#[diag("MIR pass `{$name}` is unknown and will be ignored")]
117pub(crate) struct UnknownPassName<'a> {
118 pub(crate) name: &'a str,
119}
120
121pub(crate) struct AssertLint<P> {
122 pub span: Span,
123 pub assert_kind: AssertKind<P>,
124 pub lint_kind: AssertLintKind,
125}
126
127pub(crate) enum AssertLintKind {
128 ArithmeticOverflow,
129 UnconditionalPanic,
130}
131
132impl<'a, P: std::fmt::Debug> LintDiagnostic<'a, ()> for AssertLint<P> {
133 fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
134 diag.primary_message(match self.lint_kind {
135 AssertLintKind::ArithmeticOverflow => {
136 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this arithmetic operation will overflow"))msg!("this arithmetic operation will overflow")
137 }
138 AssertLintKind::UnconditionalPanic => {
139 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this operation will panic at runtime"))msg!("this operation will panic at runtime")
140 }
141 });
142 let label = self.assert_kind.diagnostic_message();
143 self.assert_kind.add_args(&mut |name, value| {
144 diag.arg(name, value);
145 });
146 diag.span_label(self.span, label);
147 }
148}
149
150impl AssertLintKind {
151 pub(crate) fn lint(&self) -> &'static Lint {
152 match self {
153 AssertLintKind::ArithmeticOverflow => lint::builtin::ARITHMETIC_OVERFLOW,
154 AssertLintKind::UnconditionalPanic => lint::builtin::UNCONDITIONAL_PANIC,
155 }
156 }
157}
158
159#[derive(const _: () =
{
impl<'__a> rustc_errors::LintDiagnostic<'__a, ()> for AsmUnwindCall {
#[track_caller]
fn decorate_lint<'__b>(self,
diag: &'__b mut rustc_errors::Diag<'__a, ()>) {
match self {
AsmUnwindCall { span: __binding_0 } => {
diag.primary_message(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("call to inline assembly that may unwind")));
;
diag.span_label(__binding_0,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("call to inline assembly that may unwind")));
diag
}
};
}
}
};LintDiagnostic)]
160#[diag("call to inline assembly that may unwind")]
161pub(crate) struct AsmUnwindCall {
162 #[label("call to inline assembly that may unwind")]
163 pub span: Span,
164}
165
166#[derive(const _: () =
{
impl<'__a> rustc_errors::LintDiagnostic<'__a, ()> for FfiUnwindCall {
#[track_caller]
fn decorate_lint<'__b>(self,
diag: &'__b mut rustc_errors::Diag<'__a, ()>) {
match self {
FfiUnwindCall { span: __binding_0, foreign: __binding_1 } =>
{
diag.primary_message(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("call to {$foreign ->\n [true] foreign function\n *[false] function pointer\n } with FFI-unwind ABI")));
;
diag.arg("foreign", __binding_1);
diag.span_label(__binding_0,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("call to {$foreign ->\n [true] foreign function\n *[false] function pointer\n } with FFI-unwind ABI")));
diag
}
};
}
}
};LintDiagnostic)]
167#[diag(
168 "call to {$foreign ->
169 [true] foreign function
170 *[false] function pointer
171 } with FFI-unwind ABI"
172)]
173pub(crate) struct FfiUnwindCall {
174 #[label(
175 "call to {$foreign ->
176 [true] foreign function
177 *[false] function pointer
178 } with FFI-unwind ABI"
179 )]
180 pub span: Span,
181 pub foreign: bool,
182}
183
184#[derive(const _: () =
{
impl<'__a> rustc_errors::LintDiagnostic<'__a, ()> for FnItemRef {
#[track_caller]
fn decorate_lint<'__b>(self,
diag: &'__b mut rustc_errors::Diag<'__a, ()>) {
match self {
FnItemRef {
span: __binding_0, sugg: __binding_1, ident: __binding_2 }
=> {
diag.primary_message(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("taking a reference to a function item does not give a function pointer")));
;
let __code_0 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0}", __binding_1))
})].into_iter();
diag.arg("sugg", __binding_1);
diag.arg("ident", __binding_2);
diag.span_suggestions_with_style(__binding_0,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("cast `{$ident}` to obtain a function pointer")),
__code_0, rustc_errors::Applicability::Unspecified,
rustc_errors::SuggestionStyle::ShowCode);
diag
}
};
}
}
};LintDiagnostic)]
185#[diag("taking a reference to a function item does not give a function pointer")]
186pub(crate) struct FnItemRef {
187 #[suggestion(
188 "cast `{$ident}` to obtain a function pointer",
189 code = "{sugg}",
190 applicability = "unspecified"
191 )]
192 pub span: Span,
193 pub sugg: String,
194 pub ident: Ident,
195}
196
197#[derive(const _: () =
{
impl<'__a> rustc_errors::LintDiagnostic<'__a, ()> for
UnusedCaptureMaybeCaptureRef {
#[track_caller]
fn decorate_lint<'__b>(self,
diag: &'__b mut rustc_errors::Diag<'__a, ()>) {
match self {
UnusedCaptureMaybeCaptureRef { name: __binding_0 } => {
diag.primary_message(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("value captured by `{$name}` is never read")));
diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("did you mean to capture by reference instead?")));
;
diag.arg("name", __binding_0);
diag
}
};
}
}
};LintDiagnostic)]
198#[diag("value captured by `{$name}` is never read")]
199#[help("did you mean to capture by reference instead?")]
200pub(crate) struct UnusedCaptureMaybeCaptureRef {
201 pub name: Symbol,
202}
203
204#[derive(const _: () =
{
impl<'__a> rustc_errors::LintDiagnostic<'__a, ()> for
UnusedVarAssignedOnly {
#[track_caller]
fn decorate_lint<'__b>(self,
diag: &'__b mut rustc_errors::Diag<'__a, ()>) {
match self {
UnusedVarAssignedOnly { name: __binding_0, typo: __binding_1
} => {
diag.primary_message(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("variable `{$name}` is assigned to, but never used")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider using `_{$name}` instead")));
;
diag.arg("name", __binding_0);
if let Some(__binding_1) = __binding_1 {
diag.subdiagnostic(__binding_1);
}
diag
}
};
}
}
};LintDiagnostic)]
205#[diag("variable `{$name}` is assigned to, but never used")]
206#[note("consider using `_{$name}` instead")]
207pub(crate) struct UnusedVarAssignedOnly {
208 pub name: Symbol,
209 #[subdiagnostic]
210 pub typo: Option<PatternTypo>,
211}
212
213#[derive(const _: () =
{
impl<'__a> rustc_errors::LintDiagnostic<'__a, ()> for UnusedAssign {
#[track_caller]
fn decorate_lint<'__b>(self,
diag: &'__b mut rustc_errors::Diag<'__a, ()>) {
match self {
UnusedAssign {
name: __binding_0,
suggestion: __binding_1,
help: __binding_2 } => {
diag.primary_message(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("value assigned to `{$name}` is never read")));
;
diag.arg("name", __binding_0);
if let Some(__binding_1) = __binding_1 {
diag.subdiagnostic(__binding_1);
}
if __binding_2 {
diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("maybe it is overwritten before being read?")));
}
diag
}
};
}
}
};LintDiagnostic)]
214#[diag("value assigned to `{$name}` is never read")]
215pub(crate) struct UnusedAssign {
216 pub name: Symbol,
217 #[subdiagnostic]
218 pub suggestion: Option<UnusedAssignSuggestion>,
219 #[help("maybe it is overwritten before being read?")]
220 pub help: bool,
221}
222
223#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for UnusedAssignSuggestion {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
UnusedAssignSuggestion {
pre: __binding_0,
ty_span: __binding_1,
ty_ref_span: __binding_2,
pre_lhs_span: __binding_3,
rhs_borrow_span: __binding_4 } => {
let mut suggestions = Vec::new();
let __code_1 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0}mut ", __binding_0))
});
let __code_2 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!(""))
});
let __code_3 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("*"))
});
let __code_4 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!(""))
});
if let Some(__binding_1) = __binding_1 {
suggestions.push((__binding_1, __code_1));
}
suggestions.push((__binding_2, __code_2));
suggestions.push((__binding_3, __code_3));
suggestions.push((__binding_4, __code_4));
diag.store_args();
diag.arg("pre", __binding_0);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("you might have meant to mutate the pointed at value being passed in, instead of changing the reference in the local binding")));
diag.multipart_suggestion_with_style(__message, suggestions,
rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowCode);
diag.restore_args();
}
}
}
}
};Subdiagnostic)]
224#[multipart_suggestion(
225 "you might have meant to mutate the pointed at value being passed in, instead of changing the reference in the local binding",
226 applicability = "maybe-incorrect"
227)]
228pub(crate) struct UnusedAssignSuggestion {
229 pub pre: &'static str,
230 #[suggestion_part(code = "{pre}mut ")]
231 pub ty_span: Option<Span>,
232 #[suggestion_part(code = "")]
233 pub ty_ref_span: Span,
234 #[suggestion_part(code = "*")]
235 pub pre_lhs_span: Span,
236 #[suggestion_part(code = "")]
237 pub rhs_borrow_span: Span,
238}
239
240#[derive(const _: () =
{
impl<'__a> rustc_errors::LintDiagnostic<'__a, ()> for
UnusedAssignPassed {
#[track_caller]
fn decorate_lint<'__b>(self,
diag: &'__b mut rustc_errors::Diag<'__a, ()>) {
match self {
UnusedAssignPassed { name: __binding_0 } => {
diag.primary_message(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("value passed to `{$name}` is never read")));
diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("maybe it is overwritten before being read?")));
;
diag.arg("name", __binding_0);
diag
}
};
}
}
};LintDiagnostic)]
241#[diag("value passed to `{$name}` is never read")]
242#[help("maybe it is overwritten before being read?")]
243pub(crate) struct UnusedAssignPassed {
244 pub name: Symbol,
245}
246
247#[derive(const _: () =
{
impl<'__a> rustc_errors::LintDiagnostic<'__a, ()> for UnusedVariable {
#[track_caller]
fn decorate_lint<'__b>(self,
diag: &'__b mut rustc_errors::Diag<'__a, ()>) {
match self {
UnusedVariable {
name: __binding_0,
string_interp: __binding_1,
sugg: __binding_2 } => {
diag.primary_message(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("unused variable: `{$name}`")));
;
diag.arg("name", __binding_0);
for __binding_1 in __binding_1 {
diag.subdiagnostic(__binding_1);
}
diag.subdiagnostic(__binding_2);
diag
}
};
}
}
};LintDiagnostic)]
248#[diag("unused variable: `{$name}`")]
249pub(crate) struct UnusedVariable {
250 pub name: Symbol,
251 #[subdiagnostic]
252 pub string_interp: Vec<UnusedVariableStringInterp>,
253 #[subdiagnostic]
254 pub sugg: UnusedVariableSugg,
255}
256
257#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for UnusedVariableSugg {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
UnusedVariableSugg::TryIgnore {
shorthands: __binding_0,
non_shorthands: __binding_1,
name: __binding_2 } => {
let mut suggestions = Vec::new();
let __code_5 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0}: _", __binding_2))
});
let __code_6 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("_"))
});
for __binding_0 in __binding_0 {
suggestions.push((__binding_0, __code_5.clone()));
}
for __binding_1 in __binding_1 {
suggestions.push((__binding_1, __code_6.clone()));
}
diag.store_args();
diag.arg("name", __binding_2);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("try ignoring the field")));
diag.multipart_suggestion_with_style(__message, suggestions,
rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::ShowCode);
diag.restore_args();
}
UnusedVariableSugg::TryPrefix {
spans: __binding_0, name: __binding_1, typo: __binding_2 }
=> {
let mut suggestions = Vec::new();
let __code_7 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("_{0}", __binding_1))
});
for __binding_0 in __binding_0 {
suggestions.push((__binding_0, __code_7.clone()));
}
if let Some(__binding_2) = __binding_2 {
__binding_2.add_to_diag(diag);
}
diag.store_args();
diag.arg("name", __binding_1);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("if this is intentional, prefix it with an underscore")));
diag.multipart_suggestion_with_style(__message, suggestions,
rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::ShowCode);
diag.restore_args();
}
UnusedVariableSugg::NoSugg {
span: __binding_0, name: __binding_1 } => {
diag.store_args();
diag.arg("name", __binding_1);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`{$name}` is captured in macro and introduced a unused variable")));
diag.span_help(__binding_0, __message);
diag.restore_args();
}
}
}
}
};Subdiagnostic)]
258pub(crate) enum UnusedVariableSugg {
259 #[multipart_suggestion("try ignoring the field", applicability = "machine-applicable")]
260 TryIgnore {
261 #[suggestion_part(code = "{name}: _")]
262 shorthands: Vec<Span>,
263 #[suggestion_part(code = "_")]
264 non_shorthands: Vec<Span>,
265 name: Symbol,
266 },
267
268 #[multipart_suggestion(
269 "if this is intentional, prefix it with an underscore",
270 applicability = "machine-applicable"
271 )]
272 TryPrefix {
273 #[suggestion_part(code = "_{name}")]
274 spans: Vec<Span>,
275 name: Symbol,
276 #[subdiagnostic]
277 typo: Option<PatternTypo>,
278 },
279
280 #[help("`{$name}` is captured in macro and introduced a unused variable")]
281 NoSugg {
282 #[primary_span]
283 span: Span,
284 name: Symbol,
285 },
286}
287
288pub(crate) struct UnusedVariableStringInterp {
289 pub lit: Span,
290}
291
292impl Subdiagnostic for UnusedVariableStringInterp {
293 fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
294 diag.span_label(
295 self.lit,
296 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("you might have meant to use string interpolation in this string literal"))msg!("you might have meant to use string interpolation in this string literal"),
297 );
298 diag.multipart_suggestion(
299 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("string interpolation only works in `format!` invocations"))msg!("string interpolation only works in `format!` invocations"),
300 <[_]>::into_vec(::alloc::boxed::box_new([(self.lit.shrink_to_lo(),
String::from("format!(")),
(self.lit.shrink_to_hi(), String::from(")"))]))vec![
301 (self.lit.shrink_to_lo(), String::from("format!(")),
302 (self.lit.shrink_to_hi(), String::from(")")),
303 ],
304 Applicability::MachineApplicable,
305 );
306 }
307}
308
309#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for PatternTypo {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
PatternTypo {
span: __binding_0,
code: __binding_1,
item_name: __binding_2,
kind: __binding_3 } => {
let mut suggestions = Vec::new();
let __code_8 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0}", __binding_1))
});
suggestions.push((__binding_0, __code_8));
diag.store_args();
diag.arg("code", __binding_1);
diag.arg("item_name", __binding_2);
diag.arg("kind", __binding_3);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("you might have meant to pattern match on the similarly named {$kind} `{$item_name}`")));
diag.multipart_suggestion_with_style(__message, suggestions,
rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowAlways);
diag.restore_args();
}
}
}
}
};Subdiagnostic)]
310#[multipart_suggestion(
311 "you might have meant to pattern match on the similarly named {$kind} `{$item_name}`",
312 style = "verbose",
313 applicability = "maybe-incorrect"
314)]
315pub(crate) struct PatternTypo {
316 #[suggestion_part(code = "{code}")]
317 pub span: Span,
318 pub code: String,
319 pub item_name: Symbol,
320 pub kind: &'static str,
321}
322
323pub(crate) struct MustNotSupend<'a, 'tcx> {
324 pub tcx: TyCtxt<'tcx>,
325 pub yield_sp: Span,
326 pub reason: Option<MustNotSuspendReason>,
327 pub src_sp: Span,
328 pub pre: &'a str,
329 pub def_id: DefId,
330 pub post: &'a str,
331}
332
333impl<'a> LintDiagnostic<'a, ()> for MustNotSupend<'_, '_> {
335 fn decorate_lint<'b>(self, diag: &'b mut rustc_errors::Diag<'a, ()>) {
336 diag.primary_message(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$pre}`{$def_path}`{$post} held across a suspend point, but should not be"))msg!(
337 "{$pre}`{$def_path}`{$post} held across a suspend point, but should not be"
338 ));
339 diag.span_label(self.yield_sp, rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the value is held across this suspend point"))msg!("the value is held across this suspend point"));
340 if let Some(reason) = self.reason {
341 diag.subdiagnostic(reason);
342 }
343 diag.span_help(self.src_sp, rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider using a block (`{\"{ ... }\"}`) to shrink the value's scope, ending before the suspend point"))msg!("consider using a block (`{\"{ ... }\"}`) to shrink the value's scope, ending before the suspend point"));
344 diag.arg("pre", self.pre);
345 diag.arg("def_path", self.tcx.def_path_str(self.def_id));
346 diag.arg("post", self.post);
347 }
348}
349
350#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for MustNotSuspendReason {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
MustNotSuspendReason {
span: __binding_0, reason: __binding_1 } => {
diag.store_args();
diag.arg("reason", __binding_1);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$reason}")));
diag.span_note(__binding_0, __message);
diag.restore_args();
}
}
}
}
};Subdiagnostic)]
351#[note("{$reason}")]
352pub(crate) struct MustNotSuspendReason {
353 #[primary_span]
354 pub span: Span,
355 pub reason: Symbol,
356}
357
358#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
ForceInlineFailure 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 {
ForceInlineFailure {
caller_span: __binding_0,
callee_span: __binding_1,
attr_span: __binding_2,
call_span: __binding_3,
callee: __binding_4,
caller: __binding_5,
reason: __binding_6,
justification: __binding_7 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`{$callee}` could not be inlined into `{$caller}` but is required to be inlined")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("could not be inlined due to: {$reason}")));
;
diag.arg("callee", __binding_4);
diag.arg("caller", __binding_5);
diag.arg("reason", __binding_6);
diag.span_label(__binding_0,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("within `{$caller}`...")));
diag.span_label(__binding_1,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`{$callee}` defined here")));
diag.span_label(__binding_2,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("annotation here")));
diag.span(__binding_3);
diag.span_label(__binding_3,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("...`{$callee}` called here")));
if let Some(__binding_7) = __binding_7 {
diag.subdiagnostic(__binding_7);
}
diag
}
}
}
}
};Diagnostic)]
359#[diag("`{$callee}` could not be inlined into `{$caller}` but is required to be inlined")]
360#[note("could not be inlined due to: {$reason}")]
361pub(crate) struct ForceInlineFailure {
362 #[label("within `{$caller}`...")]
363 pub caller_span: Span,
364 #[label("`{$callee}` defined here")]
365 pub callee_span: Span,
366 #[label("annotation here")]
367 pub attr_span: Span,
368 #[primary_span]
369 #[label("...`{$callee}` called here")]
370 pub call_span: Span,
371 pub callee: String,
372 pub caller: String,
373 pub reason: &'static str,
374 #[subdiagnostic]
375 pub justification: Option<ForceInlineJustification>,
376}
377
378#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for ForceInlineJustification {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
ForceInlineJustification { sym: __binding_0 } => {
diag.store_args();
diag.arg("sym", __binding_0);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`{$callee}` is required to be inlined to: {$sym}")));
diag.note(__message);
diag.restore_args();
}
}
}
}
};Subdiagnostic)]
379#[note("`{$callee}` is required to be inlined to: {$sym}")]
380pub(crate) struct ForceInlineJustification {
381 pub sym: Symbol,
382}