1 use std::fmt::{self, Display};
3 use rustc_errors::DiagnosticBuilder;
5 use rustc_hir::def::{DefKind, Res};
6 use rustc_middle::ty::print::RegionHighlightMode;
7 use rustc_middle::ty::subst::{GenericArgKind, SubstsRef};
8 use rustc_middle::ty::{self, RegionVid, Ty};
9 use rustc_span::symbol::kw;
10 use rustc_span::{symbol::Symbol, Span, DUMMY_SP};
12 use crate::borrow_check::{nll::ToRegionVid, universal_regions::DefiningTy, MirBorrowckCtxt};
14 /// A name for a particular region used in emitting diagnostics. This name could be a generated
15 /// name like `'1`, a name used by the user like `'a`, or a name like `'static`.
16 #[derive(Debug, Clone)]
17 crate struct RegionName {
18 /// The name of the region (interned).
20 /// Where the region comes from.
21 crate source: RegionNameSource,
24 /// Denotes the source of a region that is named by a `RegionName`. For example, a free region that
25 /// was named by the user would get `NamedFreeRegion` and `'static` lifetime would get `Static`.
26 /// This helps to print the right kinds of diagnostics.
27 #[derive(Debug, Clone)]
28 crate enum RegionNameSource {
29 /// A bound (not free) region that was substituted at the def site (not an HRTB).
30 NamedEarlyBoundRegion(Span),
31 /// A free region that the user has a name (`'a`) for.
32 NamedFreeRegion(Span),
33 /// The `'static` region.
35 /// The free region corresponding to the environment of a closure.
36 SynthesizedFreeEnvRegion(Span, String),
37 /// The region corresponding to an argument.
38 AnonRegionFromArgument(RegionNameHighlight),
39 /// The region corresponding to a closure upvar.
40 AnonRegionFromUpvar(Span, String),
41 /// The region corresponding to the return type of a closure.
42 AnonRegionFromOutput(Span, String, String),
43 /// The region from a type yielded by a generator.
44 AnonRegionFromYieldTy(Span, String),
45 /// An anonymous region from an async fn.
46 AnonRegionFromAsyncFn(Span),
49 /// Describes what to highlight to explain to the user that we're giving an anonymous region a
50 /// synthesized name, and how to highlight it.
51 #[derive(Debug, Clone)]
52 crate enum RegionNameHighlight {
53 /// The anonymous region corresponds to a reference that was found by traversing the type in the HIR.
55 /// The anonymous region corresponds to a `'_` in the generics list of a struct/enum/union.
56 MatchedAdtAndSegment(Span),
57 /// The anonymous region corresponds to a region where the type annotation is completely missing
58 /// from the code, e.g. in a closure arguments `|x| { ... }`, where `x` is a reference.
59 CannotMatchHirTy(Span, String),
63 crate fn was_named(&self) -> bool {
65 RegionNameSource::NamedEarlyBoundRegion(..)
66 | RegionNameSource::NamedFreeRegion(..)
67 | RegionNameSource::Static => true,
68 RegionNameSource::SynthesizedFreeEnvRegion(..)
69 | RegionNameSource::AnonRegionFromArgument(..)
70 | RegionNameSource::AnonRegionFromUpvar(..)
71 | RegionNameSource::AnonRegionFromOutput(..)
72 | RegionNameSource::AnonRegionFromYieldTy(..)
73 | RegionNameSource::AnonRegionFromAsyncFn(..) => false,
77 crate fn span(&self) -> Option<Span> {
79 RegionNameSource::Static => None,
80 RegionNameSource::NamedEarlyBoundRegion(span)
81 | RegionNameSource::NamedFreeRegion(span)
82 | RegionNameSource::SynthesizedFreeEnvRegion(span, _)
83 | RegionNameSource::AnonRegionFromUpvar(span, _)
84 | RegionNameSource::AnonRegionFromOutput(span, _, _)
85 | RegionNameSource::AnonRegionFromYieldTy(span, _)
86 | RegionNameSource::AnonRegionFromAsyncFn(span) => Some(span),
87 RegionNameSource::AnonRegionFromArgument(ref highlight) => match *highlight {
88 RegionNameHighlight::MatchedHirTy(span)
89 | RegionNameHighlight::MatchedAdtAndSegment(span)
90 | RegionNameHighlight::CannotMatchHirTy(span, _) => Some(span),
95 crate fn highlight_region_name(&self, diag: &mut DiagnosticBuilder<'_>) {
97 RegionNameSource::NamedFreeRegion(span)
98 | RegionNameSource::NamedEarlyBoundRegion(span) => {
99 diag.span_label(*span, format!("lifetime `{}` defined here", self));
101 RegionNameSource::SynthesizedFreeEnvRegion(span, note) => {
104 format!("lifetime `{}` represents this closure's body", self),
108 RegionNameSource::AnonRegionFromArgument(RegionNameHighlight::CannotMatchHirTy(
112 diag.span_label(*span, format!("has type `{}`", type_name));
114 RegionNameSource::AnonRegionFromArgument(RegionNameHighlight::MatchedHirTy(span))
115 | RegionNameSource::AnonRegionFromAsyncFn(span) => {
118 format!("let's call the lifetime of this reference `{}`", self),
121 RegionNameSource::AnonRegionFromArgument(
122 RegionNameHighlight::MatchedAdtAndSegment(span),
124 diag.span_label(*span, format!("let's call this `{}`", self));
126 RegionNameSource::AnonRegionFromUpvar(span, upvar_name) => {
129 format!("lifetime `{}` appears in the type of `{}`", self, upvar_name),
132 RegionNameSource::AnonRegionFromOutput(span, mir_description, type_name) => {
133 diag.span_label(*span, format!("return type{} is {}", mir_description, type_name));
135 RegionNameSource::AnonRegionFromYieldTy(span, type_name) => {
136 diag.span_label(*span, format!("yield type is {}", type_name));
138 RegionNameSource::Static => {}
143 impl Display for RegionName {
144 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
145 write!(f, "{}", self.name)
149 impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
150 /// Generate a synthetic region named `'N`, where `N` is the next value of the counter. Then,
151 /// increment the counter.
153 /// This is _not_ idempotent. Call `give_region_a_name` when possible.
154 fn synthesize_region_name(&self) -> Symbol {
155 let c = self.next_region_name.replace_with(|counter| *counter + 1);
156 Symbol::intern(&format!("'{:?}", c))
159 /// Maps from an internal MIR region vid to something that we can
160 /// report to the user. In some cases, the region vids will map
161 /// directly to lifetimes that the user has a name for (e.g.,
162 /// `'static`). But frequently they will not, in which case we
163 /// have to find some way to identify the lifetime to the user. To
164 /// that end, this function takes a "diagnostic" so that it can
165 /// create auxiliary notes as needed.
167 /// The names are memoized, so this is both cheap to recompute and idempotent.
169 /// Example (function arguments):
171 /// Suppose we are trying to give a name to the lifetime of the
175 /// fn foo(x: &u32) { .. }
178 /// This function would create a label like this:
181 /// | fn foo(x: &u32) { .. }
182 /// ------- fully elaborated type of `x` is `&'1 u32`
185 /// and then return the name `'1` for us to use.
186 crate fn give_region_a_name(&self, fr: RegionVid) -> Option<RegionName> {
188 "give_region_a_name(fr={:?}, counter={:?})",
190 self.next_region_name.try_borrow().unwrap()
193 assert!(self.regioncx.universal_regions().is_universal_region(fr));
195 if let Some(value) = self.region_names.try_borrow_mut().unwrap().get(&fr) {
196 return Some(value.clone());
200 .give_name_from_error_region(fr)
201 .or_else(|| self.give_name_if_anonymous_region_appears_in_arguments(fr))
202 .or_else(|| self.give_name_if_anonymous_region_appears_in_upvars(fr))
203 .or_else(|| self.give_name_if_anonymous_region_appears_in_output(fr))
204 .or_else(|| self.give_name_if_anonymous_region_appears_in_yield_ty(fr));
206 if let Some(ref value) = value {
207 self.region_names.try_borrow_mut().unwrap().insert(fr, value.clone());
210 debug!("give_region_a_name: gave name {:?}", value);
214 /// Checks for the case where `fr` maps to something that the
215 /// *user* has a name for. In that case, we'll be able to map
216 /// `fr` to a `Region<'tcx>`, and that region will be one of
218 fn give_name_from_error_region(&self, fr: RegionVid) -> Option<RegionName> {
219 let error_region = self.to_error_region(fr)?;
221 let tcx = self.infcx.tcx;
223 debug!("give_region_a_name: error_region = {:?}", error_region);
225 ty::ReEarlyBound(ebr) => {
227 let span = tcx.hir().span_if_local(ebr.def_id).unwrap_or(DUMMY_SP);
230 source: RegionNameSource::NamedEarlyBoundRegion(span),
238 Some(RegionName { name: kw::StaticLifetime, source: RegionNameSource::Static })
241 ty::ReFree(free_region) => match free_region.bound_region {
242 ty::BoundRegion::BrNamed(region_def_id, name) => {
243 // Get the span to point to, even if we don't use the name.
244 let span = tcx.hir().span_if_local(region_def_id).unwrap_or(DUMMY_SP);
246 "bound region named: {:?}, is_named: {:?}",
248 free_region.bound_region.is_named()
251 if free_region.bound_region.is_named() {
252 // A named region that is actually named.
253 Some(RegionName { name, source: RegionNameSource::NamedFreeRegion(span) })
255 // If we spuriously thought that the region is named, we should let the
256 // system generate a true name for error messages. Currently this can
257 // happen if we have an elided name in an async fn for example: the
258 // compiler will generate a region named `'_`, but reporting such a name is
259 // not actually useful, so we synthesize a name for it instead.
260 let name = self.synthesize_region_name();
263 source: RegionNameSource::AnonRegionFromAsyncFn(span),
268 ty::BoundRegion::BrEnv => {
269 let mir_hir_id = self.infcx.tcx.hir().as_local_hir_id(self.mir_def_id);
270 let def_ty = self.regioncx.universal_regions().defining_ty;
272 if let DefiningTy::Closure(_, substs) = def_ty {
273 let args_span = if let hir::ExprKind::Closure(_, _, _, span, _) =
274 tcx.hir().expect_expr(mir_hir_id).kind
278 bug!("Closure is not defined by a closure expr");
280 let region_name = self.synthesize_region_name();
282 let closure_kind_ty = substs.as_closure().kind_ty();
283 let note = match closure_kind_ty.to_opt_closure_kind() {
284 Some(ty::ClosureKind::Fn) => {
285 "closure implements `Fn`, so references to captured variables \
286 can't escape the closure"
288 Some(ty::ClosureKind::FnMut) => {
289 "closure implements `FnMut`, so references to captured variables \
290 can't escape the closure"
292 Some(ty::ClosureKind::FnOnce) => {
293 bug!("BrEnv in a `FnOnce` closure");
295 None => bug!("Closure kind not inferred in borrow check"),
300 source: RegionNameSource::SynthesizedFreeEnvRegion(
306 // Can't have BrEnv in functions, constants or generators.
307 bug!("BrEnv outside of closure.");
311 ty::BoundRegion::BrAnon(_) => None,
316 | ty::RePlaceholder(..)
318 | ty::ReErased => None,
322 /// Finds an argument that contains `fr` and label it with a fully
323 /// elaborated type, returning something like `'1`. Result looks
327 /// | fn foo(x: &u32) { .. }
328 /// ------- fully elaborated type of `x` is `&'1 u32`
330 fn give_name_if_anonymous_region_appears_in_arguments(
333 ) -> Option<RegionName> {
334 let implicit_inputs = self.regioncx.universal_regions().defining_ty.implicit_inputs();
335 let argument_index = self.regioncx.get_argument_index_for_region(self.infcx.tcx, fr)?;
337 let arg_ty = self.regioncx.universal_regions().unnormalized_input_tys
338 [implicit_inputs + argument_index];
339 if let Some(highlight) =
340 self.give_name_if_we_can_match_hir_ty_from_argument(fr, arg_ty, argument_index)
342 return Some(RegionName {
343 name: self.synthesize_region_name(),
344 source: RegionNameSource::AnonRegionFromArgument(highlight),
348 let counter = *self.next_region_name.try_borrow().unwrap();
349 if let Some(highlight) = self.give_name_if_we_cannot_match_hir_ty(fr, arg_ty, counter) {
351 // This counter value will already have been used, so this function will increment
352 // it so the next value will be used next and return the region name that would
354 name: self.synthesize_region_name(),
355 source: RegionNameSource::AnonRegionFromArgument(highlight),
362 fn give_name_if_we_can_match_hir_ty_from_argument(
364 needle_fr: RegionVid,
365 argument_ty: Ty<'tcx>,
366 argument_index: usize,
367 ) -> Option<RegionNameHighlight> {
368 let mir_hir_id = self.infcx.tcx.hir().as_local_hir_id(self.mir_def_id);
369 let fn_decl = self.infcx.tcx.hir().fn_decl_by_hir_id(mir_hir_id)?;
370 let argument_hir_ty: &hir::Ty<'_> = fn_decl.inputs.get(argument_index)?;
371 match argument_hir_ty.kind {
372 // This indicates a variable with no type annotation, like
373 // `|x|`... in that case, we can't highlight the type but
374 // must highlight the variable.
375 // NOTE(eddyb) this is handled in/by the sole caller
376 // (`give_name_if_anonymous_region_appears_in_arguments`).
377 hir::TyKind::Infer => None,
379 _ => self.give_name_if_we_can_match_hir_ty(needle_fr, argument_ty, argument_hir_ty),
383 /// Attempts to highlight the specific part of a type in an argument
384 /// that has no type annotation.
385 /// For example, we might produce an annotation like this:
391 /// | | has type `&'1 u32`
392 /// | has type `&'2 u32`
394 fn give_name_if_we_cannot_match_hir_ty(
396 needle_fr: RegionVid,
397 argument_ty: Ty<'tcx>,
399 ) -> Option<RegionNameHighlight> {
400 let mut highlight = RegionHighlightMode::default();
401 highlight.highlighting_region_vid(needle_fr, counter);
402 let type_name = self.infcx.extract_type_name(&argument_ty, Some(highlight)).0;
405 "give_name_if_we_cannot_match_hir_ty: type_name={:?} needle_fr={:?}",
408 if type_name.find(&format!("'{}", counter)).is_some() {
409 // Only add a label if we can confirm that a region was labelled.
411 self.regioncx.get_argument_index_for_region(self.infcx.tcx, needle_fr)?;
412 let (_, span) = self.regioncx.get_argument_name_and_span_for_region(
418 Some(RegionNameHighlight::CannotMatchHirTy(span, type_name))
424 /// Attempts to highlight the specific part of a type annotation
425 /// that contains the anonymous reference we want to give a name
426 /// to. For example, we might produce an annotation like this:
429 /// | fn a<T>(items: &[T]) -> Box<dyn Iterator<Item = &T>> {
430 /// | - let's call the lifetime of this reference `'1`
433 /// the way this works is that we match up `argument_ty`, which is
434 /// a `Ty<'tcx>` (the internal form of the type) with
435 /// `argument_hir_ty`, a `hir::Ty` (the syntax of the type
436 /// annotation). We are descending through the types stepwise,
437 /// looking in to find the region `needle_fr` in the internal
438 /// type. Once we find that, we can use the span of the `hir::Ty`
439 /// to add the highlight.
441 /// This is a somewhat imperfect process, so along the way we also
442 /// keep track of the **closest** type we've found. If we fail to
443 /// find the exact `&` or `'_` to highlight, then we may fall back
444 /// to highlighting that closest type instead.
445 fn give_name_if_we_can_match_hir_ty(
447 needle_fr: RegionVid,
448 argument_ty: Ty<'tcx>,
449 argument_hir_ty: &hir::Ty<'_>,
450 ) -> Option<RegionNameHighlight> {
451 let search_stack: &mut Vec<(Ty<'tcx>, &hir::Ty<'_>)> =
452 &mut vec![(argument_ty, argument_hir_ty)];
454 while let Some((ty, hir_ty)) = search_stack.pop() {
455 match (&ty.kind, &hir_ty.kind) {
456 // Check if the `argument_ty` is `&'X ..` where `'X`
457 // is the region we are looking for -- if so, and we have a `&T`
458 // on the RHS, then we want to highlight the `&` like so:
461 // - let's call the lifetime of this reference `'1`
463 ty::Ref(region, referent_ty, _),
464 hir::TyKind::Rptr(_lifetime, referent_hir_ty),
466 if region.to_region_vid() == needle_fr {
467 // Just grab the first character, the `&`.
468 let source_map = self.infcx.tcx.sess.source_map();
469 let ampersand_span = source_map.start_point(hir_ty.span);
471 return Some(RegionNameHighlight::MatchedHirTy(ampersand_span));
474 // Otherwise, let's descend into the referent types.
475 search_stack.push((referent_ty, &referent_hir_ty.ty));
478 // Match up something like `Foo<'1>`
480 ty::Adt(_adt_def, substs),
481 hir::TyKind::Path(hir::QPath::Resolved(None, path)),
484 // Type parameters of the type alias have no reason to
485 // be the same as those of the ADT.
486 // FIXME: We should be able to do something similar to
487 // match_adt_and_segment in this case.
488 Res::Def(DefKind::TyAlias, _) => (),
490 if let Some(last_segment) = path.segments.last() {
491 if let Some(highlight) = self.match_adt_and_segment(
497 return Some(highlight);
504 // The following cases don't have lifetimes, so we
505 // just worry about trying to match up the rustc type
506 // with the HIR types:
507 (ty::Tuple(elem_tys), hir::TyKind::Tup(elem_hir_tys)) => {
508 search_stack.extend(elem_tys.iter().map(|k| k.expect_ty()).zip(*elem_hir_tys));
511 (ty::Slice(elem_ty), hir::TyKind::Slice(elem_hir_ty))
512 | (ty::Array(elem_ty, _), hir::TyKind::Array(elem_hir_ty, _)) => {
513 search_stack.push((elem_ty, elem_hir_ty));
516 (ty::RawPtr(mut_ty), hir::TyKind::Ptr(mut_hir_ty)) => {
517 search_stack.push((mut_ty.ty, &mut_hir_ty.ty));
521 // FIXME there are other cases that we could trace
529 /// We've found an enum/struct/union type with the substitutions
530 /// `substs` and -- in the HIR -- a path type with the final
531 /// segment `last_segment`. Try to find a `'_` to highlight in
532 /// the generic args (or, if not, to produce new zipped pairs of
533 /// types+hir to search through).
534 fn match_adt_and_segment<'hir>(
536 substs: SubstsRef<'tcx>,
537 needle_fr: RegionVid,
538 last_segment: &'hir hir::PathSegment<'hir>,
539 search_stack: &mut Vec<(Ty<'tcx>, &'hir hir::Ty<'hir>)>,
540 ) -> Option<RegionNameHighlight> {
541 // Did the user give explicit arguments? (e.g., `Foo<..>`)
542 let args = last_segment.args.as_ref()?;
544 self.try_match_adt_and_generic_args(substs, needle_fr, args, search_stack)?;
545 match lifetime.name {
546 hir::LifetimeName::Param(_)
547 | hir::LifetimeName::Error
548 | hir::LifetimeName::Static
549 | hir::LifetimeName::Underscore => {
550 let lifetime_span = lifetime.span;
551 Some(RegionNameHighlight::MatchedAdtAndSegment(lifetime_span))
554 hir::LifetimeName::ImplicitObjectLifetimeDefault | hir::LifetimeName::Implicit => {
555 // In this case, the user left off the lifetime; so
556 // they wrote something like:
562 // where the fully elaborated form is `Foo<'_, '1,
563 // T>`. We don't consider this a match; instead we let
564 // the "fully elaborated" type fallback above handle
571 /// We've found an enum/struct/union type with the substitutions
572 /// `substs` and -- in the HIR -- a path with the generic
573 /// arguments `args`. If `needle_fr` appears in the args, return
574 /// the `hir::Lifetime` that corresponds to it. If not, push onto
575 /// `search_stack` the types+hir to search through.
576 fn try_match_adt_and_generic_args<'hir>(
578 substs: SubstsRef<'tcx>,
579 needle_fr: RegionVid,
580 args: &'hir hir::GenericArgs<'hir>,
581 search_stack: &mut Vec<(Ty<'tcx>, &'hir hir::Ty<'hir>)>,
582 ) -> Option<&'hir hir::Lifetime> {
583 for (kind, hir_arg) in substs.iter().zip(args.args) {
584 match (kind.unpack(), hir_arg) {
585 (GenericArgKind::Lifetime(r), hir::GenericArg::Lifetime(lt)) => {
586 if r.to_region_vid() == needle_fr {
591 (GenericArgKind::Type(ty), hir::GenericArg::Type(hir_ty)) => {
592 search_stack.push((ty, hir_ty));
595 (GenericArgKind::Const(_ct), hir::GenericArg::Const(_hir_ct)) => {
596 // Lifetimes cannot be found in consts, so we don't need
597 // to search anything here.
601 GenericArgKind::Lifetime(_)
602 | GenericArgKind::Type(_)
603 | GenericArgKind::Const(_),
606 // I *think* that HIR lowering should ensure this
607 // doesn't happen, even in erroneous
608 // programs. Else we should use delay-span-bug.
611 "unmatched subst and hir arg: found {:?} vs {:?}",
622 /// Finds a closure upvar that contains `fr` and label it with a
623 /// fully elaborated type, returning something like `'1`. Result
627 /// | let x = Some(&22);
628 /// - fully elaborated type of `x` is `Option<&'1 u32>`
630 fn give_name_if_anonymous_region_appears_in_upvars(&self, fr: RegionVid) -> Option<RegionName> {
631 let upvar_index = self.regioncx.get_upvar_index_for_region(self.infcx.tcx, fr)?;
632 let (upvar_name, upvar_span) = self.regioncx.get_upvar_name_and_span_for_region(
637 let region_name = self.synthesize_region_name();
641 source: RegionNameSource::AnonRegionFromUpvar(upvar_span, upvar_name.to_string()),
645 /// Checks for arguments appearing in the (closure) return type. It
646 /// must be a closure since, in a free fn, such an argument would
647 /// have to either also appear in an argument (if using elision)
648 /// or be early bound (named, not in argument).
649 fn give_name_if_anonymous_region_appears_in_output(&self, fr: RegionVid) -> Option<RegionName> {
650 let tcx = self.infcx.tcx;
652 let return_ty = self.regioncx.universal_regions().unnormalized_output_ty;
653 debug!("give_name_if_anonymous_region_appears_in_output: return_ty = {:?}", return_ty);
654 if !tcx.any_free_region_meets(&return_ty, |r| r.to_region_vid() == fr) {
658 let mut highlight = RegionHighlightMode::default();
659 highlight.highlighting_region_vid(fr, *self.next_region_name.try_borrow().unwrap());
660 let type_name = self.infcx.extract_type_name(&return_ty, Some(highlight)).0;
662 let mir_hir_id = tcx.hir().as_local_hir_id(self.mir_def_id);
664 let (return_span, mir_description) = match tcx.hir().get(mir_hir_id) {
665 hir::Node::Expr(hir::Expr {
666 kind: hir::ExprKind::Closure(_, return_ty, _, span, gen_move),
669 match return_ty.output {
670 hir::FnRetTy::DefaultReturn(_) => tcx.sess.source_map().end_point(*span),
671 hir::FnRetTy::Return(_) => return_ty.output.span(),
673 if gen_move.is_some() { " of generator" } else { " of closure" },
675 hir::Node::ImplItem(hir::ImplItem {
676 kind: hir::ImplItemKind::Fn(method_sig, _),
678 }) => (method_sig.decl.output.span(), ""),
679 _ => (self.body.span, ""),
683 // This counter value will already have been used, so this function will increment it
684 // so the next value will be used next and return the region name that would have been
686 name: self.synthesize_region_name(),
687 source: RegionNameSource::AnonRegionFromOutput(
689 mir_description.to_string(),
695 fn give_name_if_anonymous_region_appears_in_yield_ty(
698 ) -> Option<RegionName> {
699 // Note: generators from `async fn` yield `()`, so we don't have to
700 // worry about them here.
701 let yield_ty = self.regioncx.universal_regions().yield_ty?;
702 debug!("give_name_if_anonymous_region_appears_in_yield_ty: yield_ty = {:?}", yield_ty,);
704 let tcx = self.infcx.tcx;
706 if !tcx.any_free_region_meets(&yield_ty, |r| r.to_region_vid() == fr) {
710 let mut highlight = RegionHighlightMode::default();
711 highlight.highlighting_region_vid(fr, *self.next_region_name.try_borrow().unwrap());
712 let type_name = self.infcx.extract_type_name(&yield_ty, Some(highlight)).0;
714 let mir_hir_id = tcx.hir().as_local_hir_id(self.mir_def_id);
716 let yield_span = match tcx.hir().get(mir_hir_id) {
717 hir::Node::Expr(hir::Expr {
718 kind: hir::ExprKind::Closure(_, _, _, span, _), ..
719 }) => (tcx.sess.source_map().end_point(*span)),
724 "give_name_if_anonymous_region_appears_in_yield_ty: \
725 type_name = {:?}, yield_span = {:?}",
726 yield_span, type_name,
730 name: self.synthesize_region_name(),
731 source: RegionNameSource::AnonRegionFromYieldTy(yield_span, type_name),