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, inline_fluent,
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(dcx, level, rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("found both positive and negative implementation of trait `{$trait_desc}`{$self_desc ->
[none] {\"\"}
*[default] {\" \"}for type `{$self_desc}`
}:"))inline_fluent!("found both positive and negative implementation of trait `{$trait_desc}`{$self_desc ->
106[none] {\"\"}
107*[default] {\" \"}for type `{$self_desc}`
108}:"));
109 diag.arg("trait_desc", self.trait_desc.print_only_trait_path().to_string());
110 diag.arg("self_desc", self.self_ty.map_or_else(|| "none".to_string(), |ty| ty.to_string()));
111 diag.span(self.impl_span);
112 diag.code(E0751);
113 match self.negative_impl_span {
114 Ok(span) => {
115 diag.span_label(span, rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("negative implementation here"))inline_fluent!("negative implementation here"));
116 }
117 Err(cname) => {
118 diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("negative implementation in crate `{$negative_impl_cname}`"))inline_fluent!(
119 "negative implementation in crate `{$negative_impl_cname}`"
120 ));
121 diag.arg("negative_impl_cname", cname.to_string());
122 }
123 }
124 match self.positive_impl_span {
125 Ok(span) => {
126 diag.span_label(span, rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("positive implementation here"))inline_fluent!("positive implementation here"));
127 }
128 Err(cname) => {
129 diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("positive implementation in crate `{$positive_impl_cname}`"))inline_fluent!(
130 "positive implementation in crate `{$positive_impl_cname}`"
131 ));
132 diag.arg("positive_impl_cname", cname.to_string());
133 }
134 }
135 diag
136 }
137}
138
139#[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)]
140#[diag("overflow evaluating associated type `{$ty}`")]
141pub struct InherentProjectionNormalizationOverflow {
142 #[primary_span]
143 pub span: Span,
144 pub ty: String,
145}
146
147pub enum AdjustSignatureBorrow {
148 Borrow { to_borrow: Vec<(Span, String)> },
149 RemoveBorrow { remove_borrow: Vec<(Span, String)> },
150}
151
152impl Subdiagnostic for AdjustSignatureBorrow {
153 fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
154 match self {
155 AdjustSignatureBorrow::Borrow { to_borrow } => {
156 diag.arg("borrow_len", to_borrow.len());
157 diag.multipart_suggestion_verbose(
158 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider adjusting the signature so it borrows its {$borrow_len ->
[one] argument
*[other] arguments
}"))inline_fluent!(
159 "consider adjusting the signature so it borrows its {$borrow_len ->
160[one] argument
161*[other] arguments
162}"
163 ),
164 to_borrow,
165 Applicability::MaybeIncorrect,
166 );
167 }
168 AdjustSignatureBorrow::RemoveBorrow { remove_borrow } => {
169 diag.arg("remove_borrow_len", remove_borrow.len());
170 diag.multipart_suggestion_verbose(
171 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider adjusting the signature so it does not borrow its {$remove_borrow_len ->
[one] argument
*[other] arguments
}"))inline_fluent!(
172 "consider adjusting the signature so it does not borrow its {$remove_borrow_len ->
173[one] argument
174*[other] arguments
175}"
176 ),
177 remove_borrow,
178 Applicability::MaybeIncorrect,
179 );
180 }
181 }
182 }
183}
184
185#[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)]
186#[diag("expected a closure that implements the `{$trait_prefix}{$expected}` trait, but this closure only implements `{$trait_prefix}{$found}`", code = E0525)]
187pub struct ClosureKindMismatch {
188 #[primary_span]
189 #[label("this closure implements `{$trait_prefix}{$found}`, not `{$trait_prefix}{$expected}`")]
190 pub closure_span: Span,
191 pub expected: ClosureKind,
192 pub found: ClosureKind,
193 #[label("the requirement to implement `{$trait_prefix}{$expected}` derives from here")]
194 pub cause_span: Span,
195
196 pub trait_prefix: &'static str,
197
198 #[subdiagnostic]
199 pub fn_once_label: Option<ClosureFnOnceLabel>,
200
201 #[subdiagnostic]
202 pub fn_mut_label: Option<ClosureFnMutLabel>,
203}
204
205#[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)]
206#[label(
207 "closure is `{$trait_prefix}FnOnce` because it moves the variable `{$place}` out of its environment"
208)]
209pub struct ClosureFnOnceLabel {
210 #[primary_span]
211 pub span: Span,
212 pub place: String,
213}
214
215#[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)]
216#[label("closure is `{$trait_prefix}FnMut` because it mutates the variable `{$place}` here")]
217pub struct ClosureFnMutLabel {
218 #[primary_span]
219 pub span: Span,
220 pub place: String,
221}
222
223#[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)]
224#[diag(
225 "{$coro_kind}closure does not implement `{$kind}` because it captures state from its environment"
226)]
227pub(crate) struct CoroClosureNotFn {
228 #[primary_span]
229 pub span: Span,
230 pub kind: &'static str,
231 pub coro_kind: String,
232}
233
234#[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)]
235#[diag("{$source_kind ->
236[closure] type annotations needed for the closure `{$source_name}`
237[normal] type annotations needed for `{$source_name}`
238*[other] type annotations needed
239}", code = E0282)]
240pub struct AnnotationRequired<'a> {
241 #[primary_span]
242 pub span: Span,
243 pub source_kind: &'static str,
244 pub source_name: &'a str,
245 #[label("type must be known at this point")]
246 pub failure_span: Option<Span>,
247 #[subdiagnostic]
248 pub bad_label: Option<InferenceBadError<'a>>,
249 #[subdiagnostic]
250 pub infer_subdiags: Vec<SourceKindSubdiag<'a>>,
251 #[subdiagnostic]
252 pub multi_suggestions: Vec<SourceKindMultiSuggestion<'a>>,
253}
254
255#[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)]
257#[diag("{$source_kind ->
258[closure] type annotations needed for the closure `{$source_name}`
259[normal] type annotations needed for `{$source_name}`
260*[other] type annotations needed
261}", code = E0283)]
262pub struct AmbiguousImpl<'a> {
263 #[primary_span]
264 pub span: Span,
265 pub source_kind: &'static str,
266 pub source_name: &'a str,
267 #[label("type must be known at this point")]
268 pub failure_span: Option<Span>,
269 #[subdiagnostic]
270 pub bad_label: Option<InferenceBadError<'a>>,
271 #[subdiagnostic]
272 pub infer_subdiags: Vec<SourceKindSubdiag<'a>>,
273 #[subdiagnostic]
274 pub multi_suggestions: Vec<SourceKindMultiSuggestion<'a>>,
275}
276
277#[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)]
279#[diag("{$source_kind ->
280[closure] type annotations needed for the closure `{$source_name}`
281[normal] type annotations needed for `{$source_name}`
282*[other] type annotations needed
283}", code = E0284)]
284pub struct AmbiguousReturn<'a> {
285 #[primary_span]
286 pub span: Span,
287 pub source_kind: &'static str,
288 pub source_name: &'a str,
289 #[label("type must be known at this point")]
290 pub failure_span: Option<Span>,
291 #[subdiagnostic]
292 pub bad_label: Option<InferenceBadError<'a>>,
293 #[subdiagnostic]
294 pub infer_subdiags: Vec<SourceKindSubdiag<'a>>,
295 #[subdiagnostic]
296 pub multi_suggestions: Vec<SourceKindMultiSuggestion<'a>>,
297}
298
299#[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)]
301#[label(
302 "{$bad_kind ->
303*[other] cannot infer type
304[more_info] cannot infer {$prefix_kind ->
305*[type] type for {$prefix}
306[const_with_param] the value of const parameter
307[const] the value of the constant
308} `{$name}`{$has_parent ->
309[true] {\" \"}declared on the {$parent_prefix} `{$parent_name}`
310*[false] {\"\"}
311}
312}"
313)]
314pub struct InferenceBadError<'a> {
315 #[primary_span]
316 pub span: Span,
317 pub bad_kind: &'static str,
318 pub prefix_kind: UnderspecifiedArgKind,
319 pub has_parent: bool,
320 pub prefix: &'a str,
321 pub parent_prefix: &'a str,
322 pub parent_name: String,
323 pub name: String,
324}
325
326#[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)]
327pub enum SourceKindSubdiag<'a> {
328 #[suggestion(
329 "{$kind ->
330 [with_pattern] consider giving `{$name}` an explicit type
331 [closure] consider giving this closure parameter an explicit type
332 *[other] consider giving this pattern a type
333 }{$x_kind ->
334 [has_name] , where the {$prefix_kind ->
335 *[type] type for {$prefix}
336 [const_with_param] value of const parameter
337 [const] value of the constant
338 } `{$arg_name}` is specified
339 [underscore] , where the placeholders `_` are specified
340 *[empty] {\"\"}
341 }",
342 style = "verbose",
343 code = ": {type_name}",
344 applicability = "has-placeholders"
345 )]
346 LetLike {
347 #[primary_span]
348 span: Span,
349 name: String,
350 type_name: String,
351 kind: &'static str,
352 x_kind: &'static str,
353 prefix_kind: UnderspecifiedArgKind,
354 prefix: &'a str,
355 arg_name: String,
356 },
357 #[label(
358 "cannot infer {$is_type ->
359 [true] type
360 *[false] the value
361 } of the {$is_type ->
362 [true] type
363 *[false] const
364 } {$parent_exists ->
365 [true] parameter `{$param_name}` declared on the {$parent_prefix} `{$parent_name}`
366 *[false] parameter {$param_name}
367 }"
368 )]
369 GenericLabel {
370 #[primary_span]
371 span: Span,
372 is_type: bool,
373 param_name: String,
374 parent_exists: bool,
375 parent_prefix: String,
376 parent_name: String,
377 },
378 #[suggestion(
379 "consider specifying the generic {$arg_count ->
380 [one] argument
381 *[other] arguments
382 }",
383 style = "verbose",
384 code = "::<{args}>",
385 applicability = "has-placeholders"
386 )]
387 GenericSuggestion {
388 #[primary_span]
389 span: Span,
390 arg_count: usize,
391 args: String,
392 },
393}
394
395#[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)]
396pub enum SourceKindMultiSuggestion<'a> {
397 #[multipart_suggestion(
398 "try using a fully qualified path to specify the expected types",
399 style = "verbose",
400 applicability = "has-placeholders"
401 )]
402 FullyQualified {
403 #[suggestion_part(code = "{def_path}({adjustment}")]
404 span_lo: Span,
405 #[suggestion_part(code = "{successor_pos}")]
406 span_hi: Span,
407 def_path: String,
408 adjustment: &'a str,
409 successor_pos: &'a str,
410 },
411 #[multipart_suggestion(
412 "try giving this closure an explicit return type",
413 style = "verbose",
414 applicability = "has-placeholders"
415 )]
416 ClosureReturn {
417 #[suggestion_part(code = "{start_span_code}")]
418 start_span: Span,
419 start_span_code: String,
420 #[suggestion_part(code = " }}")]
421 end_span: Option<Span>,
422 },
423}
424
425impl<'a> SourceKindMultiSuggestion<'a> {
426 pub fn new_fully_qualified(
427 span: Span,
428 def_path: String,
429 adjustment: &'a str,
430 successor: (&'a str, BytePos),
431 ) -> Self {
432 Self::FullyQualified {
433 span_lo: span.shrink_to_lo(),
434 span_hi: span.shrink_to_hi().with_hi(successor.1),
435 def_path,
436 adjustment,
437 successor_pos: successor.0,
438 }
439 }
440
441 pub fn new_closure_return(
442 ty_info: String,
443 data: &'a FnRetTy<'a>,
444 should_wrap_expr: Option<Span>,
445 ) -> Self {
446 let arrow = match data {
447 FnRetTy::DefaultReturn(_) => " -> ",
448 _ => "",
449 };
450 let (start_span, start_span_code, end_span) = match should_wrap_expr {
451 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)),
452 None => (data.span(), ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0}{1}", arrow, ty_info))
})format!("{arrow}{ty_info}"), None),
453 };
454 Self::ClosureReturn { start_span, start_span_code, end_span }
455 }
456}
457
458pub enum RegionOriginNote<'a> {
459 Plain {
460 span: Span,
461 msg: DiagMessage,
462 },
463 WithName {
464 span: Span,
465 msg: DiagMessage,
466 name: &'a str,
467 continues: bool,
468 },
469 WithRequirement {
470 span: Span,
471 requirement: ObligationCauseAsDiagArg<'a>,
472 expected_found: Option<(DiagStyledString, DiagStyledString)>,
473 },
474}
475
476impl Subdiagnostic for RegionOriginNote<'_> {
477 fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
478 let mut label_or_note = |span, msg: DiagMessage| {
479 let sub_count = diag.children.iter().filter(|d| d.span.is_dummy()).count();
480 let expanded_sub_count = diag.children.iter().filter(|d| !d.span.is_dummy()).count();
481 let span_is_primary = diag.span.primary_spans().iter().all(|&sp| sp == span);
482 if span_is_primary && sub_count == 0 && expanded_sub_count == 0 {
483 diag.span_label(span, msg);
484 } else if span_is_primary && expanded_sub_count == 0 {
485 diag.note(msg);
486 } else {
487 diag.span_note(span, msg);
488 }
489 };
490 match self {
491 RegionOriginNote::Plain { span, msg } => {
492 label_or_note(span, msg);
493 }
494 RegionOriginNote::WithName { span, msg, name, continues } => {
495 label_or_note(span, msg);
496 diag.arg("name", name);
497 diag.arg("continues", continues);
498 }
499 RegionOriginNote::WithRequirement {
500 span,
501 requirement,
502 expected_found: Some((expected, found)),
503 } => {
504 label_or_note(
505 span,
506 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("...so that the {$requirement ->
[method_compat] method type is compatible with trait
[type_compat] associated type is compatible with trait
[const_compat] const is compatible with trait
[expr_assignable] expression is assignable
[if_else_different] `if` and `else` have incompatible types
[no_else] `if` missing an `else` returns `()`
[fn_main_correct_type] `main` function has the correct type
[fn_lang_correct_type] lang item function has the correct type
[intrinsic_correct_type] intrinsic has the correct type
[method_correct_type] method receiver has the correct type
*[other] types are compatible
}"))inline_fluent!(
507 "...so that the {$requirement ->
508[method_compat] method type is compatible with trait
509[type_compat] associated type is compatible with trait
510[const_compat] const is compatible with trait
511[expr_assignable] expression is assignable
512[if_else_different] `if` and `else` have incompatible types
513[no_else] `if` missing an `else` returns `()`
514[fn_main_correct_type] `main` function has the correct type
515[fn_lang_correct_type] lang item function has the correct type
516[intrinsic_correct_type] intrinsic has the correct type
517[method_correct_type] method receiver has the correct type
518*[other] types are compatible
519}"
520 ),
521 );
522 diag.arg("requirement", requirement);
523
524 diag.note_expected_found("", expected, "", found);
525 }
526 RegionOriginNote::WithRequirement { span, requirement, expected_found: None } => {
527 label_or_note(
531 span,
532 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("...so that {$requirement ->
[method_compat] method type is compatible with trait
[type_compat] associated type is compatible with trait
[const_compat] const is compatible with trait
[expr_assignable] expression is assignable
[if_else_different] `if` and `else` have incompatible types
[no_else] `if` missing an `else` returns `()`
[fn_main_correct_type] `main` function has the correct type
[fn_lang_correct_type] lang item function has the correct type
[intrinsic_correct_type] intrinsic has the correct type
[method_correct_type] method receiver has the correct type
*[other] types are compatible
}"))inline_fluent!(
533 "...so that {$requirement ->
534[method_compat] method type is compatible with trait
535[type_compat] associated type is compatible with trait
536[const_compat] const is compatible with trait
537[expr_assignable] expression is assignable
538[if_else_different] `if` and `else` have incompatible types
539[no_else] `if` missing an `else` returns `()`
540[fn_main_correct_type] `main` function has the correct type
541[fn_lang_correct_type] lang item function has the correct type
542[intrinsic_correct_type] intrinsic has the correct type
543[method_correct_type] method receiver has the correct type
544*[other] types are compatible
545}"
546 ),
547 );
548 diag.arg("requirement", requirement);
549 }
550 };
551 }
552}
553
554pub enum LifetimeMismatchLabels {
555 InRet {
556 param_span: Span,
557 ret_span: Span,
558 span: Span,
559 label_var1: Option<Ident>,
560 },
561 Normal {
562 hir_equal: bool,
563 ty_sup: Span,
564 ty_sub: Span,
565 span: Span,
566 sup: Option<Ident>,
567 sub: Option<Ident>,
568 },
569}
570
571impl Subdiagnostic for LifetimeMismatchLabels {
572 fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
573 match self {
574 LifetimeMismatchLabels::InRet { param_span, ret_span, span, label_var1 } => {
575 diag.span_label(param_span, rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this parameter and the return type are declared with different lifetimes..."))inline_fluent!("this parameter and the return type are declared with different lifetimes..."));
576 diag.span_label(ret_span, rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{\"\"}"))inline_fluent!("{\"\"}"));
577 diag.span_label(
578 span,
579 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("...but data{$label_var1_exists ->
[true] {\" \"}from `{$label_var1}`
*[false] {\"\"}
} is returned here"))inline_fluent!(
580 "...but data{$label_var1_exists ->
581[true] {\" \"}from `{$label_var1}`
582*[false] {\"\"}
583} is returned here"
584 ),
585 );
586 diag.arg("label_var1_exists", label_var1.is_some());
587 diag.arg("label_var1", label_var1.map(|x| x.to_string()).unwrap_or_default());
588 }
589 LifetimeMismatchLabels::Normal {
590 hir_equal,
591 ty_sup,
592 ty_sub,
593 span,
594 sup: label_var1,
595 sub: label_var2,
596 } => {
597 if hir_equal {
598 diag.span_label(
599 ty_sup,
600 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this type is declared with multiple lifetimes..."))inline_fluent!("this type is declared with multiple lifetimes..."),
601 );
602 diag.span_label(ty_sub, rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{\"\"}"))inline_fluent!("{\"\"}"));
603 diag.span_label(
604 span,
605 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("...but data with one lifetime flows into the other here"))inline_fluent!("...but data with one lifetime flows into the other here"),
606 );
607 } else {
608 diag.span_label(
609 ty_sup,
610 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("these two types are declared with different lifetimes..."))inline_fluent!("these two types are declared with different lifetimes..."),
611 );
612 diag.span_label(ty_sub, rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{\"\"}"))inline_fluent!("{\"\"}"));
613 diag.span_label(
614 span,
615 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("...but data{$label_var1_exists ->
[true] {\" \"}from `{$label_var1}`
*[false] {\"\"}
} flows{$label_var2_exists ->
[true] {\" \"}into `{$label_var2}`
*[false] {\"\"}
} here"))inline_fluent!(
616 "...but data{$label_var1_exists ->
617[true] {\" \"}from `{$label_var1}`
618*[false] {\"\"}
619} flows{$label_var2_exists ->
620[true] {\" \"}into `{$label_var2}`
621*[false] {\"\"}
622} here"
623 ),
624 );
625 diag.arg("label_var1_exists", label_var1.is_some());
626 diag.arg("label_var1", label_var1.map(|x| x.to_string()).unwrap_or_default());
627 diag.arg("label_var2_exists", label_var2.is_some());
628 diag.arg("label_var2", label_var2.map(|x| x.to_string()).unwrap_or_default());
629 }
630 }
631 }
632 }
633}
634
635pub struct AddLifetimeParamsSuggestion<'a> {
636 pub tcx: TyCtxt<'a>,
637 pub generic_param_scope: LocalDefId,
638 pub sub: Region<'a>,
639 pub ty_sup: &'a hir::Ty<'a>,
640 pub ty_sub: &'a hir::Ty<'a>,
641 pub add_note: bool,
642}
643
644impl Subdiagnostic for AddLifetimeParamsSuggestion<'_> {
645 fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
646 let mut mk_suggestion = || {
647 let Some(anon_reg) = self.tcx.is_suitable_region(self.generic_param_scope, self.sub)
648 else {
649 return false;
650 };
651
652 let node = self.tcx.hir_node_by_def_id(anon_reg.scope);
653 let is_impl = #[allow(non_exhaustive_omitted_patterns)] match &node {
hir::Node::ImplItem(_) => true,
_ => false,
}matches!(&node, hir::Node::ImplItem(_));
654 let (generics, parent_generics) = match node {
655 hir::Node::Item(hir::Item { kind: hir::ItemKind::Fn { generics, .. }, .. })
656 | hir::Node::TraitItem(hir::TraitItem { generics, .. })
657 | hir::Node::ImplItem(hir::ImplItem { generics, .. }) => (
658 generics,
659 match self.tcx.parent_hir_node(self.tcx.local_def_id_to_hir_id(anon_reg.scope))
660 {
661 hir::Node::Item(hir::Item {
662 kind: hir::ItemKind::Trait(_, _, _, _, generics, ..),
663 ..
664 })
665 | hir::Node::Item(hir::Item {
666 kind: hir::ItemKind::Impl(hir::Impl { generics, .. }),
667 ..
668 }) => Some(generics),
669 _ => None,
670 },
671 ),
672 _ => return false,
673 };
674
675 let suggestion_param_name = generics
676 .params
677 .iter()
678 .filter(|p| #[allow(non_exhaustive_omitted_patterns)] match p.kind {
GenericParamKind::Lifetime { .. } => true,
_ => false,
}matches!(p.kind, GenericParamKind::Lifetime { .. }))
679 .map(|p| p.name.ident().name)
680 .find(|i| *i != kw::UnderscoreLifetime);
681 let introduce_new = suggestion_param_name.is_none();
682
683 let mut default = "'a".to_string();
684 if let Some(parent_generics) = parent_generics {
685 let used: FxHashSet<_> = parent_generics
686 .params
687 .iter()
688 .filter(|p| #[allow(non_exhaustive_omitted_patterns)] match p.kind {
GenericParamKind::Lifetime { .. } => true,
_ => false,
}matches!(p.kind, GenericParamKind::Lifetime { .. }))
689 .map(|p| p.name.ident().name)
690 .filter(|i| *i != kw::UnderscoreLifetime)
691 .map(|l| l.to_string())
692 .collect();
693 if let Some(lt) =
694 ('a'..='z').map(|it| ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("\'{0}", it))
})format!("'{it}")).find(|it| !used.contains(it))
695 {
696 default = lt;
701 }
702 }
703 let suggestion_param_name =
704 suggestion_param_name.map(|n| n.to_string()).unwrap_or_else(|| default);
705
706 struct ImplicitLifetimeFinder {
707 suggestions: Vec<(Span, String)>,
708 suggestion_param_name: String,
709 }
710
711 impl<'v> Visitor<'v> for ImplicitLifetimeFinder {
712 fn visit_ty(&mut self, ty: &'v hir::Ty<'v, AmbigArg>) {
713 match ty.kind {
714 hir::TyKind::Path(hir::QPath::Resolved(_, path)) => {
715 for segment in path.segments {
716 if let Some(args) = segment.args {
717 if args.args.iter().all(|arg| {
718 #[allow(non_exhaustive_omitted_patterns)] match arg {
hir::GenericArg::Lifetime(lifetime) if lifetime.is_implicit() => true,
_ => false,
}matches!(
719 arg,
720 hir::GenericArg::Lifetime(lifetime)
721 if lifetime.is_implicit()
722 )
723 }) {
724 self.suggestions.push((
725 segment.ident.span.shrink_to_hi(),
726 ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("<{0}>",
args.args.iter().map(|_|
self.suggestion_param_name.clone()).collect::<Vec<_>>().join(", ")))
})format!(
727 "<{}>",
728 args.args
729 .iter()
730 .map(|_| self.suggestion_param_name.clone())
731 .collect::<Vec<_>>()
732 .join(", ")
733 ),
734 ));
735 } else {
736 for arg in args.args {
737 if let hir::GenericArg::Lifetime(lifetime) = arg
738 && lifetime.is_anonymous()
739 {
740 self.suggestions.push(
741 lifetime
742 .suggestion(&self.suggestion_param_name),
743 );
744 }
745 }
746 }
747 }
748 }
749 }
750 hir::TyKind::Ref(lifetime, ..) if lifetime.is_anonymous() => {
751 self.suggestions.push(lifetime.suggestion(&self.suggestion_param_name));
752 }
753 _ => {}
754 }
755 walk_ty(self, ty);
756 }
757 }
758 let mut visitor = ImplicitLifetimeFinder {
759 suggestions: ::alloc::vec::Vec::new()vec![],
760 suggestion_param_name: suggestion_param_name.clone(),
761 };
762 if let Some(fn_decl) = node.fn_decl()
763 && let hir::FnRetTy::Return(ty) = fn_decl.output
764 {
765 visitor.visit_ty_unambig(ty);
766 }
767 if visitor.suggestions.is_empty() {
768 visitor.visit_ty_unambig(self.ty_sup);
773 }
774 visitor.visit_ty_unambig(self.ty_sub);
775 if visitor.suggestions.is_empty() {
776 return false;
777 }
778 if introduce_new {
779 let new_param_suggestion = if let Some(first) =
780 generics.params.iter().find(|p| !p.name.ident().span.is_empty())
781 {
782 (first.span.shrink_to_lo(), ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0}, ", suggestion_param_name))
})format!("{suggestion_param_name}, "))
783 } else {
784 (generics.span, ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("<{0}>", suggestion_param_name))
})format!("<{suggestion_param_name}>"))
785 };
786
787 visitor.suggestions.push(new_param_suggestion);
788 }
789 diag.multipart_suggestion_verbose(
790 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider {$is_reuse ->
[true] reusing
*[false] introducing
} a named lifetime parameter{$is_impl ->
[true] {\" \"}and update trait if needed
*[false] {\"\"}
}"))inline_fluent!(
791 "consider {$is_reuse ->
792[true] reusing
793*[false] introducing
794} a named lifetime parameter{$is_impl ->
795[true] {\" \"}and update trait if needed
796*[false] {\"\"}
797}"
798 ),
799 visitor.suggestions,
800 Applicability::MaybeIncorrect,
801 );
802 diag.arg("is_impl", is_impl);
803 diag.arg("is_reuse", !introduce_new);
804
805 true
806 };
807 if mk_suggestion() && self.add_note {
808 diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("each elided lifetime in input position becomes a distinct lifetime"))inline_fluent!(
809 "each elided lifetime in input position becomes a distinct lifetime"
810 ));
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"))inline_fluent!("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"))inline_fluent!("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.push_span_label(
1224 span,
1225 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider borrowing this type parameter in the trait"))inline_fluent!("consider borrowing this type parameter in the trait"),
1226 );
1227 }
1228 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`"))inline_fluent!("the lifetime requirements from the `impl` do not correspond to the requirements in the `trait`"));
1229 diag.span_help(type_param_span, msg);
1230 }
1231}
1232
1233#[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)]
1234#[diag("`impl` item signature doesn't match `trait` item signature")]
1235pub struct TraitImplDiff {
1236 #[primary_span]
1237 #[label("found `{$found}`")]
1238 pub sp: Span,
1239 #[label("expected `{$expected}`")]
1240 pub trait_sp: Span,
1241 #[note(
1242 "expected signature `{$expected}`
1243 {\" \"}found signature `{$found}`"
1244 )]
1245 pub note: (),
1246 #[subdiagnostic]
1247 pub param_help: ConsiderBorrowingParamHelp,
1248 #[help(
1249 "verify the lifetime relationships in the `trait` and `impl` between the `self` argument, the other inputs and its output"
1250 )]
1251 pub rel_help: bool,
1252 pub expected: String,
1253 pub found: String,
1254}
1255
1256pub struct DynTraitConstraintSuggestion {
1257 pub span: Span,
1258 pub ident: Ident,
1259}
1260
1261impl Subdiagnostic for DynTraitConstraintSuggestion {
1262 fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
1263 let mut multi_span: MultiSpan = <[_]>::into_vec(::alloc::boxed::box_new([self.span]))vec![self.span].into();
1264 multi_span.push_span_label(
1265 self.span,
1266 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this has an implicit `'static` lifetime requirement"))inline_fluent!("this has an implicit `'static` lifetime requirement"),
1267 );
1268 multi_span.push_span_label(
1269 self.ident.span,
1270 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("calling this method introduces the `impl`'s `'static` requirement"))inline_fluent!("calling this method introduces the `impl`'s `'static` requirement"),
1271 );
1272 let msg =
1273 diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the used `impl` has a `'static` requirement"))inline_fluent!("the used `impl` has a `'static` requirement"));
1274 diag.span_note(multi_span, msg);
1275 let msg = diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider relaxing the implicit `'static` requirement"))inline_fluent!(
1276 "consider relaxing the implicit `'static` requirement"
1277 ));
1278 diag.span_suggestion_verbose(
1279 self.span.shrink_to_hi(),
1280 msg,
1281 " + '_",
1282 Applicability::MaybeIncorrect,
1283 );
1284 }
1285}
1286
1287#[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)]
1288#[diag("{$has_param_name ->
1289 [true] `{$param_name}`
1290 *[false] `fn` parameter
1291} has {$lifetime_kind ->
1292 [true] lifetime `{$lifetime}`
1293 *[false] an anonymous lifetime `'_`
1294} but calling `{$assoc_item}` introduces an implicit `'static` lifetime requirement", code = E0772)]
1295pub struct ButCallingIntroduces {
1296 #[label(
1297 "{$has_lifetime ->
1298 [true] lifetime `{$lifetime}`
1299 *[false] an anonymous lifetime `'_`
1300 }"
1301 )]
1302 pub param_ty_span: Span,
1303 #[primary_span]
1304 #[label("...is used and required to live as long as `'static` here because of an implicit lifetime bound on the {$has_impl_path ->
1305 [true] `impl` of `{$impl_path}`
1306 *[false] inherent `impl`
1307 }")]
1308 pub cause_span: Span,
1309
1310 pub has_param_name: bool,
1311 pub param_name: String,
1312 pub has_lifetime: bool,
1313 pub lifetime: String,
1314 pub assoc_item: Symbol,
1315 pub has_impl_path: bool,
1316 pub impl_path: String,
1317}
1318
1319pub struct ReqIntroducedLocations {
1320 pub span: MultiSpan,
1321 pub spans: Vec<Span>,
1322 pub fn_decl_span: Span,
1323 pub cause_span: Span,
1324 pub add_label: bool,
1325}
1326
1327impl Subdiagnostic for ReqIntroducedLocations {
1328 fn add_to_diag<G: EmissionGuarantee>(mut self, diag: &mut Diag<'_, G>) {
1329 for sp in self.spans {
1330 self.span.push_span_label(sp, rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`'static` requirement introduced here"))inline_fluent!("`'static` requirement introduced here"));
1331 }
1332
1333 if self.add_label {
1334 self.span.push_span_label(
1335 self.fn_decl_span,
1336 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("requirement introduced by this return type"))inline_fluent!("requirement introduced by this return type"),
1337 );
1338 }
1339 self.span.push_span_label(
1340 self.cause_span,
1341 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("because of this returned expression"))inline_fluent!("because of this returned expression"),
1342 );
1343 let msg = diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("\"`'static` lifetime requirement introduced by the return type"))inline_fluent!(
1344 "\"`'static` lifetime requirement introduced by the return type"
1345 ));
1346 diag.span_note(self.span, msg);
1347 }
1348}
1349
1350#[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)]
1351#[diag("{$has_param_name ->
1352 [true] `{$param_name}`
1353 *[false] `fn` parameter
1354} has {$has_lifetime ->
1355 [true] lifetime `{$lifetime}`
1356 *[false] an anonymous lifetime `'_`
1357} but it needs to satisfy a `'static` lifetime requirement", code = E0759)]
1358pub struct ButNeedsToSatisfy {
1359 #[primary_span]
1360 pub sp: Span,
1361 #[label(
1362 "this data with {$has_lifetime ->
1363 [true] lifetime `{$lifetime}`
1364 *[false] an anonymous lifetime `'_`
1365 }..."
1366 )]
1367 pub influencer_point: Span,
1368 #[label("...is used here...")]
1369 pub spans: Vec<Span>,
1370 #[label(
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_label: Option<Span>,
1377 #[note(
1378 "{$spans_empty ->
1379 *[true] ...is used and required to live as long as `'static` here
1380 [false] ...and is required to live as long as `'static` here
1381 }"
1382 )]
1383 pub require_span_as_note: Option<Span>,
1384 #[note("`'static` lifetime requirement introduced by this bound")]
1385 pub bound: Option<Span>,
1386
1387 pub has_param_name: bool,
1388 pub param_name: String,
1389 pub spans_empty: bool,
1390 pub has_lifetime: bool,
1391 pub lifetime: String,
1392}
1393
1394#[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)]
1395#[diag("lifetime of reference outlives lifetime of borrowed content...", code = E0312)]
1396pub struct OutlivesContent<'a> {
1397 #[primary_span]
1398 pub span: Span,
1399 #[subdiagnostic]
1400 pub notes: Vec<note_and_explain::RegionExplanation<'a>>,
1401}
1402
1403#[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)]
1404#[diag("lifetime of the source pointer does not outlive lifetime bound of the object type", code = E0476)]
1405pub struct OutlivesBound<'a> {
1406 #[primary_span]
1407 pub span: Span,
1408 #[subdiagnostic]
1409 pub notes: Vec<note_and_explain::RegionExplanation<'a>>,
1410}
1411
1412#[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)]
1413#[diag("the type `{$ty}` does not fulfill the required lifetime", code = E0477)]
1414pub struct FulfillReqLifetime<'a> {
1415 #[primary_span]
1416 pub span: Span,
1417 pub ty: Ty<'a>,
1418 #[subdiagnostic]
1419 pub note: Option<note_and_explain::RegionExplanation<'a>>,
1420}
1421
1422#[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)]
1423#[diag("lifetime bound not satisfied", code = E0478)]
1424pub struct LfBoundNotSatisfied<'a> {
1425 #[primary_span]
1426 pub span: Span,
1427 #[subdiagnostic]
1428 pub notes: Vec<note_and_explain::RegionExplanation<'a>>,
1429}
1430
1431#[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)]
1432#[diag("in type `{$ty}`, reference has a longer lifetime than the data it references", code = E0491)]
1433pub struct RefLongerThanData<'a> {
1434 #[primary_span]
1435 pub span: Span,
1436 pub ty: Ty<'a>,
1437 #[subdiagnostic]
1438 pub notes: Vec<note_and_explain::RegionExplanation<'a>>,
1439}
1440
1441#[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)]
1442pub enum WhereClauseSuggestions {
1443 #[suggestion(
1444 "remove the `where` clause",
1445 code = "",
1446 applicability = "machine-applicable",
1447 style = "verbose"
1448 )]
1449 Remove {
1450 #[primary_span]
1451 span: Span,
1452 },
1453 #[suggestion(
1454 "copy the `where` clause predicates from the trait",
1455 code = "{space}where {trait_predicates}",
1456 applicability = "machine-applicable",
1457 style = "verbose"
1458 )]
1459 CopyPredicates {
1460 #[primary_span]
1461 span: Span,
1462 space: &'static str,
1463 trait_predicates: String,
1464 },
1465}
1466
1467#[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)]
1468pub enum SuggestRemoveSemiOrReturnBinding {
1469 #[multipart_suggestion(
1470 "consider removing this semicolon and boxing the expressions",
1471 applicability = "machine-applicable"
1472 )]
1473 RemoveAndBox {
1474 #[suggestion_part(code = "Box::new(")]
1475 first_lo: Span,
1476 #[suggestion_part(code = ")")]
1477 first_hi: Span,
1478 #[suggestion_part(code = "Box::new(")]
1479 second_lo: Span,
1480 #[suggestion_part(code = ")")]
1481 second_hi: Span,
1482 #[suggestion_part(code = "")]
1483 sp: Span,
1484 },
1485 #[suggestion(
1486 "consider removing this semicolon",
1487 style = "short",
1488 code = "",
1489 applicability = "machine-applicable"
1490 )]
1491 Remove {
1492 #[primary_span]
1493 sp: Span,
1494 },
1495 #[suggestion(
1496 "consider returning the local binding `{$ident}`",
1497 style = "verbose",
1498 code = "{code}",
1499 applicability = "maybe-incorrect"
1500 )]
1501 Add {
1502 #[primary_span]
1503 sp: Span,
1504 code: String,
1505 ident: Ident,
1506 },
1507 #[note("consider returning one of these bindings")]
1508 AddOne {
1509 #[primary_span]
1510 spans: MultiSpan,
1511 },
1512}
1513
1514#[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)]
1515pub enum ConsiderAddingAwait {
1516 #[help("consider `await`ing on both `Future`s")]
1517 BothFuturesHelp,
1518 #[multipart_suggestion(
1519 "consider `await`ing on both `Future`s",
1520 applicability = "maybe-incorrect"
1521 )]
1522 BothFuturesSugg {
1523 #[suggestion_part(code = ".await")]
1524 first: Span,
1525 #[suggestion_part(code = ".await")]
1526 second: Span,
1527 },
1528 #[suggestion(
1529 "consider `await`ing on the `Future`",
1530 code = ".await",
1531 style = "verbose",
1532 applicability = "maybe-incorrect"
1533 )]
1534 FutureSugg {
1535 #[primary_span]
1536 span: Span,
1537 },
1538 #[note("calling an async function returns a future")]
1539 FutureSuggNote {
1540 #[primary_span]
1541 span: Span,
1542 },
1543 #[multipart_suggestion(
1544 "consider `await`ing on the `Future`",
1545 style = "verbose",
1546 applicability = "maybe-incorrect"
1547 )]
1548 FutureSuggMultiple {
1549 #[suggestion_part(code = ".await")]
1550 spans: Vec<Span>,
1551 },
1552}
1553
1554#[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)]
1555pub enum PlaceholderRelationLfNotSatisfied {
1556 #[diag("lifetime bound not satisfied")]
1557 HasBoth {
1558 #[primary_span]
1559 span: Span,
1560 #[note("the lifetime `{$sub_symbol}` defined here...")]
1561 sub_span: Span,
1562 #[note("...must outlive the lifetime `{$sup_symbol}` defined here")]
1563 sup_span: Span,
1564 sub_symbol: Symbol,
1565 sup_symbol: Symbol,
1566 #[note(
1567 "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)"
1568 )]
1569 note: (),
1570 },
1571 #[diag("lifetime bound not satisfied")]
1572 HasSub {
1573 #[primary_span]
1574 span: Span,
1575 #[note("the lifetime `{$sub_symbol}` defined here...")]
1576 sub_span: Span,
1577 #[note("...must outlive the lifetime defined here")]
1578 sup_span: Span,
1579 sub_symbol: Symbol,
1580 #[note(
1581 "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)"
1582 )]
1583 note: (),
1584 },
1585 #[diag("lifetime bound not satisfied")]
1586 HasSup {
1587 #[primary_span]
1588 span: Span,
1589 #[note("the lifetime defined here...")]
1590 sub_span: Span,
1591 #[note("...must outlive the lifetime `{$sup_symbol}` defined here")]
1592 sup_span: Span,
1593 sup_symbol: Symbol,
1594 #[note(
1595 "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)"
1596 )]
1597 note: (),
1598 },
1599 #[diag("lifetime bound not satisfied")]
1600 HasNone {
1601 #[primary_span]
1602 span: Span,
1603 #[note("the lifetime defined here...")]
1604 sub_span: Span,
1605 #[note("...must outlive the lifetime defined here")]
1606 sup_span: Span,
1607 #[note(
1608 "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)"
1609 )]
1610 note: (),
1611 },
1612 #[diag("lifetime bound not satisfied")]
1613 OnlyPrimarySpan {
1614 #[primary_span]
1615 span: Span,
1616 #[note(
1617 "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)"
1618 )]
1619 note: (),
1620 },
1621}
1622
1623#[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)]
1624#[diag("hidden type for `{$opaque_ty}` captures lifetime that does not appear in bounds", code = E0700)]
1625pub struct OpaqueCapturesLifetime<'tcx> {
1626 #[primary_span]
1627 pub span: Span,
1628 #[label("opaque type defined here")]
1629 pub opaque_ty_span: Span,
1630 pub opaque_ty: Ty<'tcx>,
1631}
1632
1633#[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)]
1634pub enum FunctionPointerSuggestion<'a> {
1635 #[suggestion(
1636 "consider using a reference",
1637 code = "&",
1638 style = "verbose",
1639 applicability = "maybe-incorrect"
1640 )]
1641 UseRef {
1642 #[primary_span]
1643 span: Span,
1644 },
1645 #[suggestion(
1646 "consider removing the reference",
1647 code = "{fn_name}",
1648 style = "verbose",
1649 applicability = "maybe-incorrect"
1650 )]
1651 RemoveRef {
1652 #[primary_span]
1653 span: Span,
1654 #[skip_arg]
1655 fn_name: String,
1656 },
1657 #[suggestion(
1658 "consider casting to a fn pointer",
1659 code = "&({fn_name} as {sig})",
1660 style = "verbose",
1661 applicability = "maybe-incorrect"
1662 )]
1663 CastRef {
1664 #[primary_span]
1665 span: Span,
1666 #[skip_arg]
1667 fn_name: String,
1668 #[skip_arg]
1669 sig: Binder<'a, FnSig<'a>>,
1670 },
1671 #[suggestion(
1672 "consider casting to a fn pointer",
1673 code = " as {sig}",
1674 style = "verbose",
1675 applicability = "maybe-incorrect"
1676 )]
1677 Cast {
1678 #[primary_span]
1679 span: Span,
1680 #[skip_arg]
1681 sig: Binder<'a, FnSig<'a>>,
1682 },
1683 #[suggestion(
1684 "consider casting both fn items to fn pointers using `as {$expected_sig}`",
1685 code = " as {found_sig}",
1686 style = "hidden",
1687 applicability = "maybe-incorrect"
1688 )]
1689 CastBoth {
1690 #[primary_span]
1691 span: Span,
1692 #[skip_arg]
1693 found_sig: Binder<'a, FnSig<'a>>,
1694 expected_sig: Binder<'a, FnSig<'a>>,
1695 },
1696 #[suggestion(
1697 "consider casting both fn items to fn pointers using `as {$expected_sig}`",
1698 code = "&({fn_name} as {found_sig})",
1699 style = "hidden",
1700 applicability = "maybe-incorrect"
1701 )]
1702 CastBothRef {
1703 #[primary_span]
1704 span: Span,
1705 #[skip_arg]
1706 fn_name: String,
1707 #[skip_arg]
1708 found_sig: Binder<'a, FnSig<'a>>,
1709 expected_sig: Binder<'a, FnSig<'a>>,
1710 },
1711}
1712
1713#[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)]
1714#[note("fn items are distinct from fn pointers")]
1715pub struct FnItemsAreDistinct;
1716
1717#[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)]
1718#[note("different fn items have unique types, even if their signatures are the same")]
1719pub struct FnUniqTypes;
1720
1721#[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)]
1722#[help("consider casting the fn item to a fn pointer: `{$casting}`")]
1723pub struct FnConsiderCasting {
1724 pub casting: String,
1725}
1726
1727#[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)]
1728#[help("consider casting both fn items to fn pointers using `as {$sig}`")]
1729pub struct FnConsiderCastingBoth<'a> {
1730 pub sig: Binder<'a, FnSig<'a>>,
1731}
1732
1733#[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)]
1734pub enum SuggestAccessingField<'a> {
1735 #[suggestion(
1736 "you might have meant to use field `{$name}` whose type is `{$ty}`",
1737 code = "{snippet}.{name}",
1738 applicability = "maybe-incorrect",
1739 style = "verbose"
1740 )]
1741 Safe {
1742 #[primary_span]
1743 span: Span,
1744 snippet: String,
1745 name: Symbol,
1746 ty: Ty<'a>,
1747 },
1748 #[suggestion(
1749 "you might have meant to use field `{$name}` whose type is `{$ty}`",
1750 code = "unsafe {{ {snippet}.{name} }}",
1751 applicability = "maybe-incorrect",
1752 style = "verbose"
1753 )]
1754 Unsafe {
1755 #[primary_span]
1756 span: Span,
1757 snippet: String,
1758 name: Symbol,
1759 ty: Ty<'a>,
1760 },
1761}
1762
1763#[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)]
1764#[multipart_suggestion(
1765 "try wrapping the pattern in `{$variant}`",
1766 applicability = "maybe-incorrect"
1767)]
1768pub struct SuggestTuplePatternOne {
1769 pub variant: String,
1770 #[suggestion_part(code = "{variant}(")]
1771 pub span_low: Span,
1772 #[suggestion_part(code = ")")]
1773 pub span_high: Span,
1774}
1775
1776pub struct SuggestTuplePatternMany {
1777 pub path: String,
1778 pub cause_span: Span,
1779 pub compatible_variants: Vec<String>,
1780}
1781
1782impl Subdiagnostic for SuggestTuplePatternMany {
1783 fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
1784 diag.arg("path", self.path);
1785 let message = diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("try wrapping the pattern in a variant of `{$path}`"))inline_fluent!(
1786 "try wrapping the pattern in a variant of `{$path}`"
1787 ));
1788 diag.multipart_suggestions(
1789 message,
1790 self.compatible_variants.into_iter().map(|variant| {
1791 <[_]>::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![
1792 (self.cause_span.shrink_to_lo(), format!("{variant}(")),
1793 (self.cause_span.shrink_to_hi(), ")".to_string()),
1794 ]
1795 }),
1796 rustc_errors::Applicability::MaybeIncorrect,
1797 );
1798 }
1799}
1800
1801#[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)]
1802pub enum TypeErrorAdditionalDiags {
1803 #[suggestion(
1804 "if you meant to write a byte literal, prefix with `b`",
1805 code = "b'{code}'",
1806 applicability = "machine-applicable"
1807 )]
1808 MeantByteLiteral {
1809 #[primary_span]
1810 span: Span,
1811 code: String,
1812 },
1813 #[suggestion(
1814 "if you meant to write a `char` literal, use single quotes",
1815 code = "'{code}'",
1816 applicability = "machine-applicable"
1817 )]
1818 MeantCharLiteral {
1819 #[primary_span]
1820 span: Span,
1821 code: String,
1822 },
1823 #[multipart_suggestion(
1824 "if you meant to write a string literal, use double quotes",
1825 applicability = "machine-applicable"
1826 )]
1827 MeantStrLiteral {
1828 #[suggestion_part(code = "\"")]
1829 start: Span,
1830 #[suggestion_part(code = "\"")]
1831 end: Span,
1832 },
1833 #[suggestion(
1834 "consider specifying the actual array length",
1835 code = "{length}",
1836 applicability = "maybe-incorrect"
1837 )]
1838 ConsiderSpecifyingLength {
1839 #[primary_span]
1840 span: Span,
1841 length: u64,
1842 },
1843 #[note("`?` operator cannot convert from `{$found}` to `{$expected}`")]
1844 TryCannotConvert { found: String, expected: String },
1845 #[suggestion(
1846 "use a trailing comma to create a tuple with one element",
1847 code = ",",
1848 applicability = "machine-applicable"
1849 )]
1850 TupleOnlyComma {
1851 #[primary_span]
1852 span: Span,
1853 },
1854 #[multipart_suggestion(
1855 "use a trailing comma to create a tuple with one element",
1856 applicability = "machine-applicable"
1857 )]
1858 TupleAlsoParentheses {
1859 #[suggestion_part(code = "(")]
1860 span_low: Span,
1861 #[suggestion_part(code = ",)")]
1862 span_high: Span,
1863 },
1864 #[suggestion(
1865 "consider adding `let`",
1866 style = "verbose",
1867 applicability = "machine-applicable",
1868 code = "let "
1869 )]
1870 AddLetForLetChains {
1871 #[primary_span]
1872 span: Span,
1873 },
1874}
1875
1876#[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)]
1877pub enum ObligationCauseFailureCode {
1878 #[diag("method not compatible with trait", code = E0308)]
1879 MethodCompat {
1880 #[primary_span]
1881 span: Span,
1882 #[subdiagnostic]
1883 subdiags: Vec<TypeErrorAdditionalDiags>,
1884 },
1885 #[diag("type not compatible with trait", code = E0308)]
1886 TypeCompat {
1887 #[primary_span]
1888 span: Span,
1889 #[subdiagnostic]
1890 subdiags: Vec<TypeErrorAdditionalDiags>,
1891 },
1892 #[diag("const not compatible with trait", code = E0308)]
1893 ConstCompat {
1894 #[primary_span]
1895 span: Span,
1896 #[subdiagnostic]
1897 subdiags: Vec<TypeErrorAdditionalDiags>,
1898 },
1899 #[diag("`?` operator has incompatible types", code = E0308)]
1900 TryCompat {
1901 #[primary_span]
1902 span: Span,
1903 #[subdiagnostic]
1904 subdiags: Vec<TypeErrorAdditionalDiags>,
1905 },
1906 #[diag("`match` arms have incompatible types", code = E0308)]
1907 MatchCompat {
1908 #[primary_span]
1909 span: Span,
1910 #[subdiagnostic]
1911 subdiags: Vec<TypeErrorAdditionalDiags>,
1912 },
1913 #[diag("`if` and `else` have incompatible types", code = E0308)]
1914 IfElseDifferent {
1915 #[primary_span]
1916 span: Span,
1917 #[subdiagnostic]
1918 subdiags: Vec<TypeErrorAdditionalDiags>,
1919 },
1920 #[diag("`if` may be missing an `else` clause", code = E0317)]
1921 NoElse {
1922 #[primary_span]
1923 span: Span,
1924 },
1925 #[diag("`else` clause of `let...else` does not diverge", code = E0308)]
1926 NoDiverge {
1927 #[primary_span]
1928 span: Span,
1929 #[subdiagnostic]
1930 subdiags: Vec<TypeErrorAdditionalDiags>,
1931 },
1932 #[diag("`main` function has wrong type", code = E0580)]
1933 FnMainCorrectType {
1934 #[primary_span]
1935 span: Span,
1936 },
1937 #[diag(
1938 "{$lang_item_name ->
1939 [panic_impl] `#[panic_handler]`
1940 *[lang_item_name] lang item `{$lang_item_name}`
1941 } function has wrong type"
1942 , code = E0308)]
1943 FnLangCorrectType {
1944 #[primary_span]
1945 span: Span,
1946 #[subdiagnostic]
1947 subdiags: Vec<TypeErrorAdditionalDiags>,
1948 lang_item_name: Symbol,
1949 },
1950 #[diag("intrinsic has wrong type", code = E0308)]
1951 IntrinsicCorrectType {
1952 #[primary_span]
1953 span: Span,
1954 #[subdiagnostic]
1955 subdiags: Vec<TypeErrorAdditionalDiags>,
1956 },
1957 #[diag("mismatched `self` parameter type", code = E0308)]
1958 MethodCorrectType {
1959 #[primary_span]
1960 span: Span,
1961 #[subdiagnostic]
1962 subdiags: Vec<TypeErrorAdditionalDiags>,
1963 },
1964 #[diag("closure/coroutine type that references itself", code = E0644)]
1965 ClosureSelfref {
1966 #[primary_span]
1967 span: Span,
1968 },
1969 #[diag("cannot coerce functions which must be inlined to function pointers", code = E0308)]
1970 CantCoerceForceInline {
1971 #[primary_span]
1972 span: Span,
1973 #[subdiagnostic]
1974 subdiags: Vec<TypeErrorAdditionalDiags>,
1975 },
1976 #[diag("cannot coerce intrinsics to function pointers", code = E0308)]
1977 CantCoerceIntrinsic {
1978 #[primary_span]
1979 span: Span,
1980 #[subdiagnostic]
1981 subdiags: Vec<TypeErrorAdditionalDiags>,
1982 },
1983 #[diag("mismatched types", code = E0308)]
1984 Generic {
1985 #[primary_span]
1986 span: Span,
1987 #[subdiagnostic]
1988 subdiags: Vec<TypeErrorAdditionalDiags>,
1989 },
1990}
1991
1992#[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)]
1993pub enum AddPreciseCapturing {
1994 #[suggestion(
1995 "add a `use<...>` bound to explicitly capture `{$new_lifetime}`",
1996 style = "verbose",
1997 code = " + use<{concatenated_bounds}>",
1998 applicability = "machine-applicable"
1999 )]
2000 New {
2001 #[primary_span]
2002 span: Span,
2003 new_lifetime: Symbol,
2004 concatenated_bounds: String,
2005 },
2006 #[suggestion(
2007 "add `{$new_lifetime}` to the `use<...>` bound to explicitly capture it",
2008 style = "verbose",
2009 code = "{pre}{new_lifetime}{post}",
2010 applicability = "machine-applicable"
2011 )]
2012 Existing {
2013 #[primary_span]
2014 span: Span,
2015 new_lifetime: Symbol,
2016 pre: &'static str,
2017 post: &'static str,
2018 },
2019}
2020
2021pub struct AddPreciseCapturingAndParams {
2022 pub suggs: Vec<(Span, String)>,
2023 pub new_lifetime: Symbol,
2024 pub apit_spans: Vec<Span>,
2025}
2026
2027impl Subdiagnostic for AddPreciseCapturingAndParams {
2028 fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
2029 diag.arg("new_lifetime", self.new_lifetime);
2030 diag.multipart_suggestion_verbose(
2031 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"))inline_fluent!("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"),
2032 self.suggs,
2033 Applicability::MaybeIncorrect,
2034 );
2035 diag.span_note(
2036 self.apit_spans,
2037 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"))inline_fluent!("you could use a `use<...>` bound to explicitly capture `{$new_lifetime}`, but argument-position `impl Trait`s are not nameable"),
2038 );
2039 }
2040}
2041
2042pub fn impl_trait_overcapture_suggestion<'tcx>(
2047 tcx: TyCtxt<'tcx>,
2048 opaque_def_id: LocalDefId,
2049 fn_def_id: LocalDefId,
2050 captured_args: FxIndexSet<DefId>,
2051) -> Option<AddPreciseCapturingForOvercapture> {
2052 let generics = tcx.generics_of(fn_def_id);
2053
2054 let mut captured_lifetimes = FxIndexSet::default();
2055 let mut captured_non_lifetimes = FxIndexSet::default();
2056 let mut synthetics = ::alloc::vec::Vec::new()vec![];
2057
2058 for arg in captured_args {
2059 if tcx.def_kind(arg) == DefKind::LifetimeParam {
2060 captured_lifetimes.insert(tcx.item_name(arg));
2061 } else {
2062 let idx = generics.param_def_id_to_index(tcx, arg).expect("expected arg in scope");
2063 let param = generics.param_at(idx as usize, tcx);
2064 if param.kind.is_synthetic() {
2065 synthetics.push((tcx.def_span(arg), param.name));
2066 } else {
2067 captured_non_lifetimes.insert(tcx.item_name(arg));
2068 }
2069 }
2070 }
2071
2072 let mut next_fresh_param = || {
2073 ["T", "U", "V", "W", "X", "Y", "A", "B", "C"]
2074 .into_iter()
2075 .map(Symbol::intern)
2076 .chain((0..).map(|i| Symbol::intern(&::alloc::__export::must_use({ ::alloc::fmt::format(format_args!("T{0}", i)) })format!("T{i}"))))
2077 .find(|s| captured_non_lifetimes.insert(*s))
2078 .unwrap()
2079 };
2080
2081 let mut suggs = ::alloc::vec::Vec::new()vec![];
2082 let mut apit_spans = ::alloc::vec::Vec::new()vec![];
2083
2084 if !synthetics.is_empty() {
2085 let mut new_params = String::new();
2086 for (i, (span, name)) in synthetics.into_iter().enumerate() {
2087 apit_spans.push(span);
2088
2089 let fresh_param = next_fresh_param();
2090
2091 suggs.push((span, fresh_param.to_string()));
2093
2094 if i > 0 {
2102 new_params += ", ";
2103 }
2104 let name_as_bounds = name.as_str().trim_start_matches("impl").trim_start();
2105 new_params += fresh_param.as_str();
2106 new_params += ": ";
2107 new_params += name_as_bounds;
2108 }
2109
2110 let Some(generics) = tcx.hir_get_generics(fn_def_id) else {
2111 return None;
2113 };
2114
2115 suggs.push(if let Some(params_span) = generics.span_for_param_suggestion() {
2117 (params_span, ::alloc::__export::must_use({
::alloc::fmt::format(format_args!(", {0}", new_params))
})format!(", {new_params}"))
2118 } else {
2119 (generics.span, ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("<{0}>", new_params))
})format!("<{new_params}>"))
2120 });
2121 }
2122
2123 let concatenated_bounds = captured_lifetimes
2124 .into_iter()
2125 .chain(captured_non_lifetimes)
2126 .map(|sym| sym.to_string())
2127 .collect::<Vec<_>>()
2128 .join(", ");
2129
2130 let opaque_hir_id = tcx.local_def_id_to_hir_id(opaque_def_id);
2131 let (lparen, rparen) = match tcx
2133 .hir_parent_iter(opaque_hir_id)
2134 .nth(1)
2135 .expect("expected ty to have a parent always")
2136 .1
2137 {
2138 Node::PathSegment(segment)
2139 if segment.args().paren_sugar_output().is_some_and(|ty| ty.hir_id == opaque_hir_id) =>
2140 {
2141 ("(", ")")
2142 }
2143 Node::Ty(ty) => match ty.kind {
2144 rustc_hir::TyKind::Ptr(_) | rustc_hir::TyKind::Ref(..) => ("(", ")"),
2145 _ => ("", ""),
2149 },
2150 _ => ("", ""),
2151 };
2152
2153 let rpit_span = tcx.def_span(opaque_def_id);
2154 if !lparen.is_empty() {
2155 suggs.push((rpit_span.shrink_to_lo(), lparen.to_string()));
2156 }
2157 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}")));
2158
2159 Some(AddPreciseCapturingForOvercapture { suggs, apit_spans })
2160}
2161
2162pub struct AddPreciseCapturingForOvercapture {
2163 pub suggs: Vec<(Span, String)>,
2164 pub apit_spans: Vec<Span>,
2165}
2166
2167impl Subdiagnostic for AddPreciseCapturingForOvercapture {
2168 fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
2169 let applicability = if self.apit_spans.is_empty() {
2170 Applicability::MachineApplicable
2171 } else {
2172 Applicability::MaybeIncorrect
2176 };
2177 diag.multipart_suggestion_verbose(
2178 rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("use the precise capturing `use<...>` syntax to make the captures explicit"))inline_fluent!(
2179 "use the precise capturing `use<...>` syntax to make the captures explicit"
2180 ),
2181 self.suggs,
2182 applicability,
2183 );
2184 if !self.apit_spans.is_empty() {
2185 diag.span_note(
2186 self.apit_spans,
2187 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"))inline_fluent!("you could use a `use<...>` bound to explicitly specify captures, but argument-position `impl Trait`s are not nameable"),
2188 );
2189 }
2190 }
2191}
2192
2193#[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)]
2194#[diag("expected generic {$kind} parameter, found `{$arg}`", code = E0792)]
2195pub(crate) struct NonGenericOpaqueTypeParam<'a, 'tcx> {
2196 pub arg: GenericArg<'tcx>,
2197 pub kind: &'a str,
2198 #[primary_span]
2199 pub span: Span,
2200 #[label("{STREQ($arg, \"'static\") ->
2201 [true] cannot use static lifetime; use a bound lifetime instead or remove the lifetime parameter from the opaque type
2202 *[other] this generic parameter must be used with a generic {$kind} parameter
2203 }")]
2204 pub param_span: Span,
2205}