1use rustc_data_structures::fx::{FxHashSet, FxIndexSet};
2use rustc_errors::codes::*;
3use rustc_errors::{
4 Applicability, Diag, DiagCtxtHandle, DiagMessage, DiagStyledString, Diagnostic,
5 EmissionGuarantee, IntoDiagArg, Level, MultiSpan, Subdiagnostic, msg,
6};
7use rustc_hir::def::DefKind;
8use rustc_hir::def_id::{DefId, LocalDefId};
9use rustc_hir::intravisit::{Visitor, VisitorExt, walk_ty};
10use rustc_hir::{self as hir, AmbigArg, FnRetTy, GenericParamKind, Node};
11use rustc_macros::{Diagnostic, Subdiagnostic};
12use rustc_middle::ty::print::{PrintTraitRefExt as _, TraitRefPrintOnlyTraitPath};
13use rustc_middle::ty::{self, Binder, ClosureKind, FnSig, GenericArg, Region, Ty, TyCtxt};
14use rustc_span::{BytePos, Ident, Span, Symbol, kw, sym};
15
16use crate::error_reporting::infer::ObligationCauseAsDiagArg;
17use crate::error_reporting::infer::need_type_info::UnderspecifiedArgKind;
18use crate::error_reporting::infer::nice_region_error::placeholder_error::Highlighted;
19
20pub mod note_and_explain;
21
22#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
UnableToConstructConstantValue<'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 {
UnableToConstructConstantValue {
span: __binding_0, unevaluated: __binding_1 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("unable to construct a constant value for the unevaluated constant {$unevaluated}")));
;
diag.arg("unevaluated", __binding_1);
diag.span(__binding_0);
diag
}
}
}
}
};Diagnostic)]
23#[diag("unable to construct a constant value for the unevaluated constant {$unevaluated}")]
24pub struct UnableToConstructConstantValue<'a> {
25 #[primary_span]
26 pub span: Span,
27 pub unevaluated: ty::UnevaluatedConst<'a>,
28}
29
30#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
NoValueInOnUnimplemented 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 {
NoValueInOnUnimplemented { span: __binding_0 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this attribute must have a value")));
diag.code(E0232);
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("e.g. `#[rustc_on_unimplemented(message=\"foo\")]`")));
;
diag.span(__binding_0);
diag.span_label(__binding_0,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("expected value here")));
diag
}
}
}
}
};Diagnostic)]
31#[diag("this attribute must have a value", code = E0232)]
32#[note("e.g. `#[rustc_on_unimplemented(message=\"foo\")]`")]
33pub struct NoValueInOnUnimplemented {
34 #[primary_span]
35 #[label("expected value here")]
36 pub span: Span,
37}
38
39pub struct NegativePositiveConflict<'tcx> {
40 pub impl_span: Span,
41 pub trait_desc: ty::TraitRef<'tcx>,
42 pub self_ty: Option<Ty<'tcx>>,
43 pub negative_impl_span: Result<Span, Symbol>,
44 pub positive_impl_span: Result<Span, Symbol>,
45}
46
47impl<G: EmissionGuarantee> Diagnostic<'_, G> for NegativePositiveConflict<'_> {
48 #[track_caller]
49 fn into_diag(self, dcx: DiagCtxtHandle<'_>, level: Level) -> Diag<'_, G> {
50 let mut diag = Diag::new(
51 dcx,
52 level,
53 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("found both positive and negative implementation of trait `{$trait_desc}`{$self_desc ->\n [none] {\"\"}\n *[default] {\" \"}for type `{$self_desc}`\n }:"))msg!(
54 "found both positive and negative implementation of trait `{$trait_desc}`{$self_desc ->
55 [none] {\"\"}
56 *[default] {\" \"}for type `{$self_desc}`
57 }:"
58 ),
59 );
60 diag.arg("trait_desc", self.trait_desc.print_only_trait_path().to_string());
61 diag.arg("self_desc", self.self_ty.map_or_else(|| "none".to_string(), |ty| ty.to_string()));
62 diag.span(self.impl_span);
63 diag.code(E0751);
64 match self.negative_impl_span {
65 Ok(span) => {
66 diag.span_label(span, rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("negative implementation here"))msg!("negative implementation here"));
67 }
68 Err(cname) => {
69 diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("negative implementation in crate `{$negative_impl_cname}`"))msg!("negative implementation in crate `{$negative_impl_cname}`"));
70 diag.arg("negative_impl_cname", cname.to_string());
71 }
72 }
73 match self.positive_impl_span {
74 Ok(span) => {
75 diag.span_label(span, rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("positive implementation here"))msg!("positive implementation here"));
76 }
77 Err(cname) => {
78 diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("positive implementation in crate `{$positive_impl_cname}`"))msg!("positive implementation in crate `{$positive_impl_cname}`"));
79 diag.arg("positive_impl_cname", cname.to_string());
80 }
81 }
82 diag
83 }
84}
85
86#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
InherentProjectionNormalizationOverflow 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 {
InherentProjectionNormalizationOverflow {
span: __binding_0, ty: __binding_1 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("overflow evaluating associated type `{$ty}`")));
;
diag.arg("ty", __binding_1);
diag.span(__binding_0);
diag
}
}
}
}
};Diagnostic)]
87#[diag("overflow evaluating associated type `{$ty}`")]
88pub struct InherentProjectionNormalizationOverflow {
89 #[primary_span]
90 pub span: Span,
91 pub ty: String,
92}
93
94pub enum AdjustSignatureBorrow {
95 Borrow { to_borrow: Vec<(Span, String)> },
96 RemoveBorrow { remove_borrow: Vec<(Span, String)> },
97}
98
99impl Subdiagnostic for AdjustSignatureBorrow {
100 fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
101 match self {
102 AdjustSignatureBorrow::Borrow { to_borrow } => {
103 diag.arg("borrow_len", to_borrow.len());
104 diag.multipart_suggestion(
105 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider adjusting the signature so it borrows its {$borrow_len ->\n [one] argument\n *[other] arguments\n }"))msg!(
106 "consider adjusting the signature so it borrows its {$borrow_len ->
107 [one] argument
108 *[other] arguments
109 }"
110 ),
111 to_borrow,
112 Applicability::MaybeIncorrect,
113 );
114 }
115 AdjustSignatureBorrow::RemoveBorrow { remove_borrow } => {
116 diag.arg("remove_borrow_len", remove_borrow.len());
117 diag.multipart_suggestion(
118 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider adjusting the signature so it does not borrow its {$remove_borrow_len ->\n [one] argument\n *[other] arguments\n }"))msg!(
119 "consider adjusting the signature so it does not borrow its {$remove_borrow_len ->
120 [one] argument
121 *[other] arguments
122 }"
123 ),
124 remove_borrow,
125 Applicability::MaybeIncorrect,
126 );
127 }
128 }
129 }
130}
131
132#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
ClosureKindMismatch 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 {
ClosureKindMismatch {
closure_span: __binding_0,
expected: __binding_1,
found: __binding_2,
cause_span: __binding_3,
trait_prefix: __binding_4,
fn_once_label: __binding_5,
fn_mut_label: __binding_6 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("expected a closure that implements the `{$trait_prefix}{$expected}` trait, but this closure only implements `{$trait_prefix}{$found}`")));
diag.code(E0525);
;
diag.arg("expected", __binding_1);
diag.arg("found", __binding_2);
diag.arg("trait_prefix", __binding_4);
diag.span(__binding_0);
diag.span_label(__binding_0,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this closure implements `{$trait_prefix}{$found}`, not `{$trait_prefix}{$expected}`")));
diag.span_label(__binding_3,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the requirement to implement `{$trait_prefix}{$expected}` derives from here")));
if let Some(__binding_5) = __binding_5 {
diag.subdiagnostic(__binding_5);
}
if let Some(__binding_6) = __binding_6 {
diag.subdiagnostic(__binding_6);
}
diag
}
}
}
}
};Diagnostic)]
133#[diag("expected a closure that implements the `{$trait_prefix}{$expected}` trait, but this closure only implements `{$trait_prefix}{$found}`", code = E0525)]
134pub struct ClosureKindMismatch {
135 #[primary_span]
136 #[label("this closure implements `{$trait_prefix}{$found}`, not `{$trait_prefix}{$expected}`")]
137 pub closure_span: Span,
138 pub expected: ClosureKind,
139 pub found: ClosureKind,
140 #[label("the requirement to implement `{$trait_prefix}{$expected}` derives from here")]
141 pub cause_span: Span,
142
143 pub trait_prefix: &'static str,
144
145 #[subdiagnostic]
146 pub fn_once_label: Option<ClosureFnOnceLabel>,
147
148 #[subdiagnostic]
149 pub fn_mut_label: Option<ClosureFnMutLabel>,
150}
151
152#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for ClosureFnOnceLabel {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
ClosureFnOnceLabel {
span: __binding_0,
place: __binding_1,
trait_prefix: __binding_2 } => {
diag.store_args();
diag.arg("place", __binding_1);
diag.arg("trait_prefix", __binding_2);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("closure is `{$trait_prefix}FnOnce` because it moves the variable `{$place}` out of its environment")));
diag.span_label(__binding_0, __message);
diag.restore_args();
}
}
}
}
};Subdiagnostic)]
153#[label(
154 "closure is `{$trait_prefix}FnOnce` because it moves the variable `{$place}` out of its environment"
155)]
156pub struct ClosureFnOnceLabel {
157 #[primary_span]
158 pub span: Span,
159 pub place: String,
160 pub trait_prefix: &'static str,
161}
162
163#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for ClosureFnMutLabel {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
ClosureFnMutLabel {
span: __binding_0,
place: __binding_1,
trait_prefix: __binding_2 } => {
diag.store_args();
diag.arg("place", __binding_1);
diag.arg("trait_prefix", __binding_2);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("closure is `{$trait_prefix}FnMut` because it mutates the variable `{$place}` here")));
diag.span_label(__binding_0, __message);
diag.restore_args();
}
}
}
}
};Subdiagnostic)]
164#[label("closure is `{$trait_prefix}FnMut` because it mutates the variable `{$place}` here")]
165pub struct ClosureFnMutLabel {
166 #[primary_span]
167 pub span: Span,
168 pub place: String,
169 pub trait_prefix: &'static str,
170}
171
172#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
CoroClosureNotFn 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 {
CoroClosureNotFn {
span: __binding_0, kind: __binding_1, coro_kind: __binding_2
} => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$coro_kind}closure does not implement `{$kind}` because it captures state from its environment")));
;
diag.arg("kind", __binding_1);
diag.arg("coro_kind", __binding_2);
diag.span(__binding_0);
diag
}
}
}
}
};Diagnostic)]
173#[diag(
174 "{$coro_kind}closure does not implement `{$kind}` because it captures state from its environment"
175)]
176pub(crate) struct CoroClosureNotFn {
177 #[primary_span]
178 pub span: Span,
179 pub kind: &'static str,
180 pub coro_kind: String,
181}
182
183#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
AnnotationRequired<'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 {
AnnotationRequired {
span: __binding_0,
source_kind: __binding_1,
source_name: __binding_2,
failure_span: __binding_3,
bad_label: __binding_4,
infer_subdiags: __binding_5,
multi_suggestions: __binding_6 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$source_kind ->\n[closure] type annotations needed for the closure `{$source_name}`\n[normal] type annotations needed for `{$source_name}`\n*[other] type annotations needed\n}")));
diag.code(E0282);
;
diag.arg("source_kind", __binding_1);
diag.arg("source_name", __binding_2);
diag.span(__binding_0);
if let Some(__binding_3) = __binding_3 {
diag.span_label(__binding_3,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("type must be known at this point")));
}
if let Some(__binding_4) = __binding_4 {
diag.subdiagnostic(__binding_4);
}
for __binding_5 in __binding_5 {
diag.subdiagnostic(__binding_5);
}
for __binding_6 in __binding_6 {
diag.subdiagnostic(__binding_6);
}
diag
}
}
}
}
};Diagnostic)]
184#[diag("{$source_kind ->
185[closure] type annotations needed for the closure `{$source_name}`
186[normal] type annotations needed for `{$source_name}`
187*[other] type annotations needed
188}", code = E0282)]
189pub struct AnnotationRequired<'a> {
190 #[primary_span]
191 pub span: Span,
192 pub source_kind: &'static str,
193 pub source_name: &'a str,
194 #[label("type must be known at this point")]
195 pub failure_span: Option<Span>,
196 #[subdiagnostic]
197 pub bad_label: Option<InferenceBadError<'a>>,
198 #[subdiagnostic]
199 pub infer_subdiags: Vec<SourceKindSubdiag<'a>>,
200 #[subdiagnostic]
201 pub multi_suggestions: Vec<SourceKindMultiSuggestion<'a>>,
202}
203
204#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
AmbiguousImpl<'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 {
AmbiguousImpl {
span: __binding_0,
source_kind: __binding_1,
source_name: __binding_2,
failure_span: __binding_3,
bad_label: __binding_4,
infer_subdiags: __binding_5,
multi_suggestions: __binding_6 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$source_kind ->\n[closure] type annotations needed for the closure `{$source_name}`\n[normal] type annotations needed for `{$source_name}`\n*[other] type annotations needed\n}")));
diag.code(E0283);
;
diag.arg("source_kind", __binding_1);
diag.arg("source_name", __binding_2);
diag.span(__binding_0);
if let Some(__binding_3) = __binding_3 {
diag.span_label(__binding_3,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("type must be known at this point")));
}
if let Some(__binding_4) = __binding_4 {
diag.subdiagnostic(__binding_4);
}
for __binding_5 in __binding_5 {
diag.subdiagnostic(__binding_5);
}
for __binding_6 in __binding_6 {
diag.subdiagnostic(__binding_6);
}
diag
}
}
}
}
};Diagnostic)]
206#[diag("{$source_kind ->
207[closure] type annotations needed for the closure `{$source_name}`
208[normal] type annotations needed for `{$source_name}`
209*[other] type annotations needed
210}", code = E0283)]
211pub struct AmbiguousImpl<'a> {
212 #[primary_span]
213 pub span: Span,
214 pub source_kind: &'static str,
215 pub source_name: &'a str,
216 #[label("type must be known at this point")]
217 pub failure_span: Option<Span>,
218 #[subdiagnostic]
219 pub bad_label: Option<InferenceBadError<'a>>,
220 #[subdiagnostic]
221 pub infer_subdiags: Vec<SourceKindSubdiag<'a>>,
222 #[subdiagnostic]
223 pub multi_suggestions: Vec<SourceKindMultiSuggestion<'a>>,
224}
225
226#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
AmbiguousReturn<'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 {
AmbiguousReturn {
span: __binding_0,
source_kind: __binding_1,
source_name: __binding_2,
failure_span: __binding_3,
bad_label: __binding_4,
infer_subdiags: __binding_5,
multi_suggestions: __binding_6 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$source_kind ->\n[closure] type annotations needed for the closure `{$source_name}`\n[normal] type annotations needed for `{$source_name}`\n*[other] type annotations needed\n}")));
diag.code(E0284);
;
diag.arg("source_kind", __binding_1);
diag.arg("source_name", __binding_2);
diag.span(__binding_0);
if let Some(__binding_3) = __binding_3 {
diag.span_label(__binding_3,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("type must be known at this point")));
}
if let Some(__binding_4) = __binding_4 {
diag.subdiagnostic(__binding_4);
}
for __binding_5 in __binding_5 {
diag.subdiagnostic(__binding_5);
}
for __binding_6 in __binding_6 {
diag.subdiagnostic(__binding_6);
}
diag
}
}
}
}
};Diagnostic)]
228#[diag("{$source_kind ->
229[closure] type annotations needed for the closure `{$source_name}`
230[normal] type annotations needed for `{$source_name}`
231*[other] type annotations needed
232}", code = E0284)]
233pub struct AmbiguousReturn<'a> {
234 #[primary_span]
235 pub span: Span,
236 pub source_kind: &'static str,
237 pub source_name: &'a str,
238 #[label("type must be known at this point")]
239 pub failure_span: Option<Span>,
240 #[subdiagnostic]
241 pub bad_label: Option<InferenceBadError<'a>>,
242 #[subdiagnostic]
243 pub infer_subdiags: Vec<SourceKindSubdiag<'a>>,
244 #[subdiagnostic]
245 pub multi_suggestions: Vec<SourceKindMultiSuggestion<'a>>,
246}
247
248#[derive(const _: () =
{
impl<'a> rustc_errors::Subdiagnostic for InferenceBadError<'a> {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
InferenceBadError {
span: __binding_0,
bad_kind: __binding_1,
prefix_kind: __binding_2,
has_parent: __binding_3,
prefix: __binding_4,
parent_prefix: __binding_5,
parent_name: __binding_6,
name: __binding_7 } => {
diag.store_args();
diag.arg("bad_kind", __binding_1);
diag.arg("prefix_kind", __binding_2);
diag.arg("has_parent", __binding_3);
diag.arg("prefix", __binding_4);
diag.arg("parent_prefix", __binding_5);
diag.arg("parent_name", __binding_6);
diag.arg("name", __binding_7);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$bad_kind ->\n*[other] cannot infer type\n[more_info] cannot infer {$prefix_kind ->\n*[type] type for {$prefix}\n[const_with_param] the value of const parameter\n[const] the value of the constant\n} `{$name}`{$has_parent ->\n[true] {\" \"}declared on the {$parent_prefix} `{$parent_name}`\n*[false] {\"\"}\n}\n}")));
diag.span_label(__binding_0, __message);
diag.restore_args();
}
}
}
}
};Subdiagnostic)]
250#[label(
251 "{$bad_kind ->
252*[other] cannot infer type
253[more_info] cannot infer {$prefix_kind ->
254*[type] type for {$prefix}
255[const_with_param] the value of const parameter
256[const] the value of the constant
257} `{$name}`{$has_parent ->
258[true] {\" \"}declared on the {$parent_prefix} `{$parent_name}`
259*[false] {\"\"}
260}
261}"
262)]
263pub struct InferenceBadError<'a> {
264 #[primary_span]
265 pub span: Span,
266 pub bad_kind: &'static str,
267 pub prefix_kind: UnderspecifiedArgKind,
268 pub has_parent: bool,
269 pub prefix: &'a str,
270 pub parent_prefix: &'a str,
271 pub parent_name: String,
272 pub name: String,
273}
274
275#[derive(const _: () =
{
impl<'a> rustc_errors::Subdiagnostic for SourceKindSubdiag<'a> {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
SourceKindSubdiag::LetLike {
span: __binding_0,
name: __binding_1,
type_name: __binding_2,
kind: __binding_3,
x_kind: __binding_4,
prefix_kind: __binding_5,
prefix: __binding_6,
arg_name: __binding_7 } => {
let __code_0 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!(": {0}", __binding_2))
})].into_iter();
diag.store_args();
diag.arg("name", __binding_1);
diag.arg("type_name", __binding_2);
diag.arg("kind", __binding_3);
diag.arg("x_kind", __binding_4);
diag.arg("prefix_kind", __binding_5);
diag.arg("prefix", __binding_6);
diag.arg("arg_name", __binding_7);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$kind ->\n [with_pattern] consider giving `{$name}` an explicit type\n [closure] consider giving this closure parameter an explicit type\n *[other] consider giving this pattern a type\n }{$x_kind ->\n [has_name] , where the {$prefix_kind ->\n *[type] type for {$prefix}\n [const_with_param] value of const parameter\n [const] value of the constant\n } `{$arg_name}` is specified\n [underscore] , where the placeholders `_` are specified\n *[empty] {\"\"}\n }")));
diag.span_suggestions_with_style(__binding_0, __message,
__code_0, rustc_errors::Applicability::HasPlaceholders,
rustc_errors::SuggestionStyle::ShowAlways);
diag.restore_args();
}
SourceKindSubdiag::GenericLabel {
span: __binding_0,
is_type: __binding_1,
param_name: __binding_2,
parent_exists: __binding_3,
parent_prefix: __binding_4,
parent_name: __binding_5 } => {
diag.store_args();
diag.arg("is_type", __binding_1);
diag.arg("param_name", __binding_2);
diag.arg("parent_exists", __binding_3);
diag.arg("parent_prefix", __binding_4);
diag.arg("parent_name", __binding_5);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("cannot infer {$is_type ->\n [true] type\n *[false] the value\n } of the {$is_type ->\n [true] type\n *[false] const\n } {$parent_exists ->\n [true] parameter `{$param_name}` declared on the {$parent_prefix} `{$parent_name}`\n *[false] parameter {$param_name}\n }")));
diag.span_label(__binding_0, __message);
diag.restore_args();
}
SourceKindSubdiag::GenericSuggestion {
span: __binding_0, arg_count: __binding_1, args: __binding_2
} => {
let __code_1 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("::<{0}>", __binding_2))
})].into_iter();
diag.store_args();
diag.arg("arg_count", __binding_1);
diag.arg("args", __binding_2);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider specifying the generic {$arg_count ->\n [one] argument\n *[other] arguments\n }")));
diag.span_suggestions_with_style(__binding_0, __message,
__code_1, rustc_errors::Applicability::HasPlaceholders,
rustc_errors::SuggestionStyle::ShowAlways);
diag.restore_args();
}
}
}
}
};Subdiagnostic)]
276pub enum SourceKindSubdiag<'a> {
277 #[suggestion(
278 "{$kind ->
279 [with_pattern] consider giving `{$name}` an explicit type
280 [closure] consider giving this closure parameter an explicit type
281 *[other] consider giving this pattern a type
282 }{$x_kind ->
283 [has_name] , where the {$prefix_kind ->
284 *[type] type for {$prefix}
285 [const_with_param] value of const parameter
286 [const] value of the constant
287 } `{$arg_name}` is specified
288 [underscore] , where the placeholders `_` are specified
289 *[empty] {\"\"}
290 }",
291 style = "verbose",
292 code = ": {type_name}",
293 applicability = "has-placeholders"
294 )]
295 LetLike {
296 #[primary_span]
297 span: Span,
298 name: String,
299 type_name: String,
300 kind: &'static str,
301 x_kind: &'static str,
302 prefix_kind: UnderspecifiedArgKind,
303 prefix: &'a str,
304 arg_name: String,
305 },
306 #[label(
307 "cannot infer {$is_type ->
308 [true] type
309 *[false] the value
310 } of the {$is_type ->
311 [true] type
312 *[false] const
313 } {$parent_exists ->
314 [true] parameter `{$param_name}` declared on the {$parent_prefix} `{$parent_name}`
315 *[false] parameter {$param_name}
316 }"
317 )]
318 GenericLabel {
319 #[primary_span]
320 span: Span,
321 is_type: bool,
322 param_name: String,
323 parent_exists: bool,
324 parent_prefix: String,
325 parent_name: String,
326 },
327 #[suggestion(
328 "consider specifying the generic {$arg_count ->
329 [one] argument
330 *[other] arguments
331 }",
332 style = "verbose",
333 code = "::<{args}>",
334 applicability = "has-placeholders"
335 )]
336 GenericSuggestion {
337 #[primary_span]
338 span: Span,
339 arg_count: usize,
340 args: String,
341 },
342}
343
344#[derive(const _: () =
{
impl<'a> rustc_errors::Subdiagnostic for SourceKindMultiSuggestion<'a>
{
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
SourceKindMultiSuggestion::FullyQualified {
span_lo: __binding_0,
span_hi: __binding_1,
def_path: __binding_2,
adjustment: __binding_3,
successor_pos: __binding_4 } => {
let mut suggestions = Vec::new();
let __code_2 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{1}({0}", __binding_3,
__binding_2))
});
let __code_3 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0}", __binding_4))
});
suggestions.push((__binding_0, __code_2));
suggestions.push((__binding_1, __code_3));
diag.store_args();
diag.arg("def_path", __binding_2);
diag.arg("adjustment", __binding_3);
diag.arg("successor_pos", __binding_4);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("try using a fully qualified path to specify the expected types")));
diag.multipart_suggestion_with_style(__message, suggestions,
rustc_errors::Applicability::HasPlaceholders,
rustc_errors::SuggestionStyle::ShowAlways);
diag.restore_args();
}
SourceKindMultiSuggestion::ClosureReturn {
start_span: __binding_0,
start_span_code: __binding_1,
end_span: __binding_2 } => {
let mut suggestions = Vec::new();
let __code_4 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0}", __binding_1))
});
let __code_5 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!(" }}"))
});
suggestions.push((__binding_0, __code_4));
if let Some(__binding_2) = __binding_2 {
suggestions.push((__binding_2, __code_5));
}
diag.store_args();
diag.arg("start_span_code", __binding_1);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("try giving this closure an explicit return type")));
diag.multipart_suggestion_with_style(__message, suggestions,
rustc_errors::Applicability::HasPlaceholders,
rustc_errors::SuggestionStyle::ShowAlways);
diag.restore_args();
}
}
}
}
};Subdiagnostic)]
345pub enum SourceKindMultiSuggestion<'a> {
346 #[multipart_suggestion(
347 "try using a fully qualified path to specify the expected types",
348 style = "verbose",
349 applicability = "has-placeholders"
350 )]
351 FullyQualified {
352 #[suggestion_part(code = "{def_path}({adjustment}")]
353 span_lo: Span,
354 #[suggestion_part(code = "{successor_pos}")]
355 span_hi: Span,
356 def_path: String,
357 adjustment: &'a str,
358 successor_pos: &'a str,
359 },
360 #[multipart_suggestion(
361 "try giving this closure an explicit return type",
362 style = "verbose",
363 applicability = "has-placeholders"
364 )]
365 ClosureReturn {
366 #[suggestion_part(code = "{start_span_code}")]
367 start_span: Span,
368 start_span_code: String,
369 #[suggestion_part(code = " }}")]
370 end_span: Option<Span>,
371 },
372}
373
374impl<'a> SourceKindMultiSuggestion<'a> {
375 pub fn new_fully_qualified(
376 span: Span,
377 def_path: String,
378 adjustment: &'a str,
379 successor: (&'a str, BytePos),
380 ) -> Self {
381 Self::FullyQualified {
382 span_lo: span.shrink_to_lo(),
383 span_hi: span.shrink_to_hi().with_hi(successor.1),
384 def_path,
385 adjustment,
386 successor_pos: successor.0,
387 }
388 }
389
390 pub fn new_closure_return(
391 ty_info: String,
392 data: &'a FnRetTy<'a>,
393 should_wrap_expr: Option<Span>,
394 ) -> Self {
395 let arrow = match data {
396 FnRetTy::DefaultReturn(_) => " -> ",
397 _ => "",
398 };
399 let (start_span, start_span_code, end_span) = match should_wrap_expr {
400 Some(end_span) => (data.span(), ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0}{1} {{", arrow, ty_info))
})format!("{arrow}{ty_info} {{"), Some(end_span)),
401 None => (data.span(), ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0}{1}", arrow, ty_info))
})format!("{arrow}{ty_info}"), None),
402 };
403 Self::ClosureReturn { start_span, start_span_code, end_span }
404 }
405}
406
407pub enum RegionOriginNote<'a> {
408 Plain {
409 span: Span,
410 msg: DiagMessage,
411 },
412 WithName {
413 span: Span,
414 msg: DiagMessage,
415 name: &'a str,
416 continues: bool,
417 },
418 WithRequirement {
419 span: Span,
420 requirement: ObligationCauseAsDiagArg<'a>,
421 expected_found: Option<(DiagStyledString, DiagStyledString)>,
422 },
423}
424
425impl Subdiagnostic for RegionOriginNote<'_> {
426 fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
427 let label_or_note = |diag: &mut Diag<'_, G>, span, msg: DiagMessage| {
428 let sub_count = diag.children.iter().filter(|d| d.span.is_dummy()).count();
429 let expanded_sub_count = diag.children.iter().filter(|d| !d.span.is_dummy()).count();
430 let span_is_primary = diag.span.primary_spans().iter().all(|&sp| sp == span);
431 if span_is_primary && sub_count == 0 && expanded_sub_count == 0 {
432 diag.span_label(span, msg);
433 } else if span_is_primary && expanded_sub_count == 0 {
434 diag.note(msg);
435 } else {
436 diag.span_note(span, msg);
437 }
438 };
439 match self {
440 RegionOriginNote::Plain { span, msg } => {
441 label_or_note(diag, span, msg);
442 }
443 RegionOriginNote::WithName { span, msg, name, continues } => {
444 diag.arg("name", name);
445 diag.arg("continues", continues);
446 label_or_note(diag, span, msg);
447 }
448 RegionOriginNote::WithRequirement {
449 span,
450 requirement,
451 expected_found: Some((expected, found)),
452 } => {
453 diag.store_args();
458 diag.arg("requirement", requirement);
459 let msg = diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("...so that the {$requirement ->\n [method_compat] method type is compatible with trait\n [type_compat] associated type is compatible with trait\n [const_compat] const is compatible with trait\n [expr_assignable] expression is assignable\n [if_else_different] `if` and `else` have incompatible types\n [no_else] `if` missing an `else` returns `()`\n [fn_main_correct_type] `main` function has the correct type\n [fn_lang_correct_type] lang item function has the correct type\n [intrinsic_correct_type] intrinsic has the correct type\n [method_correct_type] method receiver has the correct type\n *[other] types are compatible\n }"))msg!(
460 "...so that the {$requirement ->
461 [method_compat] method type is compatible with trait
462 [type_compat] associated type is compatible with trait
463 [const_compat] const is compatible with trait
464 [expr_assignable] expression is assignable
465 [if_else_different] `if` and `else` have incompatible types
466 [no_else] `if` missing an `else` returns `()`
467 [fn_main_correct_type] `main` function has the correct type
468 [fn_lang_correct_type] lang item function has the correct type
469 [intrinsic_correct_type] intrinsic has the correct type
470 [method_correct_type] method receiver has the correct type
471 *[other] types are compatible
472 }"
473 ));
474 diag.restore_args();
475 label_or_note(diag, span, msg);
476
477 diag.note_expected_found("", expected, "", found);
478 }
479 RegionOriginNote::WithRequirement { span, requirement, expected_found: None } => {
480 diag.store_args();
484 diag.arg("requirement", requirement);
485 let msg = diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("...so that {$requirement ->\n [method_compat] method type is compatible with trait\n [type_compat] associated type is compatible with trait\n [const_compat] const is compatible with trait\n [expr_assignable] expression is assignable\n [if_else_different] `if` and `else` have incompatible types\n [no_else] `if` missing an `else` returns `()`\n [fn_main_correct_type] `main` function has the correct type\n [fn_lang_correct_type] lang item function has the correct type\n [intrinsic_correct_type] intrinsic has the correct type\n [method_correct_type] method receiver has the correct type\n *[other] types are compatible\n }"))msg!(
486 "...so that {$requirement ->
487 [method_compat] method type is compatible with trait
488 [type_compat] associated type is compatible with trait
489 [const_compat] const is compatible with trait
490 [expr_assignable] expression is assignable
491 [if_else_different] `if` and `else` have incompatible types
492 [no_else] `if` missing an `else` returns `()`
493 [fn_main_correct_type] `main` function has the correct type
494 [fn_lang_correct_type] lang item function has the correct type
495 [intrinsic_correct_type] intrinsic has the correct type
496 [method_correct_type] method receiver has the correct type
497 *[other] types are compatible
498 }"
499 ));
500 diag.restore_args();
501 label_or_note(diag, span, msg);
502 }
503 };
504 }
505}
506
507pub enum LifetimeMismatchLabels {
508 InRet {
509 param_span: Span,
510 ret_span: Span,
511 span: Span,
512 label_var1: Option<Ident>,
513 },
514 Normal {
515 hir_equal: bool,
516 ty_sup: Span,
517 ty_sub: Span,
518 span: Span,
519 sup: Option<Ident>,
520 sub: Option<Ident>,
521 },
522}
523
524impl Subdiagnostic for LifetimeMismatchLabels {
525 fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
526 match self {
527 LifetimeMismatchLabels::InRet { param_span, ret_span, span, label_var1 } => {
528 diag.span_label(param_span, rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this parameter and the return type are declared with different lifetimes..."))msg!("this parameter and the return type are declared with different lifetimes..."));
529 diag.span_label(ret_span, rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{\"\"}"))msg!("{\"\"}"));
530 diag.span_label(
531 span,
532 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("...but data{$label_var1_exists ->\n [true] {\" \"}from `{$label_var1}`\n *[false] {\"\"}\n } is returned here"))msg!(
533 "...but data{$label_var1_exists ->
534 [true] {\" \"}from `{$label_var1}`
535 *[false] {\"\"}
536 } is returned here"
537 ),
538 );
539 diag.arg("label_var1_exists", label_var1.is_some());
540 diag.arg("label_var1", label_var1.map(|x| x.to_string()).unwrap_or_default());
541 }
542 LifetimeMismatchLabels::Normal {
543 hir_equal,
544 ty_sup,
545 ty_sub,
546 span,
547 sup: label_var1,
548 sub: label_var2,
549 } => {
550 if hir_equal {
551 diag.span_label(
552 ty_sup,
553 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this type is declared with multiple lifetimes..."))msg!("this type is declared with multiple lifetimes..."),
554 );
555 diag.span_label(ty_sub, rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{\"\"}"))msg!("{\"\"}"));
556 diag.span_label(
557 span,
558 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("...but data with one lifetime flows into the other here"))msg!("...but data with one lifetime flows into the other here"),
559 );
560 } else {
561 diag.span_label(
562 ty_sup,
563 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("these two types are declared with different lifetimes..."))msg!("these two types are declared with different lifetimes..."),
564 );
565 diag.span_label(ty_sub, rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{\"\"}"))msg!("{\"\"}"));
566 diag.span_label(
567 span,
568 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("...but data{$label_var1_exists ->\n [true] {\" \"}from `{$label_var1}`\n *[false] {\"\"}\n } flows{$label_var2_exists ->\n [true] {\" \"}into `{$label_var2}`\n *[false] {\"\"}\n } here"))msg!(
569 "...but data{$label_var1_exists ->
570 [true] {\" \"}from `{$label_var1}`
571 *[false] {\"\"}
572 } flows{$label_var2_exists ->
573 [true] {\" \"}into `{$label_var2}`
574 *[false] {\"\"}
575 } here"
576 ),
577 );
578 diag.arg("label_var1_exists", label_var1.is_some());
579 diag.arg("label_var1", label_var1.map(|x| x.to_string()).unwrap_or_default());
580 diag.arg("label_var2_exists", label_var2.is_some());
581 diag.arg("label_var2", label_var2.map(|x| x.to_string()).unwrap_or_default());
582 }
583 }
584 }
585 }
586}
587
588pub struct AddLifetimeParamsSuggestion<'a> {
589 pub tcx: TyCtxt<'a>,
590 pub generic_param_scope: LocalDefId,
591 pub sub: Region<'a>,
592 pub ty_sup: &'a hir::Ty<'a>,
593 pub ty_sub: &'a hir::Ty<'a>,
594 pub add_note: bool,
595}
596
597impl Subdiagnostic for AddLifetimeParamsSuggestion<'_> {
598 fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
599 let mut mk_suggestion = || {
600 let Some(anon_reg) = self.tcx.is_suitable_region(self.generic_param_scope, self.sub)
601 else {
602 return false;
603 };
604
605 let node = self.tcx.hir_node_by_def_id(anon_reg.scope);
606 let is_impl = #[allow(non_exhaustive_omitted_patterns)] match &node {
hir::Node::ImplItem(_) => true,
_ => false,
}matches!(&node, hir::Node::ImplItem(_));
607 let (generics, parent_generics) = match node {
608 hir::Node::Item(hir::Item { kind: hir::ItemKind::Fn { generics, .. }, .. })
609 | hir::Node::TraitItem(hir::TraitItem { generics, .. })
610 | hir::Node::ImplItem(hir::ImplItem { generics, .. }) => (
611 generics,
612 match self.tcx.parent_hir_node(self.tcx.local_def_id_to_hir_id(anon_reg.scope))
613 {
614 hir::Node::Item(hir::Item {
615 kind: hir::ItemKind::Trait(_, _, _, _, generics, ..),
616 ..
617 })
618 | hir::Node::Item(hir::Item {
619 kind: hir::ItemKind::Impl(hir::Impl { generics, .. }),
620 ..
621 }) => Some(generics),
622 _ => None,
623 },
624 ),
625 _ => return false,
626 };
627
628 let suggestion_param_name = generics
629 .params
630 .iter()
631 .filter(|p| #[allow(non_exhaustive_omitted_patterns)] match p.kind {
GenericParamKind::Lifetime { .. } => true,
_ => false,
}matches!(p.kind, GenericParamKind::Lifetime { .. }))
632 .map(|p| p.name.ident().name)
633 .find(|i| *i != kw::UnderscoreLifetime);
634 let introduce_new = suggestion_param_name.is_none();
635
636 let mut default = "'a".to_string();
637 if let Some(parent_generics) = parent_generics {
638 let used: FxHashSet<_> = parent_generics
639 .params
640 .iter()
641 .filter(|p| #[allow(non_exhaustive_omitted_patterns)] match p.kind {
GenericParamKind::Lifetime { .. } => true,
_ => false,
}matches!(p.kind, GenericParamKind::Lifetime { .. }))
642 .map(|p| p.name.ident().name)
643 .filter(|i| *i != kw::UnderscoreLifetime)
644 .map(|l| l.to_string())
645 .collect();
646 if let Some(lt) =
647 ('a'..='z').map(|it| ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("\'{0}", it))
})format!("'{it}")).find(|it| !used.contains(it))
648 {
649 default = lt;
654 }
655 }
656 let suggestion_param_name =
657 suggestion_param_name.map(|n| n.to_string()).unwrap_or_else(|| default);
658
659 struct ImplicitLifetimeFinder {
660 suggestions: Vec<(Span, String)>,
661 suggestion_param_name: String,
662 }
663
664 impl<'v> Visitor<'v> for ImplicitLifetimeFinder {
665 fn visit_ty(&mut self, ty: &'v hir::Ty<'v, AmbigArg>) {
666 match ty.kind {
667 hir::TyKind::Path(hir::QPath::Resolved(_, path)) => {
668 for segment in path.segments {
669 if let Some(args) = segment.args {
670 if args.args.iter().all(|arg| {
671 #[allow(non_exhaustive_omitted_patterns)] match arg {
hir::GenericArg::Lifetime(lifetime) if lifetime.is_implicit() => true,
_ => false,
}matches!(
672 arg,
673 hir::GenericArg::Lifetime(lifetime)
674 if lifetime.is_implicit()
675 )
676 }) {
677 self.suggestions.push((
678 segment.ident.span.shrink_to_hi(),
679 ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("<{0}>",
args.args.iter().map(|_|
self.suggestion_param_name.clone()).collect::<Vec<_>>().join(", ")))
})format!(
680 "<{}>",
681 args.args
682 .iter()
683 .map(|_| self.suggestion_param_name.clone())
684 .collect::<Vec<_>>()
685 .join(", ")
686 ),
687 ));
688 } else {
689 for arg in args.args {
690 if let hir::GenericArg::Lifetime(lifetime) = arg
691 && lifetime.is_anonymous()
692 {
693 self.suggestions.push(
694 lifetime
695 .suggestion(&self.suggestion_param_name),
696 );
697 }
698 }
699 }
700 }
701 }
702 }
703 hir::TyKind::Ref(lifetime, ..) if lifetime.is_anonymous() => {
704 self.suggestions.push(lifetime.suggestion(&self.suggestion_param_name));
705 }
706 _ => {}
707 }
708 walk_ty(self, ty);
709 }
710 }
711 let mut visitor = ImplicitLifetimeFinder {
712 suggestions: ::alloc::vec::Vec::new()vec![],
713 suggestion_param_name: suggestion_param_name.clone(),
714 };
715 if let Some(fn_decl) = node.fn_decl()
716 && let hir::FnRetTy::Return(ty) = fn_decl.output
717 {
718 visitor.visit_ty_unambig(ty);
719 }
720 if visitor.suggestions.is_empty() {
721 visitor.visit_ty_unambig(self.ty_sup);
726 }
727 visitor.visit_ty_unambig(self.ty_sub);
728 if visitor.suggestions.is_empty() {
729 return false;
730 }
731 if introduce_new {
732 let new_param_suggestion = if let Some(first) =
733 generics.params.iter().find(|p| !p.name.ident().span.is_empty())
734 {
735 (first.span.shrink_to_lo(), ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0}, ", suggestion_param_name))
})format!("{suggestion_param_name}, "))
736 } else {
737 (generics.span, ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("<{0}>", suggestion_param_name))
})format!("<{suggestion_param_name}>"))
738 };
739
740 visitor.suggestions.push(new_param_suggestion);
741 }
742 diag.multipart_suggestion(
743 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider {$is_reuse ->\n [true] reusing\n *[false] introducing\n } a named lifetime parameter{$is_impl ->\n [true] {\" \"}and update trait if needed\n *[false] {\"\"}\n }"))msg!(
744 "consider {$is_reuse ->
745 [true] reusing
746 *[false] introducing
747 } a named lifetime parameter{$is_impl ->
748 [true] {\" \"}and update trait if needed
749 *[false] {\"\"}
750 }"
751 ),
752 visitor.suggestions,
753 Applicability::MaybeIncorrect,
754 );
755 diag.arg("is_impl", is_impl);
756 diag.arg("is_reuse", !introduce_new);
757
758 true
759 };
760 if mk_suggestion() && self.add_note {
761 diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("each elided lifetime in input position becomes a distinct lifetime"))msg!("each elided lifetime in input position becomes a distinct lifetime"));
762 }
763 }
764}
765
766#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
LifetimeMismatch<'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 {
LifetimeMismatch {
span: __binding_0,
labels: __binding_1,
suggestion: __binding_2 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("lifetime mismatch")));
diag.code(E0623);
;
diag.span(__binding_0);
diag.subdiagnostic(__binding_1);
diag.subdiagnostic(__binding_2);
diag
}
}
}
}
};Diagnostic)]
767#[diag("lifetime mismatch", code = E0623)]
768pub struct LifetimeMismatch<'a> {
769 #[primary_span]
770 pub span: Span,
771 #[subdiagnostic]
772 pub labels: LifetimeMismatchLabels,
773 #[subdiagnostic]
774 pub suggestion: AddLifetimeParamsSuggestion<'a>,
775}
776
777pub struct IntroducesStaticBecauseUnmetLifetimeReq {
778 pub unmet_requirements: MultiSpan,
779 pub binding_span: Span,
780}
781
782impl Subdiagnostic for IntroducesStaticBecauseUnmetLifetimeReq {
783 fn add_to_diag<G: EmissionGuarantee>(mut self, diag: &mut Diag<'_, G>) {
784 self.unmet_requirements.push_span_label(
785 self.binding_span,
786 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("introduces a `'static` lifetime requirement"))msg!("introduces a `'static` lifetime requirement"),
787 );
788 diag.span_note(
789 self.unmet_requirements,
790 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("because this has an unmet lifetime requirement"))msg!("because this has an unmet lifetime requirement"),
791 );
792 }
793}
794
795#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for DoesNotOutliveStaticFromImpl {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
DoesNotOutliveStaticFromImpl::Spanned { span: __binding_0 }
=> {
diag.store_args();
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("...does not necessarily outlive the static lifetime introduced by the compatible `impl`")));
diag.span_note(__binding_0, __message);
diag.restore_args();
}
DoesNotOutliveStaticFromImpl::Unspanned => {
diag.store_args();
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("...does not necessarily outlive the static lifetime introduced by the compatible `impl`")));
diag.note(__message);
diag.restore_args();
}
}
}
}
};Subdiagnostic)]
797pub enum DoesNotOutliveStaticFromImpl {
798 #[note(
799 "...does not necessarily outlive the static lifetime introduced by the compatible `impl`"
800 )]
801 Spanned {
802 #[primary_span]
803 span: Span,
804 },
805 #[note(
806 "...does not necessarily outlive the static lifetime introduced by the compatible `impl`"
807 )]
808 Unspanned,
809}
810
811#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for ImplicitStaticLifetimeSubdiag {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
ImplicitStaticLifetimeSubdiag::Note { span: __binding_0 } =>
{
diag.store_args();
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this has an implicit `'static` lifetime requirement")));
diag.span_note(__binding_0, __message);
diag.restore_args();
}
ImplicitStaticLifetimeSubdiag::Sugg { span: __binding_0 } =>
{
let __code_6 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!(" + \'_"))
})].into_iter();
diag.store_args();
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider relaxing the implicit `'static` requirement")));
diag.span_suggestions_with_style(__binding_0, __message,
__code_6, rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowAlways);
diag.restore_args();
}
}
}
}
};Subdiagnostic)]
812pub enum ImplicitStaticLifetimeSubdiag {
813 #[note("this has an implicit `'static` lifetime requirement")]
814 Note {
815 #[primary_span]
816 span: Span,
817 },
818 #[suggestion(
819 "consider relaxing the implicit `'static` requirement",
820 style = "verbose",
821 code = " + '_",
822 applicability = "maybe-incorrect"
823 )]
824 Sugg {
825 #[primary_span]
826 span: Span,
827 },
828}
829
830#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
MismatchedStaticLifetime<'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 {
MismatchedStaticLifetime {
cause_span: __binding_0,
unmet_lifetime_reqs: __binding_1,
expl: __binding_2,
does_not_outlive_static_from_impl: __binding_3,
implicit_static_lifetimes: __binding_4 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("incompatible lifetime on type")));
;
diag.span(__binding_0);
diag.subdiagnostic(__binding_1);
if let Some(__binding_2) = __binding_2 {
diag.subdiagnostic(__binding_2);
}
diag.subdiagnostic(__binding_3);
for __binding_4 in __binding_4 {
diag.subdiagnostic(__binding_4);
}
diag
}
}
}
}
};Diagnostic)]
831#[diag("incompatible lifetime on type")]
832pub struct MismatchedStaticLifetime<'a> {
833 #[primary_span]
834 pub cause_span: Span,
835 #[subdiagnostic]
836 pub unmet_lifetime_reqs: IntroducesStaticBecauseUnmetLifetimeReq,
837 #[subdiagnostic]
838 pub expl: Option<note_and_explain::RegionExplanation<'a>>,
839 #[subdiagnostic]
840 pub does_not_outlive_static_from_impl: DoesNotOutliveStaticFromImpl,
841 #[subdiagnostic]
842 pub implicit_static_lifetimes: Vec<ImplicitStaticLifetimeSubdiag>,
843}
844
845#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
ExplicitLifetimeRequired<'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 {
ExplicitLifetimeRequired::WithIdent {
span: __binding_0,
simple_ident: __binding_1,
named: __binding_2,
new_ty_span: __binding_3,
new_ty: __binding_4 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("explicit lifetime required in the type of `{$simple_ident}`")));
let __code_7 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0}", __binding_4))
})].into_iter();
diag.code(E0621);
;
diag.arg("simple_ident", __binding_1);
diag.arg("named", __binding_2);
diag.span(__binding_0);
diag.span_label(__binding_0,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("lifetime `{$named}` required")));
diag.span_suggestions_with_style(__binding_3,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("add explicit lifetime `{$named}` to the type of `{$simple_ident}`")),
__code_7, rustc_errors::Applicability::Unspecified,
rustc_errors::SuggestionStyle::ShowAlways);
diag
}
ExplicitLifetimeRequired::WithParamType {
span: __binding_0,
named: __binding_1,
new_ty_span: __binding_2,
new_ty: __binding_3 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("explicit lifetime required in parameter type")));
let __code_8 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0}", __binding_3))
})].into_iter();
diag.code(E0621);
;
diag.arg("named", __binding_1);
diag.span(__binding_0);
diag.span_label(__binding_0,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("lifetime `{$named}` required")));
diag.span_suggestions_with_style(__binding_2,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("add explicit lifetime `{$named}` to type")),
__code_8, rustc_errors::Applicability::Unspecified,
rustc_errors::SuggestionStyle::ShowAlways);
diag
}
}
}
}
};Diagnostic)]
846pub enum ExplicitLifetimeRequired<'a> {
847 #[diag("explicit lifetime required in the type of `{$simple_ident}`", code = E0621)]
848 WithIdent {
849 #[primary_span]
850 #[label("lifetime `{$named}` required")]
851 span: Span,
852 simple_ident: Ident,
853 named: String,
854 #[suggestion(
855 "add explicit lifetime `{$named}` to the type of `{$simple_ident}`",
856 code = "{new_ty}",
857 applicability = "unspecified",
858 style = "verbose"
859 )]
860 new_ty_span: Span,
861 #[skip_arg]
862 new_ty: Ty<'a>,
863 },
864 #[diag("explicit lifetime required in parameter type", code = E0621)]
865 WithParamType {
866 #[primary_span]
867 #[label("lifetime `{$named}` required")]
868 span: Span,
869 named: String,
870 #[suggestion(
871 "add explicit lifetime `{$named}` to type",
872 code = "{new_ty}",
873 applicability = "unspecified",
874 style = "verbose"
875 )]
876 new_ty_span: Span,
877 #[skip_arg]
878 new_ty: Ty<'a>,
879 },
880}
881
882pub enum TyOrSig<'tcx> {
883 Ty(Highlighted<'tcx, Ty<'tcx>>),
884 ClosureSig(Highlighted<'tcx, Binder<'tcx, FnSig<'tcx>>>),
885}
886
887impl IntoDiagArg for TyOrSig<'_> {
888 fn into_diag_arg(self, path: &mut Option<std::path::PathBuf>) -> rustc_errors::DiagArgValue {
889 match self {
890 TyOrSig::Ty(ty) => ty.into_diag_arg(path),
891 TyOrSig::ClosureSig(sig) => sig.into_diag_arg(path),
892 }
893 }
894}
895
896#[derive(const _: () =
{
impl<'tcx> rustc_errors::Subdiagnostic for ActualImplExplNotes<'tcx> {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
ActualImplExplNotes::ExpectedSignatureTwo {
leading_ellipsis: __binding_0,
ty_or_sig: __binding_1,
trait_path: __binding_2,
lifetime_1: __binding_3,
lifetime_2: __binding_4 } => {
diag.store_args();
diag.arg("leading_ellipsis", __binding_0);
diag.arg("ty_or_sig", __binding_1);
diag.arg("trait_path", __binding_2);
diag.arg("lifetime_1", __binding_3);
diag.arg("lifetime_2", __binding_4);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$leading_ellipsis ->\n [true] ...\n *[false] {\"\"}\n }closure with signature `{$ty_or_sig}` must implement `{$trait_path}`, for any two lifetimes `'{$lifetime_1}` and `'{$lifetime_2}`...")));
diag.note(__message);
diag.restore_args();
}
ActualImplExplNotes::ExpectedSignatureAny {
leading_ellipsis: __binding_0,
ty_or_sig: __binding_1,
trait_path: __binding_2,
lifetime_1: __binding_3 } => {
diag.store_args();
diag.arg("leading_ellipsis", __binding_0);
diag.arg("ty_or_sig", __binding_1);
diag.arg("trait_path", __binding_2);
diag.arg("lifetime_1", __binding_3);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$leading_ellipsis ->\n [true] ...\n *[false] {\"\"}\n }closure with signature `{$ty_or_sig}` must implement `{$trait_path}`, for any lifetime `'{$lifetime_1}`...")));
diag.note(__message);
diag.restore_args();
}
ActualImplExplNotes::ExpectedSignatureSome {
leading_ellipsis: __binding_0,
ty_or_sig: __binding_1,
trait_path: __binding_2,
lifetime_1: __binding_3 } => {
diag.store_args();
diag.arg("leading_ellipsis", __binding_0);
diag.arg("ty_or_sig", __binding_1);
diag.arg("trait_path", __binding_2);
diag.arg("lifetime_1", __binding_3);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$leading_ellipsis ->\n [true] ...\n *[false] {\"\"}\n }closure with signature `{$ty_or_sig}` must implement `{$trait_path}`, for some specific lifetime `'{$lifetime_1}`...")));
diag.note(__message);
diag.restore_args();
}
ActualImplExplNotes::ExpectedSignatureNothing {
leading_ellipsis: __binding_0,
ty_or_sig: __binding_1,
trait_path: __binding_2 } => {
diag.store_args();
diag.arg("leading_ellipsis", __binding_0);
diag.arg("ty_or_sig", __binding_1);
diag.arg("trait_path", __binding_2);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$leading_ellipsis ->\n [true] ...\n *[false] {\"\"}\n }closure with signature `{$ty_or_sig}` must implement `{$trait_path}`")));
diag.note(__message);
diag.restore_args();
}
ActualImplExplNotes::ExpectedPassiveTwo {
leading_ellipsis: __binding_0,
ty_or_sig: __binding_1,
trait_path: __binding_2,
lifetime_1: __binding_3,
lifetime_2: __binding_4 } => {
diag.store_args();
diag.arg("leading_ellipsis", __binding_0);
diag.arg("ty_or_sig", __binding_1);
diag.arg("trait_path", __binding_2);
diag.arg("lifetime_1", __binding_3);
diag.arg("lifetime_2", __binding_4);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$leading_ellipsis ->\n [true] ...\n *[false] {\"\"}\n }`{$trait_path}` would have to be implemented for the type `{$ty_or_sig}`, for any two lifetimes `'{$lifetime_1}` and `'{$lifetime_2}`...")));
diag.note(__message);
diag.restore_args();
}
ActualImplExplNotes::ExpectedPassiveAny {
leading_ellipsis: __binding_0,
ty_or_sig: __binding_1,
trait_path: __binding_2,
lifetime_1: __binding_3 } => {
diag.store_args();
diag.arg("leading_ellipsis", __binding_0);
diag.arg("ty_or_sig", __binding_1);
diag.arg("trait_path", __binding_2);
diag.arg("lifetime_1", __binding_3);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$leading_ellipsis ->\n [true] ...\n *[false] {\"\"}\n }`{$trait_path}` would have to be implemented for the type `{$ty_or_sig}`, for any lifetime `'{$lifetime_1}`...")));
diag.note(__message);
diag.restore_args();
}
ActualImplExplNotes::ExpectedPassiveSome {
leading_ellipsis: __binding_0,
ty_or_sig: __binding_1,
trait_path: __binding_2,
lifetime_1: __binding_3 } => {
diag.store_args();
diag.arg("leading_ellipsis", __binding_0);
diag.arg("ty_or_sig", __binding_1);
diag.arg("trait_path", __binding_2);
diag.arg("lifetime_1", __binding_3);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$leading_ellipsis ->\n [true] ...\n *[false] {\"\"}\n }`{$trait_path}` would have to be implemented for the type `{$ty_or_sig}`, for some specific lifetime `'{$lifetime_1}`...")));
diag.note(__message);
diag.restore_args();
}
ActualImplExplNotes::ExpectedPassiveNothing {
leading_ellipsis: __binding_0,
ty_or_sig: __binding_1,
trait_path: __binding_2 } => {
diag.store_args();
diag.arg("leading_ellipsis", __binding_0);
diag.arg("ty_or_sig", __binding_1);
diag.arg("trait_path", __binding_2);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$leading_ellipsis ->\n [true] ...\n *[false] {\"\"}\n }`{$trait_path}` would have to be implemented for the type `{$ty_or_sig}`")));
diag.note(__message);
diag.restore_args();
}
ActualImplExplNotes::ExpectedOtherTwo {
leading_ellipsis: __binding_0,
ty_or_sig: __binding_1,
trait_path: __binding_2,
lifetime_1: __binding_3,
lifetime_2: __binding_4 } => {
diag.store_args();
diag.arg("leading_ellipsis", __binding_0);
diag.arg("ty_or_sig", __binding_1);
diag.arg("trait_path", __binding_2);
diag.arg("lifetime_1", __binding_3);
diag.arg("lifetime_2", __binding_4);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$leading_ellipsis ->\n [true] ...\n *[false] {\"\"}\n }`{$ty_or_sig}` must implement `{$trait_path}`, for any two lifetimes `'{$lifetime_1}` and `'{$lifetime_2}`...")));
diag.note(__message);
diag.restore_args();
}
ActualImplExplNotes::ExpectedOtherAny {
leading_ellipsis: __binding_0,
ty_or_sig: __binding_1,
trait_path: __binding_2,
lifetime_1: __binding_3 } => {
diag.store_args();
diag.arg("leading_ellipsis", __binding_0);
diag.arg("ty_or_sig", __binding_1);
diag.arg("trait_path", __binding_2);
diag.arg("lifetime_1", __binding_3);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$leading_ellipsis ->\n [true] ...\n *[false] {\"\"}\n }`{$ty_or_sig}` must implement `{$trait_path}`, for any lifetime `'{$lifetime_1}`...")));
diag.note(__message);
diag.restore_args();
}
ActualImplExplNotes::ExpectedOtherSome {
leading_ellipsis: __binding_0,
ty_or_sig: __binding_1,
trait_path: __binding_2,
lifetime_1: __binding_3 } => {
diag.store_args();
diag.arg("leading_ellipsis", __binding_0);
diag.arg("ty_or_sig", __binding_1);
diag.arg("trait_path", __binding_2);
diag.arg("lifetime_1", __binding_3);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$leading_ellipsis ->\n [true] ...\n *[false] {\"\"}\n }`{$ty_or_sig}` must implement `{$trait_path}`, for some specific lifetime `'{$lifetime_1}`...")));
diag.note(__message);
diag.restore_args();
}
ActualImplExplNotes::ExpectedOtherNothing {
leading_ellipsis: __binding_0,
ty_or_sig: __binding_1,
trait_path: __binding_2 } => {
diag.store_args();
diag.arg("leading_ellipsis", __binding_0);
diag.arg("ty_or_sig", __binding_1);
diag.arg("trait_path", __binding_2);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$leading_ellipsis ->\n [true] ...\n *[false] {\"\"}\n }`{$ty_or_sig}` must implement `{$trait_path}`")));
diag.note(__message);
diag.restore_args();
}
ActualImplExplNotes::ButActuallyImplementsTrait {
trait_path: __binding_0,
has_lifetime: __binding_1,
lifetime: __binding_2 } => {
diag.store_args();
diag.arg("trait_path", __binding_0);
diag.arg("has_lifetime", __binding_1);
diag.arg("lifetime", __binding_2);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("...but it actually implements `{$trait_path}`{$has_lifetime ->\n [true] , for some specific lifetime `'{$lifetime}`\n *[false] {\"\"}\n }")));
diag.note(__message);
diag.restore_args();
}
ActualImplExplNotes::ButActuallyImplementedForTy {
trait_path: __binding_0,
has_lifetime: __binding_1,
lifetime: __binding_2,
ty: __binding_3 } => {
diag.store_args();
diag.arg("trait_path", __binding_0);
diag.arg("has_lifetime", __binding_1);
diag.arg("lifetime", __binding_2);
diag.arg("ty", __binding_3);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("...but `{$trait_path}` is actually implemented for the type `{$ty}`{$has_lifetime ->\n [true] , for some specific lifetime `'{$lifetime}`\n *[false] {\"\"}\n }")));
diag.note(__message);
diag.restore_args();
}
ActualImplExplNotes::ButActuallyTyImplements {
trait_path: __binding_0,
has_lifetime: __binding_1,
lifetime: __binding_2,
ty: __binding_3 } => {
diag.store_args();
diag.arg("trait_path", __binding_0);
diag.arg("has_lifetime", __binding_1);
diag.arg("lifetime", __binding_2);
diag.arg("ty", __binding_3);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("...but `{$ty}` actually implements `{$trait_path}`{$has_lifetime ->\n [true] , for some specific lifetime `'{$lifetime}`\n *[false] {\"\"}\n }")));
diag.note(__message);
diag.restore_args();
}
}
}
}
};Subdiagnostic)]
897pub enum ActualImplExplNotes<'tcx> {
898 #[note("{$leading_ellipsis ->
899 [true] ...
900 *[false] {\"\"}
901 }closure with signature `{$ty_or_sig}` must implement `{$trait_path}`, for any two lifetimes `'{$lifetime_1}` and `'{$lifetime_2}`...")]
902 ExpectedSignatureTwo {
903 leading_ellipsis: bool,
904 ty_or_sig: TyOrSig<'tcx>,
905 trait_path: Highlighted<'tcx, TraitRefPrintOnlyTraitPath<'tcx>>,
906 lifetime_1: usize,
907 lifetime_2: usize,
908 },
909 #[note("{$leading_ellipsis ->
910 [true] ...
911 *[false] {\"\"}
912 }closure with signature `{$ty_or_sig}` must implement `{$trait_path}`, for any lifetime `'{$lifetime_1}`...")]
913 ExpectedSignatureAny {
914 leading_ellipsis: bool,
915 ty_or_sig: TyOrSig<'tcx>,
916 trait_path: Highlighted<'tcx, TraitRefPrintOnlyTraitPath<'tcx>>,
917 lifetime_1: usize,
918 },
919 #[note("{$leading_ellipsis ->
920 [true] ...
921 *[false] {\"\"}
922 }closure with signature `{$ty_or_sig}` must implement `{$trait_path}`, for some specific lifetime `'{$lifetime_1}`...")]
923 ExpectedSignatureSome {
924 leading_ellipsis: bool,
925 ty_or_sig: TyOrSig<'tcx>,
926 trait_path: Highlighted<'tcx, TraitRefPrintOnlyTraitPath<'tcx>>,
927 lifetime_1: usize,
928 },
929 #[note(
930 "{$leading_ellipsis ->
931 [true] ...
932 *[false] {\"\"}
933 }closure with signature `{$ty_or_sig}` must implement `{$trait_path}`"
934 )]
935 ExpectedSignatureNothing {
936 leading_ellipsis: bool,
937 ty_or_sig: TyOrSig<'tcx>,
938 trait_path: Highlighted<'tcx, TraitRefPrintOnlyTraitPath<'tcx>>,
939 },
940 #[note("{$leading_ellipsis ->
941 [true] ...
942 *[false] {\"\"}
943 }`{$trait_path}` would have to be implemented for the type `{$ty_or_sig}`, for any two lifetimes `'{$lifetime_1}` and `'{$lifetime_2}`...")]
944 ExpectedPassiveTwo {
945 leading_ellipsis: bool,
946 ty_or_sig: TyOrSig<'tcx>,
947 trait_path: Highlighted<'tcx, TraitRefPrintOnlyTraitPath<'tcx>>,
948 lifetime_1: usize,
949 lifetime_2: usize,
950 },
951 #[note("{$leading_ellipsis ->
952 [true] ...
953 *[false] {\"\"}
954 }`{$trait_path}` would have to be implemented for the type `{$ty_or_sig}`, for any lifetime `'{$lifetime_1}`...")]
955 ExpectedPassiveAny {
956 leading_ellipsis: bool,
957 ty_or_sig: TyOrSig<'tcx>,
958 trait_path: Highlighted<'tcx, TraitRefPrintOnlyTraitPath<'tcx>>,
959 lifetime_1: usize,
960 },
961 #[note("{$leading_ellipsis ->
962 [true] ...
963 *[false] {\"\"}
964 }`{$trait_path}` would have to be implemented for the type `{$ty_or_sig}`, for some specific lifetime `'{$lifetime_1}`...")]
965 ExpectedPassiveSome {
966 leading_ellipsis: bool,
967 ty_or_sig: TyOrSig<'tcx>,
968 trait_path: Highlighted<'tcx, TraitRefPrintOnlyTraitPath<'tcx>>,
969 lifetime_1: usize,
970 },
971 #[note(
972 "{$leading_ellipsis ->
973 [true] ...
974 *[false] {\"\"}
975 }`{$trait_path}` would have to be implemented for the type `{$ty_or_sig}`"
976 )]
977 ExpectedPassiveNothing {
978 leading_ellipsis: bool,
979 ty_or_sig: TyOrSig<'tcx>,
980 trait_path: Highlighted<'tcx, TraitRefPrintOnlyTraitPath<'tcx>>,
981 },
982 #[note("{$leading_ellipsis ->
983 [true] ...
984 *[false] {\"\"}
985 }`{$ty_or_sig}` must implement `{$trait_path}`, for any two lifetimes `'{$lifetime_1}` and `'{$lifetime_2}`...")]
986 ExpectedOtherTwo {
987 leading_ellipsis: bool,
988 ty_or_sig: TyOrSig<'tcx>,
989 trait_path: Highlighted<'tcx, TraitRefPrintOnlyTraitPath<'tcx>>,
990 lifetime_1: usize,
991 lifetime_2: usize,
992 },
993 #[note(
994 "{$leading_ellipsis ->
995 [true] ...
996 *[false] {\"\"}
997 }`{$ty_or_sig}` must implement `{$trait_path}`, for any lifetime `'{$lifetime_1}`..."
998 )]
999 ExpectedOtherAny {
1000 leading_ellipsis: bool,
1001 ty_or_sig: TyOrSig<'tcx>,
1002 trait_path: Highlighted<'tcx, TraitRefPrintOnlyTraitPath<'tcx>>,
1003 lifetime_1: usize,
1004 },
1005 #[note(
1006 "{$leading_ellipsis ->
1007 [true] ...
1008 *[false] {\"\"}
1009 }`{$ty_or_sig}` must implement `{$trait_path}`, for some specific lifetime `'{$lifetime_1}`..."
1010 )]
1011 ExpectedOtherSome {
1012 leading_ellipsis: bool,
1013 ty_or_sig: TyOrSig<'tcx>,
1014 trait_path: Highlighted<'tcx, TraitRefPrintOnlyTraitPath<'tcx>>,
1015 lifetime_1: usize,
1016 },
1017 #[note(
1018 "{$leading_ellipsis ->
1019 [true] ...
1020 *[false] {\"\"}
1021 }`{$ty_or_sig}` must implement `{$trait_path}`"
1022 )]
1023 ExpectedOtherNothing {
1024 leading_ellipsis: bool,
1025 ty_or_sig: TyOrSig<'tcx>,
1026 trait_path: Highlighted<'tcx, TraitRefPrintOnlyTraitPath<'tcx>>,
1027 },
1028 #[note(
1029 "...but it actually implements `{$trait_path}`{$has_lifetime ->
1030 [true] , for some specific lifetime `'{$lifetime}`
1031 *[false] {\"\"}
1032 }"
1033 )]
1034 ButActuallyImplementsTrait {
1035 trait_path: Highlighted<'tcx, TraitRefPrintOnlyTraitPath<'tcx>>,
1036 has_lifetime: bool,
1037 lifetime: usize,
1038 },
1039 #[note(
1040 "...but `{$trait_path}` is actually implemented for the type `{$ty}`{$has_lifetime ->
1041 [true] , for some specific lifetime `'{$lifetime}`
1042 *[false] {\"\"}
1043 }"
1044 )]
1045 ButActuallyImplementedForTy {
1046 trait_path: Highlighted<'tcx, TraitRefPrintOnlyTraitPath<'tcx>>,
1047 has_lifetime: bool,
1048 lifetime: usize,
1049 ty: String,
1050 },
1051 #[note(
1052 "...but `{$ty}` actually implements `{$trait_path}`{$has_lifetime ->
1053 [true] , for some specific lifetime `'{$lifetime}`
1054 *[false] {\"\"}
1055 }"
1056 )]
1057 ButActuallyTyImplements {
1058 trait_path: Highlighted<'tcx, TraitRefPrintOnlyTraitPath<'tcx>>,
1059 has_lifetime: bool,
1060 lifetime: usize,
1061 ty: String,
1062 },
1063}
1064
1065pub enum ActualImplExpectedKind {
1066 Signature,
1067 Passive,
1068 Other,
1069}
1070
1071pub enum ActualImplExpectedLifetimeKind {
1072 Two,
1073 Any,
1074 Some,
1075 Nothing,
1076}
1077
1078impl<'tcx> ActualImplExplNotes<'tcx> {
1079 pub fn new_expected(
1080 kind: ActualImplExpectedKind,
1081 lt_kind: ActualImplExpectedLifetimeKind,
1082 leading_ellipsis: bool,
1083 ty_or_sig: TyOrSig<'tcx>,
1084 trait_path: Highlighted<'tcx, TraitRefPrintOnlyTraitPath<'tcx>>,
1085 lifetime_1: usize,
1086 lifetime_2: usize,
1087 ) -> Self {
1088 match (kind, lt_kind) {
1089 (ActualImplExpectedKind::Signature, ActualImplExpectedLifetimeKind::Two) => {
1090 Self::ExpectedSignatureTwo {
1091 leading_ellipsis,
1092 ty_or_sig,
1093 trait_path,
1094 lifetime_1,
1095 lifetime_2,
1096 }
1097 }
1098 (ActualImplExpectedKind::Signature, ActualImplExpectedLifetimeKind::Any) => {
1099 Self::ExpectedSignatureAny { leading_ellipsis, ty_or_sig, trait_path, lifetime_1 }
1100 }
1101 (ActualImplExpectedKind::Signature, ActualImplExpectedLifetimeKind::Some) => {
1102 Self::ExpectedSignatureSome { leading_ellipsis, ty_or_sig, trait_path, lifetime_1 }
1103 }
1104 (ActualImplExpectedKind::Signature, ActualImplExpectedLifetimeKind::Nothing) => {
1105 Self::ExpectedSignatureNothing { leading_ellipsis, ty_or_sig, trait_path }
1106 }
1107 (ActualImplExpectedKind::Passive, ActualImplExpectedLifetimeKind::Two) => {
1108 Self::ExpectedPassiveTwo {
1109 leading_ellipsis,
1110 ty_or_sig,
1111 trait_path,
1112 lifetime_1,
1113 lifetime_2,
1114 }
1115 }
1116 (ActualImplExpectedKind::Passive, ActualImplExpectedLifetimeKind::Any) => {
1117 Self::ExpectedPassiveAny { leading_ellipsis, ty_or_sig, trait_path, lifetime_1 }
1118 }
1119 (ActualImplExpectedKind::Passive, ActualImplExpectedLifetimeKind::Some) => {
1120 Self::ExpectedPassiveSome { leading_ellipsis, ty_or_sig, trait_path, lifetime_1 }
1121 }
1122 (ActualImplExpectedKind::Passive, ActualImplExpectedLifetimeKind::Nothing) => {
1123 Self::ExpectedPassiveNothing { leading_ellipsis, ty_or_sig, trait_path }
1124 }
1125 (ActualImplExpectedKind::Other, ActualImplExpectedLifetimeKind::Two) => {
1126 Self::ExpectedOtherTwo {
1127 leading_ellipsis,
1128 ty_or_sig,
1129 trait_path,
1130 lifetime_1,
1131 lifetime_2,
1132 }
1133 }
1134 (ActualImplExpectedKind::Other, ActualImplExpectedLifetimeKind::Any) => {
1135 Self::ExpectedOtherAny { leading_ellipsis, ty_or_sig, trait_path, lifetime_1 }
1136 }
1137 (ActualImplExpectedKind::Other, ActualImplExpectedLifetimeKind::Some) => {
1138 Self::ExpectedOtherSome { leading_ellipsis, ty_or_sig, trait_path, lifetime_1 }
1139 }
1140 (ActualImplExpectedKind::Other, ActualImplExpectedLifetimeKind::Nothing) => {
1141 Self::ExpectedOtherNothing { leading_ellipsis, ty_or_sig, trait_path }
1142 }
1143 }
1144 }
1145}
1146
1147#[derive(const _: () =
{
impl<'_sess, 'tcx, G> rustc_errors::Diagnostic<'_sess, G> for
TraitPlaceholderMismatch<'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 {
TraitPlaceholderMismatch {
span: __binding_0,
satisfy_span: __binding_1,
where_span: __binding_2,
dup_span: __binding_3,
def_id: __binding_4,
trait_def_id: __binding_5,
actual_impl_expl_notes: __binding_6 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("implementation of `{$trait_def_id}` is not general enough")));
;
diag.arg("def_id", __binding_4);
diag.arg("trait_def_id", __binding_5);
diag.span(__binding_0);
if let Some(__binding_1) = __binding_1 {
diag.span_label(__binding_1,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("doesn't satisfy where-clause")));
}
if let Some(__binding_2) = __binding_2 {
diag.span_label(__binding_2,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("due to a where-clause on `{$def_id}`...")));
}
if let Some(__binding_3) = __binding_3 {
diag.span_label(__binding_3,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("implementation of `{$trait_def_id}` is not general enough")));
}
for __binding_6 in __binding_6 {
diag.subdiagnostic(__binding_6);
}
diag
}
}
}
}
};Diagnostic)]
1148#[diag("implementation of `{$trait_def_id}` is not general enough")]
1149pub struct TraitPlaceholderMismatch<'tcx> {
1150 #[primary_span]
1151 pub span: Span,
1152 #[label("doesn't satisfy where-clause")]
1153 pub satisfy_span: Option<Span>,
1154 #[label("due to a where-clause on `{$def_id}`...")]
1155 pub where_span: Option<Span>,
1156 #[label("implementation of `{$trait_def_id}` is not general enough")]
1157 pub dup_span: Option<Span>,
1158 pub def_id: String,
1159 pub trait_def_id: String,
1160
1161 #[subdiagnostic]
1162 pub actual_impl_expl_notes: Vec<ActualImplExplNotes<'tcx>>,
1163}
1164
1165pub struct ConsiderBorrowingParamHelp {
1166 pub spans: Vec<Span>,
1167}
1168
1169impl Subdiagnostic for ConsiderBorrowingParamHelp {
1170 fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
1171 let mut type_param_span: MultiSpan = self.spans.clone().into();
1172 for &span in &self.spans {
1173 type_param_span
1175 .push_span_label(span, rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider borrowing this type parameter in the trait"))msg!("consider borrowing this type parameter in the trait"));
1176 }
1177 let msg = diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the lifetime requirements from the `impl` do not correspond to the requirements in the `trait`"))msg!("the lifetime requirements from the `impl` do not correspond to the requirements in the `trait`"));
1178 diag.span_help(type_param_span, msg);
1179 }
1180}
1181
1182#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for TraitImplDiff
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 {
TraitImplDiff {
sp: __binding_0,
trait_sp: __binding_1,
note: __binding_2,
param_help: __binding_3,
rel_help: __binding_4,
expected: __binding_5,
found: __binding_6 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`impl` item signature doesn't match `trait` item signature")));
;
diag.arg("expected", __binding_5);
diag.arg("found", __binding_6);
diag.span(__binding_0);
diag.span_label(__binding_0,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("found `{$found}`")));
diag.span_label(__binding_1,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("expected `{$expected}`")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("expected signature `{$expected}`\n {\" \"}found signature `{$found}`")));
diag.subdiagnostic(__binding_3);
if __binding_4 {
diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("verify the lifetime relationships in the `trait` and `impl` between the `self` argument, the other inputs and its output")));
}
diag
}
}
}
}
};Diagnostic)]
1183#[diag("`impl` item signature doesn't match `trait` item signature")]
1184pub struct TraitImplDiff {
1185 #[primary_span]
1186 #[label("found `{$found}`")]
1187 pub sp: Span,
1188 #[label("expected `{$expected}`")]
1189 pub trait_sp: Span,
1190 #[note(
1191 "expected signature `{$expected}`
1192 {\" \"}found signature `{$found}`"
1193 )]
1194 pub note: (),
1195 #[subdiagnostic]
1196 pub param_help: ConsiderBorrowingParamHelp,
1197 #[help(
1198 "verify the lifetime relationships in the `trait` and `impl` between the `self` argument, the other inputs and its output"
1199 )]
1200 pub rel_help: bool,
1201 pub expected: String,
1202 pub found: String,
1203}
1204
1205pub struct DynTraitConstraintSuggestion {
1206 pub span: Span,
1207 pub ident: Ident,
1208}
1209
1210impl Subdiagnostic for DynTraitConstraintSuggestion {
1211 fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
1212 let mut multi_span: MultiSpan = ::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
[self.span]))vec![self.span].into();
1213 multi_span.push_span_label(
1214 self.span,
1215 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this has an implicit `'static` lifetime requirement"))msg!("this has an implicit `'static` lifetime requirement"),
1216 );
1217 multi_span.push_span_label(
1218 self.ident.span,
1219 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("calling this method introduces the `impl`'s `'static` requirement"))msg!("calling this method introduces the `impl`'s `'static` requirement"),
1220 );
1221 let msg = diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the used `impl` has a `'static` requirement"))msg!("the used `impl` has a `'static` requirement"));
1222 diag.span_note(multi_span, msg);
1223 let msg =
1224 diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider relaxing the implicit `'static` requirement"))msg!("consider relaxing the implicit `'static` requirement"));
1225 diag.span_suggestion_verbose(
1226 self.span.shrink_to_hi(),
1227 msg,
1228 " + '_",
1229 Applicability::MaybeIncorrect,
1230 );
1231 }
1232}
1233
1234#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
ButCallingIntroduces 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 {
ButCallingIntroduces {
param_ty_span: __binding_0,
cause_span: __binding_1,
has_param_name: __binding_2,
param_name: __binding_3,
has_lifetime: __binding_4,
lifetime: __binding_5,
assoc_item: __binding_6,
has_impl_path: __binding_7,
impl_path: __binding_8 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$has_param_name ->\n [true] `{$param_name}`\n *[false] `fn` parameter\n} has {$lifetime_kind ->\n [true] lifetime `{$lifetime}`\n *[false] an anonymous lifetime `'_`\n} but calling `{$assoc_item}` introduces an implicit `'static` lifetime requirement")));
diag.code(E0772);
;
diag.arg("has_param_name", __binding_2);
diag.arg("param_name", __binding_3);
diag.arg("has_lifetime", __binding_4);
diag.arg("lifetime", __binding_5);
diag.arg("assoc_item", __binding_6);
diag.arg("has_impl_path", __binding_7);
diag.arg("impl_path", __binding_8);
diag.span_label(__binding_0,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$has_lifetime ->\n [true] lifetime `{$lifetime}`\n *[false] an anonymous lifetime `'_`\n }")));
diag.span(__binding_1);
diag.span_label(__binding_1,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("...is used and required to live as long as `'static` here because of an implicit lifetime bound on the {$has_impl_path ->\n [true] `impl` of `{$impl_path}`\n *[false] inherent `impl`\n }")));
diag
}
}
}
}
};Diagnostic)]
1235#[diag("{$has_param_name ->
1236 [true] `{$param_name}`
1237 *[false] `fn` parameter
1238} has {$lifetime_kind ->
1239 [true] lifetime `{$lifetime}`
1240 *[false] an anonymous lifetime `'_`
1241} but calling `{$assoc_item}` introduces an implicit `'static` lifetime requirement", code = E0772)]
1242pub struct ButCallingIntroduces {
1243 #[label(
1244 "{$has_lifetime ->
1245 [true] lifetime `{$lifetime}`
1246 *[false] an anonymous lifetime `'_`
1247 }"
1248 )]
1249 pub param_ty_span: Span,
1250 #[primary_span]
1251 #[label("...is used and required to live as long as `'static` here because of an implicit lifetime bound on the {$has_impl_path ->
1252 [true] `impl` of `{$impl_path}`
1253 *[false] inherent `impl`
1254 }")]
1255 pub cause_span: Span,
1256
1257 pub has_param_name: bool,
1258 pub param_name: String,
1259 pub has_lifetime: bool,
1260 pub lifetime: String,
1261 pub assoc_item: Symbol,
1262 pub has_impl_path: bool,
1263 pub impl_path: String,
1264}
1265
1266pub struct ReqIntroducedLocations {
1267 pub span: MultiSpan,
1268 pub spans: Vec<Span>,
1269 pub fn_decl_span: Span,
1270 pub cause_span: Span,
1271 pub add_label: bool,
1272}
1273
1274impl Subdiagnostic for ReqIntroducedLocations {
1275 fn add_to_diag<G: EmissionGuarantee>(mut self, diag: &mut Diag<'_, G>) {
1276 for sp in self.spans {
1277 self.span.push_span_label(sp, rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`'static` requirement introduced here"))msg!("`'static` requirement introduced here"));
1278 }
1279
1280 if self.add_label {
1281 self.span.push_span_label(
1282 self.fn_decl_span,
1283 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("requirement introduced by this return type"))msg!("requirement introduced by this return type"),
1284 );
1285 }
1286 self.span.push_span_label(self.cause_span, rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("because of this returned expression"))msg!("because of this returned expression"));
1287 let msg = diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("\"`'static` lifetime requirement introduced by the return type"))msg!(
1288 "\"`'static` lifetime requirement introduced by the return type"
1289 ));
1290 diag.span_note(self.span, msg);
1291 }
1292}
1293
1294#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
ButNeedsToSatisfy 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 {
ButNeedsToSatisfy {
sp: __binding_0,
influencer_point: __binding_1,
spans: __binding_2,
require_span_as_label: __binding_3,
require_span_as_note: __binding_4,
bound: __binding_5,
has_param_name: __binding_6,
param_name: __binding_7,
spans_empty: __binding_8,
has_lifetime: __binding_9,
lifetime: __binding_10 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$has_param_name ->\n [true] `{$param_name}`\n *[false] `fn` parameter\n} has {$has_lifetime ->\n [true] lifetime `{$lifetime}`\n *[false] an anonymous lifetime `'_`\n} but it needs to satisfy a `'static` lifetime requirement")));
diag.code(E0759);
;
diag.arg("has_param_name", __binding_6);
diag.arg("param_name", __binding_7);
diag.arg("spans_empty", __binding_8);
diag.arg("has_lifetime", __binding_9);
diag.arg("lifetime", __binding_10);
diag.span(__binding_0);
diag.span_label(__binding_1,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this data with {$has_lifetime ->\n [true] lifetime `{$lifetime}`\n *[false] an anonymous lifetime `'_`\n }...")));
for __binding_2 in __binding_2 {
diag.span_label(__binding_2,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("...is used here...")));
}
if let Some(__binding_3) = __binding_3 {
diag.span_label(__binding_3,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$spans_empty ->\n *[true] ...is used and required to live as long as `'static` here\n [false] ...and is required to live as long as `'static` here\n }")));
}
if let Some(__binding_4) = __binding_4 {
diag.span_note(__binding_4,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$spans_empty ->\n *[true] ...is used and required to live as long as `'static` here\n [false] ...and is required to live as long as `'static` here\n }")));
}
if let Some(__binding_5) = __binding_5 {
diag.span_note(__binding_5,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`'static` lifetime requirement introduced by this bound")));
}
diag
}
}
}
}
};Diagnostic)]
1295#[diag("{$has_param_name ->
1296 [true] `{$param_name}`
1297 *[false] `fn` parameter
1298} has {$has_lifetime ->
1299 [true] lifetime `{$lifetime}`
1300 *[false] an anonymous lifetime `'_`
1301} but it needs to satisfy a `'static` lifetime requirement", code = E0759)]
1302pub struct ButNeedsToSatisfy {
1303 #[primary_span]
1304 pub sp: Span,
1305 #[label(
1306 "this data with {$has_lifetime ->
1307 [true] lifetime `{$lifetime}`
1308 *[false] an anonymous lifetime `'_`
1309 }..."
1310 )]
1311 pub influencer_point: Span,
1312 #[label("...is used here...")]
1313 pub spans: Vec<Span>,
1314 #[label(
1315 "{$spans_empty ->
1316 *[true] ...is used and required to live as long as `'static` here
1317 [false] ...and is required to live as long as `'static` here
1318 }"
1319 )]
1320 pub require_span_as_label: Option<Span>,
1321 #[note(
1322 "{$spans_empty ->
1323 *[true] ...is used and required to live as long as `'static` here
1324 [false] ...and is required to live as long as `'static` here
1325 }"
1326 )]
1327 pub require_span_as_note: Option<Span>,
1328 #[note("`'static` lifetime requirement introduced by this bound")]
1329 pub bound: Option<Span>,
1330
1331 pub has_param_name: bool,
1332 pub param_name: String,
1333 pub spans_empty: bool,
1334 pub has_lifetime: bool,
1335 pub lifetime: String,
1336}
1337
1338#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
OutlivesContent<'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 {
OutlivesContent { span: __binding_0, notes: __binding_1 } =>
{
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("lifetime of reference outlives lifetime of borrowed content...")));
diag.code(E0312);
;
diag.span(__binding_0);
for __binding_1 in __binding_1 {
diag.subdiagnostic(__binding_1);
}
diag
}
}
}
}
};Diagnostic)]
1339#[diag("lifetime of reference outlives lifetime of borrowed content...", code = E0312)]
1340pub struct OutlivesContent<'a> {
1341 #[primary_span]
1342 pub span: Span,
1343 #[subdiagnostic]
1344 pub notes: Vec<note_and_explain::RegionExplanation<'a>>,
1345}
1346
1347#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
OutlivesBound<'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 {
OutlivesBound { span: __binding_0, notes: __binding_1 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("lifetime of the source pointer does not outlive lifetime bound of the object type")));
diag.code(E0476);
;
diag.span(__binding_0);
for __binding_1 in __binding_1 {
diag.subdiagnostic(__binding_1);
}
diag
}
}
}
}
};Diagnostic)]
1348#[diag("lifetime of the source pointer does not outlive lifetime bound of the object type", code = E0476)]
1349pub struct OutlivesBound<'a> {
1350 #[primary_span]
1351 pub span: Span,
1352 #[subdiagnostic]
1353 pub notes: Vec<note_and_explain::RegionExplanation<'a>>,
1354}
1355
1356#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
FulfillReqLifetime<'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 {
FulfillReqLifetime {
span: __binding_0, ty: __binding_1, note: __binding_2 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the type `{$ty}` does not fulfill the required lifetime")));
diag.code(E0477);
;
diag.arg("ty", __binding_1);
diag.span(__binding_0);
if let Some(__binding_2) = __binding_2 {
diag.subdiagnostic(__binding_2);
}
diag
}
}
}
}
};Diagnostic)]
1357#[diag("the type `{$ty}` does not fulfill the required lifetime", code = E0477)]
1358pub struct FulfillReqLifetime<'a> {
1359 #[primary_span]
1360 pub span: Span,
1361 pub ty: Ty<'a>,
1362 #[subdiagnostic]
1363 pub note: Option<note_and_explain::RegionExplanation<'a>>,
1364}
1365
1366#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
LfBoundNotSatisfied<'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 {
LfBoundNotSatisfied { span: __binding_0, notes: __binding_1
} => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("lifetime bound not satisfied")));
diag.code(E0478);
;
diag.span(__binding_0);
for __binding_1 in __binding_1 {
diag.subdiagnostic(__binding_1);
}
diag
}
}
}
}
};Diagnostic)]
1367#[diag("lifetime bound not satisfied", code = E0478)]
1368pub struct LfBoundNotSatisfied<'a> {
1369 #[primary_span]
1370 pub span: Span,
1371 #[subdiagnostic]
1372 pub notes: Vec<note_and_explain::RegionExplanation<'a>>,
1373}
1374
1375#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
RefLongerThanData<'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 {
RefLongerThanData {
span: __binding_0, ty: __binding_1, notes: __binding_2 } =>
{
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("in type `{$ty}`, reference has a longer lifetime than the data it references")));
diag.code(E0491);
;
diag.arg("ty", __binding_1);
diag.span(__binding_0);
for __binding_2 in __binding_2 {
diag.subdiagnostic(__binding_2);
}
diag
}
}
}
}
};Diagnostic)]
1376#[diag("in type `{$ty}`, reference has a longer lifetime than the data it references", code = E0491)]
1377pub struct RefLongerThanData<'a> {
1378 #[primary_span]
1379 pub span: Span,
1380 pub ty: Ty<'a>,
1381 #[subdiagnostic]
1382 pub notes: Vec<note_and_explain::RegionExplanation<'a>>,
1383}
1384
1385#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for WhereClauseSuggestions {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
WhereClauseSuggestions::Remove { span: __binding_0 } => {
let __code_9 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!(""))
})].into_iter();
diag.store_args();
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("remove the `where` clause")));
diag.span_suggestions_with_style(__binding_0, __message,
__code_9, rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::ShowAlways);
diag.restore_args();
}
WhereClauseSuggestions::CopyPredicates {
span: __binding_0,
space: __binding_1,
trait_predicates: __binding_2 } => {
let __code_10 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0}where {1}",
__binding_1, __binding_2))
})].into_iter();
diag.store_args();
diag.arg("space", __binding_1);
diag.arg("trait_predicates", __binding_2);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("copy the `where` clause predicates from the trait")));
diag.span_suggestions_with_style(__binding_0, __message,
__code_10, rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::ShowAlways);
diag.restore_args();
}
}
}
}
};Subdiagnostic)]
1386pub enum WhereClauseSuggestions {
1387 #[suggestion(
1388 "remove the `where` clause",
1389 code = "",
1390 applicability = "machine-applicable",
1391 style = "verbose"
1392 )]
1393 Remove {
1394 #[primary_span]
1395 span: Span,
1396 },
1397 #[suggestion(
1398 "copy the `where` clause predicates from the trait",
1399 code = "{space}where {trait_predicates}",
1400 applicability = "machine-applicable",
1401 style = "verbose"
1402 )]
1403 CopyPredicates {
1404 #[primary_span]
1405 span: Span,
1406 space: &'static str,
1407 trait_predicates: String,
1408 },
1409}
1410
1411#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for SuggestRemoveSemiOrReturnBinding
{
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
SuggestRemoveSemiOrReturnBinding::RemoveAndBox {
first_lo: __binding_0,
first_hi: __binding_1,
second_lo: __binding_2,
second_hi: __binding_3,
sp: __binding_4 } => {
let mut suggestions = Vec::new();
let __code_11 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("Box::new("))
});
let __code_12 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!(")"))
});
let __code_13 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("Box::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!(""))
});
suggestions.push((__binding_0, __code_11));
suggestions.push((__binding_1, __code_12));
suggestions.push((__binding_2, __code_13));
suggestions.push((__binding_3, __code_14));
suggestions.push((__binding_4, __code_15));
diag.store_args();
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider removing this semicolon and boxing the expressions")));
diag.multipart_suggestion_with_style(__message, suggestions,
rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::ShowCode);
diag.restore_args();
}
SuggestRemoveSemiOrReturnBinding::Remove { sp: __binding_0 }
=> {
let __code_16 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!(""))
})].into_iter();
diag.store_args();
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider removing this semicolon")));
diag.span_suggestions_with_style(__binding_0, __message,
__code_16, rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::HideCodeInline);
diag.restore_args();
}
SuggestRemoveSemiOrReturnBinding::Add {
sp: __binding_0, code: __binding_1, ident: __binding_2 } =>
{
let __code_17 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0}", __binding_1))
})].into_iter();
diag.store_args();
diag.arg("code", __binding_1);
diag.arg("ident", __binding_2);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider returning the local binding `{$ident}`")));
diag.span_suggestions_with_style(__binding_0, __message,
__code_17, rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowAlways);
diag.restore_args();
}
SuggestRemoveSemiOrReturnBinding::AddOne {
spans: __binding_0 } => {
diag.store_args();
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider returning one of these bindings")));
diag.span_note(__binding_0, __message);
diag.restore_args();
}
}
}
}
};Subdiagnostic)]
1412pub enum SuggestRemoveSemiOrReturnBinding {
1413 #[multipart_suggestion(
1414 "consider removing this semicolon and boxing the expressions",
1415 applicability = "machine-applicable"
1416 )]
1417 RemoveAndBox {
1418 #[suggestion_part(code = "Box::new(")]
1419 first_lo: Span,
1420 #[suggestion_part(code = ")")]
1421 first_hi: Span,
1422 #[suggestion_part(code = "Box::new(")]
1423 second_lo: Span,
1424 #[suggestion_part(code = ")")]
1425 second_hi: Span,
1426 #[suggestion_part(code = "")]
1427 sp: Span,
1428 },
1429 #[suggestion(
1430 "consider removing this semicolon",
1431 style = "short",
1432 code = "",
1433 applicability = "machine-applicable"
1434 )]
1435 Remove {
1436 #[primary_span]
1437 sp: Span,
1438 },
1439 #[suggestion(
1440 "consider returning the local binding `{$ident}`",
1441 style = "verbose",
1442 code = "{code}",
1443 applicability = "maybe-incorrect"
1444 )]
1445 Add {
1446 #[primary_span]
1447 sp: Span,
1448 code: String,
1449 ident: Ident,
1450 },
1451 #[note("consider returning one of these bindings")]
1452 AddOne {
1453 #[primary_span]
1454 spans: MultiSpan,
1455 },
1456}
1457
1458#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for ConsiderAddingAwait {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
ConsiderAddingAwait::BothFuturesHelp => {
diag.store_args();
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider `await`ing on both `Future`s")));
diag.help(__message);
diag.restore_args();
}
ConsiderAddingAwait::BothFuturesSugg {
first: __binding_0, second: __binding_1 } => {
let mut suggestions = Vec::new();
let __code_18 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!(".await"))
});
let __code_19 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!(".await"))
});
suggestions.push((__binding_0, __code_18));
suggestions.push((__binding_1, __code_19));
diag.store_args();
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider `await`ing on both `Future`s")));
diag.multipart_suggestion_with_style(__message, suggestions,
rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowCode);
diag.restore_args();
}
ConsiderAddingAwait::FutureSugg { span: __binding_0 } => {
let __code_20 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!(".await"))
})].into_iter();
diag.store_args();
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider `await`ing on the `Future`")));
diag.span_suggestions_with_style(__binding_0, __message,
__code_20, rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowAlways);
diag.restore_args();
}
ConsiderAddingAwait::FutureSuggNote { span: __binding_0 } =>
{
diag.store_args();
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("calling an async function returns a future")));
diag.span_note(__binding_0, __message);
diag.restore_args();
}
ConsiderAddingAwait::FutureSuggMultiple { spans: __binding_0
} => {
let mut suggestions = Vec::new();
let __code_21 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!(".await"))
});
for __binding_0 in __binding_0 {
suggestions.push((__binding_0, __code_21.clone()));
}
diag.store_args();
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider `await`ing on the `Future`")));
diag.multipart_suggestion_with_style(__message, suggestions,
rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowAlways);
diag.restore_args();
}
}
}
}
};Subdiagnostic)]
1459pub enum ConsiderAddingAwait {
1460 #[help("consider `await`ing on both `Future`s")]
1461 BothFuturesHelp,
1462 #[multipart_suggestion(
1463 "consider `await`ing on both `Future`s",
1464 applicability = "maybe-incorrect"
1465 )]
1466 BothFuturesSugg {
1467 #[suggestion_part(code = ".await")]
1468 first: Span,
1469 #[suggestion_part(code = ".await")]
1470 second: Span,
1471 },
1472 #[suggestion(
1473 "consider `await`ing on the `Future`",
1474 code = ".await",
1475 style = "verbose",
1476 applicability = "maybe-incorrect"
1477 )]
1478 FutureSugg {
1479 #[primary_span]
1480 span: Span,
1481 },
1482 #[note("calling an async function returns a future")]
1483 FutureSuggNote {
1484 #[primary_span]
1485 span: Span,
1486 },
1487 #[multipart_suggestion(
1488 "consider `await`ing on the `Future`",
1489 style = "verbose",
1490 applicability = "maybe-incorrect"
1491 )]
1492 FutureSuggMultiple {
1493 #[suggestion_part(code = ".await")]
1494 spans: Vec<Span>,
1495 },
1496}
1497
1498#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
PlaceholderRelationLfNotSatisfied 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 {
PlaceholderRelationLfNotSatisfied::HasBoth {
span: __binding_0,
sub_span: __binding_1,
sup_span: __binding_2,
sub_symbol: __binding_3,
sup_symbol: __binding_4,
note: __binding_5 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("lifetime bound not satisfied")));
;
diag.arg("sub_symbol", __binding_3);
diag.arg("sup_symbol", __binding_4);
diag.span(__binding_0);
diag.span_note(__binding_1,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the lifetime `{$sub_symbol}` defined here...")));
diag.span_note(__binding_2,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("...must outlive the lifetime `{$sup_symbol}` defined here")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this is a known limitation that will be removed in the future (see issue #100013 <https://github.com/rust-lang/rust/issues/100013> for more information)")));
diag
}
PlaceholderRelationLfNotSatisfied::HasSub {
span: __binding_0,
sub_span: __binding_1,
sup_span: __binding_2,
sub_symbol: __binding_3,
note: __binding_4 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("lifetime bound not satisfied")));
;
diag.arg("sub_symbol", __binding_3);
diag.span(__binding_0);
diag.span_note(__binding_1,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the lifetime `{$sub_symbol}` defined here...")));
diag.span_note(__binding_2,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("...must outlive the lifetime defined here")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this is a known limitation that will be removed in the future (see issue #100013 <https://github.com/rust-lang/rust/issues/100013> for more information)")));
diag
}
PlaceholderRelationLfNotSatisfied::HasSup {
span: __binding_0,
sub_span: __binding_1,
sup_span: __binding_2,
sup_symbol: __binding_3,
note: __binding_4 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("lifetime bound not satisfied")));
;
diag.arg("sup_symbol", __binding_3);
diag.span(__binding_0);
diag.span_note(__binding_1,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the lifetime defined here...")));
diag.span_note(__binding_2,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("...must outlive the lifetime `{$sup_symbol}` defined here")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this is a known limitation that will be removed in the future (see issue #100013 <https://github.com/rust-lang/rust/issues/100013> for more information)")));
diag
}
PlaceholderRelationLfNotSatisfied::HasNone {
span: __binding_0,
sub_span: __binding_1,
sup_span: __binding_2,
note: __binding_3 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("lifetime bound not satisfied")));
;
diag.span(__binding_0);
diag.span_note(__binding_1,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the lifetime defined here...")));
diag.span_note(__binding_2,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("...must outlive the lifetime defined here")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this is a known limitation that will be removed in the future (see issue #100013 <https://github.com/rust-lang/rust/issues/100013> for more information)")));
diag
}
PlaceholderRelationLfNotSatisfied::OnlyPrimarySpan {
span: __binding_0, note: __binding_1 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("lifetime bound not satisfied")));
;
diag.span(__binding_0);
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this is a known limitation that will be removed in the future (see issue #100013 <https://github.com/rust-lang/rust/issues/100013> for more information)")));
diag
}
}
}
}
};Diagnostic)]
1499pub enum PlaceholderRelationLfNotSatisfied {
1500 #[diag("lifetime bound not satisfied")]
1501 HasBoth {
1502 #[primary_span]
1503 span: Span,
1504 #[note("the lifetime `{$sub_symbol}` defined here...")]
1505 sub_span: Span,
1506 #[note("...must outlive the lifetime `{$sup_symbol}` defined here")]
1507 sup_span: Span,
1508 sub_symbol: Symbol,
1509 sup_symbol: Symbol,
1510 #[note(
1511 "this is a known limitation that will be removed in the future (see issue #100013 <https://github.com/rust-lang/rust/issues/100013> for more information)"
1512 )]
1513 note: (),
1514 },
1515 #[diag("lifetime bound not satisfied")]
1516 HasSub {
1517 #[primary_span]
1518 span: Span,
1519 #[note("the lifetime `{$sub_symbol}` defined here...")]
1520 sub_span: Span,
1521 #[note("...must outlive the lifetime defined here")]
1522 sup_span: Span,
1523 sub_symbol: Symbol,
1524 #[note(
1525 "this is a known limitation that will be removed in the future (see issue #100013 <https://github.com/rust-lang/rust/issues/100013> for more information)"
1526 )]
1527 note: (),
1528 },
1529 #[diag("lifetime bound not satisfied")]
1530 HasSup {
1531 #[primary_span]
1532 span: Span,
1533 #[note("the lifetime defined here...")]
1534 sub_span: Span,
1535 #[note("...must outlive the lifetime `{$sup_symbol}` defined here")]
1536 sup_span: Span,
1537 sup_symbol: Symbol,
1538 #[note(
1539 "this is a known limitation that will be removed in the future (see issue #100013 <https://github.com/rust-lang/rust/issues/100013> for more information)"
1540 )]
1541 note: (),
1542 },
1543 #[diag("lifetime bound not satisfied")]
1544 HasNone {
1545 #[primary_span]
1546 span: Span,
1547 #[note("the lifetime defined here...")]
1548 sub_span: Span,
1549 #[note("...must outlive the lifetime defined here")]
1550 sup_span: Span,
1551 #[note(
1552 "this is a known limitation that will be removed in the future (see issue #100013 <https://github.com/rust-lang/rust/issues/100013> for more information)"
1553 )]
1554 note: (),
1555 },
1556 #[diag("lifetime bound not satisfied")]
1557 OnlyPrimarySpan {
1558 #[primary_span]
1559 span: Span,
1560 #[note(
1561 "this is a known limitation that will be removed in the future (see issue #100013 <https://github.com/rust-lang/rust/issues/100013> for more information)"
1562 )]
1563 note: (),
1564 },
1565}
1566
1567#[derive(const _: () =
{
impl<'_sess, 'tcx, G> rustc_errors::Diagnostic<'_sess, G> for
OpaqueCapturesLifetime<'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 {
OpaqueCapturesLifetime {
span: __binding_0,
opaque_ty_span: __binding_1,
opaque_ty: __binding_2 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("hidden type for `{$opaque_ty}` captures lifetime that does not appear in bounds")));
diag.code(E0700);
;
diag.arg("opaque_ty", __binding_2);
diag.span(__binding_0);
diag.span_label(__binding_1,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("opaque type defined here")));
diag
}
}
}
}
};Diagnostic)]
1568#[diag("hidden type for `{$opaque_ty}` captures lifetime that does not appear in bounds", code = E0700)]
1569pub struct OpaqueCapturesLifetime<'tcx> {
1570 #[primary_span]
1571 pub span: Span,
1572 #[label("opaque type defined here")]
1573 pub opaque_ty_span: Span,
1574 pub opaque_ty: Ty<'tcx>,
1575}
1576
1577#[derive(const _: () =
{
impl<'a> rustc_errors::Subdiagnostic for FunctionPointerSuggestion<'a>
{
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
FunctionPointerSuggestion::UseRef { span: __binding_0 } => {
let __code_22 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("&"))
})].into_iter();
diag.store_args();
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider using a reference")));
diag.span_suggestions_with_style(__binding_0, __message,
__code_22, rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowAlways);
diag.restore_args();
}
FunctionPointerSuggestion::RemoveRef {
span: __binding_0, fn_name: __binding_1 } => {
let __code_23 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0}", __binding_1))
})].into_iter();
diag.store_args();
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider removing the reference")));
diag.span_suggestions_with_style(__binding_0, __message,
__code_23, rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowAlways);
diag.restore_args();
}
FunctionPointerSuggestion::CastRef {
span: __binding_0, fn_name: __binding_1, sig: __binding_2 }
=> {
let __code_24 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("&({0} as {1})",
__binding_1, __binding_2))
})].into_iter();
diag.store_args();
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider casting to a fn pointer")));
diag.span_suggestions_with_style(__binding_0, __message,
__code_24, rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowAlways);
diag.restore_args();
}
FunctionPointerSuggestion::Cast {
span: __binding_0, sig: __binding_1 } => {
let __code_25 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!(" as {0}", __binding_1))
})].into_iter();
diag.store_args();
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider casting to a fn pointer")));
diag.span_suggestions_with_style(__binding_0, __message,
__code_25, rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowAlways);
diag.restore_args();
}
FunctionPointerSuggestion::CastBoth {
span: __binding_0,
found_sig: __binding_1,
expected_sig: __binding_2 } => {
let __code_26 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!(" as {0}", __binding_1))
})].into_iter();
diag.store_args();
diag.arg("expected_sig", __binding_2);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider casting both fn items to fn pointers using `as {$expected_sig}`")));
diag.span_suggestions_with_style(__binding_0, __message,
__code_26, rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::HideCodeAlways);
diag.restore_args();
}
FunctionPointerSuggestion::CastBothRef {
span: __binding_0,
fn_name: __binding_1,
found_sig: __binding_2,
expected_sig: __binding_3 } => {
let __code_27 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("&({0} as {1})",
__binding_1, __binding_2))
})].into_iter();
diag.store_args();
diag.arg("expected_sig", __binding_3);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider casting both fn items to fn pointers using `as {$expected_sig}`")));
diag.span_suggestions_with_style(__binding_0, __message,
__code_27, rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::HideCodeAlways);
diag.restore_args();
}
}
}
}
};Subdiagnostic)]
1578pub enum FunctionPointerSuggestion<'a> {
1579 #[suggestion(
1580 "consider using a reference",
1581 code = "&",
1582 style = "verbose",
1583 applicability = "maybe-incorrect"
1584 )]
1585 UseRef {
1586 #[primary_span]
1587 span: Span,
1588 },
1589 #[suggestion(
1590 "consider removing the reference",
1591 code = "{fn_name}",
1592 style = "verbose",
1593 applicability = "maybe-incorrect"
1594 )]
1595 RemoveRef {
1596 #[primary_span]
1597 span: Span,
1598 #[skip_arg]
1599 fn_name: String,
1600 },
1601 #[suggestion(
1602 "consider casting to a fn pointer",
1603 code = "&({fn_name} as {sig})",
1604 style = "verbose",
1605 applicability = "maybe-incorrect"
1606 )]
1607 CastRef {
1608 #[primary_span]
1609 span: Span,
1610 #[skip_arg]
1611 fn_name: String,
1612 #[skip_arg]
1613 sig: Binder<'a, FnSig<'a>>,
1614 },
1615 #[suggestion(
1616 "consider casting to a fn pointer",
1617 code = " as {sig}",
1618 style = "verbose",
1619 applicability = "maybe-incorrect"
1620 )]
1621 Cast {
1622 #[primary_span]
1623 span: Span,
1624 #[skip_arg]
1625 sig: Binder<'a, FnSig<'a>>,
1626 },
1627 #[suggestion(
1628 "consider casting both fn items to fn pointers using `as {$expected_sig}`",
1629 code = " as {found_sig}",
1630 style = "hidden",
1631 applicability = "maybe-incorrect"
1632 )]
1633 CastBoth {
1634 #[primary_span]
1635 span: Span,
1636 #[skip_arg]
1637 found_sig: Binder<'a, FnSig<'a>>,
1638 expected_sig: Binder<'a, FnSig<'a>>,
1639 },
1640 #[suggestion(
1641 "consider casting both fn items to fn pointers using `as {$expected_sig}`",
1642 code = "&({fn_name} as {found_sig})",
1643 style = "hidden",
1644 applicability = "maybe-incorrect"
1645 )]
1646 CastBothRef {
1647 #[primary_span]
1648 span: Span,
1649 #[skip_arg]
1650 fn_name: String,
1651 #[skip_arg]
1652 found_sig: Binder<'a, FnSig<'a>>,
1653 expected_sig: Binder<'a, FnSig<'a>>,
1654 },
1655}
1656
1657#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for FnItemsAreDistinct {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
FnItemsAreDistinct => {
diag.store_args();
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("fn items are distinct from fn pointers")));
diag.note(__message);
diag.restore_args();
}
}
}
}
};Subdiagnostic)]
1658#[note("fn items are distinct from fn pointers")]
1659pub struct FnItemsAreDistinct;
1660
1661#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for FnUniqTypes {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
FnUniqTypes => {
diag.store_args();
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("different fn items have unique types, even if their signatures are the same")));
diag.note(__message);
diag.restore_args();
}
}
}
}
};Subdiagnostic)]
1662#[note("different fn items have unique types, even if their signatures are the same")]
1663pub struct FnUniqTypes;
1664
1665#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for FnConsiderCasting {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
FnConsiderCasting { casting: __binding_0 } => {
diag.store_args();
diag.arg("casting", __binding_0);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider casting the fn item to a fn pointer: `{$casting}`")));
diag.help(__message);
diag.restore_args();
}
}
}
}
};Subdiagnostic)]
1666#[help("consider casting the fn item to a fn pointer: `{$casting}`")]
1667pub struct FnConsiderCasting {
1668 pub casting: String,
1669}
1670
1671#[derive(const _: () =
{
impl<'a> rustc_errors::Subdiagnostic for FnConsiderCastingBoth<'a> {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
FnConsiderCastingBoth { sig: __binding_0 } => {
diag.store_args();
diag.arg("sig", __binding_0);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider casting both fn items to fn pointers using `as {$sig}`")));
diag.help(__message);
diag.restore_args();
}
}
}
}
};Subdiagnostic)]
1672#[help("consider casting both fn items to fn pointers using `as {$sig}`")]
1673pub struct FnConsiderCastingBoth<'a> {
1674 pub sig: Binder<'a, FnSig<'a>>,
1675}
1676
1677#[derive(const _: () =
{
impl<'a> rustc_errors::Subdiagnostic for SuggestAccessingField<'a> {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
SuggestAccessingField::Safe {
span: __binding_0,
snippet: __binding_1,
name: __binding_2,
ty: __binding_3 } => {
let __code_28 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{1}.{0}", __binding_2,
__binding_1))
})].into_iter();
diag.store_args();
diag.arg("snippet", __binding_1);
diag.arg("name", __binding_2);
diag.arg("ty", __binding_3);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("you might have meant to use field `{$name}` whose type is `{$ty}`")));
diag.span_suggestions_with_style(__binding_0, __message,
__code_28, rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowAlways);
diag.restore_args();
}
SuggestAccessingField::Unsafe {
span: __binding_0,
snippet: __binding_1,
name: __binding_2,
ty: __binding_3 } => {
let __code_29 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("unsafe {{ {1}.{0} }}",
__binding_2, __binding_1))
})].into_iter();
diag.store_args();
diag.arg("snippet", __binding_1);
diag.arg("name", __binding_2);
diag.arg("ty", __binding_3);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("you might have meant to use field `{$name}` whose type is `{$ty}`")));
diag.span_suggestions_with_style(__binding_0, __message,
__code_29, rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowAlways);
diag.restore_args();
}
}
}
}
};Subdiagnostic)]
1678pub enum SuggestAccessingField<'a> {
1679 #[suggestion(
1680 "you might have meant to use field `{$name}` whose type is `{$ty}`",
1681 code = "{snippet}.{name}",
1682 applicability = "maybe-incorrect",
1683 style = "verbose"
1684 )]
1685 Safe {
1686 #[primary_span]
1687 span: Span,
1688 snippet: String,
1689 name: Symbol,
1690 ty: Ty<'a>,
1691 },
1692 #[suggestion(
1693 "you might have meant to use field `{$name}` whose type is `{$ty}`",
1694 code = "unsafe {{ {snippet}.{name} }}",
1695 applicability = "maybe-incorrect",
1696 style = "verbose"
1697 )]
1698 Unsafe {
1699 #[primary_span]
1700 span: Span,
1701 snippet: String,
1702 name: Symbol,
1703 ty: Ty<'a>,
1704 },
1705}
1706
1707#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for SuggestTuplePatternOne {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
SuggestTuplePatternOne {
variant: __binding_0,
span_low: __binding_1,
span_high: __binding_2 } => {
let mut suggestions = Vec::new();
let __code_30 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0}(", __binding_0))
});
let __code_31 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!(")"))
});
suggestions.push((__binding_1, __code_30));
suggestions.push((__binding_2, __code_31));
diag.store_args();
diag.arg("variant", __binding_0);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("try wrapping the pattern in `{$variant}`")));
diag.multipart_suggestion_with_style(__message, suggestions,
rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowCode);
diag.restore_args();
}
}
}
}
};Subdiagnostic)]
1708#[multipart_suggestion(
1709 "try wrapping the pattern in `{$variant}`",
1710 applicability = "maybe-incorrect"
1711)]
1712pub struct SuggestTuplePatternOne {
1713 pub variant: String,
1714 #[suggestion_part(code = "{variant}(")]
1715 pub span_low: Span,
1716 #[suggestion_part(code = ")")]
1717 pub span_high: Span,
1718}
1719
1720pub struct SuggestTuplePatternMany {
1721 pub path: String,
1722 pub cause_span: Span,
1723 pub compatible_variants: Vec<String>,
1724}
1725
1726impl Subdiagnostic for SuggestTuplePatternMany {
1727 fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
1728 diag.arg("path", self.path);
1729 let message =
1730 diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("try wrapping the pattern in a variant of `{$path}`"))msg!("try wrapping the pattern in a variant of `{$path}`"));
1731 diag.multipart_suggestions(
1732 message,
1733 self.compatible_variants.into_iter().map(|variant| {
1734 ::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
[(self.cause_span.shrink_to_lo(),
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0}(", variant))
})), (self.cause_span.shrink_to_hi(), ")".to_string())]))vec![
1735 (self.cause_span.shrink_to_lo(), format!("{variant}(")),
1736 (self.cause_span.shrink_to_hi(), ")".to_string()),
1737 ]
1738 }),
1739 rustc_errors::Applicability::MaybeIncorrect,
1740 );
1741 }
1742}
1743
1744#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for TypeErrorAdditionalDiags {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
TypeErrorAdditionalDiags::MeantByteLiteral {
span: __binding_0, code: __binding_1 } => {
let __code_32 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("b\'{0}\'", __binding_1))
})].into_iter();
diag.store_args();
diag.arg("code", __binding_1);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("if you meant to write a byte literal, prefix with `b`")));
diag.span_suggestions_with_style(__binding_0, __message,
__code_32, rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::ShowCode);
diag.restore_args();
}
TypeErrorAdditionalDiags::MeantCharLiteral {
span: __binding_0, code: __binding_1 } => {
let __code_33 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("\'{0}\'", __binding_1))
})].into_iter();
diag.store_args();
diag.arg("code", __binding_1);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("if you meant to write a `char` literal, use single quotes")));
diag.span_suggestions_with_style(__binding_0, __message,
__code_33, rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::ShowCode);
diag.restore_args();
}
TypeErrorAdditionalDiags::MeantStrLiteral {
start: __binding_0, end: __binding_1 } => {
let mut suggestions = Vec::new();
let __code_34 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("\""))
});
let __code_35 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("\""))
});
suggestions.push((__binding_0, __code_34));
suggestions.push((__binding_1, __code_35));
diag.store_args();
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("if you meant to write a string literal, use double quotes")));
diag.multipart_suggestion_with_style(__message, suggestions,
rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::ShowCode);
diag.restore_args();
}
TypeErrorAdditionalDiags::ConsiderSpecifyingLength {
span: __binding_0, length: __binding_1 } => {
let __code_36 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0}", __binding_1))
})].into_iter();
diag.store_args();
diag.arg("length", __binding_1);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider specifying the actual array length")));
diag.span_suggestions_with_style(__binding_0, __message,
__code_36, rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowCode);
diag.restore_args();
}
TypeErrorAdditionalDiags::TryCannotConvert {
found: __binding_0, expected: __binding_1 } => {
diag.store_args();
diag.arg("found", __binding_0);
diag.arg("expected", __binding_1);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`?` operator cannot convert from `{$found}` to `{$expected}`")));
diag.note(__message);
diag.restore_args();
}
TypeErrorAdditionalDiags::TupleOnlyComma { span: __binding_0
} => {
let __code_37 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!(","))
})].into_iter();
diag.store_args();
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("use a trailing comma to create a tuple with one element")));
diag.span_suggestions_with_style(__binding_0, __message,
__code_37, rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::ShowCode);
diag.restore_args();
}
TypeErrorAdditionalDiags::TupleAlsoParentheses {
span_low: __binding_0, span_high: __binding_1 } => {
let mut suggestions = Vec::new();
let __code_38 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("("))
});
let __code_39 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!(",)"))
});
suggestions.push((__binding_0, __code_38));
suggestions.push((__binding_1, __code_39));
diag.store_args();
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("use a trailing comma to create a tuple with one element")));
diag.multipart_suggestion_with_style(__message, suggestions,
rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::ShowCode);
diag.restore_args();
}
TypeErrorAdditionalDiags::AddLetForLetChains {
span: __binding_0 } => {
let __code_40 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("let "))
})].into_iter();
diag.store_args();
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider adding `let`")));
diag.span_suggestions_with_style(__binding_0, __message,
__code_40, rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::ShowAlways);
diag.restore_args();
}
}
}
}
};Subdiagnostic)]
1745pub enum TypeErrorAdditionalDiags {
1746 #[suggestion(
1747 "if you meant to write a byte literal, prefix with `b`",
1748 code = "b'{code}'",
1749 applicability = "machine-applicable"
1750 )]
1751 MeantByteLiteral {
1752 #[primary_span]
1753 span: Span,
1754 code: String,
1755 },
1756 #[suggestion(
1757 "if you meant to write a `char` literal, use single quotes",
1758 code = "'{code}'",
1759 applicability = "machine-applicable"
1760 )]
1761 MeantCharLiteral {
1762 #[primary_span]
1763 span: Span,
1764 code: String,
1765 },
1766 #[multipart_suggestion(
1767 "if you meant to write a string literal, use double quotes",
1768 applicability = "machine-applicable"
1769 )]
1770 MeantStrLiteral {
1771 #[suggestion_part(code = "\"")]
1772 start: Span,
1773 #[suggestion_part(code = "\"")]
1774 end: Span,
1775 },
1776 #[suggestion(
1777 "consider specifying the actual array length",
1778 code = "{length}",
1779 applicability = "maybe-incorrect"
1780 )]
1781 ConsiderSpecifyingLength {
1782 #[primary_span]
1783 span: Span,
1784 length: u64,
1785 },
1786 #[note("`?` operator cannot convert from `{$found}` to `{$expected}`")]
1787 TryCannotConvert { found: String, expected: String },
1788 #[suggestion(
1789 "use a trailing comma to create a tuple with one element",
1790 code = ",",
1791 applicability = "machine-applicable"
1792 )]
1793 TupleOnlyComma {
1794 #[primary_span]
1795 span: Span,
1796 },
1797 #[multipart_suggestion(
1798 "use a trailing comma to create a tuple with one element",
1799 applicability = "machine-applicable"
1800 )]
1801 TupleAlsoParentheses {
1802 #[suggestion_part(code = "(")]
1803 span_low: Span,
1804 #[suggestion_part(code = ",)")]
1805 span_high: Span,
1806 },
1807 #[suggestion(
1808 "consider adding `let`",
1809 style = "verbose",
1810 applicability = "machine-applicable",
1811 code = "let "
1812 )]
1813 AddLetForLetChains {
1814 #[primary_span]
1815 span: Span,
1816 },
1817}
1818
1819#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
ObligationCauseFailureCode 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 {
ObligationCauseFailureCode::MethodCompat {
span: __binding_0, subdiags: __binding_1 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("method not compatible with trait")));
diag.code(E0308);
;
diag.span(__binding_0);
for __binding_1 in __binding_1 {
diag.subdiagnostic(__binding_1);
}
diag
}
ObligationCauseFailureCode::TypeCompat {
span: __binding_0, subdiags: __binding_1 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("type not compatible with trait")));
diag.code(E0308);
;
diag.span(__binding_0);
for __binding_1 in __binding_1 {
diag.subdiagnostic(__binding_1);
}
diag
}
ObligationCauseFailureCode::ConstCompat {
span: __binding_0, subdiags: __binding_1 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("const not compatible with trait")));
diag.code(E0308);
;
diag.span(__binding_0);
for __binding_1 in __binding_1 {
diag.subdiagnostic(__binding_1);
}
diag
}
ObligationCauseFailureCode::TryCompat {
span: __binding_0, subdiags: __binding_1 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`?` operator has incompatible types")));
diag.code(E0308);
;
diag.span(__binding_0);
for __binding_1 in __binding_1 {
diag.subdiagnostic(__binding_1);
}
diag
}
ObligationCauseFailureCode::MatchCompat {
span: __binding_0, subdiags: __binding_1 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`match` arms have incompatible types")));
diag.code(E0308);
;
diag.span(__binding_0);
for __binding_1 in __binding_1 {
diag.subdiagnostic(__binding_1);
}
diag
}
ObligationCauseFailureCode::IfElseDifferent {
span: __binding_0, subdiags: __binding_1 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`if` and `else` have incompatible types")));
diag.code(E0308);
;
diag.span(__binding_0);
for __binding_1 in __binding_1 {
diag.subdiagnostic(__binding_1);
}
diag
}
ObligationCauseFailureCode::NoElse { span: __binding_0 } =>
{
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`if` may be missing an `else` clause")));
diag.code(E0317);
;
diag.span(__binding_0);
diag
}
ObligationCauseFailureCode::NoDiverge {
span: __binding_0, subdiags: __binding_1 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`else` clause of `let...else` does not diverge")));
diag.code(E0308);
;
diag.span(__binding_0);
for __binding_1 in __binding_1 {
diag.subdiagnostic(__binding_1);
}
diag
}
ObligationCauseFailureCode::FnMainCorrectType {
span: __binding_0 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`main` function has wrong type")));
diag.code(E0580);
;
diag.span(__binding_0);
diag
}
ObligationCauseFailureCode::FnLangCorrectType {
span: __binding_0,
subdiags: __binding_1,
lang_item_name: __binding_2 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$lang_item_name ->\n [panic_impl] `#[panic_handler]`\n *[lang_item_name] lang item `{$lang_item_name}`\n } function has wrong type")));
diag.code(E0308);
;
diag.arg("lang_item_name", __binding_2);
diag.span(__binding_0);
for __binding_1 in __binding_1 {
diag.subdiagnostic(__binding_1);
}
diag
}
ObligationCauseFailureCode::IntrinsicCorrectType {
span: __binding_0, subdiags: __binding_1 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("intrinsic has wrong type")));
diag.code(E0308);
;
diag.span(__binding_0);
for __binding_1 in __binding_1 {
diag.subdiagnostic(__binding_1);
}
diag
}
ObligationCauseFailureCode::MethodCorrectType {
span: __binding_0, subdiags: __binding_1 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("mismatched `self` parameter type")));
diag.code(E0308);
;
diag.span(__binding_0);
for __binding_1 in __binding_1 {
diag.subdiagnostic(__binding_1);
}
diag
}
ObligationCauseFailureCode::ClosureSelfref {
span: __binding_0 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("closure/coroutine type that references itself")));
diag.code(E0644);
;
diag.span(__binding_0);
diag
}
ObligationCauseFailureCode::CantCoerceForceInline {
span: __binding_0, subdiags: __binding_1 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("cannot coerce functions which must be inlined to function pointers")));
diag.code(E0308);
;
diag.span(__binding_0);
for __binding_1 in __binding_1 {
diag.subdiagnostic(__binding_1);
}
diag
}
ObligationCauseFailureCode::CantCoerceIntrinsic {
span: __binding_0, subdiags: __binding_1 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("cannot coerce intrinsics to function pointers")));
diag.code(E0308);
;
diag.span(__binding_0);
for __binding_1 in __binding_1 {
diag.subdiagnostic(__binding_1);
}
diag
}
ObligationCauseFailureCode::Generic {
span: __binding_0, subdiags: __binding_1 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("mismatched types")));
diag.code(E0308);
;
diag.span(__binding_0);
for __binding_1 in __binding_1 {
diag.subdiagnostic(__binding_1);
}
diag
}
}
}
}
};Diagnostic)]
1820pub enum ObligationCauseFailureCode {
1821 #[diag("method not compatible with trait", code = E0308)]
1822 MethodCompat {
1823 #[primary_span]
1824 span: Span,
1825 #[subdiagnostic]
1826 subdiags: Vec<TypeErrorAdditionalDiags>,
1827 },
1828 #[diag("type not compatible with trait", code = E0308)]
1829 TypeCompat {
1830 #[primary_span]
1831 span: Span,
1832 #[subdiagnostic]
1833 subdiags: Vec<TypeErrorAdditionalDiags>,
1834 },
1835 #[diag("const not compatible with trait", code = E0308)]
1836 ConstCompat {
1837 #[primary_span]
1838 span: Span,
1839 #[subdiagnostic]
1840 subdiags: Vec<TypeErrorAdditionalDiags>,
1841 },
1842 #[diag("`?` operator has incompatible types", code = E0308)]
1843 TryCompat {
1844 #[primary_span]
1845 span: Span,
1846 #[subdiagnostic]
1847 subdiags: Vec<TypeErrorAdditionalDiags>,
1848 },
1849 #[diag("`match` arms have incompatible types", code = E0308)]
1850 MatchCompat {
1851 #[primary_span]
1852 span: Span,
1853 #[subdiagnostic]
1854 subdiags: Vec<TypeErrorAdditionalDiags>,
1855 },
1856 #[diag("`if` and `else` have incompatible types", code = E0308)]
1857 IfElseDifferent {
1858 #[primary_span]
1859 span: Span,
1860 #[subdiagnostic]
1861 subdiags: Vec<TypeErrorAdditionalDiags>,
1862 },
1863 #[diag("`if` may be missing an `else` clause", code = E0317)]
1864 NoElse {
1865 #[primary_span]
1866 span: Span,
1867 },
1868 #[diag("`else` clause of `let...else` does not diverge", code = E0308)]
1869 NoDiverge {
1870 #[primary_span]
1871 span: Span,
1872 #[subdiagnostic]
1873 subdiags: Vec<TypeErrorAdditionalDiags>,
1874 },
1875 #[diag("`main` function has wrong type", code = E0580)]
1876 FnMainCorrectType {
1877 #[primary_span]
1878 span: Span,
1879 },
1880 #[diag(
1881 "{$lang_item_name ->
1882 [panic_impl] `#[panic_handler]`
1883 *[lang_item_name] lang item `{$lang_item_name}`
1884 } function has wrong type"
1885 , code = E0308)]
1886 FnLangCorrectType {
1887 #[primary_span]
1888 span: Span,
1889 #[subdiagnostic]
1890 subdiags: Vec<TypeErrorAdditionalDiags>,
1891 lang_item_name: Symbol,
1892 },
1893 #[diag("intrinsic has wrong type", code = E0308)]
1894 IntrinsicCorrectType {
1895 #[primary_span]
1896 span: Span,
1897 #[subdiagnostic]
1898 subdiags: Vec<TypeErrorAdditionalDiags>,
1899 },
1900 #[diag("mismatched `self` parameter type", code = E0308)]
1901 MethodCorrectType {
1902 #[primary_span]
1903 span: Span,
1904 #[subdiagnostic]
1905 subdiags: Vec<TypeErrorAdditionalDiags>,
1906 },
1907 #[diag("closure/coroutine type that references itself", code = E0644)]
1908 ClosureSelfref {
1909 #[primary_span]
1910 span: Span,
1911 },
1912 #[diag("cannot coerce functions which must be inlined to function pointers", code = E0308)]
1913 CantCoerceForceInline {
1914 #[primary_span]
1915 span: Span,
1916 #[subdiagnostic]
1917 subdiags: Vec<TypeErrorAdditionalDiags>,
1918 },
1919 #[diag("cannot coerce intrinsics to function pointers", code = E0308)]
1920 CantCoerceIntrinsic {
1921 #[primary_span]
1922 span: Span,
1923 #[subdiagnostic]
1924 subdiags: Vec<TypeErrorAdditionalDiags>,
1925 },
1926 #[diag("mismatched types", code = E0308)]
1927 Generic {
1928 #[primary_span]
1929 span: Span,
1930 #[subdiagnostic]
1931 subdiags: Vec<TypeErrorAdditionalDiags>,
1932 },
1933}
1934
1935#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for AddPreciseCapturing {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
AddPreciseCapturing::New {
span: __binding_0,
new_lifetime: __binding_1,
concatenated_bounds: __binding_2 } => {
let __code_41 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!(" + use<{0}>",
__binding_2))
})].into_iter();
diag.store_args();
diag.arg("new_lifetime", __binding_1);
diag.arg("concatenated_bounds", __binding_2);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("add a `use<...>` bound to explicitly capture `{$new_lifetime}`")));
diag.span_suggestions_with_style(__binding_0, __message,
__code_41, rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::ShowAlways);
diag.restore_args();
}
AddPreciseCapturing::Existing {
span: __binding_0,
new_lifetime: __binding_1,
pre: __binding_2,
post: __binding_3 } => {
let __code_42 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{2}{0}{1}", __binding_1,
__binding_3, __binding_2))
})].into_iter();
diag.store_args();
diag.arg("new_lifetime", __binding_1);
diag.arg("pre", __binding_2);
diag.arg("post", __binding_3);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("add `{$new_lifetime}` to the `use<...>` bound to explicitly capture it")));
diag.span_suggestions_with_style(__binding_0, __message,
__code_42, rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::ShowAlways);
diag.restore_args();
}
}
}
}
};Subdiagnostic)]
1936pub enum AddPreciseCapturing {
1937 #[suggestion(
1938 "add a `use<...>` bound to explicitly capture `{$new_lifetime}`",
1939 style = "verbose",
1940 code = " + use<{concatenated_bounds}>",
1941 applicability = "machine-applicable"
1942 )]
1943 New {
1944 #[primary_span]
1945 span: Span,
1946 new_lifetime: Symbol,
1947 concatenated_bounds: String,
1948 },
1949 #[suggestion(
1950 "add `{$new_lifetime}` to the `use<...>` bound to explicitly capture it",
1951 style = "verbose",
1952 code = "{pre}{new_lifetime}{post}",
1953 applicability = "machine-applicable"
1954 )]
1955 Existing {
1956 #[primary_span]
1957 span: Span,
1958 new_lifetime: Symbol,
1959 pre: &'static str,
1960 post: &'static str,
1961 },
1962}
1963
1964pub struct AddPreciseCapturingAndParams {
1965 pub suggs: Vec<(Span, String)>,
1966 pub new_lifetime: Symbol,
1967 pub apit_spans: Vec<Span>,
1968}
1969
1970impl Subdiagnostic for AddPreciseCapturingAndParams {
1971 fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
1972 diag.arg("new_lifetime", self.new_lifetime);
1973 diag.multipart_suggestion(
1974 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("add a `use<...>` bound to explicitly capture `{$new_lifetime}` after turning all argument-position `impl Trait` into type parameters, noting that this possibly affects the API of this crate"))msg!("add a `use<...>` bound to explicitly capture `{$new_lifetime}` after turning all argument-position `impl Trait` into type parameters, noting that this possibly affects the API of this crate"),
1975 self.suggs,
1976 Applicability::MaybeIncorrect,
1977 );
1978 diag.span_note(
1979 self.apit_spans,
1980 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("you could use a `use<...>` bound to explicitly capture `{$new_lifetime}`, but argument-position `impl Trait`s are not nameable"))msg!("you could use a `use<...>` bound to explicitly capture `{$new_lifetime}`, but argument-position `impl Trait`s are not nameable"),
1981 );
1982 }
1983}
1984
1985pub fn impl_trait_overcapture_suggestion<'tcx>(
1990 tcx: TyCtxt<'tcx>,
1991 opaque_def_id: LocalDefId,
1992 fn_def_id: LocalDefId,
1993 captured_args: FxIndexSet<DefId>,
1994) -> Option<AddPreciseCapturingForOvercapture> {
1995 let generics = tcx.generics_of(fn_def_id);
1996
1997 let mut captured_lifetimes = FxIndexSet::default();
1998 let mut captured_non_lifetimes = FxIndexSet::default();
1999 let mut synthetics = ::alloc::vec::Vec::new()vec![];
2000
2001 for arg in captured_args {
2002 if tcx.def_kind(arg) == DefKind::LifetimeParam {
2003 captured_lifetimes.insert(tcx.item_name(arg));
2004 } else {
2005 let idx = generics.param_def_id_to_index(tcx, arg).expect("expected arg in scope");
2006 let param = generics.param_at(idx as usize, tcx);
2007 if param.kind.is_synthetic() {
2008 synthetics.push((tcx.def_span(arg), param.name));
2009 } else {
2010 captured_non_lifetimes.insert(tcx.item_name(arg));
2011 }
2012 }
2013 }
2014
2015 let mut next_fresh_param = || {
2016 ['T', 'U', 'V', 'W', 'X', 'Y', 'A', 'B', 'C']
2017 .into_iter()
2018 .map(sym::character)
2019 .chain((0..).map(|i| Symbol::intern(&::alloc::__export::must_use({ ::alloc::fmt::format(format_args!("T{0}", i)) })format!("T{i}"))))
2020 .find(|s| captured_non_lifetimes.insert(*s))
2021 .unwrap()
2022 };
2023
2024 let mut suggs = ::alloc::vec::Vec::new()vec![];
2025 let mut apit_spans = ::alloc::vec::Vec::new()vec![];
2026
2027 if !synthetics.is_empty() {
2028 let mut new_params = String::new();
2029 for (i, (span, name)) in synthetics.into_iter().enumerate() {
2030 apit_spans.push(span);
2031
2032 let fresh_param = next_fresh_param();
2033
2034 suggs.push((span, fresh_param.to_string()));
2036
2037 if i > 0 {
2045 new_params += ", ";
2046 }
2047 let name_as_bounds = name.as_str().trim_start_matches("impl").trim_start();
2048 new_params += fresh_param.as_str();
2049 new_params += ": ";
2050 new_params += name_as_bounds;
2051 }
2052
2053 let Some(generics) = tcx.hir_get_generics(fn_def_id) else {
2054 return None;
2056 };
2057
2058 suggs.push(if let Some(params_span) = generics.span_for_param_suggestion() {
2060 (params_span, ::alloc::__export::must_use({
::alloc::fmt::format(format_args!(", {0}", new_params))
})format!(", {new_params}"))
2061 } else {
2062 (generics.span, ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("<{0}>", new_params))
})format!("<{new_params}>"))
2063 });
2064 }
2065
2066 let concatenated_bounds = captured_lifetimes
2067 .into_iter()
2068 .chain(captured_non_lifetimes)
2069 .map(|sym| sym.to_string())
2070 .collect::<Vec<_>>()
2071 .join(", ");
2072
2073 let opaque_hir_id = tcx.local_def_id_to_hir_id(opaque_def_id);
2074 let (lparen, rparen) = match tcx
2076 .hir_parent_iter(opaque_hir_id)
2077 .nth(1)
2078 .expect("expected ty to have a parent always")
2079 .1
2080 {
2081 Node::PathSegment(segment)
2082 if segment.args().paren_sugar_output().is_some_and(|ty| ty.hir_id == opaque_hir_id) =>
2083 {
2084 ("(", ")")
2085 }
2086 Node::Ty(ty) => match ty.kind {
2087 rustc_hir::TyKind::Ptr(_) | rustc_hir::TyKind::Ref(..) => ("(", ")"),
2088 _ => ("", ""),
2092 },
2093 _ => ("", ""),
2094 };
2095
2096 let rpit_span = tcx.def_span(opaque_def_id);
2097 if !lparen.is_empty() {
2098 suggs.push((rpit_span.shrink_to_lo(), lparen.to_string()));
2099 }
2100 suggs.push((rpit_span.shrink_to_hi(), ::alloc::__export::must_use({
::alloc::fmt::format(format_args!(" + use<{0}>{1}",
concatenated_bounds, rparen))
})format!(" + use<{concatenated_bounds}>{rparen}")));
2101
2102 Some(AddPreciseCapturingForOvercapture { suggs, apit_spans })
2103}
2104
2105pub struct AddPreciseCapturingForOvercapture {
2106 pub suggs: Vec<(Span, String)>,
2107 pub apit_spans: Vec<Span>,
2108}
2109
2110impl Subdiagnostic for AddPreciseCapturingForOvercapture {
2111 fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
2112 let applicability = if self.apit_spans.is_empty() {
2113 Applicability::MachineApplicable
2114 } else {
2115 Applicability::MaybeIncorrect
2119 };
2120 diag.multipart_suggestion(
2121 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("use the precise capturing `use<...>` syntax to make the captures explicit"))msg!("use the precise capturing `use<...>` syntax to make the captures explicit"),
2122 self.suggs,
2123 applicability,
2124 );
2125 if !self.apit_spans.is_empty() {
2126 diag.span_note(
2127 self.apit_spans,
2128 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("you could use a `use<...>` bound to explicitly specify captures, but argument-position `impl Trait`s are not nameable"))msg!("you could use a `use<...>` bound to explicitly specify captures, but argument-position `impl Trait`s are not nameable"),
2129 );
2130 }
2131 }
2132}
2133
2134#[derive(const _: () =
{
impl<'_sess, 'a, 'tcx, G> rustc_errors::Diagnostic<'_sess, G> for
NonGenericOpaqueTypeParam<'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 {
NonGenericOpaqueTypeParam {
arg: __binding_0,
kind: __binding_1,
span: __binding_2,
param_span: __binding_3 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("expected generic {$kind} parameter, found `{$arg}`")));
diag.code(E0792);
;
diag.arg("arg", __binding_0);
diag.arg("kind", __binding_1);
diag.span(__binding_2);
diag.span_label(__binding_3,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{STREQ($arg, \"'static\") ->\n [true] cannot use static lifetime; use a bound lifetime instead or remove the lifetime parameter from the opaque type\n *[other] this generic parameter must be used with a generic {$kind} parameter\n }")));
diag
}
}
}
}
};Diagnostic)]
2135#[diag("expected generic {$kind} parameter, found `{$arg}`", code = E0792)]
2136pub(crate) struct NonGenericOpaqueTypeParam<'a, 'tcx> {
2137 pub arg: GenericArg<'tcx>,
2138 pub kind: &'a str,
2139 #[primary_span]
2140 pub span: Span,
2141 #[label("{STREQ($arg, \"'static\") ->
2142 [true] cannot use static lifetime; use a bound lifetime instead or remove the lifetime parameter from the opaque type
2143 *[other] this generic parameter must be used with a generic {$kind} parameter
2144 }")]
2145 pub param_span: Span,
2146}