diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs index d5e4b6de581c3..ac04d1bbed3db 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs @@ -214,7 +214,7 @@ impl<'a, 'tcx> AstConv<'tcx> for FnCtxt<'a, 'tcx> { fn re_infer(&self, def: Option<&ty::GenericParamDef>, span: Span) -> Option> { let v = match def { - Some(def) => infer::EarlyBoundRegion(span, def.name), + Some(def) => infer::EarlyBoundRegion(span, def.def_id), None => infer::MiscVariable(span), }; Some(self.next_region_var(v)) diff --git a/compiler/rustc_hir_typeck/src/generator_interior/mod.rs b/compiler/rustc_hir_typeck/src/generator_interior/mod.rs index 7bbfb70f2c3a3..dffad1092da75 100644 --- a/compiler/rustc_hir_typeck/src/generator_interior/mod.rs +++ b/compiler/rustc_hir_typeck/src/generator_interior/mod.rs @@ -228,8 +228,8 @@ pub fn resolve_interior<'a, 'tcx>( // typeck had previously found constraints that would cause them to be related. let mut counter = 0; - let mut mk_bound_region = |span| { - let kind = ty::BrAnon(counter, span); + let mut mk_bound_region = |def_id| { + let kind = ty::BrAnon(counter, def_id); let var = ty::BoundVar::from_u32(counter); counter += 1; ty::BoundRegion { var, kind } @@ -240,22 +240,18 @@ pub fn resolve_interior<'a, 'tcx>( ty::ReVar(vid) => { let origin = fcx.region_var_origin(vid); match origin { - RegionVariableOrigin::EarlyBoundRegion(span, _) => { - mk_bound_region(Some(span)) + RegionVariableOrigin::EarlyBoundRegion(_, def_id) => { + mk_bound_region(Some(def_id)) } _ => mk_bound_region(None), } } // FIXME: these should use `BrNamed` - ty::ReEarlyBound(region) => { - mk_bound_region(Some(fcx.tcx.def_span(region.def_id))) - } + ty::ReEarlyBound(region) => mk_bound_region(Some(region.def_id)), ty::ReLateBound(_, ty::BoundRegion { kind, .. }) | ty::ReFree(ty::FreeRegion { bound_region: kind, .. }) => match kind { - ty::BoundRegionKind::BrAnon(_, span) => mk_bound_region(span), - ty::BoundRegionKind::BrNamed(def_id, _) => { - mk_bound_region(Some(fcx.tcx.def_span(def_id))) - } + ty::BoundRegionKind::BrAnon(_, def_id) => mk_bound_region(def_id), + ty::BoundRegionKind::BrNamed(def_id, _) => mk_bound_region(Some(def_id)), ty::BoundRegionKind::BrEnv => mk_bound_region(None), }, _ => mk_bound_region(None), diff --git a/compiler/rustc_infer/src/errors/note_and_explain.rs b/compiler/rustc_infer/src/errors/note_and_explain.rs index 7aaa5ce2f4242..21f9dd5d35e37 100644 --- a/compiler/rustc_infer/src/errors/note_and_explain.rs +++ b/compiler/rustc_infer/src/errors/note_and_explain.rs @@ -89,11 +89,11 @@ impl<'a> DescriptionCtx<'a> { }; me.span = Some(sp); } - ty::BrAnon(idx, span) => { + ty::BrAnon(idx, def_id) => { me.kind = "anon_num_here"; me.num_arg = idx+1; - me.span = match span { - Some(_) => span, + me.span = match def_id { + Some(def_id) => Some(tcx.def_span(def_id)), None => Some(tcx.def_span(scope)), } }, diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs index 22f32251f6df0..aba0cc6a7cd3f 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs @@ -211,10 +211,10 @@ fn msg_span_from_early_bound_and_free_regions<'tcx>( }; (text, sp) } - ty::BrAnon(idx, span) => ( + ty::BrAnon(idx, def_id) => ( format!("the anonymous lifetime #{} defined here", idx + 1), - match span { - Some(span) => span, + match def_id { + Some(def_id) => tcx.def_span(def_id), None => tcx.def_span(scope) } ), @@ -3048,7 +3048,9 @@ impl<'tcx> InferCtxt<'tcx> { br_string(br), self.tcx.associated_item(def_id).name ), - infer::EarlyBoundRegion(_, name) => format!(" for lifetime parameter `{}`", name), + infer::EarlyBoundRegion(_, def_id) => { + format!(" for lifetime parameter `{}`", self.tcx.item_name(def_id)) + } infer::UpvarRegion(ref upvar_id, _) => { let var_name = self.tcx.hir().name(upvar_id.var_path.hir_id); format!(" for capture of `{}` by closure", var_name) diff --git a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/placeholder_relation.rs b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/placeholder_relation.rs index c42240f21724f..97b173d93f5a0 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/placeholder_relation.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/placeholder_relation.rs @@ -22,14 +22,16 @@ impl<'tcx> NiceRegionError<'_, 'tcx> { ty::BrNamed(def_id, symbol) => { (Some(self.tcx().def_span(def_id)), Some(symbol)) } - ty::BrAnon(_, span) => (*span, None), + ty::BrAnon(_, Some(def_id)) => (Some(self.tcx().def_span(def_id)), None), + ty::BrAnon(_, None) => (None, None), ty::BrEnv => (None, None), }; let (sup_span, sup_symbol) = match sup_name { ty::BrNamed(def_id, symbol) => { (Some(self.tcx().def_span(def_id)), Some(symbol)) } - ty::BrAnon(_, span) => (*span, None), + ty::BrAnon(_, Some(def_id)) => (Some(self.tcx().def_span(def_id)), None), + ty::BrAnon(_, None) => (None, None), ty::BrEnv => (None, None), }; match (sub_span, sup_span, sub_symbol, sup_symbol) { diff --git a/compiler/rustc_infer/src/infer/mod.rs b/compiler/rustc_infer/src/infer/mod.rs index ccba197dc80b7..c916f465c3062 100644 --- a/compiler/rustc_infer/src/infer/mod.rs +++ b/compiler/rustc_infer/src/infer/mod.rs @@ -33,7 +33,6 @@ use rustc_middle::ty::visit::TypeVisitable; pub use rustc_middle::ty::IntVarValue; use rustc_middle::ty::{self, GenericParamDefKind, InferConst, Ty, TyCtxt}; use rustc_middle::ty::{ConstVid, FloatVid, IntVid, TyVid}; -use rustc_span::symbol::Symbol; use rustc_span::{Span, DUMMY_SP}; use std::cell::{Cell, RefCell}; @@ -470,7 +469,7 @@ pub enum RegionVariableOrigin { Coercion(Span), /// Region variables created as the values for early-bound regions - EarlyBoundRegion(Span, Symbol), + EarlyBoundRegion(Span, DefId), /// Region variables created for bound regions /// in a function or method that is called @@ -1181,7 +1180,7 @@ impl<'tcx> InferCtxt<'tcx> { GenericParamDefKind::Lifetime => { // Create a region inference variable for the given // region parameter definition. - self.next_region_var(EarlyBoundRegion(span, param.name)).into() + self.next_region_var(EarlyBoundRegion(span, param.def_id)).into() } GenericParamDefKind::Type { .. } => { // Create a type inference variable for the given diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs index 49d82b503a4bb..84f841c713101 100644 --- a/compiler/rustc_middle/src/ty/sty.rs +++ b/compiler/rustc_middle/src/ty/sty.rs @@ -59,7 +59,7 @@ pub struct FreeRegion { #[derive(HashStable)] pub enum BoundRegionKind { /// An anonymous region parameter for a given fn (&T) - BrAnon(u32, Option), + BrAnon(u32, Option), /// Named region parameters for functions (a in &'a T) /// diff --git a/src/test/ui/generic-associated-types/bugs/issue-100013.stderr b/src/test/ui/generic-associated-types/bugs/issue-100013.stderr index 72ae288dcab64..8c0a212de642d 100644 --- a/src/test/ui/generic-associated-types/bugs/issue-100013.stderr +++ b/src/test/ui/generic-associated-types/bugs/issue-100013.stderr @@ -9,15 +9,15 @@ LL | | } | |_____^ | note: the lifetime defined here... - --> $DIR/issue-100013.rs:17:38 + --> $DIR/issue-100013.rs:9:21 | -LL | let x = None::>; // a type referencing GAT - | ^^ +LL | type Future<'s, 'cx>: Send + | ^^^ note: ...must outlive the lifetime defined here - --> $DIR/issue-100013.rs:17:34 + --> $DIR/issue-100013.rs:9:17 | -LL | let x = None::>; // a type referencing GAT - | ^^ +LL | type Future<'s, 'cx>: Send + | ^^ = note: this is a known limitation that will be removed in the future (see issue #100013 for more information) error: lifetime bound not satisfied