Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 9f84345

Browse files
authoredJun 1, 2022
Rollup merge of rust-lang#97023 - cjgillot:uniform-anon, r=estebank
Diagnose anonymous lifetimes errors more uniformly between async and regular fns Async fns and regular fns are desugared differently. For the former, we create a generic parameter at HIR level. For the latter, we just create an anonymous region for typeck. I plan to migrate regular fns to the async fn desugaring. Before that, this PR attempts to merge the diagnostics for both cases. r? `@estebank`
2 parents 5f5a27f + 0cf79d7 commit 9f84345

33 files changed

+620
-194
lines changed
 

‎compiler/rustc_borrowck/src/diagnostics/region_name.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -567,15 +567,17 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
567567
let lifetime =
568568
self.try_match_adt_and_generic_args(substs, needle_fr, args, search_stack)?;
569569
match lifetime.name {
570-
hir::LifetimeName::Param(_)
570+
hir::LifetimeName::Param(hir::ParamName::Plain(_) | hir::ParamName::Error)
571571
| hir::LifetimeName::Error
572-
| hir::LifetimeName::Static
573-
| hir::LifetimeName::Underscore => {
572+
| hir::LifetimeName::Static => {
574573
let lifetime_span = lifetime.span;
575574
Some(RegionNameHighlight::MatchedAdtAndSegment(lifetime_span))
576575
}
577576

578-
hir::LifetimeName::ImplicitObjectLifetimeDefault | hir::LifetimeName::Implicit => {
577+
hir::LifetimeName::Param(hir::ParamName::Fresh(_))
578+
| hir::LifetimeName::ImplicitObjectLifetimeDefault
579+
| hir::LifetimeName::Implicit
580+
| hir::LifetimeName::Underscore => {
579581
// In this case, the user left off the lifetime; so
580582
// they wrote something like:
581583
//

‎compiler/rustc_hir/src/hir.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,17 @@ impl LifetimeName {
131131
}
132132
}
133133

134+
pub fn is_anonymous(&self) -> bool {
135+
match *self {
136+
LifetimeName::ImplicitObjectLifetimeDefault
137+
| LifetimeName::Implicit
138+
| LifetimeName::Underscore
139+
| LifetimeName::Param(ParamName::Fresh(_))
140+
| LifetimeName::Error => true,
141+
LifetimeName::Static | LifetimeName::Param(_) => false,
142+
}
143+
}
144+
134145
pub fn is_elided(&self) -> bool {
135146
match self {
136147
LifetimeName::ImplicitObjectLifetimeDefault

‎compiler/rustc_infer/src/infer/error_reporting/mod.rs

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ use rustc_middle::ty::{
7272
subst::{GenericArgKind, Subst, SubstsRef},
7373
Binder, EarlyBinder, List, Region, Ty, TyCtxt, TypeFoldable,
7474
};
75-
use rustc_span::{sym, BytePos, DesugaringKind, Pos, Span};
75+
use rustc_span::{sym, symbol::kw, BytePos, DesugaringKind, Pos, Span};
7676
use rustc_target::spec::abi;
7777
use std::ops::ControlFlow;
7878
use std::{cmp, fmt, iter};
@@ -161,35 +161,45 @@ fn msg_span_from_early_bound_and_free_regions<'tcx>(
161161
{
162162
sp = param.span;
163163
}
164-
(format!("the lifetime `{}` as defined here", br.name), sp)
164+
let text = if br.has_name() {
165+
format!("the lifetime `{}` as defined here", br.name)
166+
} else {
167+
format!("the anonymous lifetime as defined here")
168+
};
169+
(text, sp)
165170
}
166-
ty::ReFree(ty::FreeRegion {
167-
bound_region: ty::BoundRegionKind::BrNamed(_, name), ..
168-
}) => {
169-
let mut sp = sm.guess_head_span(tcx.def_span(scope));
170-
if let Some(param) =
171-
tcx.hir().get_generics(scope).and_then(|generics| generics.get_named(name))
171+
ty::ReFree(ref fr) => {
172+
if !fr.bound_region.is_named()
173+
&& let Some((ty, _)) = find_anon_type(tcx, region, &fr.bound_region)
172174
{
173-
sp = param.span;
174-
}
175-
(format!("the lifetime `{}` as defined here", name), sp)
176-
}
177-
ty::ReFree(ref fr) => match fr.bound_region {
178-
ty::BrAnon(idx) => {
179-
if let Some((ty, _)) = find_anon_type(tcx, region, &fr.bound_region) {
180-
("the anonymous lifetime defined here".to_string(), ty.span)
181-
} else {
182-
(
175+
("the anonymous lifetime defined here".to_string(), ty.span)
176+
} else {
177+
match fr.bound_region {
178+
ty::BoundRegionKind::BrNamed(_, name) => {
179+
let mut sp = sm.guess_head_span(tcx.def_span(scope));
180+
if let Some(param) =
181+
tcx.hir().get_generics(scope).and_then(|generics| generics.get_named(name))
182+
{
183+
sp = param.span;
184+
}
185+
let text = if name == kw::UnderscoreLifetime {
186+
format!("the anonymous lifetime as defined here")
187+
} else {
188+
format!("the lifetime `{}` as defined here", name)
189+
};
190+
(text, sp)
191+
}
192+
ty::BrAnon(idx) => (
183193
format!("the anonymous lifetime #{} defined here", idx + 1),
184-
tcx.def_span(scope),
185-
)
194+
tcx.def_span(scope)
195+
),
196+
_ => (
197+
format!("the lifetime `{}` as defined here", region),
198+
sm.guess_head_span(tcx.def_span(scope)),
199+
),
186200
}
187201
}
188-
_ => (
189-
format!("the lifetime `{}` as defined here", region),
190-
sm.guess_head_span(tcx.def_span(scope)),
191-
),
192-
},
202+
}
193203
_ => bug!(),
194204
}
195205
}
@@ -2552,7 +2562,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
25522562
ty::ReEarlyBound(ty::EarlyBoundRegion { name, .. })
25532563
| ty::ReFree(ty::FreeRegion { bound_region: ty::BrNamed(_, name), .. }),
25542564
_,
2555-
) => {
2565+
) if name != kw::UnderscoreLifetime => {
25562566
// Does the required lifetime have a nice name we can print?
25572567
let mut err = struct_span_err!(
25582568
self.tcx.sess,

‎compiler/rustc_infer/src/infer/error_reporting/nice_region_error/different_lifetimes.rs

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use rustc_errors::{struct_span_err, Applicability, Diagnostic, ErrorGuaranteed};
1212
use rustc_hir as hir;
1313
use rustc_hir::{GenericParamKind, Ty};
1414
use rustc_middle::ty::Region;
15+
use rustc_span::symbol::kw;
1516

1617
impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
1718
/// Print the error message for lifetime errors when both the concerned regions are anonymous.
@@ -169,7 +170,7 @@ pub fn suggest_adding_lifetime_params<'tcx>(
169170
return false;
170171
};
171172

172-
if !lifetime_sub.name.is_elided() || !lifetime_sup.name.is_elided() {
173+
if !lifetime_sub.name.is_anonymous() || !lifetime_sup.name.is_anonymous() {
173174
return false;
174175
};
175176

@@ -188,32 +189,37 @@ pub fn suggest_adding_lifetime_params<'tcx>(
188189
_ => return false,
189190
};
190191

191-
let (suggestion_param_name, introduce_new) = generics
192+
let suggestion_param_name = generics
192193
.params
193194
.iter()
194-
.find(|p| matches!(p.kind, GenericParamKind::Lifetime { .. }))
195-
.and_then(|p| tcx.sess.source_map().span_to_snippet(p.span).ok())
196-
.map(|name| (name, false))
197-
.unwrap_or_else(|| ("'a".to_string(), true));
198-
199-
let mut suggestions = vec![
200-
if let hir::LifetimeName::Underscore = lifetime_sub.name {
201-
(lifetime_sub.span, suggestion_param_name.clone())
195+
.filter(|p| matches!(p.kind, GenericParamKind::Lifetime { .. }))
196+
.map(|p| p.name.ident().name)
197+
.find(|i| *i != kw::UnderscoreLifetime);
198+
let introduce_new = suggestion_param_name.is_none();
199+
let suggestion_param_name =
200+
suggestion_param_name.map(|n| n.to_string()).unwrap_or_else(|| "'a".to_owned());
201+
202+
debug!(?lifetime_sup.span);
203+
debug!(?lifetime_sub.span);
204+
let make_suggestion = |span: rustc_span::Span| {
205+
if span.is_empty() {
206+
(span, format!("{}, ", suggestion_param_name))
207+
} else if let Ok("&") = tcx.sess.source_map().span_to_snippet(span).as_deref() {
208+
(span.shrink_to_hi(), format!("{} ", suggestion_param_name))
202209
} else {
203-
(lifetime_sub.span.shrink_to_hi(), suggestion_param_name.clone() + " ")
204-
},
205-
if let hir::LifetimeName::Underscore = lifetime_sup.name {
206-
(lifetime_sup.span, suggestion_param_name.clone())
207-
} else {
208-
(lifetime_sup.span.shrink_to_hi(), suggestion_param_name.clone() + " ")
209-
},
210-
];
210+
(span, suggestion_param_name.clone())
211+
}
212+
};
213+
let mut suggestions =
214+
vec![make_suggestion(lifetime_sub.span), make_suggestion(lifetime_sup.span)];
211215

212216
if introduce_new {
213-
let new_param_suggestion = match &generics.params {
214-
[] => (generics.span, format!("<{}>", suggestion_param_name)),
215-
[first, ..] => (first.span.shrink_to_lo(), format!("{}, ", suggestion_param_name)),
216-
};
217+
let new_param_suggestion =
218+
if let Some(first) = generics.params.iter().find(|p| !p.name.ident().span.is_empty()) {
219+
(first.span.shrink_to_lo(), format!("{}, ", suggestion_param_name))
220+
} else {
221+
(generics.span, format!("<{}>", suggestion_param_name))
222+
};
217223

218224
suggestions.push(new_param_suggestion);
219225
}

‎compiler/rustc_infer/src/infer/error_reporting/nice_region_error/named_anon_conflict.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use crate::infer::error_reporting::nice_region_error::find_anon_type::find_anon_
44
use crate::infer::error_reporting::nice_region_error::NiceRegionError;
55
use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder, ErrorGuaranteed};
66
use rustc_middle::ty;
7+
use rustc_span::symbol::kw;
78

89
impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
910
/// When given a `ConcreteFailure` for a function with parameters containing a named region and
@@ -67,7 +68,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
6768
let is_impl_item = region_info.is_impl_item;
6869

6970
match br {
70-
ty::BrAnon(_) => {}
71+
ty::BrNamed(_, kw::UnderscoreLifetime) | ty::BrAnon(_) => {}
7172
_ => {
7273
/* not an anonymous region */
7374
debug!("try_report_named_anon_conflict: not an anonymous region");

‎compiler/rustc_middle/src/ty/print/pretty.rs

Lines changed: 28 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2177,61 +2177,47 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
21772177
define_scoped_cx!(self);
21782178

21792179
let mut region_index = self.region_index;
2180+
let mut next_name = |this: &Self| loop {
2181+
let name = name_by_region_index(region_index);
2182+
region_index += 1;
2183+
if !this.used_region_names.contains(&name) {
2184+
break name;
2185+
}
2186+
};
2187+
21802188
// If we want to print verbosely, then print *all* binders, even if they
21812189
// aren't named. Eventually, we might just want this as the default, but
21822190
// this is not *quite* right and changes the ordering of some output
21832191
// anyways.
21842192
let (new_value, map) = if self.tcx().sess.verbose() {
21852193
// anon index + 1 (BrEnv takes 0) -> name
2186-
let mut region_map: BTreeMap<u32, Symbol> = BTreeMap::default();
2194+
let mut region_map: FxHashMap<_, _> = Default::default();
21872195
let bound_vars = value.bound_vars();
21882196
for var in bound_vars {
2197+
let ty::BoundVariableKind::Region(var) = var else { continue };
21892198
match var {
2190-
ty::BoundVariableKind::Region(ty::BrNamed(_, name)) => {
2199+
ty::BrAnon(_) | ty::BrEnv => {
21912200
start_or_continue(&mut self, "for<", ", ");
2201+
let name = next_name(&self);
21922202
do_continue(&mut self, name);
2203+
region_map.insert(var, ty::BrNamed(CRATE_DEF_ID.to_def_id(), name));
21932204
}
2194-
ty::BoundVariableKind::Region(ty::BrAnon(i)) => {
2205+
ty::BrNamed(def_id, kw::UnderscoreLifetime) => {
21952206
start_or_continue(&mut self, "for<", ", ");
2196-
let name = loop {
2197-
let name = name_by_region_index(region_index);
2198-
region_index += 1;
2199-
if !self.used_region_names.contains(&name) {
2200-
break name;
2201-
}
2202-
};
2207+
let name = next_name(&self);
22032208
do_continue(&mut self, name);
2204-
region_map.insert(i + 1, name);
2209+
region_map.insert(var, ty::BrNamed(def_id, name));
22052210
}
2206-
ty::BoundVariableKind::Region(ty::BrEnv) => {
2211+
ty::BrNamed(_, name) => {
22072212
start_or_continue(&mut self, "for<", ", ");
2208-
let name = loop {
2209-
let name = name_by_region_index(region_index);
2210-
region_index += 1;
2211-
if !self.used_region_names.contains(&name) {
2212-
break name;
2213-
}
2214-
};
22152213
do_continue(&mut self, name);
2216-
region_map.insert(0, name);
22172214
}
2218-
_ => continue,
22192215
}
22202216
}
22212217
start_or_continue(&mut self, "", "> ");
22222218

22232219
self.tcx.replace_late_bound_regions(value.clone(), |br| {
2224-
let kind = match br.kind {
2225-
ty::BrNamed(_, _) => br.kind,
2226-
ty::BrAnon(i) => {
2227-
let name = region_map[&(i + 1)];
2228-
ty::BrNamed(CRATE_DEF_ID.to_def_id(), name)
2229-
}
2230-
ty::BrEnv => {
2231-
let name = region_map[&0];
2232-
ty::BrNamed(CRATE_DEF_ID.to_def_id(), name)
2233-
}
2234-
};
2220+
let kind = region_map[&br.kind];
22352221
self.tcx.mk_region(ty::ReLateBound(
22362222
ty::INNERMOST,
22372223
ty::BoundRegion { var: br.var, kind },
@@ -2242,21 +2228,20 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
22422228
let mut name = |br: ty::BoundRegion| {
22432229
start_or_continue(&mut self, "for<", ", ");
22442230
let kind = match br.kind {
2245-
ty::BrNamed(_, name) => {
2246-
do_continue(&mut self, name);
2247-
br.kind
2248-
}
22492231
ty::BrAnon(_) | ty::BrEnv => {
2250-
let name = loop {
2251-
let name = name_by_region_index(region_index);
2252-
region_index += 1;
2253-
if !self.used_region_names.contains(&name) {
2254-
break name;
2255-
}
2256-
};
2232+
let name = next_name(&self);
22572233
do_continue(&mut self, name);
22582234
ty::BrNamed(CRATE_DEF_ID.to_def_id(), name)
22592235
}
2236+
ty::BrNamed(def_id, kw::UnderscoreLifetime) => {
2237+
let name = next_name(&self);
2238+
do_continue(&mut self, name);
2239+
ty::BrNamed(def_id, name)
2240+
}
2241+
ty::BrNamed(_, name) => {
2242+
do_continue(&mut self, name);
2243+
br.kind
2244+
}
22602245
};
22612246
tcx.mk_region(ty::ReLateBound(ty::INNERMOST, ty::BoundRegion { var: br.var, kind }))
22622247
};

‎compiler/rustc_typeck/src/check/check.rs

Lines changed: 107 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ use super::*;
88
use rustc_attr as attr;
99
use rustc_errors::{Applicability, ErrorGuaranteed, MultiSpan};
1010
use rustc_hir as hir;
11+
use rustc_hir::def::{DefKind, Res};
1112
use rustc_hir::def_id::{DefId, LocalDefId};
1213
use rustc_hir::intravisit::Visitor;
1314
use rustc_hir::lang_items::LangItem;
14-
use rustc_hir::{def::Res, ItemKind, Node, PathSegment};
15+
use rustc_hir::{ItemKind, Node, PathSegment};
1516
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
1617
use rustc_infer::infer::{RegionVariableOrigin, TyCtxtInferExt};
1718
use rustc_infer::traits::Obligation;
@@ -29,7 +30,6 @@ use rustc_trait_selection::traits;
2930
use rustc_trait_selection::traits::error_reporting::InferCtxtExt as _;
3031
use rustc_ty_utils::representability::{self, Representability};
3132

32-
use rustc_hir::def::DefKind;
3333
use std::iter;
3434
use std::ops::ControlFlow;
3535

@@ -93,7 +93,6 @@ pub(super) fn check_fn<'a, 'tcx>(
9393
fcx.return_type_pre_known = return_type_pre_known;
9494

9595
let tcx = fcx.tcx;
96-
let sess = tcx.sess;
9796
let hir = tcx.hir();
9897

9998
let declared_ret_ty = fn_sig.output();
@@ -259,85 +258,123 @@ pub(super) fn check_fn<'a, 'tcx>(
259258
if let Some(panic_impl_did) = tcx.lang_items().panic_impl()
260259
&& panic_impl_did == hir.local_def_id(fn_id).to_def_id()
261260
{
262-
if let Some(panic_info_did) = tcx.lang_items().panic_info() {
263-
if *declared_ret_ty.kind() != ty::Never {
264-
sess.span_err(decl.output.span(), "return type should be `!`");
265-
}
266-
267-
let inputs = fn_sig.inputs();
268-
let span = hir.span(fn_id);
269-
if inputs.len() == 1 {
270-
let arg_is_panic_info = match *inputs[0].kind() {
271-
ty::Ref(region, ty, mutbl) => match *ty.kind() {
272-
ty::Adt(ref adt, _) => {
273-
adt.did() == panic_info_did
274-
&& mutbl == hir::Mutability::Not
275-
&& !region.is_static()
276-
}
277-
_ => false,
278-
},
279-
_ => false,
280-
};
281-
282-
if !arg_is_panic_info {
283-
sess.span_err(decl.inputs[0].span, "argument should be `&PanicInfo`");
284-
}
285-
286-
if let Node::Item(item) = hir.get(fn_id)
287-
&& let ItemKind::Fn(_, ref generics, _) = item.kind
288-
&& !generics.params.is_empty()
289-
{
290-
sess.span_err(span, "should have no type parameters");
291-
}
292-
} else {
293-
let span = sess.source_map().guess_head_span(span);
294-
sess.span_err(span, "function should have one argument");
295-
}
296-
} else {
297-
sess.err("language item required, but not found: `panic_info`");
298-
}
261+
check_panic_info_fn(tcx, panic_impl_did.expect_local(), fn_sig, decl, declared_ret_ty);
299262
}
300263

301264
// Check that a function marked as `#[alloc_error_handler]` has signature `fn(Layout) -> !`
302265
if let Some(alloc_error_handler_did) = tcx.lang_items().oom()
303266
&& alloc_error_handler_did == hir.local_def_id(fn_id).to_def_id()
304267
{
305-
if let Some(alloc_layout_did) = tcx.lang_items().alloc_layout() {
306-
if *declared_ret_ty.kind() != ty::Never {
307-
sess.span_err(decl.output.span(), "return type should be `!`");
308-
}
268+
check_alloc_error_fn(tcx, alloc_error_handler_did.expect_local(), fn_sig, decl, declared_ret_ty);
269+
}
309270

310-
let inputs = fn_sig.inputs();
311-
let span = hir.span(fn_id);
312-
if inputs.len() == 1 {
313-
let arg_is_alloc_layout = match inputs[0].kind() {
314-
ty::Adt(ref adt, _) => adt.did() == alloc_layout_did,
315-
_ => false,
316-
};
271+
(fcx, gen_ty)
272+
}
317273

318-
if !arg_is_alloc_layout {
319-
sess.span_err(decl.inputs[0].span, "argument should be `Layout`");
320-
}
274+
fn check_panic_info_fn(
275+
tcx: TyCtxt<'_>,
276+
fn_id: LocalDefId,
277+
fn_sig: ty::FnSig<'_>,
278+
decl: &hir::FnDecl<'_>,
279+
declared_ret_ty: Ty<'_>,
280+
) {
281+
let Some(panic_info_did) = tcx.lang_items().panic_info() else {
282+
tcx.sess.err("language item required, but not found: `panic_info`");
283+
return;
284+
};
321285

322-
if let Node::Item(item) = hir.get(fn_id)
323-
&& let ItemKind::Fn(_, ref generics, _) = item.kind
324-
&& !generics.params.is_empty()
325-
{
326-
sess.span_err(
327-
span,
328-
"`#[alloc_error_handler]` function should have no type parameters",
329-
);
330-
}
331-
} else {
332-
let span = sess.source_map().guess_head_span(span);
333-
sess.span_err(span, "function should have one argument");
286+
if *declared_ret_ty.kind() != ty::Never {
287+
tcx.sess.span_err(decl.output.span(), "return type should be `!`");
288+
}
289+
290+
let span = tcx.def_span(fn_id);
291+
let inputs = fn_sig.inputs();
292+
if inputs.len() != 1 {
293+
let span = tcx.sess.source_map().guess_head_span(span);
294+
tcx.sess.span_err(span, "function should have one argument");
295+
return;
296+
}
297+
298+
let arg_is_panic_info = match *inputs[0].kind() {
299+
ty::Ref(region, ty, mutbl) => match *ty.kind() {
300+
ty::Adt(ref adt, _) => {
301+
adt.did() == panic_info_did && mutbl == hir::Mutability::Not && !region.is_static()
334302
}
335-
} else {
336-
sess.err("language item required, but not found: `alloc_layout`");
337-
}
303+
_ => false,
304+
},
305+
_ => false,
306+
};
307+
308+
if !arg_is_panic_info {
309+
tcx.sess.span_err(decl.inputs[0].span, "argument should be `&PanicInfo`");
338310
}
339311

340-
(fcx, gen_ty)
312+
let DefKind::Fn = tcx.def_kind(fn_id) else {
313+
let span = tcx.def_span(fn_id);
314+
tcx.sess.span_err(span, "should be a function");
315+
return;
316+
};
317+
318+
let generic_counts = tcx.generics_of(fn_id).own_counts();
319+
if generic_counts.types != 0 {
320+
let span = tcx.def_span(fn_id);
321+
tcx.sess.span_err(span, "should have no type parameters");
322+
}
323+
if generic_counts.consts != 0 {
324+
let span = tcx.def_span(fn_id);
325+
tcx.sess.span_err(span, "should have no const parameters");
326+
}
327+
}
328+
329+
fn check_alloc_error_fn(
330+
tcx: TyCtxt<'_>,
331+
fn_id: LocalDefId,
332+
fn_sig: ty::FnSig<'_>,
333+
decl: &hir::FnDecl<'_>,
334+
declared_ret_ty: Ty<'_>,
335+
) {
336+
let Some(alloc_layout_did) = tcx.lang_items().alloc_layout() else {
337+
tcx.sess.err("language item required, but not found: `alloc_layout`");
338+
return;
339+
};
340+
341+
if *declared_ret_ty.kind() != ty::Never {
342+
tcx.sess.span_err(decl.output.span(), "return type should be `!`");
343+
}
344+
345+
let inputs = fn_sig.inputs();
346+
if inputs.len() != 1 {
347+
let span = tcx.def_span(fn_id);
348+
let span = tcx.sess.source_map().guess_head_span(span);
349+
tcx.sess.span_err(span, "function should have one argument");
350+
return;
351+
}
352+
353+
let arg_is_alloc_layout = match inputs[0].kind() {
354+
ty::Adt(ref adt, _) => adt.did() == alloc_layout_did,
355+
_ => false,
356+
};
357+
358+
if !arg_is_alloc_layout {
359+
tcx.sess.span_err(decl.inputs[0].span, "argument should be `Layout`");
360+
}
361+
362+
let DefKind::Fn = tcx.def_kind(fn_id) else {
363+
let span = tcx.def_span(fn_id);
364+
tcx.sess.span_err(span, "`#[alloc_error_handler]` should be a function");
365+
return;
366+
};
367+
368+
let generic_counts = tcx.generics_of(fn_id).own_counts();
369+
if generic_counts.types != 0 {
370+
let span = tcx.def_span(fn_id);
371+
tcx.sess.span_err(span, "`#[alloc_error_handler]` function should have no type parameters");
372+
}
373+
if generic_counts.consts != 0 {
374+
let span = tcx.def_span(fn_id);
375+
tcx.sess
376+
.span_err(span, "`#[alloc_error_handler]` function should have no const parameters");
377+
}
341378
}
342379

343380
fn check_struct(tcx: TyCtxt<'_>, def_id: LocalDefId, span: Span) {

‎compiler/rustc_typeck/src/check/compare_method.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -660,8 +660,24 @@ fn compare_number_of_generics<'tcx>(
660660
_ => None,
661661
})
662662
.collect();
663-
let spans = impl_item.generics.spans();
664-
let span = spans.primary_span();
663+
let spans = if impl_item.generics.params.is_empty() {
664+
vec![impl_item.generics.span]
665+
} else {
666+
impl_item
667+
.generics
668+
.params
669+
.iter()
670+
.filter(|p| {
671+
matches!(
672+
p.kind,
673+
hir::GenericParamKind::Type { .. }
674+
| hir::GenericParamKind::Const { .. }
675+
)
676+
})
677+
.map(|p| p.span)
678+
.collect::<Vec<Span>>()
679+
};
680+
let span = spans.first().copied();
665681

666682
let mut err = tcx.sess.struct_span_err_with_code(
667683
spans,

‎src/test/ui/async-await/issue-76547.base.stderr

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ LL | async fn fut(bufs: &mut [&mut [u8]]) {
55
| ---------------- these two types are declared with different lifetimes...
66
LL | ListFut(bufs).await
77
| ^^^^ ...but data from `bufs` flows into `bufs` here
8+
|
9+
= note: each elided lifetime in input position becomes a distinct lifetime
10+
help: consider introducing a named lifetime parameter
11+
|
12+
LL | async fn fut<'a>(bufs: &'a mut [&'a mut [u8]]) {
13+
| ++++ ++ ++
814

915
error[E0623]: lifetime mismatch
1016
--> $DIR/issue-76547.rs:39:14
@@ -13,6 +19,12 @@ LL | async fn fut2(bufs: &mut [&mut [u8]]) -> i32 {
1319
| ---------------- these two types are declared with different lifetimes...
1420
LL | ListFut2(bufs).await
1521
| ^^^^ ...but data from `bufs` flows into `bufs` here
22+
|
23+
= note: each elided lifetime in input position becomes a distinct lifetime
24+
help: consider introducing a named lifetime parameter
25+
|
26+
LL | async fn fut2<'a>(bufs: &'a mut [&'a mut [u8]]) -> i32 {
27+
| ++++ ++ ++
1628

1729
error: aborting due to 2 previous errors
1830

‎src/test/ui/async-await/issue-76547.nll.stderr

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ LL | async fn fut(bufs: &mut [&mut [u8]]) {
77
| let's call the lifetime of this reference `'1`
88
LL | ListFut(bufs).await
99
| ^^^^ this usage requires that `'1` must outlive `'2`
10+
|
11+
help: consider introducing a named lifetime parameter
12+
|
13+
LL | async fn fut<'a>(bufs: &'a mut [&'a mut [u8]]) {
14+
| ++++ ++ ++
1015

1116
error: lifetime may not live long enough
1217
--> $DIR/issue-76547.rs:39:14
@@ -17,6 +22,11 @@ LL | async fn fut2(bufs: &mut [&mut [u8]]) -> i32 {
1722
| let's call the lifetime of this reference `'1`
1823
LL | ListFut2(bufs).await
1924
| ^^^^ this usage requires that `'1` must outlive `'2`
25+
|
26+
help: consider introducing a named lifetime parameter
27+
|
28+
LL | async fn fut2<'a>(bufs: &'a mut [&'a mut [u8]]) -> i32 {
29+
| ++++ ++ ++
2030

2131
error: aborting due to 2 previous errors
2232

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
error[E0623]: lifetime mismatch
1+
error[E0621]: explicit lifetime required in the type of `foo`
22
--> $DIR/issue-63388-1.rs:19:9
33
|
44
LL | &'a self, foo: &dyn Foo
5-
| -------- this parameter and the return type are declared with different lifetimes...
6-
LL | ) -> &dyn Foo
7-
| --------
5+
| -------- help: add explicit lifetime `'a` to the type of `foo`: `&'a (dyn Foo + 'a)`
86
...
97
LL | foo
10-
| ^^^ ...but data from `foo` is returned here
8+
| ^^^ lifetime `'a` required
119

1210
error: aborting due to previous error
1311

14-
For more information about this error, try `rustc --explain E0623`.
12+
For more information about this error, try `rustc --explain E0621`.
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
error: lifetime may not live long enough
1+
error[E0621]: explicit lifetime required in the type of `foo`
22
--> $DIR/issue-63388-1.rs:17:5
33
|
4-
LL | async fn do_sth<'a>(
5-
| -- lifetime `'a` defined here
64
LL | &'a self, foo: &dyn Foo
7-
| - let's call the lifetime of this reference `'1`
5+
| -------- help: add explicit lifetime `'a` to the type of `foo`: `&'a (dyn Foo + 'a)`
86
LL | ) -> &dyn Foo
97
LL | / {
108
LL | |
119
LL | | foo
1210
LL | |
1311
LL | | }
14-
| |_____^ associated function was supposed to return data with lifetime `'a` but it is returning data with lifetime `'1`
12+
| |_____^ lifetime `'a` required
1513

1614
error: aborting due to previous error
1715

16+
For more information about this error, try `rustc --explain E0621`.

‎src/test/ui/async-await/issues/issue-63388-1.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ impl Xyz {
1515
&'a self, foo: &dyn Foo
1616
) -> &dyn Foo
1717
{
18-
//[nll]~^ ERROR lifetime may not live long enough
18+
//[nll]~^ ERROR explicit lifetime required in the type of `foo` [E0621]
1919
foo
20-
//[base]~^ ERROR lifetime mismatch
20+
//[base]~^ ERROR explicit lifetime required in the type of `foo` [E0621]
2121
}
2222
}
2323

‎src/test/ui/error-codes/E0308-2.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ LL | impl Eq for &dyn DynEq {}
66
|
77
= note: expected trait `<&dyn DynEq as PartialEq>`
88
found trait `<&(dyn DynEq + 'static) as PartialEq>`
9-
note: the lifetime `'_` as defined here...
9+
note: the anonymous lifetime as defined here...
1010
--> $DIR/E0308-2.rs:9:13
1111
|
1212
LL | impl Eq for &dyn DynEq {}

‎src/test/ui/generic-associated-types/parameter_number_and_kind_impl.stderr

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,15 @@ LL | type A = u32;
88
| ^ lifetimes do not match type in trait
99

1010
error[E0049]: type `B` has 1 type parameter but its trait declaration has 0 type parameters
11-
--> $DIR/parameter_number_and_kind_impl.rs:17:12
11+
--> $DIR/parameter_number_and_kind_impl.rs:17:16
1212
|
1313
LL | type B<'a, 'b>;
1414
| -- --
1515
| |
1616
| expected 0 type parameters
1717
...
1818
LL | type B<'a, T> = Vec<T>;
19-
| ^^ ^
20-
| |
21-
| found 1 type parameter
19+
| ^ found 1 type parameter
2220

2321
error[E0195]: lifetime parameters or bounds on type `C` do not match the trait declaration
2422
--> $DIR/parameter_number_and_kind_impl.rs:19:11

‎src/test/ui/issues/issue-17905-2.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ note: the anonymous lifetime defined here...
1111
|
1212
LL | fn say(self: &Pair<&str, isize>) {
1313
| ^^^^
14-
note: ...does not necessarily outlive the lifetime `'_` as defined here
14+
note: ...does not necessarily outlive the anonymous lifetime as defined here
1515
--> $DIR/issue-17905-2.rs:5:5
1616
|
1717
LL | &str,
@@ -25,7 +25,7 @@ LL | fn say(self: &Pair<&str, isize>) {
2525
|
2626
= note: expected struct `Pair<&str, _>`
2727
found struct `Pair<&str, _>`
28-
note: the lifetime `'_` as defined here...
28+
note: the anonymous lifetime as defined here...
2929
--> $DIR/issue-17905-2.rs:5:5
3030
|
3131
LL | &str,

‎src/test/ui/issues/issue-65230.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ LL | impl T1 for &dyn T2 {}
66
|
77
= note: expected trait `<&dyn T2 as T0>`
88
found trait `<&(dyn T2 + 'static) as T0>`
9-
note: the lifetime `'_` as defined here...
9+
note: the anonymous lifetime as defined here...
1010
--> $DIR/issue-65230.rs:8:13
1111
|
1212
LL | impl T1 for &dyn T2 {}

‎src/test/ui/nll/issue-52742.base.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0312]: lifetime of reference outlives lifetime of borrowed content...
44
LL | self.y = b.z
55
| ^^^
66
|
7-
note: ...the reference is valid for the lifetime `'_` as defined here...
7+
note: ...the reference is valid for the anonymous lifetime as defined here...
88
--> $DIR/issue-52742.rs:15:10
99
|
1010
LL | impl Foo<'_, '_> {

‎src/test/ui/nll/issue-52742.nll.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error: lifetime may not live long enough
22
--> $DIR/issue-52742.rs:17:9
33
|
44
LL | fn take_bar(&mut self, b: Bar<'_>) {
5-
| --------- -- let's call this `'1`
5+
| --------- - has type `Bar<'1>`
66
| |
77
| has type `&mut Foo<'_, '2>`
88
LL | self.y = b.z

‎src/test/ui/nll/issue-55394.base.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ note: ...so that reference does not outlive borrowed content
1414
|
1515
LL | Foo { bar }
1616
| ^^^
17-
note: but, the lifetime must be valid for the lifetime `'_` as defined here...
17+
note: but, the lifetime must be valid for the anonymous lifetime as defined here...
1818
--> $DIR/issue-55394.rs:11:10
1919
|
2020
LL | impl Foo<'_> {

‎src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait-async.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ error[E0700]: hidden type for `impl Trait` captures lifetime that does not appea
22
--> $DIR/arbitrary_self_types_pin_lifetime_impl_trait-async.rs:8:48
33
|
44
LL | async fn f(self: Pin<&Self>) -> impl Clone { self }
5-
| - ^^^^^^^^
5+
| ----- ^^^^^^^^
66
| |
7-
| hidden type `Pin<&Foo>` captures the lifetime `'_` as defined here
7+
| hidden type `Pin<&Foo>` captures the anonymous lifetime defined here
88
|
99
help: to declare that the `impl Trait` captures `'_`, you can add an explicit `'_` lifetime bound
1010
|

‎src/test/ui/self/arbitrary_self_types_pin_lifetime_mismatch-async.base.stderr

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ LL | async fn a(self: Pin<&Foo>, f: &Foo) -> &Foo { f }
55
| ---- ---- ^ ...but data from `f` is returned here
66
| |
77
| this parameter and the return type are declared with different lifetimes...
8+
|
9+
= note: each elided lifetime in input position becomes a distinct lifetime
10+
help: consider introducing a named lifetime parameter and update trait if needed
11+
|
12+
LL | async fn a<'a>(self: Pin<&'a Foo>, f: &'a Foo) -> &Foo { f }
13+
| ++++ ++ ++
814

915
error[E0623]: lifetime mismatch
1016
--> $DIR/arbitrary_self_types_pin_lifetime_mismatch-async.rs:15:82
@@ -13,6 +19,12 @@ LL | async fn c(self: Pin<&Self>, f: &Foo, g: &Foo) -> (Pin<&Foo>, &Foo) { (
1319
| ---- ----------------- ^ ...but data from `f` is returned here
1420
| |
1521
| this parameter and the return type are declared with different lifetimes...
22+
|
23+
= note: each elided lifetime in input position becomes a distinct lifetime
24+
help: consider introducing a named lifetime parameter and update trait if needed
25+
|
26+
LL | async fn c<'a>(self: Pin<&'a Self>, f: &'a Foo, g: &Foo) -> (Pin<&Foo>, &Foo) { (self, f) }
27+
| ++++ ++ ++
1628

1729
error[E0623]: lifetime mismatch
1830
--> $DIR/arbitrary_self_types_pin_lifetime_mismatch-async.rs:22:64

‎src/test/ui/self/arbitrary_self_types_pin_lifetime_mismatch-async.nll.stderr

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ LL | async fn a(self: Pin<&Foo>, f: &Foo) -> &Foo { f }
66
| | |
77
| | let's call the lifetime of this reference `'1`
88
| let's call the lifetime of this reference `'2`
9+
|
10+
help: consider introducing a named lifetime parameter and update trait if needed
11+
|
12+
LL | async fn a<'a>(self: Pin<&'a Foo>, f: &'a Foo) -> &Foo { f }
13+
| ++++ ++ ++
914

1015
error: lifetime may not live long enough
1116
--> $DIR/arbitrary_self_types_pin_lifetime_mismatch-async.rs:15:75
@@ -15,6 +20,11 @@ LL | async fn c(self: Pin<&Self>, f: &Foo, g: &Foo) -> (Pin<&Foo>, &Foo) { (
1520
| | |
1621
| | let's call the lifetime of this reference `'1`
1722
| let's call the lifetime of this reference `'2`
23+
|
24+
help: consider introducing a named lifetime parameter and update trait if needed
25+
|
26+
LL | async fn c<'a>(self: Pin<&'a Self>, f: &'a Foo, g: &Foo) -> (Pin<&Foo>, &Foo) { (self, f) }
27+
| ++++ ++ ++
1828

1929
error: lifetime may not live long enough
2030
--> $DIR/arbitrary_self_types_pin_lifetime_mismatch-async.rs:22:64

‎src/test/ui/self/elision/lt-ref-self-async.base.stderr

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ LL | async fn ref_self(&self, f: &u32) -> &u32 {
77
| this parameter and the return type are declared with different lifetimes...
88
LL | f
99
| ^ ...but data from `f` is returned here
10+
|
11+
= note: each elided lifetime in input position becomes a distinct lifetime
12+
help: consider introducing a named lifetime parameter and update trait if needed
13+
|
14+
LL | async fn ref_self<'a>(&'a self, f: &'a u32) -> &u32 {
15+
| ++++ ++ ++
1016

1117
error[E0623]: lifetime mismatch
1218
--> $DIR/lt-ref-self-async.rs:24:9
@@ -17,6 +23,12 @@ LL | async fn ref_Self(self: &Self, f: &u32) -> &u32 {
1723
| this parameter and the return type are declared with different lifetimes...
1824
LL | f
1925
| ^ ...but data from `f` is returned here
26+
|
27+
= note: each elided lifetime in input position becomes a distinct lifetime
28+
help: consider introducing a named lifetime parameter and update trait if needed
29+
|
30+
LL | async fn ref_Self<'a>(self: &'a Self, f: &'a u32) -> &u32 {
31+
| ++++ ++ ++
2032

2133
error[E0623]: lifetime mismatch
2234
--> $DIR/lt-ref-self-async.rs:30:9
@@ -27,6 +39,12 @@ LL | async fn box_ref_Self(self: Box<&Self>, f: &u32) -> &u32 {
2739
| this parameter and the return type are declared with different lifetimes...
2840
LL | f
2941
| ^ ...but data from `f` is returned here
42+
|
43+
= note: each elided lifetime in input position becomes a distinct lifetime
44+
help: consider introducing a named lifetime parameter and update trait if needed
45+
|
46+
LL | async fn box_ref_Self<'a>(self: Box<&'a Self>, f: &'a u32) -> &u32 {
47+
| ++++ ++ ++
3048

3149
error[E0623]: lifetime mismatch
3250
--> $DIR/lt-ref-self-async.rs:36:9
@@ -37,6 +55,12 @@ LL | async fn pin_ref_Self(self: Pin<&Self>, f: &u32) -> &u32 {
3755
| this parameter and the return type are declared with different lifetimes...
3856
LL | f
3957
| ^ ...but data from `f` is returned here
58+
|
59+
= note: each elided lifetime in input position becomes a distinct lifetime
60+
help: consider introducing a named lifetime parameter and update trait if needed
61+
|
62+
LL | async fn pin_ref_Self<'a>(self: Pin<&'a Self>, f: &'a u32) -> &u32 {
63+
| ++++ ++ ++
4064

4165
error[E0623]: lifetime mismatch
4266
--> $DIR/lt-ref-self-async.rs:42:9
@@ -47,6 +71,12 @@ LL | async fn box_box_ref_Self(self: Box<Box<&Self>>, f: &u32) -> &u32 {
4771
| this parameter and the return type are declared with different lifetimes...
4872
LL | f
4973
| ^ ...but data from `f` is returned here
74+
|
75+
= note: each elided lifetime in input position becomes a distinct lifetime
76+
help: consider introducing a named lifetime parameter and update trait if needed
77+
|
78+
LL | async fn box_box_ref_Self<'a>(self: Box<Box<&'a Self>>, f: &'a u32) -> &u32 {
79+
| ++++ ++ ++
5080

5181
error[E0623]: lifetime mismatch
5282
--> $DIR/lt-ref-self-async.rs:48:9
@@ -57,6 +87,12 @@ LL | async fn box_pin_Self(self: Box<Pin<&Self>>, f: &u32) -> &u32 {
5787
| this parameter and the return type are declared with different lifetimes...
5888
LL | f
5989
| ^ ...but data from `f` is returned here
90+
|
91+
= note: each elided lifetime in input position becomes a distinct lifetime
92+
help: consider introducing a named lifetime parameter and update trait if needed
93+
|
94+
LL | async fn box_pin_Self<'a>(self: Box<Pin<&'a Self>>, f: &'a u32) -> &u32 {
95+
| ++++ ++ ++
6096

6197
error: aborting due to 6 previous errors
6298

‎src/test/ui/self/elision/lt-ref-self-async.nll.stderr

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ LL | async fn ref_self(&self, f: &u32) -> &u32 {
77
| let's call the lifetime of this reference `'2`
88
LL | f
99
| ^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
10+
|
11+
help: consider introducing a named lifetime parameter and update trait if needed
12+
|
13+
LL | async fn ref_self<'a>(&'a self, f: &'a u32) -> &u32 {
14+
| ++++ ++ ++
1015

1116
error: lifetime may not live long enough
1217
--> $DIR/lt-ref-self-async.rs:24:9
@@ -17,6 +22,11 @@ LL | async fn ref_Self(self: &Self, f: &u32) -> &u32 {
1722
| let's call the lifetime of this reference `'2`
1823
LL | f
1924
| ^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
25+
|
26+
help: consider introducing a named lifetime parameter and update trait if needed
27+
|
28+
LL | async fn ref_Self<'a>(self: &'a Self, f: &'a u32) -> &u32 {
29+
| ++++ ++ ++
2030

2131
error: lifetime may not live long enough
2232
--> $DIR/lt-ref-self-async.rs:30:9
@@ -27,6 +37,11 @@ LL | async fn box_ref_Self(self: Box<&Self>, f: &u32) -> &u32 {
2737
| let's call the lifetime of this reference `'2`
2838
LL | f
2939
| ^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
40+
|
41+
help: consider introducing a named lifetime parameter and update trait if needed
42+
|
43+
LL | async fn box_ref_Self<'a>(self: Box<&'a Self>, f: &'a u32) -> &u32 {
44+
| ++++ ++ ++
3045

3146
error: lifetime may not live long enough
3247
--> $DIR/lt-ref-self-async.rs:36:9
@@ -37,6 +52,11 @@ LL | async fn pin_ref_Self(self: Pin<&Self>, f: &u32) -> &u32 {
3752
| let's call the lifetime of this reference `'2`
3853
LL | f
3954
| ^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
55+
|
56+
help: consider introducing a named lifetime parameter and update trait if needed
57+
|
58+
LL | async fn pin_ref_Self<'a>(self: Pin<&'a Self>, f: &'a u32) -> &u32 {
59+
| ++++ ++ ++
4060

4161
error: lifetime may not live long enough
4262
--> $DIR/lt-ref-self-async.rs:42:9
@@ -47,6 +67,11 @@ LL | async fn box_box_ref_Self(self: Box<Box<&Self>>, f: &u32) -> &u32 {
4767
| let's call the lifetime of this reference `'2`
4868
LL | f
4969
| ^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
70+
|
71+
help: consider introducing a named lifetime parameter and update trait if needed
72+
|
73+
LL | async fn box_box_ref_Self<'a>(self: Box<Box<&'a Self>>, f: &'a u32) -> &u32 {
74+
| ++++ ++ ++
5075

5176
error: lifetime may not live long enough
5277
--> $DIR/lt-ref-self-async.rs:48:9
@@ -57,6 +82,11 @@ LL | async fn box_pin_Self(self: Box<Pin<&Self>>, f: &u32) -> &u32 {
5782
| let's call the lifetime of this reference `'2`
5883
LL | f
5984
| ^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
85+
|
86+
help: consider introducing a named lifetime parameter and update trait if needed
87+
|
88+
LL | async fn box_pin_Self<'a>(self: Box<Pin<&'a Self>>, f: &'a u32) -> &u32 {
89+
| ++++ ++ ++
6090

6191
error: aborting due to 6 previous errors
6292

‎src/test/ui/self/elision/ref-mut-self-async.base.stderr

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ LL | async fn ref_self(&mut self, f: &u32) -> &u32 {
77
| this parameter and the return type are declared with different lifetimes...
88
LL | f
99
| ^ ...but data from `f` is returned here
10+
|
11+
= note: each elided lifetime in input position becomes a distinct lifetime
12+
help: consider introducing a named lifetime parameter and update trait if needed
13+
|
14+
LL | async fn ref_self<'a>(&'a mut self, f: &'a u32) -> &u32 {
15+
| ++++ ++ ++
1016

1117
error[E0623]: lifetime mismatch
1218
--> $DIR/ref-mut-self-async.rs:24:9
@@ -17,6 +23,12 @@ LL | async fn ref_Self(self: &mut Self, f: &u32) -> &u32 {
1723
| this parameter and the return type are declared with different lifetimes...
1824
LL | f
1925
| ^ ...but data from `f` is returned here
26+
|
27+
= note: each elided lifetime in input position becomes a distinct lifetime
28+
help: consider introducing a named lifetime parameter and update trait if needed
29+
|
30+
LL | async fn ref_Self<'a>(self: &'a mut Self, f: &'a u32) -> &u32 {
31+
| ++++ ++ ++
2032

2133
error[E0623]: lifetime mismatch
2234
--> $DIR/ref-mut-self-async.rs:30:9
@@ -27,6 +39,12 @@ LL | async fn box_ref_Self(self: Box<&mut Self>, f: &u32) -> &u32 {
2739
| this parameter and the return type are declared with different lifetimes...
2840
LL | f
2941
| ^ ...but data from `f` is returned here
42+
|
43+
= note: each elided lifetime in input position becomes a distinct lifetime
44+
help: consider introducing a named lifetime parameter and update trait if needed
45+
|
46+
LL | async fn box_ref_Self<'a>(self: Box<&'a mut Self>, f: &'a u32) -> &u32 {
47+
| ++++ ++ ++
3048

3149
error[E0623]: lifetime mismatch
3250
--> $DIR/ref-mut-self-async.rs:36:9
@@ -37,6 +55,12 @@ LL | async fn pin_ref_Self(self: Pin<&mut Self>, f: &u32) -> &u32 {
3755
| this parameter and the return type are declared with different lifetimes...
3856
LL | f
3957
| ^ ...but data from `f` is returned here
58+
|
59+
= note: each elided lifetime in input position becomes a distinct lifetime
60+
help: consider introducing a named lifetime parameter and update trait if needed
61+
|
62+
LL | async fn pin_ref_Self<'a>(self: Pin<&'a mut Self>, f: &'a u32) -> &u32 {
63+
| ++++ ++ ++
4064

4165
error[E0623]: lifetime mismatch
4266
--> $DIR/ref-mut-self-async.rs:42:9
@@ -47,6 +71,12 @@ LL | async fn box_box_ref_Self(self: Box<Box<&mut Self>>, f: &u32) -> &u32 {
4771
| this parameter and the return type are declared with different lifetimes...
4872
LL | f
4973
| ^ ...but data from `f` is returned here
74+
|
75+
= note: each elided lifetime in input position becomes a distinct lifetime
76+
help: consider introducing a named lifetime parameter and update trait if needed
77+
|
78+
LL | async fn box_box_ref_Self<'a>(self: Box<Box<&'a mut Self>>, f: &'a u32) -> &u32 {
79+
| ++++ ++ ++
5080

5181
error[E0623]: lifetime mismatch
5282
--> $DIR/ref-mut-self-async.rs:48:9
@@ -57,6 +87,12 @@ LL | async fn box_pin_ref_Self(self: Box<Pin<&mut Self>>, f: &u32) -> &u32 {
5787
| this parameter and the return type are declared with different lifetimes...
5888
LL | f
5989
| ^ ...but data from `f` is returned here
90+
|
91+
= note: each elided lifetime in input position becomes a distinct lifetime
92+
help: consider introducing a named lifetime parameter and update trait if needed
93+
|
94+
LL | async fn box_pin_ref_Self<'a>(self: Box<Pin<&'a mut Self>>, f: &'a u32) -> &u32 {
95+
| ++++ ++ ++
6096

6197
error: aborting due to 6 previous errors
6298

‎src/test/ui/self/elision/ref-mut-self-async.nll.stderr

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ LL | async fn ref_self(&mut self, f: &u32) -> &u32 {
77
| let's call the lifetime of this reference `'2`
88
LL | f
99
| ^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
10+
|
11+
help: consider introducing a named lifetime parameter and update trait if needed
12+
|
13+
LL | async fn ref_self<'a>(&'a mut self, f: &'a u32) -> &u32 {
14+
| ++++ ++ ++
1015

1116
error: lifetime may not live long enough
1217
--> $DIR/ref-mut-self-async.rs:24:9
@@ -17,6 +22,11 @@ LL | async fn ref_Self(self: &mut Self, f: &u32) -> &u32 {
1722
| let's call the lifetime of this reference `'2`
1823
LL | f
1924
| ^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
25+
|
26+
help: consider introducing a named lifetime parameter and update trait if needed
27+
|
28+
LL | async fn ref_Self<'a>(self: &'a mut Self, f: &'a u32) -> &u32 {
29+
| ++++ ++ ++
2030

2131
error: lifetime may not live long enough
2232
--> $DIR/ref-mut-self-async.rs:30:9
@@ -27,6 +37,11 @@ LL | async fn box_ref_Self(self: Box<&mut Self>, f: &u32) -> &u32 {
2737
| let's call the lifetime of this reference `'2`
2838
LL | f
2939
| ^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
40+
|
41+
help: consider introducing a named lifetime parameter and update trait if needed
42+
|
43+
LL | async fn box_ref_Self<'a>(self: Box<&'a mut Self>, f: &'a u32) -> &u32 {
44+
| ++++ ++ ++
3045

3146
error: lifetime may not live long enough
3247
--> $DIR/ref-mut-self-async.rs:36:9
@@ -37,6 +52,11 @@ LL | async fn pin_ref_Self(self: Pin<&mut Self>, f: &u32) -> &u32 {
3752
| let's call the lifetime of this reference `'2`
3853
LL | f
3954
| ^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
55+
|
56+
help: consider introducing a named lifetime parameter and update trait if needed
57+
|
58+
LL | async fn pin_ref_Self<'a>(self: Pin<&'a mut Self>, f: &'a u32) -> &u32 {
59+
| ++++ ++ ++
4060

4161
error: lifetime may not live long enough
4262
--> $DIR/ref-mut-self-async.rs:42:9
@@ -47,6 +67,11 @@ LL | async fn box_box_ref_Self(self: Box<Box<&mut Self>>, f: &u32) -> &u32 {
4767
| let's call the lifetime of this reference `'2`
4868
LL | f
4969
| ^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
70+
|
71+
help: consider introducing a named lifetime parameter and update trait if needed
72+
|
73+
LL | async fn box_box_ref_Self<'a>(self: Box<Box<&'a mut Self>>, f: &'a u32) -> &u32 {
74+
| ++++ ++ ++
5075

5176
error: lifetime may not live long enough
5277
--> $DIR/ref-mut-self-async.rs:48:9
@@ -57,6 +82,11 @@ LL | async fn box_pin_ref_Self(self: Box<Pin<&mut Self>>, f: &u32) -> &u32 {
5782
| let's call the lifetime of this reference `'2`
5883
LL | f
5984
| ^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
85+
|
86+
help: consider introducing a named lifetime parameter and update trait if needed
87+
|
88+
LL | async fn box_pin_ref_Self<'a>(self: Box<Pin<&'a mut Self>>, f: &'a u32) -> &u32 {
89+
| ++++ ++ ++
6090

6191
error: aborting due to 6 previous errors
6292

‎src/test/ui/self/elision/ref-mut-struct-async.base.stderr

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ LL | async fn ref_Struct(self: &mut Struct, f: &u32) -> &u32 {
77
| this parameter and the return type are declared with different lifetimes...
88
LL | f
99
| ^ ...but data from `f` is returned here
10+
|
11+
= note: each elided lifetime in input position becomes a distinct lifetime
12+
help: consider introducing a named lifetime parameter and update trait if needed
13+
|
14+
LL | async fn ref_Struct<'a>(self: &'a mut Struct, f: &'a u32) -> &u32 {
15+
| ++++ ++ ++
1016

1117
error[E0623]: lifetime mismatch
1218
--> $DIR/ref-mut-struct-async.rs:22:9
@@ -17,6 +23,12 @@ LL | async fn box_ref_Struct(self: Box<&mut Struct>, f: &u32) -> &u32 {
1723
| this parameter and the return type are declared with different lifetimes...
1824
LL | f
1925
| ^ ...but data from `f` is returned here
26+
|
27+
= note: each elided lifetime in input position becomes a distinct lifetime
28+
help: consider introducing a named lifetime parameter and update trait if needed
29+
|
30+
LL | async fn box_ref_Struct<'a>(self: Box<&'a mut Struct>, f: &'a u32) -> &u32 {
31+
| ++++ ++ ++
2032

2133
error[E0623]: lifetime mismatch
2234
--> $DIR/ref-mut-struct-async.rs:28:9
@@ -27,6 +39,12 @@ LL | async fn pin_ref_Struct(self: Pin<&mut Struct>, f: &u32) -> &u32 {
2739
| this parameter and the return type are declared with different lifetimes...
2840
LL | f
2941
| ^ ...but data from `f` is returned here
42+
|
43+
= note: each elided lifetime in input position becomes a distinct lifetime
44+
help: consider introducing a named lifetime parameter and update trait if needed
45+
|
46+
LL | async fn pin_ref_Struct<'a>(self: Pin<&'a mut Struct>, f: &'a u32) -> &u32 {
47+
| ++++ ++ ++
3048

3149
error[E0623]: lifetime mismatch
3250
--> $DIR/ref-mut-struct-async.rs:34:9
@@ -37,6 +55,12 @@ LL | async fn box_box_ref_Struct(self: Box<Box<&mut Struct>>, f: &u32) -> &u
3755
| this parameter and the return type are declared with different lifetimes...
3856
LL | f
3957
| ^ ...but data from `f` is returned here
58+
|
59+
= note: each elided lifetime in input position becomes a distinct lifetime
60+
help: consider introducing a named lifetime parameter and update trait if needed
61+
|
62+
LL | async fn box_box_ref_Struct<'a>(self: Box<Box<&'a mut Struct>>, f: &'a u32) -> &u32 {
63+
| ++++ ++ ++
4064

4165
error[E0623]: lifetime mismatch
4266
--> $DIR/ref-mut-struct-async.rs:40:9
@@ -47,6 +71,12 @@ LL | async fn box_pin_ref_Struct(self: Box<Pin<&mut Struct>>, f: &u32) -> &u
4771
| this parameter and the return type are declared with different lifetimes...
4872
LL | f
4973
| ^ ...but data from `f` is returned here
74+
|
75+
= note: each elided lifetime in input position becomes a distinct lifetime
76+
help: consider introducing a named lifetime parameter and update trait if needed
77+
|
78+
LL | async fn box_pin_ref_Struct<'a>(self: Box<Pin<&'a mut Struct>>, f: &'a u32) -> &u32 {
79+
| ++++ ++ ++
5080

5181
error: aborting due to 5 previous errors
5282

‎src/test/ui/self/elision/ref-mut-struct-async.nll.stderr

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ LL | async fn ref_Struct(self: &mut Struct, f: &u32) -> &u32 {
77
| let's call the lifetime of this reference `'2`
88
LL | f
99
| ^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
10+
|
11+
help: consider introducing a named lifetime parameter and update trait if needed
12+
|
13+
LL | async fn ref_Struct<'a>(self: &'a mut Struct, f: &'a u32) -> &u32 {
14+
| ++++ ++ ++
1015

1116
error: lifetime may not live long enough
1217
--> $DIR/ref-mut-struct-async.rs:22:9
@@ -17,6 +22,11 @@ LL | async fn box_ref_Struct(self: Box<&mut Struct>, f: &u32) -> &u32 {
1722
| let's call the lifetime of this reference `'2`
1823
LL | f
1924
| ^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
25+
|
26+
help: consider introducing a named lifetime parameter and update trait if needed
27+
|
28+
LL | async fn box_ref_Struct<'a>(self: Box<&'a mut Struct>, f: &'a u32) -> &u32 {
29+
| ++++ ++ ++
2030

2131
error: lifetime may not live long enough
2232
--> $DIR/ref-mut-struct-async.rs:28:9
@@ -27,6 +37,11 @@ LL | async fn pin_ref_Struct(self: Pin<&mut Struct>, f: &u32) -> &u32 {
2737
| let's call the lifetime of this reference `'2`
2838
LL | f
2939
| ^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
40+
|
41+
help: consider introducing a named lifetime parameter and update trait if needed
42+
|
43+
LL | async fn pin_ref_Struct<'a>(self: Pin<&'a mut Struct>, f: &'a u32) -> &u32 {
44+
| ++++ ++ ++
3045

3146
error: lifetime may not live long enough
3247
--> $DIR/ref-mut-struct-async.rs:34:9
@@ -37,6 +52,11 @@ LL | async fn box_box_ref_Struct(self: Box<Box<&mut Struct>>, f: &u32) -> &u
3752
| let's call the lifetime of this reference `'2`
3853
LL | f
3954
| ^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
55+
|
56+
help: consider introducing a named lifetime parameter and update trait if needed
57+
|
58+
LL | async fn box_box_ref_Struct<'a>(self: Box<Box<&'a mut Struct>>, f: &'a u32) -> &u32 {
59+
| ++++ ++ ++
4060

4161
error: lifetime may not live long enough
4262
--> $DIR/ref-mut-struct-async.rs:40:9
@@ -47,6 +67,11 @@ LL | async fn box_pin_ref_Struct(self: Box<Pin<&mut Struct>>, f: &u32) -> &u
4767
| let's call the lifetime of this reference `'2`
4868
LL | f
4969
| ^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
70+
|
71+
help: consider introducing a named lifetime parameter and update trait if needed
72+
|
73+
LL | async fn box_pin_ref_Struct<'a>(self: Box<Pin<&'a mut Struct>>, f: &'a u32) -> &u32 {
74+
| ++++ ++ ++
5075

5176
error: aborting due to 5 previous errors
5277

‎src/test/ui/self/elision/ref-self-async.base.stderr

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ LL | async fn ref_self(&self, f: &u32) -> &u32 {
77
| this parameter and the return type are declared with different lifetimes...
88
LL | f
99
| ^ ...but data from `f` is returned here
10+
|
11+
= note: each elided lifetime in input position becomes a distinct lifetime
12+
help: consider introducing a named lifetime parameter and update trait if needed
13+
|
14+
LL | async fn ref_self<'a>(&'a self, f: &'a u32) -> &u32 {
15+
| ++++ ++ ++
1016

1117
error[E0623]: lifetime mismatch
1218
--> $DIR/ref-self-async.rs:34:9
@@ -17,6 +23,12 @@ LL | async fn ref_Self(self: &Self, f: &u32) -> &u32 {
1723
| this parameter and the return type are declared with different lifetimes...
1824
LL | f
1925
| ^ ...but data from `f` is returned here
26+
|
27+
= note: each elided lifetime in input position becomes a distinct lifetime
28+
help: consider introducing a named lifetime parameter and update trait if needed
29+
|
30+
LL | async fn ref_Self<'a>(self: &'a Self, f: &'a u32) -> &u32 {
31+
| ++++ ++ ++
2032

2133
error[E0623]: lifetime mismatch
2234
--> $DIR/ref-self-async.rs:40:9
@@ -27,6 +39,12 @@ LL | async fn box_ref_Self(self: Box<&Self>, f: &u32) -> &u32 {
2739
| this parameter and the return type are declared with different lifetimes...
2840
LL | f
2941
| ^ ...but data from `f` is returned here
42+
|
43+
= note: each elided lifetime in input position becomes a distinct lifetime
44+
help: consider introducing a named lifetime parameter and update trait if needed
45+
|
46+
LL | async fn box_ref_Self<'a>(self: Box<&'a Self>, f: &'a u32) -> &u32 {
47+
| ++++ ++ ++
3048

3149
error[E0623]: lifetime mismatch
3250
--> $DIR/ref-self-async.rs:46:9
@@ -37,6 +55,12 @@ LL | async fn pin_ref_Self(self: Pin<&Self>, f: &u32) -> &u32 {
3755
| this parameter and the return type are declared with different lifetimes...
3856
LL | f
3957
| ^ ...but data from `f` is returned here
58+
|
59+
= note: each elided lifetime in input position becomes a distinct lifetime
60+
help: consider introducing a named lifetime parameter and update trait if needed
61+
|
62+
LL | async fn pin_ref_Self<'a>(self: Pin<&'a Self>, f: &'a u32) -> &u32 {
63+
| ++++ ++ ++
4064

4165
error[E0623]: lifetime mismatch
4266
--> $DIR/ref-self-async.rs:52:9
@@ -47,6 +71,12 @@ LL | async fn box_box_ref_Self(self: Box<Box<&Self>>, f: &u32) -> &u32 {
4771
| this parameter and the return type are declared with different lifetimes...
4872
LL | f
4973
| ^ ...but data from `f` is returned here
74+
|
75+
= note: each elided lifetime in input position becomes a distinct lifetime
76+
help: consider introducing a named lifetime parameter and update trait if needed
77+
|
78+
LL | async fn box_box_ref_Self<'a>(self: Box<Box<&'a Self>>, f: &'a u32) -> &u32 {
79+
| ++++ ++ ++
5080

5181
error[E0623]: lifetime mismatch
5282
--> $DIR/ref-self-async.rs:58:9
@@ -57,6 +87,12 @@ LL | async fn box_pin_ref_Self(self: Box<Pin<&Self>>, f: &u32) -> &u32 {
5787
| this parameter and the return type are declared with different lifetimes...
5888
LL | f
5989
| ^ ...but data from `f` is returned here
90+
|
91+
= note: each elided lifetime in input position becomes a distinct lifetime
92+
help: consider introducing a named lifetime parameter and update trait if needed
93+
|
94+
LL | async fn box_pin_ref_Self<'a>(self: Box<Pin<&'a Self>>, f: &'a u32) -> &u32 {
95+
| ++++ ++ ++
6096

6197
error[E0623]: lifetime mismatch
6298
--> $DIR/ref-self-async.rs:64:9
@@ -67,6 +103,12 @@ LL | async fn wrap_ref_Self_Self(self: Wrap<&Self, Self>, f: &u8) -> &u8 {
67103
| this parameter and the return type are declared with different lifetimes...
68104
LL | f
69105
| ^ ...but data from `f` is returned here
106+
|
107+
= note: each elided lifetime in input position becomes a distinct lifetime
108+
help: consider introducing a named lifetime parameter and update trait if needed
109+
|
110+
LL | async fn wrap_ref_Self_Self<'a>(self: Wrap<&'a Self, Self>, f: &'a u8) -> &u8 {
111+
| ++++ ++ ++
70112

71113
error: aborting due to 7 previous errors
72114

‎src/test/ui/self/elision/ref-self-async.nll.stderr

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ LL | async fn ref_self(&self, f: &u32) -> &u32 {
77
| let's call the lifetime of this reference `'2`
88
LL | f
99
| ^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
10+
|
11+
help: consider introducing a named lifetime parameter and update trait if needed
12+
|
13+
LL | async fn ref_self<'a>(&'a self, f: &'a u32) -> &u32 {
14+
| ++++ ++ ++
1015

1116
error: lifetime may not live long enough
1217
--> $DIR/ref-self-async.rs:34:9
@@ -17,6 +22,11 @@ LL | async fn ref_Self(self: &Self, f: &u32) -> &u32 {
1722
| let's call the lifetime of this reference `'2`
1823
LL | f
1924
| ^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
25+
|
26+
help: consider introducing a named lifetime parameter and update trait if needed
27+
|
28+
LL | async fn ref_Self<'a>(self: &'a Self, f: &'a u32) -> &u32 {
29+
| ++++ ++ ++
2030

2131
error: lifetime may not live long enough
2232
--> $DIR/ref-self-async.rs:40:9
@@ -27,6 +37,11 @@ LL | async fn box_ref_Self(self: Box<&Self>, f: &u32) -> &u32 {
2737
| let's call the lifetime of this reference `'2`
2838
LL | f
2939
| ^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
40+
|
41+
help: consider introducing a named lifetime parameter and update trait if needed
42+
|
43+
LL | async fn box_ref_Self<'a>(self: Box<&'a Self>, f: &'a u32) -> &u32 {
44+
| ++++ ++ ++
3045

3146
error: lifetime may not live long enough
3247
--> $DIR/ref-self-async.rs:46:9
@@ -37,6 +52,11 @@ LL | async fn pin_ref_Self(self: Pin<&Self>, f: &u32) -> &u32 {
3752
| let's call the lifetime of this reference `'2`
3853
LL | f
3954
| ^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
55+
|
56+
help: consider introducing a named lifetime parameter and update trait if needed
57+
|
58+
LL | async fn pin_ref_Self<'a>(self: Pin<&'a Self>, f: &'a u32) -> &u32 {
59+
| ++++ ++ ++
4060

4161
error: lifetime may not live long enough
4262
--> $DIR/ref-self-async.rs:52:9
@@ -47,6 +67,11 @@ LL | async fn box_box_ref_Self(self: Box<Box<&Self>>, f: &u32) -> &u32 {
4767
| let's call the lifetime of this reference `'2`
4868
LL | f
4969
| ^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
70+
|
71+
help: consider introducing a named lifetime parameter and update trait if needed
72+
|
73+
LL | async fn box_box_ref_Self<'a>(self: Box<Box<&'a Self>>, f: &'a u32) -> &u32 {
74+
| ++++ ++ ++
5075

5176
error: lifetime may not live long enough
5277
--> $DIR/ref-self-async.rs:58:9
@@ -57,6 +82,11 @@ LL | async fn box_pin_ref_Self(self: Box<Pin<&Self>>, f: &u32) -> &u32 {
5782
| let's call the lifetime of this reference `'2`
5883
LL | f
5984
| ^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
85+
|
86+
help: consider introducing a named lifetime parameter and update trait if needed
87+
|
88+
LL | async fn box_pin_ref_Self<'a>(self: Box<Pin<&'a Self>>, f: &'a u32) -> &u32 {
89+
| ++++ ++ ++
6090

6191
error: lifetime may not live long enough
6292
--> $DIR/ref-self-async.rs:64:9
@@ -67,6 +97,11 @@ LL | async fn wrap_ref_Self_Self(self: Wrap<&Self, Self>, f: &u8) -> &u8 {
6797
| let's call the lifetime of this reference `'2`
6898
LL | f
6999
| ^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
100+
|
101+
help: consider introducing a named lifetime parameter and update trait if needed
102+
|
103+
LL | async fn wrap_ref_Self_Self<'a>(self: Wrap<&'a Self, Self>, f: &'a u8) -> &u8 {
104+
| ++++ ++ ++
70105

71106
error: aborting due to 7 previous errors
72107

‎src/test/ui/self/elision/ref-struct-async.base.stderr

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ LL | async fn ref_Struct(self: &Struct, f: &u32) -> &u32 {
77
| this parameter and the return type are declared with different lifetimes...
88
LL | f
99
| ^ ...but data from `f` is returned here
10+
|
11+
= note: each elided lifetime in input position becomes a distinct lifetime
12+
help: consider introducing a named lifetime parameter and update trait if needed
13+
|
14+
LL | async fn ref_Struct<'a>(self: &'a Struct, f: &'a u32) -> &u32 {
15+
| ++++ ++ ++
1016

1117
error[E0623]: lifetime mismatch
1218
--> $DIR/ref-struct-async.rs:22:9
@@ -17,6 +23,12 @@ LL | async fn box_ref_Struct(self: Box<&Struct>, f: &u32) -> &u32 {
1723
| this parameter and the return type are declared with different lifetimes...
1824
LL | f
1925
| ^ ...but data from `f` is returned here
26+
|
27+
= note: each elided lifetime in input position becomes a distinct lifetime
28+
help: consider introducing a named lifetime parameter and update trait if needed
29+
|
30+
LL | async fn box_ref_Struct<'a>(self: Box<&'a Struct>, f: &'a u32) -> &u32 {
31+
| ++++ ++ ++
2032

2133
error[E0623]: lifetime mismatch
2234
--> $DIR/ref-struct-async.rs:28:9
@@ -27,6 +39,12 @@ LL | async fn pin_ref_Struct(self: Pin<&Struct>, f: &u32) -> &u32 {
2739
| this parameter and the return type are declared with different lifetimes...
2840
LL | f
2941
| ^ ...but data from `f` is returned here
42+
|
43+
= note: each elided lifetime in input position becomes a distinct lifetime
44+
help: consider introducing a named lifetime parameter and update trait if needed
45+
|
46+
LL | async fn pin_ref_Struct<'a>(self: Pin<&'a Struct>, f: &'a u32) -> &u32 {
47+
| ++++ ++ ++
3048

3149
error[E0623]: lifetime mismatch
3250
--> $DIR/ref-struct-async.rs:34:9
@@ -37,6 +55,12 @@ LL | async fn box_box_ref_Struct(self: Box<Box<&Struct>>, f: &u32) -> &u32 {
3755
| this parameter and the return type are declared with different lifetimes...
3856
LL | f
3957
| ^ ...but data from `f` is returned here
58+
|
59+
= note: each elided lifetime in input position becomes a distinct lifetime
60+
help: consider introducing a named lifetime parameter and update trait if needed
61+
|
62+
LL | async fn box_box_ref_Struct<'a>(self: Box<Box<&'a Struct>>, f: &'a u32) -> &u32 {
63+
| ++++ ++ ++
4064

4165
error[E0623]: lifetime mismatch
4266
--> $DIR/ref-struct-async.rs:40:9
@@ -47,6 +71,12 @@ LL | async fn box_pin_Struct(self: Box<Pin<&Struct>>, f: &u32) -> &u32 {
4771
| this parameter and the return type are declared with different lifetimes...
4872
LL | f
4973
| ^ ...but data from `f` is returned here
74+
|
75+
= note: each elided lifetime in input position becomes a distinct lifetime
76+
help: consider introducing a named lifetime parameter and update trait if needed
77+
|
78+
LL | async fn box_pin_Struct<'a>(self: Box<Pin<&'a Struct>>, f: &'a u32) -> &u32 {
79+
| ++++ ++ ++
5080

5181
error: aborting due to 5 previous errors
5282

‎src/test/ui/self/elision/ref-struct-async.nll.stderr

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ LL | async fn ref_Struct(self: &Struct, f: &u32) -> &u32 {
77
| let's call the lifetime of this reference `'2`
88
LL | f
99
| ^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
10+
|
11+
help: consider introducing a named lifetime parameter and update trait if needed
12+
|
13+
LL | async fn ref_Struct<'a>(self: &'a Struct, f: &'a u32) -> &u32 {
14+
| ++++ ++ ++
1015

1116
error: lifetime may not live long enough
1217
--> $DIR/ref-struct-async.rs:22:9
@@ -17,6 +22,11 @@ LL | async fn box_ref_Struct(self: Box<&Struct>, f: &u32) -> &u32 {
1722
| let's call the lifetime of this reference `'2`
1823
LL | f
1924
| ^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
25+
|
26+
help: consider introducing a named lifetime parameter and update trait if needed
27+
|
28+
LL | async fn box_ref_Struct<'a>(self: Box<&'a Struct>, f: &'a u32) -> &u32 {
29+
| ++++ ++ ++
2030

2131
error: lifetime may not live long enough
2232
--> $DIR/ref-struct-async.rs:28:9
@@ -27,6 +37,11 @@ LL | async fn pin_ref_Struct(self: Pin<&Struct>, f: &u32) -> &u32 {
2737
| let's call the lifetime of this reference `'2`
2838
LL | f
2939
| ^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
40+
|
41+
help: consider introducing a named lifetime parameter and update trait if needed
42+
|
43+
LL | async fn pin_ref_Struct<'a>(self: Pin<&'a Struct>, f: &'a u32) -> &u32 {
44+
| ++++ ++ ++
3045

3146
error: lifetime may not live long enough
3247
--> $DIR/ref-struct-async.rs:34:9
@@ -37,6 +52,11 @@ LL | async fn box_box_ref_Struct(self: Box<Box<&Struct>>, f: &u32) -> &u32 {
3752
| let's call the lifetime of this reference `'2`
3853
LL | f
3954
| ^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
55+
|
56+
help: consider introducing a named lifetime parameter and update trait if needed
57+
|
58+
LL | async fn box_box_ref_Struct<'a>(self: Box<Box<&'a Struct>>, f: &'a u32) -> &u32 {
59+
| ++++ ++ ++
4060

4161
error: lifetime may not live long enough
4262
--> $DIR/ref-struct-async.rs:40:9
@@ -47,6 +67,11 @@ LL | async fn box_pin_Struct(self: Box<Pin<&Struct>>, f: &u32) -> &u32 {
4767
| let's call the lifetime of this reference `'2`
4868
LL | f
4969
| ^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
70+
|
71+
help: consider introducing a named lifetime parameter and update trait if needed
72+
|
73+
LL | async fn box_pin_Struct<'a>(self: Box<Pin<&'a Struct>>, f: &'a u32) -> &u32 {
74+
| ++++ ++ ++
5075

5176
error: aborting due to 5 previous errors
5277

0 commit comments

Comments
 (0)
Please sign in to comment.