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