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