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_format(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_format(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_format(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_format(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_format(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_format(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_format(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_format(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_format(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_format(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_format(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_format(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_format(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_format(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_format(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_format(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_format(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_format(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_format(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_format(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_format(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_format(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_format(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_format(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_format(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_format(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_format(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_format(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_format(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_format(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_format(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 = diag.eagerly_format(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider relaxing the implicit `'static` requirement"))msg!("consider relaxing the implicit `'static` requirement"));
1224 diag.span_suggestion_verbose(
1225 self.span.shrink_to_hi(),
1226 msg,
1227 " + '_",
1228 Applicability::MaybeIncorrect,
1229 );
1230 }
1231}
1232
1233#[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)]
1234#[diag("{$has_param_name ->
1235 [true] `{$param_name}`
1236 *[false] `fn` parameter
1237} has {$lifetime_kind ->
1238 [true] lifetime `{$lifetime}`
1239 *[false] an anonymous lifetime `'_`
1240} but calling `{$assoc_item}` introduces an implicit `'static` lifetime requirement", code = E0772)]
1241pub struct ButCallingIntroduces {
1242 #[label(
1243 "{$has_lifetime ->
1244 [true] lifetime `{$lifetime}`
1245 *[false] an anonymous lifetime `'_`
1246 }"
1247 )]
1248 pub param_ty_span: Span,
1249 #[primary_span]
1250 #[label("...is used and required to live as long as `'static` here because of an implicit lifetime bound on the {$has_impl_path ->
1251 [true] `impl` of `{$impl_path}`
1252 *[false] inherent `impl`
1253 }")]
1254 pub cause_span: Span,
1255
1256 pub has_param_name: bool,
1257 pub param_name: String,
1258 pub has_lifetime: bool,
1259 pub lifetime: String,
1260 pub assoc_item: Symbol,
1261 pub has_impl_path: bool,
1262 pub impl_path: String,
1263}
1264
1265pub struct ReqIntroducedLocations {
1266 pub span: MultiSpan,
1267 pub spans: Vec<Span>,
1268 pub fn_decl_span: Span,
1269 pub cause_span: Span,
1270 pub add_label: bool,
1271}
1272
1273impl Subdiagnostic for ReqIntroducedLocations {
1274 fn add_to_diag<G: EmissionGuarantee>(mut self, diag: &mut Diag<'_, G>) {
1275 for sp in self.spans {
1276 self.span.push_span_label(sp, rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`'static` requirement introduced here"))msg!("`'static` requirement introduced here"));
1277 }
1278
1279 if self.add_label {
1280 self.span.push_span_label(
1281 self.fn_decl_span,
1282 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("requirement introduced by this return type"))msg!("requirement introduced by this return type"),
1283 );
1284 }
1285 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"));
1286 let msg = diag
1287 .eagerly_format(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("\"`'static` lifetime requirement introduced by the return type"))msg!("\"`'static` lifetime requirement introduced by the return type"));
1288 diag.span_note(self.span, msg);
1289 }
1290}
1291
1292#[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)]
1293#[diag("{$has_param_name ->
1294 [true] `{$param_name}`
1295 *[false] `fn` parameter
1296} has {$has_lifetime ->
1297 [true] lifetime `{$lifetime}`
1298 *[false] an anonymous lifetime `'_`
1299} but it needs to satisfy a `'static` lifetime requirement", code = E0759)]
1300pub struct ButNeedsToSatisfy {
1301 #[primary_span]
1302 pub sp: Span,
1303 #[label(
1304 "this data with {$has_lifetime ->
1305 [true] lifetime `{$lifetime}`
1306 *[false] an anonymous lifetime `'_`
1307 }..."
1308 )]
1309 pub influencer_point: Span,
1310 #[label("...is used here...")]
1311 pub spans: Vec<Span>,
1312 #[label(
1313 "{$spans_empty ->
1314 *[true] ...is used and required to live as long as `'static` here
1315 [false] ...and is required to live as long as `'static` here
1316 }"
1317 )]
1318 pub require_span_as_label: Option<Span>,
1319 #[note(
1320 "{$spans_empty ->
1321 *[true] ...is used and required to live as long as `'static` here
1322 [false] ...and is required to live as long as `'static` here
1323 }"
1324 )]
1325 pub require_span_as_note: Option<Span>,
1326 #[note("`'static` lifetime requirement introduced by this bound")]
1327 pub bound: Option<Span>,
1328
1329 pub has_param_name: bool,
1330 pub param_name: String,
1331 pub spans_empty: bool,
1332 pub has_lifetime: bool,
1333 pub lifetime: String,
1334}
1335
1336#[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)]
1337#[diag("lifetime of reference outlives lifetime of borrowed content...", code = E0312)]
1338pub struct OutlivesContent<'a> {
1339 #[primary_span]
1340 pub span: Span,
1341 #[subdiagnostic]
1342 pub notes: Vec<note_and_explain::RegionExplanation<'a>>,
1343}
1344
1345#[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)]
1346#[diag("lifetime of the source pointer does not outlive lifetime bound of the object type", code = E0476)]
1347pub struct OutlivesBound<'a> {
1348 #[primary_span]
1349 pub span: Span,
1350 #[subdiagnostic]
1351 pub notes: Vec<note_and_explain::RegionExplanation<'a>>,
1352}
1353
1354#[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)]
1355#[diag("the type `{$ty}` does not fulfill the required lifetime", code = E0477)]
1356pub struct FulfillReqLifetime<'a> {
1357 #[primary_span]
1358 pub span: Span,
1359 pub ty: Ty<'a>,
1360 #[subdiagnostic]
1361 pub note: Option<note_and_explain::RegionExplanation<'a>>,
1362}
1363
1364#[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)]
1365#[diag("lifetime bound not satisfied", code = E0478)]
1366pub struct LfBoundNotSatisfied<'a> {
1367 #[primary_span]
1368 pub span: Span,
1369 #[subdiagnostic]
1370 pub notes: Vec<note_and_explain::RegionExplanation<'a>>,
1371}
1372
1373#[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)]
1374#[diag("in type `{$ty}`, reference has a longer lifetime than the data it references", code = E0491)]
1375pub struct RefLongerThanData<'a> {
1376 #[primary_span]
1377 pub span: Span,
1378 pub ty: Ty<'a>,
1379 #[subdiagnostic]
1380 pub notes: Vec<note_and_explain::RegionExplanation<'a>>,
1381}
1382
1383#[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_format(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_format(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)]
1384pub enum WhereClauseSuggestions {
1385 #[suggestion(
1386 "remove the `where` clause",
1387 code = "",
1388 applicability = "machine-applicable",
1389 style = "verbose"
1390 )]
1391 Remove {
1392 #[primary_span]
1393 span: Span,
1394 },
1395 #[suggestion(
1396 "copy the `where` clause predicates from the trait",
1397 code = "{space}where {trait_predicates}",
1398 applicability = "machine-applicable",
1399 style = "verbose"
1400 )]
1401 CopyPredicates {
1402 #[primary_span]
1403 span: Span,
1404 space: &'static str,
1405 trait_predicates: String,
1406 },
1407}
1408
1409#[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_format(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_format(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_format(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_format(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider returning one of these bindings")));
diag.span_note(__binding_0, __message);
diag.restore_args();
}
}
}
}
};Subdiagnostic)]
1410pub enum SuggestRemoveSemiOrReturnBinding {
1411 #[multipart_suggestion(
1412 "consider removing this semicolon and boxing the expressions",
1413 applicability = "machine-applicable"
1414 )]
1415 RemoveAndBox {
1416 #[suggestion_part(code = "Box::new(")]
1417 first_lo: Span,
1418 #[suggestion_part(code = ")")]
1419 first_hi: Span,
1420 #[suggestion_part(code = "Box::new(")]
1421 second_lo: Span,
1422 #[suggestion_part(code = ")")]
1423 second_hi: Span,
1424 #[suggestion_part(code = "")]
1425 sp: Span,
1426 },
1427 #[suggestion(
1428 "consider removing this semicolon",
1429 style = "short",
1430 code = "",
1431 applicability = "machine-applicable"
1432 )]
1433 Remove {
1434 #[primary_span]
1435 sp: Span,
1436 },
1437 #[suggestion(
1438 "consider returning the local binding `{$ident}`",
1439 style = "verbose",
1440 code = "{code}",
1441 applicability = "maybe-incorrect"
1442 )]
1443 Add {
1444 #[primary_span]
1445 sp: Span,
1446 code: String,
1447 ident: Ident,
1448 },
1449 #[note("consider returning one of these bindings")]
1450 AddOne {
1451 #[primary_span]
1452 spans: MultiSpan,
1453 },
1454}
1455
1456#[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_format(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_format(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_format(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_format(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_format(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)]
1457pub enum ConsiderAddingAwait {
1458 #[help("consider `await`ing on both `Future`s")]
1459 BothFuturesHelp,
1460 #[multipart_suggestion(
1461 "consider `await`ing on both `Future`s",
1462 applicability = "maybe-incorrect"
1463 )]
1464 BothFuturesSugg {
1465 #[suggestion_part(code = ".await")]
1466 first: Span,
1467 #[suggestion_part(code = ".await")]
1468 second: Span,
1469 },
1470 #[suggestion(
1471 "consider `await`ing on the `Future`",
1472 code = ".await",
1473 style = "verbose",
1474 applicability = "maybe-incorrect"
1475 )]
1476 FutureSugg {
1477 #[primary_span]
1478 span: Span,
1479 },
1480 #[note("calling an async function returns a future")]
1481 FutureSuggNote {
1482 #[primary_span]
1483 span: Span,
1484 },
1485 #[multipart_suggestion(
1486 "consider `await`ing on the `Future`",
1487 style = "verbose",
1488 applicability = "maybe-incorrect"
1489 )]
1490 FutureSuggMultiple {
1491 #[suggestion_part(code = ".await")]
1492 spans: Vec<Span>,
1493 },
1494}
1495
1496#[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)]
1497pub enum PlaceholderRelationLfNotSatisfied {
1498 #[diag("lifetime bound not satisfied")]
1499 HasBoth {
1500 #[primary_span]
1501 span: Span,
1502 #[note("the lifetime `{$sub_symbol}` defined here...")]
1503 sub_span: Span,
1504 #[note("...must outlive the lifetime `{$sup_symbol}` defined here")]
1505 sup_span: Span,
1506 sub_symbol: Symbol,
1507 sup_symbol: Symbol,
1508 #[note(
1509 "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)"
1510 )]
1511 note: (),
1512 },
1513 #[diag("lifetime bound not satisfied")]
1514 HasSub {
1515 #[primary_span]
1516 span: Span,
1517 #[note("the lifetime `{$sub_symbol}` defined here...")]
1518 sub_span: Span,
1519 #[note("...must outlive the lifetime defined here")]
1520 sup_span: Span,
1521 sub_symbol: Symbol,
1522 #[note(
1523 "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)"
1524 )]
1525 note: (),
1526 },
1527 #[diag("lifetime bound not satisfied")]
1528 HasSup {
1529 #[primary_span]
1530 span: Span,
1531 #[note("the lifetime defined here...")]
1532 sub_span: Span,
1533 #[note("...must outlive the lifetime `{$sup_symbol}` defined here")]
1534 sup_span: Span,
1535 sup_symbol: Symbol,
1536 #[note(
1537 "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)"
1538 )]
1539 note: (),
1540 },
1541 #[diag("lifetime bound not satisfied")]
1542 HasNone {
1543 #[primary_span]
1544 span: Span,
1545 #[note("the lifetime defined here...")]
1546 sub_span: Span,
1547 #[note("...must outlive the lifetime defined here")]
1548 sup_span: Span,
1549 #[note(
1550 "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)"
1551 )]
1552 note: (),
1553 },
1554 #[diag("lifetime bound not satisfied")]
1555 OnlyPrimarySpan {
1556 #[primary_span]
1557 span: Span,
1558 #[note(
1559 "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)"
1560 )]
1561 note: (),
1562 },
1563}
1564
1565#[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)]
1566#[diag("hidden type for `{$opaque_ty}` captures lifetime that does not appear in bounds", code = E0700)]
1567pub struct OpaqueCapturesLifetime<'tcx> {
1568 #[primary_span]
1569 pub span: Span,
1570 #[label("opaque type defined here")]
1571 pub opaque_ty_span: Span,
1572 pub opaque_ty: Ty<'tcx>,
1573}
1574
1575#[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_format(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_format(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_format(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_format(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_format(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_format(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)]
1576pub enum FunctionPointerSuggestion<'a> {
1577 #[suggestion(
1578 "consider using a reference",
1579 code = "&",
1580 style = "verbose",
1581 applicability = "maybe-incorrect"
1582 )]
1583 UseRef {
1584 #[primary_span]
1585 span: Span,
1586 },
1587 #[suggestion(
1588 "consider removing the reference",
1589 code = "{fn_name}",
1590 style = "verbose",
1591 applicability = "maybe-incorrect"
1592 )]
1593 RemoveRef {
1594 #[primary_span]
1595 span: Span,
1596 #[skip_arg]
1597 fn_name: String,
1598 },
1599 #[suggestion(
1600 "consider casting to a fn pointer",
1601 code = "&({fn_name} as {sig})",
1602 style = "verbose",
1603 applicability = "maybe-incorrect"
1604 )]
1605 CastRef {
1606 #[primary_span]
1607 span: Span,
1608 #[skip_arg]
1609 fn_name: String,
1610 #[skip_arg]
1611 sig: Binder<'a, FnSig<'a>>,
1612 },
1613 #[suggestion(
1614 "consider casting to a fn pointer",
1615 code = " as {sig}",
1616 style = "verbose",
1617 applicability = "maybe-incorrect"
1618 )]
1619 Cast {
1620 #[primary_span]
1621 span: Span,
1622 #[skip_arg]
1623 sig: Binder<'a, FnSig<'a>>,
1624 },
1625 #[suggestion(
1626 "consider casting both fn items to fn pointers using `as {$expected_sig}`",
1627 code = " as {found_sig}",
1628 style = "hidden",
1629 applicability = "maybe-incorrect"
1630 )]
1631 CastBoth {
1632 #[primary_span]
1633 span: Span,
1634 #[skip_arg]
1635 found_sig: Binder<'a, FnSig<'a>>,
1636 expected_sig: Binder<'a, FnSig<'a>>,
1637 },
1638 #[suggestion(
1639 "consider casting both fn items to fn pointers using `as {$expected_sig}`",
1640 code = "&({fn_name} as {found_sig})",
1641 style = "hidden",
1642 applicability = "maybe-incorrect"
1643 )]
1644 CastBothRef {
1645 #[primary_span]
1646 span: Span,
1647 #[skip_arg]
1648 fn_name: String,
1649 #[skip_arg]
1650 found_sig: Binder<'a, FnSig<'a>>,
1651 expected_sig: Binder<'a, FnSig<'a>>,
1652 },
1653}
1654
1655#[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_format(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("fn items are distinct from fn pointers")));
diag.note(__message);
diag.restore_args();
}
}
}
}
};Subdiagnostic)]
1656#[note("fn items are distinct from fn pointers")]
1657pub struct FnItemsAreDistinct;
1658
1659#[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_format(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)]
1660#[note("different fn items have unique types, even if their signatures are the same")]
1661pub struct FnUniqTypes;
1662
1663#[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_format(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)]
1664#[help("consider casting the fn item to a fn pointer: `{$casting}`")]
1665pub struct FnConsiderCasting {
1666 pub casting: String,
1667}
1668
1669#[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_format(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)]
1670#[help("consider casting both fn items to fn pointers using `as {$sig}`")]
1671pub struct FnConsiderCastingBoth<'a> {
1672 pub sig: Binder<'a, FnSig<'a>>,
1673}
1674
1675#[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_format(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_format(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)]
1676pub enum SuggestAccessingField<'a> {
1677 #[suggestion(
1678 "you might have meant to use field `{$name}` whose type is `{$ty}`",
1679 code = "{snippet}.{name}",
1680 applicability = "maybe-incorrect",
1681 style = "verbose"
1682 )]
1683 Safe {
1684 #[primary_span]
1685 span: Span,
1686 snippet: String,
1687 name: Symbol,
1688 ty: Ty<'a>,
1689 },
1690 #[suggestion(
1691 "you might have meant to use field `{$name}` whose type is `{$ty}`",
1692 code = "unsafe {{ {snippet}.{name} }}",
1693 applicability = "maybe-incorrect",
1694 style = "verbose"
1695 )]
1696 Unsafe {
1697 #[primary_span]
1698 span: Span,
1699 snippet: String,
1700 name: Symbol,
1701 ty: Ty<'a>,
1702 },
1703}
1704
1705#[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_format(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)]
1706#[multipart_suggestion(
1707 "try wrapping the pattern in `{$variant}`",
1708 applicability = "maybe-incorrect"
1709)]
1710pub struct SuggestTuplePatternOne {
1711 pub variant: String,
1712 #[suggestion_part(code = "{variant}(")]
1713 pub span_low: Span,
1714 #[suggestion_part(code = ")")]
1715 pub span_high: Span,
1716}
1717
1718pub struct SuggestTuplePatternMany {
1719 pub path: String,
1720 pub cause_span: Span,
1721 pub compatible_variants: Vec<String>,
1722}
1723
1724impl Subdiagnostic for SuggestTuplePatternMany {
1725 fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
1726 diag.arg("path", self.path);
1727 let message =
1728 diag.eagerly_format(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}`"));
1729 diag.multipart_suggestions(
1730 message,
1731 self.compatible_variants.into_iter().map(|variant| {
1732 ::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![
1733 (self.cause_span.shrink_to_lo(), format!("{variant}(")),
1734 (self.cause_span.shrink_to_hi(), ")".to_string()),
1735 ]
1736 }),
1737 rustc_errors::Applicability::MaybeIncorrect,
1738 );
1739 }
1740}
1741
1742#[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_format(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_format(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_format(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_format(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_format(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_format(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_format(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_format(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)]
1743pub enum TypeErrorAdditionalDiags {
1744 #[suggestion(
1745 "if you meant to write a byte literal, prefix with `b`",
1746 code = "b'{code}'",
1747 applicability = "machine-applicable"
1748 )]
1749 MeantByteLiteral {
1750 #[primary_span]
1751 span: Span,
1752 code: String,
1753 },
1754 #[suggestion(
1755 "if you meant to write a `char` literal, use single quotes",
1756 code = "'{code}'",
1757 applicability = "machine-applicable"
1758 )]
1759 MeantCharLiteral {
1760 #[primary_span]
1761 span: Span,
1762 code: String,
1763 },
1764 #[multipart_suggestion(
1765 "if you meant to write a string literal, use double quotes",
1766 applicability = "machine-applicable"
1767 )]
1768 MeantStrLiteral {
1769 #[suggestion_part(code = "\"")]
1770 start: Span,
1771 #[suggestion_part(code = "\"")]
1772 end: Span,
1773 },
1774 #[suggestion(
1775 "consider specifying the actual array length",
1776 code = "{length}",
1777 applicability = "maybe-incorrect"
1778 )]
1779 ConsiderSpecifyingLength {
1780 #[primary_span]
1781 span: Span,
1782 length: u64,
1783 },
1784 #[note("`?` operator cannot convert from `{$found}` to `{$expected}`")]
1785 TryCannotConvert { found: String, expected: String },
1786 #[suggestion(
1787 "use a trailing comma to create a tuple with one element",
1788 code = ",",
1789 applicability = "machine-applicable"
1790 )]
1791 TupleOnlyComma {
1792 #[primary_span]
1793 span: Span,
1794 },
1795 #[multipart_suggestion(
1796 "use a trailing comma to create a tuple with one element",
1797 applicability = "machine-applicable"
1798 )]
1799 TupleAlsoParentheses {
1800 #[suggestion_part(code = "(")]
1801 span_low: Span,
1802 #[suggestion_part(code = ",)")]
1803 span_high: Span,
1804 },
1805 #[suggestion(
1806 "consider adding `let`",
1807 style = "verbose",
1808 applicability = "machine-applicable",
1809 code = "let "
1810 )]
1811 AddLetForLetChains {
1812 #[primary_span]
1813 span: Span,
1814 },
1815}
1816
1817#[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)]
1818pub enum ObligationCauseFailureCode {
1819 #[diag("method not compatible with trait", code = E0308)]
1820 MethodCompat {
1821 #[primary_span]
1822 span: Span,
1823 #[subdiagnostic]
1824 subdiags: Vec<TypeErrorAdditionalDiags>,
1825 },
1826 #[diag("type not compatible with trait", code = E0308)]
1827 TypeCompat {
1828 #[primary_span]
1829 span: Span,
1830 #[subdiagnostic]
1831 subdiags: Vec<TypeErrorAdditionalDiags>,
1832 },
1833 #[diag("const not compatible with trait", code = E0308)]
1834 ConstCompat {
1835 #[primary_span]
1836 span: Span,
1837 #[subdiagnostic]
1838 subdiags: Vec<TypeErrorAdditionalDiags>,
1839 },
1840 #[diag("`?` operator has incompatible types", code = E0308)]
1841 TryCompat {
1842 #[primary_span]
1843 span: Span,
1844 #[subdiagnostic]
1845 subdiags: Vec<TypeErrorAdditionalDiags>,
1846 },
1847 #[diag("`match` arms have incompatible types", code = E0308)]
1848 MatchCompat {
1849 #[primary_span]
1850 span: Span,
1851 #[subdiagnostic]
1852 subdiags: Vec<TypeErrorAdditionalDiags>,
1853 },
1854 #[diag("`if` and `else` have incompatible types", code = E0308)]
1855 IfElseDifferent {
1856 #[primary_span]
1857 span: Span,
1858 #[subdiagnostic]
1859 subdiags: Vec<TypeErrorAdditionalDiags>,
1860 },
1861 #[diag("`if` may be missing an `else` clause", code = E0317)]
1862 NoElse {
1863 #[primary_span]
1864 span: Span,
1865 },
1866 #[diag("`else` clause of `let...else` does not diverge", code = E0308)]
1867 NoDiverge {
1868 #[primary_span]
1869 span: Span,
1870 #[subdiagnostic]
1871 subdiags: Vec<TypeErrorAdditionalDiags>,
1872 },
1873 #[diag("`main` function has wrong type", code = E0580)]
1874 FnMainCorrectType {
1875 #[primary_span]
1876 span: Span,
1877 },
1878 #[diag(
1879 "{$lang_item_name ->
1880 [panic_impl] `#[panic_handler]`
1881 *[lang_item_name] lang item `{$lang_item_name}`
1882 } function has wrong type"
1883 , code = E0308)]
1884 FnLangCorrectType {
1885 #[primary_span]
1886 span: Span,
1887 #[subdiagnostic]
1888 subdiags: Vec<TypeErrorAdditionalDiags>,
1889 lang_item_name: Symbol,
1890 },
1891 #[diag("intrinsic has wrong type", code = E0308)]
1892 IntrinsicCorrectType {
1893 #[primary_span]
1894 span: Span,
1895 #[subdiagnostic]
1896 subdiags: Vec<TypeErrorAdditionalDiags>,
1897 },
1898 #[diag("mismatched `self` parameter type", code = E0308)]
1899 MethodCorrectType {
1900 #[primary_span]
1901 span: Span,
1902 #[subdiagnostic]
1903 subdiags: Vec<TypeErrorAdditionalDiags>,
1904 },
1905 #[diag("closure/coroutine type that references itself", code = E0644)]
1906 ClosureSelfref {
1907 #[primary_span]
1908 span: Span,
1909 },
1910 #[diag("cannot coerce functions which must be inlined to function pointers", code = E0308)]
1911 CantCoerceForceInline {
1912 #[primary_span]
1913 span: Span,
1914 #[subdiagnostic]
1915 subdiags: Vec<TypeErrorAdditionalDiags>,
1916 },
1917 #[diag("cannot coerce intrinsics to function pointers", code = E0308)]
1918 CantCoerceIntrinsic {
1919 #[primary_span]
1920 span: Span,
1921 #[subdiagnostic]
1922 subdiags: Vec<TypeErrorAdditionalDiags>,
1923 },
1924 #[diag("mismatched types", code = E0308)]
1925 Generic {
1926 #[primary_span]
1927 span: Span,
1928 #[subdiagnostic]
1929 subdiags: Vec<TypeErrorAdditionalDiags>,
1930 },
1931}
1932
1933#[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_format(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_format(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)]
1934pub enum AddPreciseCapturing {
1935 #[suggestion(
1936 "add a `use<...>` bound to explicitly capture `{$new_lifetime}`",
1937 style = "verbose",
1938 code = " + use<{concatenated_bounds}>",
1939 applicability = "machine-applicable"
1940 )]
1941 New {
1942 #[primary_span]
1943 span: Span,
1944 new_lifetime: Symbol,
1945 concatenated_bounds: String,
1946 },
1947 #[suggestion(
1948 "add `{$new_lifetime}` to the `use<...>` bound to explicitly capture it",
1949 style = "verbose",
1950 code = "{pre}{new_lifetime}{post}",
1951 applicability = "machine-applicable"
1952 )]
1953 Existing {
1954 #[primary_span]
1955 span: Span,
1956 new_lifetime: Symbol,
1957 pre: &'static str,
1958 post: &'static str,
1959 },
1960}
1961
1962pub struct AddPreciseCapturingAndParams {
1963 pub suggs: Vec<(Span, String)>,
1964 pub new_lifetime: Symbol,
1965 pub apit_spans: Vec<Span>,
1966}
1967
1968impl Subdiagnostic for AddPreciseCapturingAndParams {
1969 fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
1970 diag.arg("new_lifetime", self.new_lifetime);
1971 diag.multipart_suggestion(
1972 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"),
1973 self.suggs,
1974 Applicability::MaybeIncorrect,
1975 );
1976 diag.span_note(
1977 self.apit_spans,
1978 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"),
1979 );
1980 }
1981}
1982
1983pub fn impl_trait_overcapture_suggestion<'tcx>(
1988 tcx: TyCtxt<'tcx>,
1989 opaque_def_id: LocalDefId,
1990 fn_def_id: LocalDefId,
1991 captured_args: FxIndexSet<DefId>,
1992) -> Option<AddPreciseCapturingForOvercapture> {
1993 let generics = tcx.generics_of(fn_def_id);
1994
1995 let mut captured_lifetimes = FxIndexSet::default();
1996 let mut captured_non_lifetimes = FxIndexSet::default();
1997 let mut synthetics = ::alloc::vec::Vec::new()vec![];
1998
1999 for arg in captured_args {
2000 if tcx.def_kind(arg) == DefKind::LifetimeParam {
2001 captured_lifetimes.insert(tcx.item_name(arg));
2002 } else {
2003 let idx = generics.param_def_id_to_index(tcx, arg).expect("expected arg in scope");
2004 let param = generics.param_at(idx as usize, tcx);
2005 if param.kind.is_synthetic() {
2006 synthetics.push((tcx.def_span(arg), param.name));
2007 } else {
2008 captured_non_lifetimes.insert(tcx.item_name(arg));
2009 }
2010 }
2011 }
2012
2013 let mut next_fresh_param = || {
2014 ['T', 'U', 'V', 'W', 'X', 'Y', 'A', 'B', 'C']
2015 .into_iter()
2016 .map(sym::character)
2017 .chain((0..).map(|i| Symbol::intern(&::alloc::__export::must_use({ ::alloc::fmt::format(format_args!("T{0}", i)) })format!("T{i}"))))
2018 .find(|s| captured_non_lifetimes.insert(*s))
2019 .unwrap()
2020 };
2021
2022 let mut suggs = ::alloc::vec::Vec::new()vec![];
2023 let mut apit_spans = ::alloc::vec::Vec::new()vec![];
2024
2025 if !synthetics.is_empty() {
2026 let mut new_params = String::new();
2027 for (i, (span, name)) in synthetics.into_iter().enumerate() {
2028 apit_spans.push(span);
2029
2030 let fresh_param = next_fresh_param();
2031
2032 suggs.push((span, fresh_param.to_string()));
2034
2035 if i > 0 {
2043 new_params += ", ";
2044 }
2045 let name_as_bounds = name.as_str().trim_start_matches("impl").trim_start();
2046 new_params += fresh_param.as_str();
2047 new_params += ": ";
2048 new_params += name_as_bounds;
2049 }
2050
2051 let Some(generics) = tcx.hir_get_generics(fn_def_id) else {
2052 return None;
2054 };
2055
2056 suggs.push(if let Some(params_span) = generics.span_for_param_suggestion() {
2058 (params_span, ::alloc::__export::must_use({
::alloc::fmt::format(format_args!(", {0}", new_params))
})format!(", {new_params}"))
2059 } else {
2060 (generics.span, ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("<{0}>", new_params))
})format!("<{new_params}>"))
2061 });
2062 }
2063
2064 let concatenated_bounds = captured_lifetimes
2065 .into_iter()
2066 .chain(captured_non_lifetimes)
2067 .map(|sym| sym.to_string())
2068 .collect::<Vec<_>>()
2069 .join(", ");
2070
2071 let opaque_hir_id = tcx.local_def_id_to_hir_id(opaque_def_id);
2072 let (lparen, rparen) = match tcx
2074 .hir_parent_iter(opaque_hir_id)
2075 .nth(1)
2076 .expect("expected ty to have a parent always")
2077 .1
2078 {
2079 Node::PathSegment(segment)
2080 if segment.args().paren_sugar_output().is_some_and(|ty| ty.hir_id == opaque_hir_id) =>
2081 {
2082 ("(", ")")
2083 }
2084 Node::Ty(ty) => match ty.kind {
2085 rustc_hir::TyKind::Ptr(_) | rustc_hir::TyKind::Ref(..) => ("(", ")"),
2086 _ => ("", ""),
2090 },
2091 _ => ("", ""),
2092 };
2093
2094 let rpit_span = tcx.def_span(opaque_def_id);
2095 if !lparen.is_empty() {
2096 suggs.push((rpit_span.shrink_to_lo(), lparen.to_string()));
2097 }
2098 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}")));
2099
2100 Some(AddPreciseCapturingForOvercapture { suggs, apit_spans })
2101}
2102
2103pub struct AddPreciseCapturingForOvercapture {
2104 pub suggs: Vec<(Span, String)>,
2105 pub apit_spans: Vec<Span>,
2106}
2107
2108impl Subdiagnostic for AddPreciseCapturingForOvercapture {
2109 fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
2110 let applicability = if self.apit_spans.is_empty() {
2111 Applicability::MachineApplicable
2112 } else {
2113 Applicability::MaybeIncorrect
2117 };
2118 diag.multipart_suggestion(
2119 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"),
2120 self.suggs,
2121 applicability,
2122 );
2123 if !self.apit_spans.is_empty() {
2124 diag.span_note(
2125 self.apit_spans,
2126 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"),
2127 );
2128 }
2129 }
2130}
2131
2132#[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)]
2133#[diag("expected generic {$kind} parameter, found `{$arg}`", code = E0792)]
2134pub(crate) struct NonGenericOpaqueTypeParam<'a, 'tcx> {
2135 pub arg: GenericArg<'tcx>,
2136 pub kind: &'a str,
2137 #[primary_span]
2138 pub span: Span,
2139 #[label("{STREQ($arg, \"'static\") ->
2140 [true] cannot use static lifetime; use a bound lifetime instead or remove the lifetime parameter from the opaque type
2141 *[other] this generic parameter must be used with a generic {$kind} parameter
2142 }")]
2143 pub param_span: Span,
2144}