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};
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 }
=> {
diag.store_args();
diag.arg("place", __binding_1);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("closure is `{$trait_prefix}FnOnce` because it moves the variable `{$place}` out of its environment")));
diag.span_label(__binding_0, __message);
diag.restore_args();
}
}
}
}
};Subdiagnostic)]
153#[label(
154 "closure is `{$trait_prefix}FnOnce` because it moves the variable `{$place}` out of its environment"
155)]
156pub struct ClosureFnOnceLabel {
157 #[primary_span]
158 pub span: Span,
159 pub place: String,
160}
161
162#[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 }
=> {
diag.store_args();
diag.arg("place", __binding_1);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("closure is `{$trait_prefix}FnMut` because it mutates the variable `{$place}` here")));
diag.span_label(__binding_0, __message);
diag.restore_args();
}
}
}
}
};Subdiagnostic)]
163#[label("closure is `{$trait_prefix}FnMut` because it mutates the variable `{$place}` here")]
164pub struct ClosureFnMutLabel {
165 #[primary_span]
166 pub span: Span,
167 pub place: String,
168}
169
170#[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)]
171#[diag(
172 "{$coro_kind}closure does not implement `{$kind}` because it captures state from its environment"
173)]
174pub(crate) struct CoroClosureNotFn {
175 #[primary_span]
176 pub span: Span,
177 pub kind: &'static str,
178 pub coro_kind: String,
179}
180
181#[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)]
182#[diag("{$source_kind ->
183[closure] type annotations needed for the closure `{$source_name}`
184[normal] type annotations needed for `{$source_name}`
185*[other] type annotations needed
186}", code = E0282)]
187pub struct AnnotationRequired<'a> {
188 #[primary_span]
189 pub span: Span,
190 pub source_kind: &'static str,
191 pub source_name: &'a str,
192 #[label("type must be known at this point")]
193 pub failure_span: Option<Span>,
194 #[subdiagnostic]
195 pub bad_label: Option<InferenceBadError<'a>>,
196 #[subdiagnostic]
197 pub infer_subdiags: Vec<SourceKindSubdiag<'a>>,
198 #[subdiagnostic]
199 pub multi_suggestions: Vec<SourceKindMultiSuggestion<'a>>,
200}
201
202#[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)]
204#[diag("{$source_kind ->
205[closure] type annotations needed for the closure `{$source_name}`
206[normal] type annotations needed for `{$source_name}`
207*[other] type annotations needed
208}", code = E0283)]
209pub struct AmbiguousImpl<'a> {
210 #[primary_span]
211 pub span: Span,
212 pub source_kind: &'static str,
213 pub source_name: &'a str,
214 #[label("type must be known at this point")]
215 pub failure_span: Option<Span>,
216 #[subdiagnostic]
217 pub bad_label: Option<InferenceBadError<'a>>,
218 #[subdiagnostic]
219 pub infer_subdiags: Vec<SourceKindSubdiag<'a>>,
220 #[subdiagnostic]
221 pub multi_suggestions: Vec<SourceKindMultiSuggestion<'a>>,
222}
223
224#[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)]
226#[diag("{$source_kind ->
227[closure] type annotations needed for the closure `{$source_name}`
228[normal] type annotations needed for `{$source_name}`
229*[other] type annotations needed
230}", code = E0284)]
231pub struct AmbiguousReturn<'a> {
232 #[primary_span]
233 pub span: Span,
234 pub source_kind: &'static str,
235 pub source_name: &'a str,
236 #[label("type must be known at this point")]
237 pub failure_span: Option<Span>,
238 #[subdiagnostic]
239 pub bad_label: Option<InferenceBadError<'a>>,
240 #[subdiagnostic]
241 pub infer_subdiags: Vec<SourceKindSubdiag<'a>>,
242 #[subdiagnostic]
243 pub multi_suggestions: Vec<SourceKindMultiSuggestion<'a>>,
244}
245
246#[derive(const _: () =
{
impl<'a> rustc_errors::Subdiagnostic for InferenceBadError<'a> {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
InferenceBadError {
span: __binding_0,
bad_kind: __binding_1,
prefix_kind: __binding_2,
has_parent: __binding_3,
prefix: __binding_4,
parent_prefix: __binding_5,
parent_name: __binding_6,
name: __binding_7 } => {
diag.store_args();
diag.arg("bad_kind", __binding_1);
diag.arg("prefix_kind", __binding_2);
diag.arg("has_parent", __binding_3);
diag.arg("prefix", __binding_4);
diag.arg("parent_prefix", __binding_5);
diag.arg("parent_name", __binding_6);
diag.arg("name", __binding_7);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$bad_kind ->\n*[other] cannot infer type\n[more_info] cannot infer {$prefix_kind ->\n*[type] type for {$prefix}\n[const_with_param] the value of const parameter\n[const] the value of the constant\n} `{$name}`{$has_parent ->\n[true] {\" \"}declared on the {$parent_prefix} `{$parent_name}`\n*[false] {\"\"}\n}\n}")));
diag.span_label(__binding_0, __message);
diag.restore_args();
}
}
}
}
};Subdiagnostic)]
248#[label(
249 "{$bad_kind ->
250*[other] cannot infer type
251[more_info] cannot infer {$prefix_kind ->
252*[type] type for {$prefix}
253[const_with_param] the value of const parameter
254[const] the value of the constant
255} `{$name}`{$has_parent ->
256[true] {\" \"}declared on the {$parent_prefix} `{$parent_name}`
257*[false] {\"\"}
258}
259}"
260)]
261pub struct InferenceBadError<'a> {
262 #[primary_span]
263 pub span: Span,
264 pub bad_kind: &'static str,
265 pub prefix_kind: UnderspecifiedArgKind,
266 pub has_parent: bool,
267 pub prefix: &'a str,
268 pub parent_prefix: &'a str,
269 pub parent_name: String,
270 pub name: String,
271}
272
273#[derive(const _: () =
{
impl<'a> rustc_errors::Subdiagnostic for SourceKindSubdiag<'a> {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
SourceKindSubdiag::LetLike {
span: __binding_0,
name: __binding_1,
type_name: __binding_2,
kind: __binding_3,
x_kind: __binding_4,
prefix_kind: __binding_5,
prefix: __binding_6,
arg_name: __binding_7 } => {
let __code_0 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!(": {0}", __binding_2))
})].into_iter();
diag.store_args();
diag.arg("name", __binding_1);
diag.arg("type_name", __binding_2);
diag.arg("kind", __binding_3);
diag.arg("x_kind", __binding_4);
diag.arg("prefix_kind", __binding_5);
diag.arg("prefix", __binding_6);
diag.arg("arg_name", __binding_7);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$kind ->\n [with_pattern] consider giving `{$name}` an explicit type\n [closure] consider giving this closure parameter an explicit type\n *[other] consider giving this pattern a type\n }{$x_kind ->\n [has_name] , where the {$prefix_kind ->\n *[type] type for {$prefix}\n [const_with_param] value of const parameter\n [const] value of the constant\n } `{$arg_name}` is specified\n [underscore] , where the placeholders `_` are specified\n *[empty] {\"\"}\n }")));
diag.span_suggestions_with_style(__binding_0, __message,
__code_0, rustc_errors::Applicability::HasPlaceholders,
rustc_errors::SuggestionStyle::ShowAlways);
diag.restore_args();
}
SourceKindSubdiag::GenericLabel {
span: __binding_0,
is_type: __binding_1,
param_name: __binding_2,
parent_exists: __binding_3,
parent_prefix: __binding_4,
parent_name: __binding_5 } => {
diag.store_args();
diag.arg("is_type", __binding_1);
diag.arg("param_name", __binding_2);
diag.arg("parent_exists", __binding_3);
diag.arg("parent_prefix", __binding_4);
diag.arg("parent_name", __binding_5);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("cannot infer {$is_type ->\n [true] type\n *[false] the value\n } of the {$is_type ->\n [true] type\n *[false] const\n } {$parent_exists ->\n [true] parameter `{$param_name}` declared on the {$parent_prefix} `{$parent_name}`\n *[false] parameter {$param_name}\n }")));
diag.span_label(__binding_0, __message);
diag.restore_args();
}
SourceKindSubdiag::GenericSuggestion {
span: __binding_0, arg_count: __binding_1, args: __binding_2
} => {
let __code_1 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("::<{0}>", __binding_2))
})].into_iter();
diag.store_args();
diag.arg("arg_count", __binding_1);
diag.arg("args", __binding_2);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider specifying the generic {$arg_count ->\n [one] argument\n *[other] arguments\n }")));
diag.span_suggestions_with_style(__binding_0, __message,
__code_1, rustc_errors::Applicability::HasPlaceholders,
rustc_errors::SuggestionStyle::ShowAlways);
diag.restore_args();
}
}
}
}
};Subdiagnostic)]
274pub enum SourceKindSubdiag<'a> {
275 #[suggestion(
276 "{$kind ->
277 [with_pattern] consider giving `{$name}` an explicit type
278 [closure] consider giving this closure parameter an explicit type
279 *[other] consider giving this pattern a type
280 }{$x_kind ->
281 [has_name] , where the {$prefix_kind ->
282 *[type] type for {$prefix}
283 [const_with_param] value of const parameter
284 [const] value of the constant
285 } `{$arg_name}` is specified
286 [underscore] , where the placeholders `_` are specified
287 *[empty] {\"\"}
288 }",
289 style = "verbose",
290 code = ": {type_name}",
291 applicability = "has-placeholders"
292 )]
293 LetLike {
294 #[primary_span]
295 span: Span,
296 name: String,
297 type_name: String,
298 kind: &'static str,
299 x_kind: &'static str,
300 prefix_kind: UnderspecifiedArgKind,
301 prefix: &'a str,
302 arg_name: String,
303 },
304 #[label(
305 "cannot infer {$is_type ->
306 [true] type
307 *[false] the value
308 } of the {$is_type ->
309 [true] type
310 *[false] const
311 } {$parent_exists ->
312 [true] parameter `{$param_name}` declared on the {$parent_prefix} `{$parent_name}`
313 *[false] parameter {$param_name}
314 }"
315 )]
316 GenericLabel {
317 #[primary_span]
318 span: Span,
319 is_type: bool,
320 param_name: String,
321 parent_exists: bool,
322 parent_prefix: String,
323 parent_name: String,
324 },
325 #[suggestion(
326 "consider specifying the generic {$arg_count ->
327 [one] argument
328 *[other] arguments
329 }",
330 style = "verbose",
331 code = "::<{args}>",
332 applicability = "has-placeholders"
333 )]
334 GenericSuggestion {
335 #[primary_span]
336 span: Span,
337 arg_count: usize,
338 args: String,
339 },
340}
341
342#[derive(const _: () =
{
impl<'a> rustc_errors::Subdiagnostic for SourceKindMultiSuggestion<'a>
{
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
SourceKindMultiSuggestion::FullyQualified {
span_lo: __binding_0,
span_hi: __binding_1,
def_path: __binding_2,
adjustment: __binding_3,
successor_pos: __binding_4 } => {
let mut suggestions = Vec::new();
let __code_2 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{1}({0}", __binding_3,
__binding_2))
});
let __code_3 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0}", __binding_4))
});
suggestions.push((__binding_0, __code_2));
suggestions.push((__binding_1, __code_3));
diag.store_args();
diag.arg("def_path", __binding_2);
diag.arg("adjustment", __binding_3);
diag.arg("successor_pos", __binding_4);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("try using a fully qualified path to specify the expected types")));
diag.multipart_suggestion_with_style(__message, suggestions,
rustc_errors::Applicability::HasPlaceholders,
rustc_errors::SuggestionStyle::ShowAlways);
diag.restore_args();
}
SourceKindMultiSuggestion::ClosureReturn {
start_span: __binding_0,
start_span_code: __binding_1,
end_span: __binding_2 } => {
let mut suggestions = Vec::new();
let __code_4 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0}", __binding_1))
});
let __code_5 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!(" }}"))
});
suggestions.push((__binding_0, __code_4));
if let Some(__binding_2) = __binding_2 {
suggestions.push((__binding_2, __code_5));
}
diag.store_args();
diag.arg("start_span_code", __binding_1);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("try giving this closure an explicit return type")));
diag.multipart_suggestion_with_style(__message, suggestions,
rustc_errors::Applicability::HasPlaceholders,
rustc_errors::SuggestionStyle::ShowAlways);
diag.restore_args();
}
}
}
}
};Subdiagnostic)]
343pub enum SourceKindMultiSuggestion<'a> {
344 #[multipart_suggestion(
345 "try using a fully qualified path to specify the expected types",
346 style = "verbose",
347 applicability = "has-placeholders"
348 )]
349 FullyQualified {
350 #[suggestion_part(code = "{def_path}({adjustment}")]
351 span_lo: Span,
352 #[suggestion_part(code = "{successor_pos}")]
353 span_hi: Span,
354 def_path: String,
355 adjustment: &'a str,
356 successor_pos: &'a str,
357 },
358 #[multipart_suggestion(
359 "try giving this closure an explicit return type",
360 style = "verbose",
361 applicability = "has-placeholders"
362 )]
363 ClosureReturn {
364 #[suggestion_part(code = "{start_span_code}")]
365 start_span: Span,
366 start_span_code: String,
367 #[suggestion_part(code = " }}")]
368 end_span: Option<Span>,
369 },
370}
371
372impl<'a> SourceKindMultiSuggestion<'a> {
373 pub fn new_fully_qualified(
374 span: Span,
375 def_path: String,
376 adjustment: &'a str,
377 successor: (&'a str, BytePos),
378 ) -> Self {
379 Self::FullyQualified {
380 span_lo: span.shrink_to_lo(),
381 span_hi: span.shrink_to_hi().with_hi(successor.1),
382 def_path,
383 adjustment,
384 successor_pos: successor.0,
385 }
386 }
387
388 pub fn new_closure_return(
389 ty_info: String,
390 data: &'a FnRetTy<'a>,
391 should_wrap_expr: Option<Span>,
392 ) -> Self {
393 let arrow = match data {
394 FnRetTy::DefaultReturn(_) => " -> ",
395 _ => "",
396 };
397 let (start_span, start_span_code, end_span) = match should_wrap_expr {
398 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)),
399 None => (data.span(), ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0}{1}", arrow, ty_info))
})format!("{arrow}{ty_info}"), None),
400 };
401 Self::ClosureReturn { start_span, start_span_code, end_span }
402 }
403}
404
405pub enum RegionOriginNote<'a> {
406 Plain {
407 span: Span,
408 msg: DiagMessage,
409 },
410 WithName {
411 span: Span,
412 msg: DiagMessage,
413 name: &'a str,
414 continues: bool,
415 },
416 WithRequirement {
417 span: Span,
418 requirement: ObligationCauseAsDiagArg<'a>,
419 expected_found: Option<(DiagStyledString, DiagStyledString)>,
420 },
421}
422
423impl Subdiagnostic for RegionOriginNote<'_> {
424 fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
425 let label_or_note = |diag: &mut Diag<'_, G>, span, msg: DiagMessage| {
426 let sub_count = diag.children.iter().filter(|d| d.span.is_dummy()).count();
427 let expanded_sub_count = diag.children.iter().filter(|d| !d.span.is_dummy()).count();
428 let span_is_primary = diag.span.primary_spans().iter().all(|&sp| sp == span);
429 if span_is_primary && sub_count == 0 && expanded_sub_count == 0 {
430 diag.span_label(span, msg);
431 } else if span_is_primary && expanded_sub_count == 0 {
432 diag.note(msg);
433 } else {
434 diag.span_note(span, msg);
435 }
436 };
437 match self {
438 RegionOriginNote::Plain { span, msg } => {
439 label_or_note(diag, span, msg);
440 }
441 RegionOriginNote::WithName { span, msg, name, continues } => {
442 diag.arg("name", name);
443 diag.arg("continues", continues);
444 label_or_note(diag, span, msg);
445 }
446 RegionOriginNote::WithRequirement {
447 span,
448 requirement,
449 expected_found: Some((expected, found)),
450 } => {
451 diag.store_args();
456 diag.arg("requirement", requirement);
457 let msg = diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("...so that the {$requirement ->\n [method_compat] method type is compatible with trait\n [type_compat] associated type is compatible with trait\n [const_compat] const is compatible with trait\n [expr_assignable] expression is assignable\n [if_else_different] `if` and `else` have incompatible types\n [no_else] `if` missing an `else` returns `()`\n [fn_main_correct_type] `main` function has the correct type\n [fn_lang_correct_type] lang item function has the correct type\n [intrinsic_correct_type] intrinsic has the correct type\n [method_correct_type] method receiver has the correct type\n *[other] types are compatible\n }"))msg!(
458 "...so that the {$requirement ->
459 [method_compat] method type is compatible with trait
460 [type_compat] associated type is compatible with trait
461 [const_compat] const is compatible with trait
462 [expr_assignable] expression is assignable
463 [if_else_different] `if` and `else` have incompatible types
464 [no_else] `if` missing an `else` returns `()`
465 [fn_main_correct_type] `main` function has the correct type
466 [fn_lang_correct_type] lang item function has the correct type
467 [intrinsic_correct_type] intrinsic has the correct type
468 [method_correct_type] method receiver has the correct type
469 *[other] types are compatible
470 }"
471 ));
472 diag.restore_args();
473 label_or_note(diag, span, msg);
474
475 diag.note_expected_found("", expected, "", found);
476 }
477 RegionOriginNote::WithRequirement { span, requirement, expected_found: None } => {
478 diag.store_args();
482 diag.arg("requirement", requirement);
483 let msg = diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("...so that {$requirement ->\n [method_compat] method type is compatible with trait\n [type_compat] associated type is compatible with trait\n [const_compat] const is compatible with trait\n [expr_assignable] expression is assignable\n [if_else_different] `if` and `else` have incompatible types\n [no_else] `if` missing an `else` returns `()`\n [fn_main_correct_type] `main` function has the correct type\n [fn_lang_correct_type] lang item function has the correct type\n [intrinsic_correct_type] intrinsic has the correct type\n [method_correct_type] method receiver has the correct type\n *[other] types are compatible\n }"))msg!(
484 "...so that {$requirement ->
485 [method_compat] method type is compatible with trait
486 [type_compat] associated type is compatible with trait
487 [const_compat] const is compatible with trait
488 [expr_assignable] expression is assignable
489 [if_else_different] `if` and `else` have incompatible types
490 [no_else] `if` missing an `else` returns `()`
491 [fn_main_correct_type] `main` function has the correct type
492 [fn_lang_correct_type] lang item function has the correct type
493 [intrinsic_correct_type] intrinsic has the correct type
494 [method_correct_type] method receiver has the correct type
495 *[other] types are compatible
496 }"
497 ));
498 diag.restore_args();
499 label_or_note(diag, span, msg);
500 }
501 };
502 }
503}
504
505pub enum LifetimeMismatchLabels {
506 InRet {
507 param_span: Span,
508 ret_span: Span,
509 span: Span,
510 label_var1: Option<Ident>,
511 },
512 Normal {
513 hir_equal: bool,
514 ty_sup: Span,
515 ty_sub: Span,
516 span: Span,
517 sup: Option<Ident>,
518 sub: Option<Ident>,
519 },
520}
521
522impl Subdiagnostic for LifetimeMismatchLabels {
523 fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
524 match self {
525 LifetimeMismatchLabels::InRet { param_span, ret_span, span, label_var1 } => {
526 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..."));
527 diag.span_label(ret_span, rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{\"\"}"))msg!("{\"\"}"));
528 diag.span_label(
529 span,
530 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!(
531 "...but data{$label_var1_exists ->
532 [true] {\" \"}from `{$label_var1}`
533 *[false] {\"\"}
534 } is returned here"
535 ),
536 );
537 diag.arg("label_var1_exists", label_var1.is_some());
538 diag.arg("label_var1", label_var1.map(|x| x.to_string()).unwrap_or_default());
539 }
540 LifetimeMismatchLabels::Normal {
541 hir_equal,
542 ty_sup,
543 ty_sub,
544 span,
545 sup: label_var1,
546 sub: label_var2,
547 } => {
548 if hir_equal {
549 diag.span_label(
550 ty_sup,
551 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this type is declared with multiple lifetimes..."))msg!("this type is declared with multiple lifetimes..."),
552 );
553 diag.span_label(ty_sub, rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{\"\"}"))msg!("{\"\"}"));
554 diag.span_label(
555 span,
556 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"),
557 );
558 } else {
559 diag.span_label(
560 ty_sup,
561 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..."),
562 );
563 diag.span_label(ty_sub, rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{\"\"}"))msg!("{\"\"}"));
564 diag.span_label(
565 span,
566 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!(
567 "...but data{$label_var1_exists ->
568 [true] {\" \"}from `{$label_var1}`
569 *[false] {\"\"}
570 } flows{$label_var2_exists ->
571 [true] {\" \"}into `{$label_var2}`
572 *[false] {\"\"}
573 } here"
574 ),
575 );
576 diag.arg("label_var1_exists", label_var1.is_some());
577 diag.arg("label_var1", label_var1.map(|x| x.to_string()).unwrap_or_default());
578 diag.arg("label_var2_exists", label_var2.is_some());
579 diag.arg("label_var2", label_var2.map(|x| x.to_string()).unwrap_or_default());
580 }
581 }
582 }
583 }
584}
585
586pub struct AddLifetimeParamsSuggestion<'a> {
587 pub tcx: TyCtxt<'a>,
588 pub generic_param_scope: LocalDefId,
589 pub sub: Region<'a>,
590 pub ty_sup: &'a hir::Ty<'a>,
591 pub ty_sub: &'a hir::Ty<'a>,
592 pub add_note: bool,
593}
594
595impl Subdiagnostic for AddLifetimeParamsSuggestion<'_> {
596 fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
597 let mut mk_suggestion = || {
598 let Some(anon_reg) = self.tcx.is_suitable_region(self.generic_param_scope, self.sub)
599 else {
600 return false;
601 };
602
603 let node = self.tcx.hir_node_by_def_id(anon_reg.scope);
604 let is_impl = #[allow(non_exhaustive_omitted_patterns)] match &node {
hir::Node::ImplItem(_) => true,
_ => false,
}matches!(&node, hir::Node::ImplItem(_));
605 let (generics, parent_generics) = match node {
606 hir::Node::Item(hir::Item { kind: hir::ItemKind::Fn { generics, .. }, .. })
607 | hir::Node::TraitItem(hir::TraitItem { generics, .. })
608 | hir::Node::ImplItem(hir::ImplItem { generics, .. }) => (
609 generics,
610 match self.tcx.parent_hir_node(self.tcx.local_def_id_to_hir_id(anon_reg.scope))
611 {
612 hir::Node::Item(hir::Item {
613 kind: hir::ItemKind::Trait(_, _, _, _, generics, ..),
614 ..
615 })
616 | hir::Node::Item(hir::Item {
617 kind: hir::ItemKind::Impl(hir::Impl { generics, .. }),
618 ..
619 }) => Some(generics),
620 _ => None,
621 },
622 ),
623 _ => return false,
624 };
625
626 let suggestion_param_name = generics
627 .params
628 .iter()
629 .filter(|p| #[allow(non_exhaustive_omitted_patterns)] match p.kind {
GenericParamKind::Lifetime { .. } => true,
_ => false,
}matches!(p.kind, GenericParamKind::Lifetime { .. }))
630 .map(|p| p.name.ident().name)
631 .find(|i| *i != kw::UnderscoreLifetime);
632 let introduce_new = suggestion_param_name.is_none();
633
634 let mut default = "'a".to_string();
635 if let Some(parent_generics) = parent_generics {
636 let used: FxHashSet<_> = parent_generics
637 .params
638 .iter()
639 .filter(|p| #[allow(non_exhaustive_omitted_patterns)] match p.kind {
GenericParamKind::Lifetime { .. } => true,
_ => false,
}matches!(p.kind, GenericParamKind::Lifetime { .. }))
640 .map(|p| p.name.ident().name)
641 .filter(|i| *i != kw::UnderscoreLifetime)
642 .map(|l| l.to_string())
643 .collect();
644 if let Some(lt) =
645 ('a'..='z').map(|it| ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("\'{0}", it))
})format!("'{it}")).find(|it| !used.contains(it))
646 {
647 default = lt;
652 }
653 }
654 let suggestion_param_name =
655 suggestion_param_name.map(|n| n.to_string()).unwrap_or_else(|| default);
656
657 struct ImplicitLifetimeFinder {
658 suggestions: Vec<(Span, String)>,
659 suggestion_param_name: String,
660 }
661
662 impl<'v> Visitor<'v> for ImplicitLifetimeFinder {
663 fn visit_ty(&mut self, ty: &'v hir::Ty<'v, AmbigArg>) {
664 match ty.kind {
665 hir::TyKind::Path(hir::QPath::Resolved(_, path)) => {
666 for segment in path.segments {
667 if let Some(args) = segment.args {
668 if args.args.iter().all(|arg| {
669 #[allow(non_exhaustive_omitted_patterns)] match arg {
hir::GenericArg::Lifetime(lifetime) if lifetime.is_implicit() => true,
_ => false,
}matches!(
670 arg,
671 hir::GenericArg::Lifetime(lifetime)
672 if lifetime.is_implicit()
673 )
674 }) {
675 self.suggestions.push((
676 segment.ident.span.shrink_to_hi(),
677 ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("<{0}>",
args.args.iter().map(|_|
self.suggestion_param_name.clone()).collect::<Vec<_>>().join(", ")))
})format!(
678 "<{}>",
679 args.args
680 .iter()
681 .map(|_| self.suggestion_param_name.clone())
682 .collect::<Vec<_>>()
683 .join(", ")
684 ),
685 ));
686 } else {
687 for arg in args.args {
688 if let hir::GenericArg::Lifetime(lifetime) = arg
689 && lifetime.is_anonymous()
690 {
691 self.suggestions.push(
692 lifetime
693 .suggestion(&self.suggestion_param_name),
694 );
695 }
696 }
697 }
698 }
699 }
700 }
701 hir::TyKind::Ref(lifetime, ..) if lifetime.is_anonymous() => {
702 self.suggestions.push(lifetime.suggestion(&self.suggestion_param_name));
703 }
704 _ => {}
705 }
706 walk_ty(self, ty);
707 }
708 }
709 let mut visitor = ImplicitLifetimeFinder {
710 suggestions: ::alloc::vec::Vec::new()vec![],
711 suggestion_param_name: suggestion_param_name.clone(),
712 };
713 if let Some(fn_decl) = node.fn_decl()
714 && let hir::FnRetTy::Return(ty) = fn_decl.output
715 {
716 visitor.visit_ty_unambig(ty);
717 }
718 if visitor.suggestions.is_empty() {
719 visitor.visit_ty_unambig(self.ty_sup);
724 }
725 visitor.visit_ty_unambig(self.ty_sub);
726 if visitor.suggestions.is_empty() {
727 return false;
728 }
729 if introduce_new {
730 let new_param_suggestion = if let Some(first) =
731 generics.params.iter().find(|p| !p.name.ident().span.is_empty())
732 {
733 (first.span.shrink_to_lo(), ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0}, ", suggestion_param_name))
})format!("{suggestion_param_name}, "))
734 } else {
735 (generics.span, ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("<{0}>", suggestion_param_name))
})format!("<{suggestion_param_name}>"))
736 };
737
738 visitor.suggestions.push(new_param_suggestion);
739 }
740 diag.multipart_suggestion(
741 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!(
742 "consider {$is_reuse ->
743 [true] reusing
744 *[false] introducing
745 } a named lifetime parameter{$is_impl ->
746 [true] {\" \"}and update trait if needed
747 *[false] {\"\"}
748 }"
749 ),
750 visitor.suggestions,
751 Applicability::MaybeIncorrect,
752 );
753 diag.arg("is_impl", is_impl);
754 diag.arg("is_reuse", !introduce_new);
755
756 true
757 };
758 if mk_suggestion() && self.add_note {
759 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"));
760 }
761 }
762}
763
764#[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)]
765#[diag("lifetime mismatch", code = E0623)]
766pub struct LifetimeMismatch<'a> {
767 #[primary_span]
768 pub span: Span,
769 #[subdiagnostic]
770 pub labels: LifetimeMismatchLabels,
771 #[subdiagnostic]
772 pub suggestion: AddLifetimeParamsSuggestion<'a>,
773}
774
775pub struct IntroducesStaticBecauseUnmetLifetimeReq {
776 pub unmet_requirements: MultiSpan,
777 pub binding_span: Span,
778}
779
780impl Subdiagnostic for IntroducesStaticBecauseUnmetLifetimeReq {
781 fn add_to_diag<G: EmissionGuarantee>(mut self, diag: &mut Diag<'_, G>) {
782 self.unmet_requirements.push_span_label(
783 self.binding_span,
784 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("introduces a `'static` lifetime requirement"))msg!("introduces a `'static` lifetime requirement"),
785 );
786 diag.span_note(
787 self.unmet_requirements,
788 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("because this has an unmet lifetime requirement"))msg!("because this has an unmet lifetime requirement"),
789 );
790 }
791}
792
793#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for DoesNotOutliveStaticFromImpl {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
DoesNotOutliveStaticFromImpl::Spanned { span: __binding_0 }
=> {
diag.store_args();
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("...does not necessarily outlive the static lifetime introduced by the compatible `impl`")));
diag.span_note(__binding_0, __message);
diag.restore_args();
}
DoesNotOutliveStaticFromImpl::Unspanned => {
diag.store_args();
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("...does not necessarily outlive the static lifetime introduced by the compatible `impl`")));
diag.note(__message);
diag.restore_args();
}
}
}
}
};Subdiagnostic)]
795pub enum DoesNotOutliveStaticFromImpl {
796 #[note(
797 "...does not necessarily outlive the static lifetime introduced by the compatible `impl`"
798 )]
799 Spanned {
800 #[primary_span]
801 span: Span,
802 },
803 #[note(
804 "...does not necessarily outlive the static lifetime introduced by the compatible `impl`"
805 )]
806 Unspanned,
807}
808
809#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for ImplicitStaticLifetimeSubdiag {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
ImplicitStaticLifetimeSubdiag::Note { span: __binding_0 } =>
{
diag.store_args();
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this has an implicit `'static` lifetime requirement")));
diag.span_note(__binding_0, __message);
diag.restore_args();
}
ImplicitStaticLifetimeSubdiag::Sugg { span: __binding_0 } =>
{
let __code_6 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!(" + \'_"))
})].into_iter();
diag.store_args();
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider relaxing the implicit `'static` requirement")));
diag.span_suggestions_with_style(__binding_0, __message,
__code_6, rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowAlways);
diag.restore_args();
}
}
}
}
};Subdiagnostic)]
810pub enum ImplicitStaticLifetimeSubdiag {
811 #[note("this has an implicit `'static` lifetime requirement")]
812 Note {
813 #[primary_span]
814 span: Span,
815 },
816 #[suggestion(
817 "consider relaxing the implicit `'static` requirement",
818 style = "verbose",
819 code = " + '_",
820 applicability = "maybe-incorrect"
821 )]
822 Sugg {
823 #[primary_span]
824 span: Span,
825 },
826}
827
828#[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)]
829#[diag("incompatible lifetime on type")]
830pub struct MismatchedStaticLifetime<'a> {
831 #[primary_span]
832 pub cause_span: Span,
833 #[subdiagnostic]
834 pub unmet_lifetime_reqs: IntroducesStaticBecauseUnmetLifetimeReq,
835 #[subdiagnostic]
836 pub expl: Option<note_and_explain::RegionExplanation<'a>>,
837 #[subdiagnostic]
838 pub does_not_outlive_static_from_impl: DoesNotOutliveStaticFromImpl,
839 #[subdiagnostic]
840 pub implicit_static_lifetimes: Vec<ImplicitStaticLifetimeSubdiag>,
841}
842
843#[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)]
844pub enum ExplicitLifetimeRequired<'a> {
845 #[diag("explicit lifetime required in the type of `{$simple_ident}`", code = E0621)]
846 WithIdent {
847 #[primary_span]
848 #[label("lifetime `{$named}` required")]
849 span: Span,
850 simple_ident: Ident,
851 named: String,
852 #[suggestion(
853 "add explicit lifetime `{$named}` to the type of `{$simple_ident}`",
854 code = "{new_ty}",
855 applicability = "unspecified",
856 style = "verbose"
857 )]
858 new_ty_span: Span,
859 #[skip_arg]
860 new_ty: Ty<'a>,
861 },
862 #[diag("explicit lifetime required in parameter type", code = E0621)]
863 WithParamType {
864 #[primary_span]
865 #[label("lifetime `{$named}` required")]
866 span: Span,
867 named: String,
868 #[suggestion(
869 "add explicit lifetime `{$named}` to type",
870 code = "{new_ty}",
871 applicability = "unspecified",
872 style = "verbose"
873 )]
874 new_ty_span: Span,
875 #[skip_arg]
876 new_ty: Ty<'a>,
877 },
878}
879
880pub enum TyOrSig<'tcx> {
881 Ty(Highlighted<'tcx, Ty<'tcx>>),
882 ClosureSig(Highlighted<'tcx, Binder<'tcx, FnSig<'tcx>>>),
883}
884
885impl IntoDiagArg for TyOrSig<'_> {
886 fn into_diag_arg(self, path: &mut Option<std::path::PathBuf>) -> rustc_errors::DiagArgValue {
887 match self {
888 TyOrSig::Ty(ty) => ty.into_diag_arg(path),
889 TyOrSig::ClosureSig(sig) => sig.into_diag_arg(path),
890 }
891 }
892}
893
894#[derive(const _: () =
{
impl<'tcx> rustc_errors::Subdiagnostic for ActualImplExplNotes<'tcx> {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
ActualImplExplNotes::ExpectedSignatureTwo {
leading_ellipsis: __binding_0,
ty_or_sig: __binding_1,
trait_path: __binding_2,
lifetime_1: __binding_3,
lifetime_2: __binding_4 } => {
diag.store_args();
diag.arg("leading_ellipsis", __binding_0);
diag.arg("ty_or_sig", __binding_1);
diag.arg("trait_path", __binding_2);
diag.arg("lifetime_1", __binding_3);
diag.arg("lifetime_2", __binding_4);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$leading_ellipsis ->\n [true] ...\n *[false] {\"\"}\n }closure with signature `{$ty_or_sig}` must implement `{$trait_path}`, for any two lifetimes `'{$lifetime_1}` and `'{$lifetime_2}`...")));
diag.note(__message);
diag.restore_args();
}
ActualImplExplNotes::ExpectedSignatureAny {
leading_ellipsis: __binding_0,
ty_or_sig: __binding_1,
trait_path: __binding_2,
lifetime_1: __binding_3 } => {
diag.store_args();
diag.arg("leading_ellipsis", __binding_0);
diag.arg("ty_or_sig", __binding_1);
diag.arg("trait_path", __binding_2);
diag.arg("lifetime_1", __binding_3);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$leading_ellipsis ->\n [true] ...\n *[false] {\"\"}\n }closure with signature `{$ty_or_sig}` must implement `{$trait_path}`, for any lifetime `'{$lifetime_1}`...")));
diag.note(__message);
diag.restore_args();
}
ActualImplExplNotes::ExpectedSignatureSome {
leading_ellipsis: __binding_0,
ty_or_sig: __binding_1,
trait_path: __binding_2,
lifetime_1: __binding_3 } => {
diag.store_args();
diag.arg("leading_ellipsis", __binding_0);
diag.arg("ty_or_sig", __binding_1);
diag.arg("trait_path", __binding_2);
diag.arg("lifetime_1", __binding_3);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$leading_ellipsis ->\n [true] ...\n *[false] {\"\"}\n }closure with signature `{$ty_or_sig}` must implement `{$trait_path}`, for some specific lifetime `'{$lifetime_1}`...")));
diag.note(__message);
diag.restore_args();
}
ActualImplExplNotes::ExpectedSignatureNothing {
leading_ellipsis: __binding_0,
ty_or_sig: __binding_1,
trait_path: __binding_2 } => {
diag.store_args();
diag.arg("leading_ellipsis", __binding_0);
diag.arg("ty_or_sig", __binding_1);
diag.arg("trait_path", __binding_2);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$leading_ellipsis ->\n [true] ...\n *[false] {\"\"}\n }closure with signature `{$ty_or_sig}` must implement `{$trait_path}`")));
diag.note(__message);
diag.restore_args();
}
ActualImplExplNotes::ExpectedPassiveTwo {
leading_ellipsis: __binding_0,
ty_or_sig: __binding_1,
trait_path: __binding_2,
lifetime_1: __binding_3,
lifetime_2: __binding_4 } => {
diag.store_args();
diag.arg("leading_ellipsis", __binding_0);
diag.arg("ty_or_sig", __binding_1);
diag.arg("trait_path", __binding_2);
diag.arg("lifetime_1", __binding_3);
diag.arg("lifetime_2", __binding_4);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$leading_ellipsis ->\n [true] ...\n *[false] {\"\"}\n }`{$trait_path}` would have to be implemented for the type `{$ty_or_sig}`, for any two lifetimes `'{$lifetime_1}` and `'{$lifetime_2}`...")));
diag.note(__message);
diag.restore_args();
}
ActualImplExplNotes::ExpectedPassiveAny {
leading_ellipsis: __binding_0,
ty_or_sig: __binding_1,
trait_path: __binding_2,
lifetime_1: __binding_3 } => {
diag.store_args();
diag.arg("leading_ellipsis", __binding_0);
diag.arg("ty_or_sig", __binding_1);
diag.arg("trait_path", __binding_2);
diag.arg("lifetime_1", __binding_3);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$leading_ellipsis ->\n [true] ...\n *[false] {\"\"}\n }`{$trait_path}` would have to be implemented for the type `{$ty_or_sig}`, for any lifetime `'{$lifetime_1}`...")));
diag.note(__message);
diag.restore_args();
}
ActualImplExplNotes::ExpectedPassiveSome {
leading_ellipsis: __binding_0,
ty_or_sig: __binding_1,
trait_path: __binding_2,
lifetime_1: __binding_3 } => {
diag.store_args();
diag.arg("leading_ellipsis", __binding_0);
diag.arg("ty_or_sig", __binding_1);
diag.arg("trait_path", __binding_2);
diag.arg("lifetime_1", __binding_3);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$leading_ellipsis ->\n [true] ...\n *[false] {\"\"}\n }`{$trait_path}` would have to be implemented for the type `{$ty_or_sig}`, for some specific lifetime `'{$lifetime_1}`...")));
diag.note(__message);
diag.restore_args();
}
ActualImplExplNotes::ExpectedPassiveNothing {
leading_ellipsis: __binding_0,
ty_or_sig: __binding_1,
trait_path: __binding_2 } => {
diag.store_args();
diag.arg("leading_ellipsis", __binding_0);
diag.arg("ty_or_sig", __binding_1);
diag.arg("trait_path", __binding_2);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$leading_ellipsis ->\n [true] ...\n *[false] {\"\"}\n }`{$trait_path}` would have to be implemented for the type `{$ty_or_sig}`")));
diag.note(__message);
diag.restore_args();
}
ActualImplExplNotes::ExpectedOtherTwo {
leading_ellipsis: __binding_0,
ty_or_sig: __binding_1,
trait_path: __binding_2,
lifetime_1: __binding_3,
lifetime_2: __binding_4 } => {
diag.store_args();
diag.arg("leading_ellipsis", __binding_0);
diag.arg("ty_or_sig", __binding_1);
diag.arg("trait_path", __binding_2);
diag.arg("lifetime_1", __binding_3);
diag.arg("lifetime_2", __binding_4);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$leading_ellipsis ->\n [true] ...\n *[false] {\"\"}\n }`{$ty_or_sig}` must implement `{$trait_path}`, for any two lifetimes `'{$lifetime_1}` and `'{$lifetime_2}`...")));
diag.note(__message);
diag.restore_args();
}
ActualImplExplNotes::ExpectedOtherAny {
leading_ellipsis: __binding_0,
ty_or_sig: __binding_1,
trait_path: __binding_2,
lifetime_1: __binding_3 } => {
diag.store_args();
diag.arg("leading_ellipsis", __binding_0);
diag.arg("ty_or_sig", __binding_1);
diag.arg("trait_path", __binding_2);
diag.arg("lifetime_1", __binding_3);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$leading_ellipsis ->\n [true] ...\n *[false] {\"\"}\n }`{$ty_or_sig}` must implement `{$trait_path}`, for any lifetime `'{$lifetime_1}`...")));
diag.note(__message);
diag.restore_args();
}
ActualImplExplNotes::ExpectedOtherSome {
leading_ellipsis: __binding_0,
ty_or_sig: __binding_1,
trait_path: __binding_2,
lifetime_1: __binding_3 } => {
diag.store_args();
diag.arg("leading_ellipsis", __binding_0);
diag.arg("ty_or_sig", __binding_1);
diag.arg("trait_path", __binding_2);
diag.arg("lifetime_1", __binding_3);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$leading_ellipsis ->\n [true] ...\n *[false] {\"\"}\n }`{$ty_or_sig}` must implement `{$trait_path}`, for some specific lifetime `'{$lifetime_1}`...")));
diag.note(__message);
diag.restore_args();
}
ActualImplExplNotes::ExpectedOtherNothing {
leading_ellipsis: __binding_0,
ty_or_sig: __binding_1,
trait_path: __binding_2 } => {
diag.store_args();
diag.arg("leading_ellipsis", __binding_0);
diag.arg("ty_or_sig", __binding_1);
diag.arg("trait_path", __binding_2);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$leading_ellipsis ->\n [true] ...\n *[false] {\"\"}\n }`{$ty_or_sig}` must implement `{$trait_path}`")));
diag.note(__message);
diag.restore_args();
}
ActualImplExplNotes::ButActuallyImplementsTrait {
trait_path: __binding_0,
has_lifetime: __binding_1,
lifetime: __binding_2 } => {
diag.store_args();
diag.arg("trait_path", __binding_0);
diag.arg("has_lifetime", __binding_1);
diag.arg("lifetime", __binding_2);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("...but it actually implements `{$trait_path}`{$has_lifetime ->\n [true] , for some specific lifetime `'{$lifetime}`\n *[false] {\"\"}\n }")));
diag.note(__message);
diag.restore_args();
}
ActualImplExplNotes::ButActuallyImplementedForTy {
trait_path: __binding_0,
has_lifetime: __binding_1,
lifetime: __binding_2,
ty: __binding_3 } => {
diag.store_args();
diag.arg("trait_path", __binding_0);
diag.arg("has_lifetime", __binding_1);
diag.arg("lifetime", __binding_2);
diag.arg("ty", __binding_3);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("...but `{$trait_path}` is actually implemented for the type `{$ty}`{$has_lifetime ->\n [true] , for some specific lifetime `'{$lifetime}`\n *[false] {\"\"}\n }")));
diag.note(__message);
diag.restore_args();
}
ActualImplExplNotes::ButActuallyTyImplements {
trait_path: __binding_0,
has_lifetime: __binding_1,
lifetime: __binding_2,
ty: __binding_3 } => {
diag.store_args();
diag.arg("trait_path", __binding_0);
diag.arg("has_lifetime", __binding_1);
diag.arg("lifetime", __binding_2);
diag.arg("ty", __binding_3);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("...but `{$ty}` actually implements `{$trait_path}`{$has_lifetime ->\n [true] , for some specific lifetime `'{$lifetime}`\n *[false] {\"\"}\n }")));
diag.note(__message);
diag.restore_args();
}
}
}
}
};Subdiagnostic)]
895pub enum ActualImplExplNotes<'tcx> {
896 #[note("{$leading_ellipsis ->
897 [true] ...
898 *[false] {\"\"}
899 }closure with signature `{$ty_or_sig}` must implement `{$trait_path}`, for any two lifetimes `'{$lifetime_1}` and `'{$lifetime_2}`...")]
900 ExpectedSignatureTwo {
901 leading_ellipsis: bool,
902 ty_or_sig: TyOrSig<'tcx>,
903 trait_path: Highlighted<'tcx, TraitRefPrintOnlyTraitPath<'tcx>>,
904 lifetime_1: usize,
905 lifetime_2: usize,
906 },
907 #[note("{$leading_ellipsis ->
908 [true] ...
909 *[false] {\"\"}
910 }closure with signature `{$ty_or_sig}` must implement `{$trait_path}`, for any lifetime `'{$lifetime_1}`...")]
911 ExpectedSignatureAny {
912 leading_ellipsis: bool,
913 ty_or_sig: TyOrSig<'tcx>,
914 trait_path: Highlighted<'tcx, TraitRefPrintOnlyTraitPath<'tcx>>,
915 lifetime_1: usize,
916 },
917 #[note("{$leading_ellipsis ->
918 [true] ...
919 *[false] {\"\"}
920 }closure with signature `{$ty_or_sig}` must implement `{$trait_path}`, for some specific lifetime `'{$lifetime_1}`...")]
921 ExpectedSignatureSome {
922 leading_ellipsis: bool,
923 ty_or_sig: TyOrSig<'tcx>,
924 trait_path: Highlighted<'tcx, TraitRefPrintOnlyTraitPath<'tcx>>,
925 lifetime_1: usize,
926 },
927 #[note(
928 "{$leading_ellipsis ->
929 [true] ...
930 *[false] {\"\"}
931 }closure with signature `{$ty_or_sig}` must implement `{$trait_path}`"
932 )]
933 ExpectedSignatureNothing {
934 leading_ellipsis: bool,
935 ty_or_sig: TyOrSig<'tcx>,
936 trait_path: Highlighted<'tcx, TraitRefPrintOnlyTraitPath<'tcx>>,
937 },
938 #[note("{$leading_ellipsis ->
939 [true] ...
940 *[false] {\"\"}
941 }`{$trait_path}` would have to be implemented for the type `{$ty_or_sig}`, for any two lifetimes `'{$lifetime_1}` and `'{$lifetime_2}`...")]
942 ExpectedPassiveTwo {
943 leading_ellipsis: bool,
944 ty_or_sig: TyOrSig<'tcx>,
945 trait_path: Highlighted<'tcx, TraitRefPrintOnlyTraitPath<'tcx>>,
946 lifetime_1: usize,
947 lifetime_2: usize,
948 },
949 #[note("{$leading_ellipsis ->
950 [true] ...
951 *[false] {\"\"}
952 }`{$trait_path}` would have to be implemented for the type `{$ty_or_sig}`, for any lifetime `'{$lifetime_1}`...")]
953 ExpectedPassiveAny {
954 leading_ellipsis: bool,
955 ty_or_sig: TyOrSig<'tcx>,
956 trait_path: Highlighted<'tcx, TraitRefPrintOnlyTraitPath<'tcx>>,
957 lifetime_1: usize,
958 },
959 #[note("{$leading_ellipsis ->
960 [true] ...
961 *[false] {\"\"}
962 }`{$trait_path}` would have to be implemented for the type `{$ty_or_sig}`, for some specific lifetime `'{$lifetime_1}`...")]
963 ExpectedPassiveSome {
964 leading_ellipsis: bool,
965 ty_or_sig: TyOrSig<'tcx>,
966 trait_path: Highlighted<'tcx, TraitRefPrintOnlyTraitPath<'tcx>>,
967 lifetime_1: usize,
968 },
969 #[note(
970 "{$leading_ellipsis ->
971 [true] ...
972 *[false] {\"\"}
973 }`{$trait_path}` would have to be implemented for the type `{$ty_or_sig}`"
974 )]
975 ExpectedPassiveNothing {
976 leading_ellipsis: bool,
977 ty_or_sig: TyOrSig<'tcx>,
978 trait_path: Highlighted<'tcx, TraitRefPrintOnlyTraitPath<'tcx>>,
979 },
980 #[note("{$leading_ellipsis ->
981 [true] ...
982 *[false] {\"\"}
983 }`{$ty_or_sig}` must implement `{$trait_path}`, for any two lifetimes `'{$lifetime_1}` and `'{$lifetime_2}`...")]
984 ExpectedOtherTwo {
985 leading_ellipsis: bool,
986 ty_or_sig: TyOrSig<'tcx>,
987 trait_path: Highlighted<'tcx, TraitRefPrintOnlyTraitPath<'tcx>>,
988 lifetime_1: usize,
989 lifetime_2: usize,
990 },
991 #[note(
992 "{$leading_ellipsis ->
993 [true] ...
994 *[false] {\"\"}
995 }`{$ty_or_sig}` must implement `{$trait_path}`, for any lifetime `'{$lifetime_1}`..."
996 )]
997 ExpectedOtherAny {
998 leading_ellipsis: bool,
999 ty_or_sig: TyOrSig<'tcx>,
1000 trait_path: Highlighted<'tcx, TraitRefPrintOnlyTraitPath<'tcx>>,
1001 lifetime_1: usize,
1002 },
1003 #[note(
1004 "{$leading_ellipsis ->
1005 [true] ...
1006 *[false] {\"\"}
1007 }`{$ty_or_sig}` must implement `{$trait_path}`, for some specific lifetime `'{$lifetime_1}`..."
1008 )]
1009 ExpectedOtherSome {
1010 leading_ellipsis: bool,
1011 ty_or_sig: TyOrSig<'tcx>,
1012 trait_path: Highlighted<'tcx, TraitRefPrintOnlyTraitPath<'tcx>>,
1013 lifetime_1: usize,
1014 },
1015 #[note(
1016 "{$leading_ellipsis ->
1017 [true] ...
1018 *[false] {\"\"}
1019 }`{$ty_or_sig}` must implement `{$trait_path}`"
1020 )]
1021 ExpectedOtherNothing {
1022 leading_ellipsis: bool,
1023 ty_or_sig: TyOrSig<'tcx>,
1024 trait_path: Highlighted<'tcx, TraitRefPrintOnlyTraitPath<'tcx>>,
1025 },
1026 #[note(
1027 "...but it actually implements `{$trait_path}`{$has_lifetime ->
1028 [true] , for some specific lifetime `'{$lifetime}`
1029 *[false] {\"\"}
1030 }"
1031 )]
1032 ButActuallyImplementsTrait {
1033 trait_path: Highlighted<'tcx, TraitRefPrintOnlyTraitPath<'tcx>>,
1034 has_lifetime: bool,
1035 lifetime: usize,
1036 },
1037 #[note(
1038 "...but `{$trait_path}` is actually implemented for the type `{$ty}`{$has_lifetime ->
1039 [true] , for some specific lifetime `'{$lifetime}`
1040 *[false] {\"\"}
1041 }"
1042 )]
1043 ButActuallyImplementedForTy {
1044 trait_path: Highlighted<'tcx, TraitRefPrintOnlyTraitPath<'tcx>>,
1045 has_lifetime: bool,
1046 lifetime: usize,
1047 ty: String,
1048 },
1049 #[note(
1050 "...but `{$ty}` actually implements `{$trait_path}`{$has_lifetime ->
1051 [true] , for some specific lifetime `'{$lifetime}`
1052 *[false] {\"\"}
1053 }"
1054 )]
1055 ButActuallyTyImplements {
1056 trait_path: Highlighted<'tcx, TraitRefPrintOnlyTraitPath<'tcx>>,
1057 has_lifetime: bool,
1058 lifetime: usize,
1059 ty: String,
1060 },
1061}
1062
1063pub enum ActualImplExpectedKind {
1064 Signature,
1065 Passive,
1066 Other,
1067}
1068
1069pub enum ActualImplExpectedLifetimeKind {
1070 Two,
1071 Any,
1072 Some,
1073 Nothing,
1074}
1075
1076impl<'tcx> ActualImplExplNotes<'tcx> {
1077 pub fn new_expected(
1078 kind: ActualImplExpectedKind,
1079 lt_kind: ActualImplExpectedLifetimeKind,
1080 leading_ellipsis: bool,
1081 ty_or_sig: TyOrSig<'tcx>,
1082 trait_path: Highlighted<'tcx, TraitRefPrintOnlyTraitPath<'tcx>>,
1083 lifetime_1: usize,
1084 lifetime_2: usize,
1085 ) -> Self {
1086 match (kind, lt_kind) {
1087 (ActualImplExpectedKind::Signature, ActualImplExpectedLifetimeKind::Two) => {
1088 Self::ExpectedSignatureTwo {
1089 leading_ellipsis,
1090 ty_or_sig,
1091 trait_path,
1092 lifetime_1,
1093 lifetime_2,
1094 }
1095 }
1096 (ActualImplExpectedKind::Signature, ActualImplExpectedLifetimeKind::Any) => {
1097 Self::ExpectedSignatureAny { leading_ellipsis, ty_or_sig, trait_path, lifetime_1 }
1098 }
1099 (ActualImplExpectedKind::Signature, ActualImplExpectedLifetimeKind::Some) => {
1100 Self::ExpectedSignatureSome { leading_ellipsis, ty_or_sig, trait_path, lifetime_1 }
1101 }
1102 (ActualImplExpectedKind::Signature, ActualImplExpectedLifetimeKind::Nothing) => {
1103 Self::ExpectedSignatureNothing { leading_ellipsis, ty_or_sig, trait_path }
1104 }
1105 (ActualImplExpectedKind::Passive, ActualImplExpectedLifetimeKind::Two) => {
1106 Self::ExpectedPassiveTwo {
1107 leading_ellipsis,
1108 ty_or_sig,
1109 trait_path,
1110 lifetime_1,
1111 lifetime_2,
1112 }
1113 }
1114 (ActualImplExpectedKind::Passive, ActualImplExpectedLifetimeKind::Any) => {
1115 Self::ExpectedPassiveAny { leading_ellipsis, ty_or_sig, trait_path, lifetime_1 }
1116 }
1117 (ActualImplExpectedKind::Passive, ActualImplExpectedLifetimeKind::Some) => {
1118 Self::ExpectedPassiveSome { leading_ellipsis, ty_or_sig, trait_path, lifetime_1 }
1119 }
1120 (ActualImplExpectedKind::Passive, ActualImplExpectedLifetimeKind::Nothing) => {
1121 Self::ExpectedPassiveNothing { leading_ellipsis, ty_or_sig, trait_path }
1122 }
1123 (ActualImplExpectedKind::Other, ActualImplExpectedLifetimeKind::Two) => {
1124 Self::ExpectedOtherTwo {
1125 leading_ellipsis,
1126 ty_or_sig,
1127 trait_path,
1128 lifetime_1,
1129 lifetime_2,
1130 }
1131 }
1132 (ActualImplExpectedKind::Other, ActualImplExpectedLifetimeKind::Any) => {
1133 Self::ExpectedOtherAny { leading_ellipsis, ty_or_sig, trait_path, lifetime_1 }
1134 }
1135 (ActualImplExpectedKind::Other, ActualImplExpectedLifetimeKind::Some) => {
1136 Self::ExpectedOtherSome { leading_ellipsis, ty_or_sig, trait_path, lifetime_1 }
1137 }
1138 (ActualImplExpectedKind::Other, ActualImplExpectedLifetimeKind::Nothing) => {
1139 Self::ExpectedOtherNothing { leading_ellipsis, ty_or_sig, trait_path }
1140 }
1141 }
1142 }
1143}
1144
1145#[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)]
1146#[diag("implementation of `{$trait_def_id}` is not general enough")]
1147pub struct TraitPlaceholderMismatch<'tcx> {
1148 #[primary_span]
1149 pub span: Span,
1150 #[label("doesn't satisfy where-clause")]
1151 pub satisfy_span: Option<Span>,
1152 #[label("due to a where-clause on `{$def_id}`...")]
1153 pub where_span: Option<Span>,
1154 #[label("implementation of `{$trait_def_id}` is not general enough")]
1155 pub dup_span: Option<Span>,
1156 pub def_id: String,
1157 pub trait_def_id: String,
1158
1159 #[subdiagnostic]
1160 pub actual_impl_expl_notes: Vec<ActualImplExplNotes<'tcx>>,
1161}
1162
1163pub struct ConsiderBorrowingParamHelp {
1164 pub spans: Vec<Span>,
1165}
1166
1167impl Subdiagnostic for ConsiderBorrowingParamHelp {
1168 fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
1169 let mut type_param_span: MultiSpan = self.spans.clone().into();
1170 for &span in &self.spans {
1171 type_param_span
1173 .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"));
1174 }
1175 let msg = diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the lifetime requirements from the `impl` do not correspond to the requirements in the `trait`"))msg!("the lifetime requirements from the `impl` do not correspond to the requirements in the `trait`"));
1176 diag.span_help(type_param_span, msg);
1177 }
1178}
1179
1180#[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)]
1181#[diag("`impl` item signature doesn't match `trait` item signature")]
1182pub struct TraitImplDiff {
1183 #[primary_span]
1184 #[label("found `{$found}`")]
1185 pub sp: Span,
1186 #[label("expected `{$expected}`")]
1187 pub trait_sp: Span,
1188 #[note(
1189 "expected signature `{$expected}`
1190 {\" \"}found signature `{$found}`"
1191 )]
1192 pub note: (),
1193 #[subdiagnostic]
1194 pub param_help: ConsiderBorrowingParamHelp,
1195 #[help(
1196 "verify the lifetime relationships in the `trait` and `impl` between the `self` argument, the other inputs and its output"
1197 )]
1198 pub rel_help: bool,
1199 pub expected: String,
1200 pub found: String,
1201}
1202
1203pub struct DynTraitConstraintSuggestion {
1204 pub span: Span,
1205 pub ident: Ident,
1206}
1207
1208impl Subdiagnostic for DynTraitConstraintSuggestion {
1209 fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
1210 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();
1211 multi_span.push_span_label(
1212 self.span,
1213 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this has an implicit `'static` lifetime requirement"))msg!("this has an implicit `'static` lifetime requirement"),
1214 );
1215 multi_span.push_span_label(
1216 self.ident.span,
1217 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"),
1218 );
1219 let msg = diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the used `impl` has a `'static` requirement"))msg!("the used `impl` has a `'static` requirement"));
1220 diag.span_note(multi_span, msg);
1221 let msg =
1222 diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider relaxing the implicit `'static` requirement"))msg!("consider relaxing the implicit `'static` requirement"));
1223 diag.span_suggestion_verbose(
1224 self.span.shrink_to_hi(),
1225 msg,
1226 " + '_",
1227 Applicability::MaybeIncorrect,
1228 );
1229 }
1230}
1231
1232#[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)]
1233#[diag("{$has_param_name ->
1234 [true] `{$param_name}`
1235 *[false] `fn` parameter
1236} has {$lifetime_kind ->
1237 [true] lifetime `{$lifetime}`
1238 *[false] an anonymous lifetime `'_`
1239} but calling `{$assoc_item}` introduces an implicit `'static` lifetime requirement", code = E0772)]
1240pub struct ButCallingIntroduces {
1241 #[label(
1242 "{$has_lifetime ->
1243 [true] lifetime `{$lifetime}`
1244 *[false] an anonymous lifetime `'_`
1245 }"
1246 )]
1247 pub param_ty_span: Span,
1248 #[primary_span]
1249 #[label("...is used and required to live as long as `'static` here because of an implicit lifetime bound on the {$has_impl_path ->
1250 [true] `impl` of `{$impl_path}`
1251 *[false] inherent `impl`
1252 }")]
1253 pub cause_span: Span,
1254
1255 pub has_param_name: bool,
1256 pub param_name: String,
1257 pub has_lifetime: bool,
1258 pub lifetime: String,
1259 pub assoc_item: Symbol,
1260 pub has_impl_path: bool,
1261 pub impl_path: String,
1262}
1263
1264pub struct ReqIntroducedLocations {
1265 pub span: MultiSpan,
1266 pub spans: Vec<Span>,
1267 pub fn_decl_span: Span,
1268 pub cause_span: Span,
1269 pub add_label: bool,
1270}
1271
1272impl Subdiagnostic for ReqIntroducedLocations {
1273 fn add_to_diag<G: EmissionGuarantee>(mut self, diag: &mut Diag<'_, G>) {
1274 for sp in self.spans {
1275 self.span.push_span_label(sp, rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`'static` requirement introduced here"))msg!("`'static` requirement introduced here"));
1276 }
1277
1278 if self.add_label {
1279 self.span.push_span_label(
1280 self.fn_decl_span,
1281 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("requirement introduced by this return type"))msg!("requirement introduced by this return type"),
1282 );
1283 }
1284 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"));
1285 let msg = diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("\"`'static` lifetime requirement introduced by the return type"))msg!(
1286 "\"`'static` lifetime requirement introduced by the return type"
1287 ));
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_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("remove the `where` clause")));
diag.span_suggestions_with_style(__binding_0, __message,
__code_9, rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::ShowAlways);
diag.restore_args();
}
WhereClauseSuggestions::CopyPredicates {
span: __binding_0,
space: __binding_1,
trait_predicates: __binding_2 } => {
let __code_10 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0}where {1}",
__binding_1, __binding_2))
})].into_iter();
diag.store_args();
diag.arg("space", __binding_1);
diag.arg("trait_predicates", __binding_2);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("copy the `where` clause predicates from the trait")));
diag.span_suggestions_with_style(__binding_0, __message,
__code_10, rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::ShowAlways);
diag.restore_args();
}
}
}
}
};Subdiagnostic)]
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_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider removing this semicolon and boxing the expressions")));
diag.multipart_suggestion_with_style(__message, suggestions,
rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::ShowCode);
diag.restore_args();
}
SuggestRemoveSemiOrReturnBinding::Remove { sp: __binding_0 }
=> {
let __code_16 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!(""))
})].into_iter();
diag.store_args();
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider removing this semicolon")));
diag.span_suggestions_with_style(__binding_0, __message,
__code_16, rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::HideCodeInline);
diag.restore_args();
}
SuggestRemoveSemiOrReturnBinding::Add {
sp: __binding_0, code: __binding_1, ident: __binding_2 } =>
{
let __code_17 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0}", __binding_1))
})].into_iter();
diag.store_args();
diag.arg("code", __binding_1);
diag.arg("ident", __binding_2);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider returning the local binding `{$ident}`")));
diag.span_suggestions_with_style(__binding_0, __message,
__code_17, rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowAlways);
diag.restore_args();
}
SuggestRemoveSemiOrReturnBinding::AddOne {
spans: __binding_0 } => {
diag.store_args();
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider returning one of these bindings")));
diag.span_note(__binding_0, __message);
diag.restore_args();
}
}
}
}
};Subdiagnostic)]
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_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider `await`ing on both `Future`s")));
diag.help(__message);
diag.restore_args();
}
ConsiderAddingAwait::BothFuturesSugg {
first: __binding_0, second: __binding_1 } => {
let mut suggestions = Vec::new();
let __code_18 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!(".await"))
});
let __code_19 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!(".await"))
});
suggestions.push((__binding_0, __code_18));
suggestions.push((__binding_1, __code_19));
diag.store_args();
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider `await`ing on both `Future`s")));
diag.multipart_suggestion_with_style(__message, suggestions,
rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowCode);
diag.restore_args();
}
ConsiderAddingAwait::FutureSugg { span: __binding_0 } => {
let __code_20 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!(".await"))
})].into_iter();
diag.store_args();
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider `await`ing on the `Future`")));
diag.span_suggestions_with_style(__binding_0, __message,
__code_20, rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowAlways);
diag.restore_args();
}
ConsiderAddingAwait::FutureSuggNote { span: __binding_0 } =>
{
diag.store_args();
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("calling an async function returns a future")));
diag.span_note(__binding_0, __message);
diag.restore_args();
}
ConsiderAddingAwait::FutureSuggMultiple { spans: __binding_0
} => {
let mut suggestions = Vec::new();
let __code_21 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!(".await"))
});
for __binding_0 in __binding_0 {
suggestions.push((__binding_0, __code_21.clone()));
}
diag.store_args();
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider `await`ing on the `Future`")));
diag.multipart_suggestion_with_style(__message, suggestions,
rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowAlways);
diag.restore_args();
}
}
}
}
};Subdiagnostic)]
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_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider using a reference")));
diag.span_suggestions_with_style(__binding_0, __message,
__code_22, rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowAlways);
diag.restore_args();
}
FunctionPointerSuggestion::RemoveRef {
span: __binding_0, fn_name: __binding_1 } => {
let __code_23 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0}", __binding_1))
})].into_iter();
diag.store_args();
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider removing the reference")));
diag.span_suggestions_with_style(__binding_0, __message,
__code_23, rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowAlways);
diag.restore_args();
}
FunctionPointerSuggestion::CastRef {
span: __binding_0, fn_name: __binding_1, sig: __binding_2 }
=> {
let __code_24 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("&({0} as {1})",
__binding_1, __binding_2))
})].into_iter();
diag.store_args();
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider casting to a fn pointer")));
diag.span_suggestions_with_style(__binding_0, __message,
__code_24, rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowAlways);
diag.restore_args();
}
FunctionPointerSuggestion::Cast {
span: __binding_0, sig: __binding_1 } => {
let __code_25 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!(" as {0}", __binding_1))
})].into_iter();
diag.store_args();
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider casting to a fn pointer")));
diag.span_suggestions_with_style(__binding_0, __message,
__code_25, rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowAlways);
diag.restore_args();
}
FunctionPointerSuggestion::CastBoth {
span: __binding_0,
found_sig: __binding_1,
expected_sig: __binding_2 } => {
let __code_26 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!(" as {0}", __binding_1))
})].into_iter();
diag.store_args();
diag.arg("expected_sig", __binding_2);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider casting both fn items to fn pointers using `as {$expected_sig}`")));
diag.span_suggestions_with_style(__binding_0, __message,
__code_26, rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::HideCodeAlways);
diag.restore_args();
}
FunctionPointerSuggestion::CastBothRef {
span: __binding_0,
fn_name: __binding_1,
found_sig: __binding_2,
expected_sig: __binding_3 } => {
let __code_27 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("&({0} as {1})",
__binding_1, __binding_2))
})].into_iter();
diag.store_args();
diag.arg("expected_sig", __binding_3);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider casting both fn items to fn pointers using `as {$expected_sig}`")));
diag.span_suggestions_with_style(__binding_0, __message,
__code_27, rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::HideCodeAlways);
diag.restore_args();
}
}
}
}
};Subdiagnostic)]
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_translate(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_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("different fn items have unique types, even if their signatures are the same")));
diag.note(__message);
diag.restore_args();
}
}
}
}
};Subdiagnostic)]
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_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider casting the fn item to a fn pointer: `{$casting}`")));
diag.help(__message);
diag.restore_args();
}
}
}
}
};Subdiagnostic)]
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_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider casting both fn items to fn pointers using `as {$sig}`")));
diag.help(__message);
diag.restore_args();
}
}
}
}
};Subdiagnostic)]
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_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("you might have meant to use field `{$name}` whose type is `{$ty}`")));
diag.span_suggestions_with_style(__binding_0, __message,
__code_28, rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowAlways);
diag.restore_args();
}
SuggestAccessingField::Unsafe {
span: __binding_0,
snippet: __binding_1,
name: __binding_2,
ty: __binding_3 } => {
let __code_29 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("unsafe {{ {1}.{0} }}",
__binding_2, __binding_1))
})].into_iter();
diag.store_args();
diag.arg("snippet", __binding_1);
diag.arg("name", __binding_2);
diag.arg("ty", __binding_3);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("you might have meant to use field `{$name}` whose type is `{$ty}`")));
diag.span_suggestions_with_style(__binding_0, __message,
__code_29, rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowAlways);
diag.restore_args();
}
}
}
}
};Subdiagnostic)]
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_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("try wrapping the pattern in `{$variant}`")));
diag.multipart_suggestion_with_style(__message, suggestions,
rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowCode);
diag.restore_args();
}
}
}
}
};Subdiagnostic)]
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_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("try wrapping the pattern in a variant of `{$path}`"))msg!("try wrapping the pattern in a variant of `{$path}`"));
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_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("if you meant to write a byte literal, prefix with `b`")));
diag.span_suggestions_with_style(__binding_0, __message,
__code_32, rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::ShowCode);
diag.restore_args();
}
TypeErrorAdditionalDiags::MeantCharLiteral {
span: __binding_0, code: __binding_1 } => {
let __code_33 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("\'{0}\'", __binding_1))
})].into_iter();
diag.store_args();
diag.arg("code", __binding_1);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("if you meant to write a `char` literal, use single quotes")));
diag.span_suggestions_with_style(__binding_0, __message,
__code_33, rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::ShowCode);
diag.restore_args();
}
TypeErrorAdditionalDiags::MeantStrLiteral {
start: __binding_0, end: __binding_1 } => {
let mut suggestions = Vec::new();
let __code_34 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("\""))
});
let __code_35 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("\""))
});
suggestions.push((__binding_0, __code_34));
suggestions.push((__binding_1, __code_35));
diag.store_args();
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("if you meant to write a string literal, use double quotes")));
diag.multipart_suggestion_with_style(__message, suggestions,
rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::ShowCode);
diag.restore_args();
}
TypeErrorAdditionalDiags::ConsiderSpecifyingLength {
span: __binding_0, length: __binding_1 } => {
let __code_36 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0}", __binding_1))
})].into_iter();
diag.store_args();
diag.arg("length", __binding_1);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider specifying the actual array length")));
diag.span_suggestions_with_style(__binding_0, __message,
__code_36, rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowCode);
diag.restore_args();
}
TypeErrorAdditionalDiags::TryCannotConvert {
found: __binding_0, expected: __binding_1 } => {
diag.store_args();
diag.arg("found", __binding_0);
diag.arg("expected", __binding_1);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`?` operator cannot convert from `{$found}` to `{$expected}`")));
diag.note(__message);
diag.restore_args();
}
TypeErrorAdditionalDiags::TupleOnlyComma { span: __binding_0
} => {
let __code_37 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!(","))
})].into_iter();
diag.store_args();
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("use a trailing comma to create a tuple with one element")));
diag.span_suggestions_with_style(__binding_0, __message,
__code_37, rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::ShowCode);
diag.restore_args();
}
TypeErrorAdditionalDiags::TupleAlsoParentheses {
span_low: __binding_0, span_high: __binding_1 } => {
let mut suggestions = Vec::new();
let __code_38 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("("))
});
let __code_39 =
::alloc::__export::must_use({
::alloc::fmt::format(format_args!(",)"))
});
suggestions.push((__binding_0, __code_38));
suggestions.push((__binding_1, __code_39));
diag.store_args();
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("use a trailing comma to create a tuple with one element")));
diag.multipart_suggestion_with_style(__message, suggestions,
rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::ShowCode);
diag.restore_args();
}
TypeErrorAdditionalDiags::AddLetForLetChains {
span: __binding_0 } => {
let __code_40 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("let "))
})].into_iter();
diag.store_args();
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider adding `let`")));
diag.span_suggestions_with_style(__binding_0, __message,
__code_40, rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::ShowAlways);
diag.restore_args();
}
}
}
}
};Subdiagnostic)]
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_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("add a `use<...>` bound to explicitly capture `{$new_lifetime}`")));
diag.span_suggestions_with_style(__binding_0, __message,
__code_41, rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::ShowAlways);
diag.restore_args();
}
AddPreciseCapturing::Existing {
span: __binding_0,
new_lifetime: __binding_1,
pre: __binding_2,
post: __binding_3 } => {
let __code_42 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{2}{0}{1}", __binding_1,
__binding_3, __binding_2))
})].into_iter();
diag.store_args();
diag.arg("new_lifetime", __binding_1);
diag.arg("pre", __binding_2);
diag.arg("post", __binding_3);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("add `{$new_lifetime}` to the `use<...>` bound to explicitly capture it")));
diag.span_suggestions_with_style(__binding_0, __message,
__code_42, rustc_errors::Applicability::MachineApplicable,
rustc_errors::SuggestionStyle::ShowAlways);
diag.restore_args();
}
}
}
}
};Subdiagnostic)]
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(Symbol::intern)
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}