+ fn print_region(
+ mut self: PrintCx<'_, '_, '_, Self>,
+ region: ty::Region<'_>,
+ ) -> Result<Self::Region, Self::Error> {
+ // Watch out for region highlights.
+ let highlight = self.printer.region_highlight_mode;
+ if let Some(n) = highlight.region_highlighted(region) {
+ write!(self.printer, "'{}", n)?;
+ return Ok(self.printer);
+ }
+
+ if self.config.is_verbose {
+ return region.print_debug(self);
+ }
+
+ // These printouts are concise. They do not contain all the information
+ // the user might want to diagnose an error, but there is basically no way
+ // to fit that into a short string. Hence the recommendation to use
+ // `explain_region()` or `note_and_explain_region()`.
+ match *region {
+ ty::ReEarlyBound(ref data) => {
+ if data.name != "'_" {
+ write!(self.printer, "{}", data.name)?;
+ }
+ }
+ ty::ReLateBound(_, br) |
+ ty::ReFree(ty::FreeRegion { bound_region: br, .. }) |
+ ty::RePlaceholder(ty::Placeholder { name: br, .. }) => {
+ if let ty::BrNamed(_, name) = br {
+ if name != "" && name != "'_" {
+ write!(self.printer, "{}", name)?;
+ return Ok(self.printer);
+ }
+ }
+
+ if let Some((region, counter)) = highlight.highlight_bound_region {
+ if br == region {
+ write!(self.printer, "'{}", counter)?;
+ }
+ }
+ }
+ ty::ReScope(scope) if self.config.identify_regions => {
+ match scope.data {
+ region::ScopeData::Node =>
+ write!(self.printer, "'{}s", scope.item_local_id().as_usize())?,
+ region::ScopeData::CallSite =>
+ write!(self.printer, "'{}cs", scope.item_local_id().as_usize())?,
+ region::ScopeData::Arguments =>
+ write!(self.printer, "'{}as", scope.item_local_id().as_usize())?,
+ region::ScopeData::Destruction =>
+ write!(self.printer, "'{}ds", scope.item_local_id().as_usize())?,
+ region::ScopeData::Remainder(first_statement_index) => write!(self.printer,
+ "'{}_{}rs",
+ scope.item_local_id().as_usize(),
+ first_statement_index.index()
+ )?,
+ }
+ }
+ ty::ReVar(region_vid) if self.config.identify_regions => {
+ write!(self.printer, "{:?}", region_vid)?;
+ }
+ ty::ReVar(_) => {}
+ ty::ReScope(_) |
+ ty::ReErased => {}
+ ty::ReStatic => write!(self.printer, "'static")?,
+ ty::ReEmpty => write!(self.printer, "'<empty>")?,
+
+ // The user should never encounter these in unsubstituted form.
+ ty::ReClosureBound(vid) => write!(self.printer, "{:?}", vid)?,
+ }
+
+ Ok(self.printer)
+ }
+