Skip to content

Commit 4b79b8b

Browse files
committed
Only use special async fn case for actual async fns in borrowck diagnostics.
1 parent bc6a2c1 commit 4b79b8b

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

compiler/rustc_borrowck/src/diagnostics/region_name.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
254254
/// *user* has a name for. In that case, we'll be able to map
255255
/// `fr` to a `Region<'tcx>`, and that region will be one of
256256
/// named variants.
257+
#[tracing::instrument(level = "trace", skip(self))]
257258
fn give_name_from_error_region(&self, fr: RegionVid) -> Option<RegionName> {
258259
let error_region = self.to_error_region(fr)?;
259260

@@ -290,7 +291,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
290291
if free_region.bound_region.is_named() {
291292
// A named region that is actually named.
292293
Some(RegionName { name, source: RegionNameSource::NamedFreeRegion(span) })
293-
} else {
294+
} else if let hir::IsAsync::Async = tcx.asyncness(self.mir_hir_id().owner) {
294295
// If we spuriously thought that the region is named, we should let the
295296
// system generate a true name for error messages. Currently this can
296297
// happen if we have an elided name in an async fn for example: the
@@ -301,6 +302,8 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
301302
name,
302303
source: RegionNameSource::AnonRegionFromAsyncFn(span),
303304
})
305+
} else {
306+
None
304307
}
305308
}
306309

@@ -362,6 +365,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
362365
/// | fn foo(x: &u32) { .. }
363366
/// ------- fully elaborated type of `x` is `&'1 u32`
364367
/// ```
368+
#[tracing::instrument(level = "trace", skip(self))]
365369
fn give_name_if_anonymous_region_appears_in_arguments(
366370
&self,
367371
fr: RegionVid,
@@ -651,6 +655,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
651655
/// | let x = Some(&22);
652656
/// - fully elaborated type of `x` is `Option<&'1 u32>`
653657
/// ```
658+
#[tracing::instrument(level = "trace", skip(self))]
654659
fn give_name_if_anonymous_region_appears_in_upvars(&self, fr: RegionVid) -> Option<RegionName> {
655660
let upvar_index = self.regioncx.get_upvar_index_for_region(self.infcx.tcx, fr)?;
656661
let (upvar_name, upvar_span) = self.regioncx.get_upvar_name_and_span_for_region(
@@ -670,6 +675,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
670675
/// must be a closure since, in a free fn, such an argument would
671676
/// have to either also appear in an argument (if using elision)
672677
/// or be early bound (named, not in argument).
678+
#[tracing::instrument(level = "trace", skip(self))]
673679
fn give_name_if_anonymous_region_appears_in_output(&self, fr: RegionVid) -> Option<RegionName> {
674680
let tcx = self.infcx.tcx;
675681
let hir = tcx.hir();
@@ -801,6 +807,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
801807
}
802808
}
803809

810+
#[tracing::instrument(level = "trace", skip(self))]
804811
fn give_name_if_anonymous_region_appears_in_yield_ty(
805812
&self,
806813
fr: RegionVid,

src/test/ui/issues/issue-37884.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ LL | | }
1111
|
1212
= note: expected fn pointer `fn(&mut RepeatMut<'a, T>) -> Option<_>`
1313
found fn pointer `fn(&'a mut RepeatMut<'a, T>) -> Option<_>`
14-
note: the anonymous lifetime as defined here...
14+
note: the anonymous lifetime #1 defined here...
1515
--> $DIR/issue-37884.rs:6:5
1616
|
1717
LL | fn next(&'a mut self) -> Option<Self::Item>

0 commit comments

Comments
 (0)