From: Bastian Kauschke Date: Sat, 27 Jun 2020 11:38:00 +0000 (+0200) Subject: more LocalDefId cleanup X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=2d280a55a9820ab18b25b8080d30e6d0a864ec17;p=rust.git more LocalDefId cleanup --- diff --git a/src/librustc_infer/infer/error_reporting/nice_region_error/find_anon_type.rs b/src/librustc_infer/infer/error_reporting/nice_region_error/find_anon_type.rs index 6677c0e59f6..20617bb8bd8 100644 --- a/src/librustc_infer/infer/error_reporting/nice_region_error/find_anon_type.rs +++ b/src/librustc_infer/infer/error_reporting/nice_region_error/find_anon_type.rs @@ -28,30 +28,27 @@ pub(super) fn find_anon_type( br: &ty::BoundRegion, ) -> Option<(&hir::Ty<'tcx>, &hir::FnDecl<'tcx>)> { if let Some(anon_reg) = self.tcx().is_suitable_region(region) { - let def_id = anon_reg.def_id; - if let Some(def_id) = def_id.as_local() { - let hir_id = self.tcx().hir().as_local_hir_id(def_id); - let fndecl = match self.tcx().hir().get(hir_id) { - Node::Item(&hir::Item { kind: hir::ItemKind::Fn(ref m, ..), .. }) - | Node::TraitItem(&hir::TraitItem { - kind: hir::TraitItemKind::Fn(ref m, ..), - .. - }) - | Node::ImplItem(&hir::ImplItem { - kind: hir::ImplItemKind::Fn(ref m, ..), - .. - }) => &m.decl, - _ => return None, - }; + let hir_id = self.tcx().hir().as_local_hir_id(anon_reg.def_id); + let fndecl = match self.tcx().hir().get(hir_id) { + Node::Item(&hir::Item { kind: hir::ItemKind::Fn(ref m, ..), .. }) + | Node::TraitItem(&hir::TraitItem { + kind: hir::TraitItemKind::Fn(ref m, ..), + .. + }) + | Node::ImplItem(&hir::ImplItem { + kind: hir::ImplItemKind::Fn(ref m, ..), .. + }) => &m.decl, + _ => return None, + }; - return fndecl - .inputs - .iter() - .find_map(|arg| self.find_component_for_bound_region(arg, br)) - .map(|ty| (ty, &**fndecl)); - } + fndecl + .inputs + .iter() + .find_map(|arg| self.find_component_for_bound_region(arg, br)) + .map(|ty| (ty, &**fndecl)) + } else { + None } - None } // This method creates a FindNestedTypeVisitor which returns the type corresponding diff --git a/src/librustc_infer/infer/error_reporting/nice_region_error/named_anon_conflict.rs b/src/librustc_infer/infer/error_reporting/nice_region_error/named_anon_conflict.rs index 3012928a098..72deba990b0 100644 --- a/src/librustc_infer/infer/error_reporting/nice_region_error/named_anon_conflict.rs +++ b/src/librustc_infer/infer/error_reporting/nice_region_error/named_anon_conflict.rs @@ -75,8 +75,7 @@ pub(super) fn try_report_named_anon_conflict(&self) -> Option NiceRegionError<'a, 'tcx> { /// Print the error message for lifetime errors when the return type is a static impl Trait. pub(super) fn try_report_static_impl_trait(&self) -> Option { debug!("try_report_static_impl_trait(error={:?})", self.error); - if let Some(ref error) = self.error { - if let RegionResolutionError::SubSupConflict( - _, - var_origin, - sub_origin, - sub_r, - sup_origin, - sup_r, - ) = error - { - debug!( - "try_report_static_impl_trait(var={:?}, sub={:?} {:?} sup={:?} {:?})", - var_origin, sub_origin, sub_r, sup_origin, sup_r + if let Some(RegionResolutionError::SubSupConflict( + _, + var_origin, + ref sub_origin, + sub_r, + ref sup_origin, + sup_r, + )) = self.error + { + debug!( + "try_report_static_impl_trait(var={:?}, sub={:?} {:?} sup={:?} {:?})", + var_origin, sub_origin, sub_r, sup_origin, sup_r + ); + let anon_reg_sup = self.tcx().is_suitable_region(sup_r)?; + debug!("try_report_static_impl_trait: anon_reg_sup={:?}", anon_reg_sup); + let fn_returns = self.tcx().return_type_impl_or_dyn_traits(anon_reg_sup.def_id); + if fn_returns.is_empty() { + return None; + } + debug!("try_report_static_impl_trait: fn_return={:?}", fn_returns); + if *sub_r == RegionKind::ReStatic { + let sp = var_origin.span(); + let return_sp = sub_origin.span(); + let param_info = self.find_param_with_region(sup_r, sub_r)?; + let (lifetime_name, lifetime) = if sup_r.has_name() { + (sup_r.to_string(), format!("lifetime `{}`", sup_r)) + } else { + ("'_".to_owned(), "an anonymous lifetime `'_`".to_string()) + }; + let mut err = struct_span_err!( + self.tcx().sess, + sp, + E0759, + "cannot infer an appropriate lifetime" ); - let anon_reg_sup = self.tcx().is_suitable_region(sup_r)?; - debug!("try_report_static_impl_trait: anon_reg_sup={:?}", anon_reg_sup); - let fn_returns = - self.tcx().return_type_impl_or_dyn_traits(anon_reg_sup.def_id.expect_local()); - if fn_returns.is_empty() { - return None; - } - debug!("try_report_static_impl_trait: fn_return={:?}", fn_returns); - if **sub_r == RegionKind::ReStatic { - let sp = var_origin.span(); - let return_sp = sub_origin.span(); - let param_info = self.find_param_with_region(sup_r, sub_r)?; - let (lifetime_name, lifetime) = if sup_r.has_name() { - (sup_r.to_string(), format!("lifetime `{}`", sup_r)) + err.span_label( + param_info.param_ty_span, + &format!("this data with {}...", lifetime), + ); + debug!("try_report_static_impl_trait: param_info={:?}", param_info); + + // We try to make the output have fewer overlapping spans if possible. + if (sp == sup_origin.span() || !return_sp.overlaps(sup_origin.span())) + && sup_origin.span() != return_sp + { + // FIXME: account for `async fn` like in `async-await/issues/issue-62097.rs` + + // Customize the spans and labels depending on their relative order so + // that split sentences flow correctly. + if sup_origin.span().overlaps(return_sp) && sp == sup_origin.span() { + // Avoid the following: + // + // error: cannot infer an appropriate lifetime + // --> $DIR/must_outlive_least_region_or_bound.rs:18:50 + // | + // LL | fn foo(x: &i32) -> Box { Box::new(x) } + // | ---- ---------^- + // + // and instead show: + // + // error: cannot infer an appropriate lifetime + // --> $DIR/must_outlive_least_region_or_bound.rs:18:50 + // | + // LL | fn foo(x: &i32) -> Box { Box::new(x) } + // | ---- ^ + err.span_label( + sup_origin.span(), + "...is captured here, requiring it to live as long as `'static`", + ); } else { - ("'_".to_owned(), "an anonymous lifetime `'_`".to_string()) - }; - let mut err = struct_span_err!( - self.tcx().sess, - sp, - E0759, - "cannot infer an appropriate lifetime" - ); + err.span_label(sup_origin.span(), "...is captured here..."); + if return_sp < sup_origin.span() { + err.span_note( + return_sp, + "...and is required to live as long as `'static` here", + ); + } else { + err.span_label( + return_sp, + "...and is required to live as long as `'static` here", + ); + } + } + } else { err.span_label( - param_info.param_ty_span, - &format!("this data with {}...", lifetime), + return_sp, + "...is captured and required to live as long as `'static` here", ); - debug!("try_report_static_impl_trait: param_info={:?}", param_info); + } - // We try to make the output have fewer overlapping spans if possible. - if (sp == sup_origin.span() || !return_sp.overlaps(sup_origin.span())) - && sup_origin.span() != return_sp - { - // FIXME: account for `async fn` like in `async-await/issues/issue-62097.rs` + // FIXME: account for the need of parens in `&(dyn Trait + '_)` + let consider = "consider changing the"; + let declare = "to declare that the"; + let arg = match param_info.param.pat.simple_ident() { + Some(simple_ident) => format!("argument `{}`", simple_ident), + None => "the argument".to_string(), + }; + let explicit = + format!("you can add an explicit `{}` lifetime bound", lifetime_name); + let explicit_static = + format!("explicit `'static` bound to the lifetime of {}", arg); + let captures = format!("captures data from {}", arg); + let add_static_bound = + "alternatively, add an explicit `'static` bound to this reference"; + let plus_lt = format!(" + {}", lifetime_name); + for fn_return in fn_returns { + if fn_return.span.desugaring_kind().is_some() { + // Skip `async` desugaring `impl Future`. + continue; + } + match fn_return.kind { + TyKind::OpaqueDef(item_id, _) => { + let item = self.tcx().hir().item(item_id.id); + let opaque = if let ItemKind::OpaqueTy(opaque) = &item.kind { + opaque + } else { + err.emit(); + return Some(ErrorReported); + }; - // Customize the spans and labels depending on their relative order so - // that split sentences flow correctly. - if sup_origin.span().overlaps(return_sp) && sp == sup_origin.span() { - // Avoid the following: - // - // error: cannot infer an appropriate lifetime - // --> $DIR/must_outlive_least_region_or_bound.rs:18:50 - // | - // LL | fn foo(x: &i32) -> Box { Box::new(x) } - // | ---- ---------^- - // - // and instead show: - // - // error: cannot infer an appropriate lifetime - // --> $DIR/must_outlive_least_region_or_bound.rs:18:50 - // | - // LL | fn foo(x: &i32) -> Box { Box::new(x) } - // | ---- ^ - err.span_label( - sup_origin.span(), - "...is captured here, requiring it to live as long as `'static`", - ); - } else { - err.span_label(sup_origin.span(), "...is captured here..."); - if return_sp < sup_origin.span() { - err.span_note( - return_sp, - "...and is required to live as long as `'static` here", + if let Some(span) = opaque + .bounds + .iter() + .filter_map(|arg| match arg { + GenericBound::Outlives(Lifetime { + name: LifetimeName::Static, + span, + .. + }) => Some(*span), + _ => None, + }) + .next() + { + err.span_suggestion_verbose( + span, + &format!("{} `impl Trait`'s {}", consider, explicit_static), + lifetime_name.clone(), + Applicability::MaybeIncorrect, ); + err.span_suggestion_verbose( + param_info.param_ty_span, + add_static_bound, + param_info.param_ty.to_string(), + Applicability::MaybeIncorrect, + ); + } else if let Some(_) = opaque + .bounds + .iter() + .filter_map(|arg| match arg { + GenericBound::Outlives(Lifetime { name, span, .. }) + if name.ident().to_string() == lifetime_name => + { + Some(*span) + } + _ => None, + }) + .next() + { } else { - err.span_label( - return_sp, - "...and is required to live as long as `'static` here", + err.span_suggestion_verbose( + fn_return.span.shrink_to_hi(), + &format!( + "{declare} `impl Trait` {captures}, {explicit}", + declare = declare, + captures = captures, + explicit = explicit, + ), + plus_lt.clone(), + Applicability::MaybeIncorrect, ); } } - } else { - err.span_label( - return_sp, - "...is captured and required to live as long as `'static` here", - ); - } - - // FIXME: account for the need of parens in `&(dyn Trait + '_)` - let consider = "consider changing the"; - let declare = "to declare that the"; - let arg = match param_info.param.pat.simple_ident() { - Some(simple_ident) => format!("argument `{}`", simple_ident), - None => "the argument".to_string(), - }; - let explicit = - format!("you can add an explicit `{}` lifetime bound", lifetime_name); - let explicit_static = - format!("explicit `'static` bound to the lifetime of {}", arg); - let captures = format!("captures data from {}", arg); - let add_static_bound = - "alternatively, add an explicit `'static` bound to this reference"; - let plus_lt = format!(" + {}", lifetime_name); - for fn_return in fn_returns { - if fn_return.span.desugaring_kind().is_some() { - // Skip `async` desugaring `impl Future`. - continue; - } - match fn_return.kind { - TyKind::OpaqueDef(item_id, _) => { - let item = self.tcx().hir().item(item_id.id); - let opaque = if let ItemKind::OpaqueTy(opaque) = &item.kind { - opaque - } else { - err.emit(); - return Some(ErrorReported); - }; - - if let Some(span) = opaque - .bounds - .iter() - .filter_map(|arg| match arg { - GenericBound::Outlives(Lifetime { - name: LifetimeName::Static, - span, - .. - }) => Some(*span), - _ => None, - }) - .next() - { - err.span_suggestion_verbose( - span, - &format!("{} `impl Trait`'s {}", consider, explicit_static), - lifetime_name.clone(), - Applicability::MaybeIncorrect, - ); - err.span_suggestion_verbose( - param_info.param_ty_span, - add_static_bound, - param_info.param_ty.to_string(), - Applicability::MaybeIncorrect, - ); - } else if let Some(_) = opaque - .bounds - .iter() - .filter_map(|arg| match arg { - GenericBound::Outlives(Lifetime { name, span, .. }) - if name.ident().to_string() == lifetime_name => - { - Some(*span) - } - _ => None, - }) - .next() - { - } else { - err.span_suggestion_verbose( - fn_return.span.shrink_to_hi(), - &format!( - "{declare} `impl Trait` {captures}, {explicit}", - declare = declare, - captures = captures, - explicit = explicit, - ), - plus_lt.clone(), - Applicability::MaybeIncorrect, - ); - } + TyKind::TraitObject(_, lt) => match lt.name { + LifetimeName::ImplicitObjectLifetimeDefault => { + err.span_suggestion_verbose( + fn_return.span.shrink_to_hi(), + &format!( + "{declare} trait object {captures}, {explicit}", + declare = declare, + captures = captures, + explicit = explicit, + ), + plus_lt.clone(), + Applicability::MaybeIncorrect, + ); + } + name if name.ident().to_string() != lifetime_name => { + // With this check we avoid suggesting redundant bounds. This + // would happen if there are nested impl/dyn traits and only + // one of them has the bound we'd suggest already there, like + // in `impl Foo + '_`. + err.span_suggestion_verbose( + lt.span, + &format!("{} trait object's {}", consider, explicit_static), + lifetime_name.clone(), + Applicability::MaybeIncorrect, + ); + err.span_suggestion_verbose( + param_info.param_ty_span, + add_static_bound, + param_info.param_ty.to_string(), + Applicability::MaybeIncorrect, + ); } - TyKind::TraitObject(_, lt) => match lt.name { - LifetimeName::ImplicitObjectLifetimeDefault => { - err.span_suggestion_verbose( - fn_return.span.shrink_to_hi(), - &format!( - "{declare} trait object {captures}, {explicit}", - declare = declare, - captures = captures, - explicit = explicit, - ), - plus_lt.clone(), - Applicability::MaybeIncorrect, - ); - } - name if name.ident().to_string() != lifetime_name => { - // With this check we avoid suggesting redundant bounds. This - // would happen if there are nested impl/dyn traits and only - // one of them has the bound we'd suggest already there, like - // in `impl Foo + '_`. - err.span_suggestion_verbose( - lt.span, - &format!("{} trait object's {}", consider, explicit_static), - lifetime_name.clone(), - Applicability::MaybeIncorrect, - ); - err.span_suggestion_verbose( - param_info.param_ty_span, - add_static_bound, - param_info.param_ty.to_string(), - Applicability::MaybeIncorrect, - ); - } - _ => {} - }, _ => {} - } + }, + _ => {} } - err.emit(); - return Some(ErrorReported); } + err.emit(); + return Some(ErrorReported); } } None diff --git a/src/librustc_infer/infer/error_reporting/nice_region_error/util.rs b/src/librustc_infer/infer/error_reporting/nice_region_error/util.rs index 22b130cdf5f..fa999abb1a8 100644 --- a/src/librustc_infer/infer/error_reporting/nice_region_error/util.rs +++ b/src/librustc_infer/infer/error_reporting/nice_region_error/util.rs @@ -3,7 +3,7 @@ use crate::infer::error_reporting::nice_region_error::NiceRegionError; use rustc_hir as hir; -use rustc_hir::def_id::DefId; +use rustc_hir::def_id::LocalDefId; use rustc_middle::ty::{self, DefIdTree, Region, Ty}; use rustc_span::Span; @@ -92,7 +92,7 @@ pub(super) fn find_param_with_region( // FIXME(#42703) - Need to handle certain cases here. pub(super) fn is_return_type_anon( &self, - scope_def_id: DefId, + scope_def_id: LocalDefId, br: ty::BoundRegion, decl: &hir::FnDecl<'_>, ) -> Option { @@ -112,9 +112,12 @@ pub(super) fn is_return_type_anon( // corresponds to self and if yes, we display E0312. // FIXME(#42700) - Need to format self properly to // enable E0621 for it. - pub(super) fn is_self_anon(&self, is_first: bool, scope_def_id: DefId) -> bool { + pub(super) fn is_self_anon(&self, is_first: bool, scope_def_id: LocalDefId) -> bool { is_first - && self.tcx().opt_associated_item(scope_def_id).map(|i| i.fn_has_self_parameter) + && self + .tcx() + .opt_associated_item(scope_def_id.to_def_id()) + .map(|i| i.fn_has_self_parameter) == Some(true) } } diff --git a/src/librustc_middle/ty/context.rs b/src/librustc_middle/ty/context.rs index fb89e0e41d9..44c8c1f6fdb 100644 --- a/src/librustc_middle/ty/context.rs +++ b/src/librustc_middle/ty/context.rs @@ -873,8 +873,8 @@ fn new(interners: &CtxtInterners<'tcx>, types: &CommonTypes<'tcx>) -> CommonCons // conflict. #[derive(Debug)] pub struct FreeRegionInfo { - // def id corresponding to FreeRegion - pub def_id: DefId, + // `LocalDefId` corresponding to FreeRegion + pub def_id: LocalDefId, // the bound region corresponding to FreeRegion pub boundregion: ty::BoundRegion, // checks if bound region is in Impl Item @@ -1412,14 +1412,17 @@ pub fn local_crate_exports_generics(self) -> bool { // Returns the `DefId` and the `BoundRegion` corresponding to the given region. pub fn is_suitable_region(&self, region: Region<'tcx>) -> Option { let (suitable_region_binding_scope, bound_region) = match *region { - ty::ReFree(ref free_region) => (free_region.scope, free_region.bound_region), - ty::ReEarlyBound(ref ebr) => { - (self.parent(ebr.def_id).unwrap(), ty::BoundRegion::BrNamed(ebr.def_id, ebr.name)) + ty::ReFree(ref free_region) => { + (free_region.scope.expect_local(), free_region.bound_region) } + ty::ReEarlyBound(ref ebr) => ( + self.parent(ebr.def_id).unwrap().expect_local(), + ty::BoundRegion::BrNamed(ebr.def_id, ebr.name), + ), _ => return None, // not a free region }; - let hir_id = self.hir().as_local_hir_id(suitable_region_binding_scope.expect_local()); + let hir_id = self.hir().as_local_hir_id(suitable_region_binding_scope); let is_impl_item = match self.hir().find(hir_id) { Some(Node::Item(..) | Node::TraitItem(..)) => false, Some(Node::ImplItem(..)) => { @@ -1515,8 +1518,9 @@ pub fn return_type_impl_trait(&self, scope_def_id: LocalDefId) -> Option<(Ty<'tc } // Checks if the bound region is in Impl Item. - pub fn is_bound_region_in_impl_item(&self, suitable_region_binding_scope: DefId) -> bool { - let container_id = self.associated_item(suitable_region_binding_scope).container.id(); + pub fn is_bound_region_in_impl_item(&self, suitable_region_binding_scope: LocalDefId) -> bool { + let container_id = + self.associated_item(suitable_region_binding_scope.to_def_id()).container.id(); if self.impl_trait_ref(container_id).is_some() { // For now, we do not try to target impls of traits. This is // because this message is going to suggest that the user diff --git a/src/librustc_mir/borrow_check/diagnostics/region_errors.rs b/src/librustc_mir/borrow_check/diagnostics/region_errors.rs index d639a0f69d4..99b9788c20b 100644 --- a/src/librustc_mir/borrow_check/diagnostics/region_errors.rs +++ b/src/librustc_mir/borrow_check/diagnostics/region_errors.rs @@ -579,11 +579,11 @@ fn add_static_impl_trait_suggestion( if let (Some(f), Some(ty::RegionKind::ReStatic)) = (self.to_error_region(fr), self.to_error_region(outlived_fr)) { - if let Some((ty::TyS { kind: ty::Opaque(did, substs), .. }, _)) = self + if let Some((&ty::TyS { kind: ty::Opaque(did, substs), .. }, _)) = self .infcx .tcx .is_suitable_region(f) - .map(|r| r.def_id.expect_local()) + .map(|r| r.def_id) .map(|id| self.infcx.tcx.return_type_impl_trait(id)) .unwrap_or(None) { @@ -592,7 +592,7 @@ fn add_static_impl_trait_suggestion( // // eg. check for `impl Trait + 'static` instead of `impl Trait`. let has_static_predicate = { - let predicates_of = self.infcx.tcx.predicates_of(*did); + let predicates_of = self.infcx.tcx.predicates_of(did); let bounds = predicates_of.instantiate(self.infcx.tcx, substs); let mut found = false; @@ -625,7 +625,7 @@ fn add_static_impl_trait_suggestion( diag.help(&format!("consider replacing `{}` with `{}`", fr_name, static_str)); } else { // Otherwise, we should suggest adding a constraint on the return type. - let span = self.infcx.tcx.def_span(*did); + let span = self.infcx.tcx.def_span(did); if let Ok(snippet) = self.infcx.tcx.sess.source_map().span_to_snippet(span) { let suggestable_fr_name = if fr_name.was_named() { fr_name.to_string() diff --git a/src/librustc_mir/borrow_check/universal_regions.rs b/src/librustc_mir/borrow_check/universal_regions.rs index 3003f4639d9..7b292ee71f9 100644 --- a/src/librustc_mir/borrow_check/universal_regions.rs +++ b/src/librustc_mir/borrow_check/universal_regions.rs @@ -232,8 +232,7 @@ pub fn new( ) -> Self { let tcx = infcx.tcx; let mir_hir_id = tcx.hir().as_local_hir_id(mir_def_id); - UniversalRegionsBuilder { infcx, mir_def_id: mir_def_id.to_def_id(), mir_hir_id, param_env } - .build() + UniversalRegionsBuilder { infcx, mir_def_id, mir_hir_id, param_env }.build() } /// Given a reference to a closure type, extracts all the values @@ -389,7 +388,7 @@ pub fn to_region_vid(&self, r: ty::Region<'tcx>) -> RegionVid { struct UniversalRegionsBuilder<'cx, 'tcx> { infcx: &'cx InferCtxt<'cx, 'tcx>, - mir_def_id: DefId, + mir_def_id: LocalDefId, mir_hir_id: HirId, param_env: ty::ParamEnv<'tcx>, } @@ -418,7 +417,7 @@ fn build(self) -> UniversalRegions<'tcx> { let mut indices = self.compute_indices(fr_static, defining_ty); debug!("build: indices={:?}", indices); - let closure_base_def_id = self.infcx.tcx.closure_base_def_id(self.mir_def_id); + let closure_base_def_id = self.infcx.tcx.closure_base_def_id(self.mir_def_id.to_def_id()); // If this is a closure or generator, then the late-bound regions from the enclosing // function are actually external regions to us. For example, here, 'a is not local @@ -426,7 +425,7 @@ fn build(self) -> UniversalRegions<'tcx> { // fn foo<'a>() { // let c = || { let x: &'a u32 = ...; } // } - if self.mir_def_id != closure_base_def_id { + if self.mir_def_id.to_def_id() != closure_base_def_id { self.infcx.replace_late_bound_regions_with_nll_infer_vars(self.mir_def_id, &mut indices) } @@ -443,7 +442,7 @@ fn build(self) -> UniversalRegions<'tcx> { ); // Converse of above, if this is a function then the late-bound regions declared on its // signature are local to the fn. - if self.mir_def_id == closure_base_def_id { + if self.mir_def_id.to_def_id() == closure_base_def_id { self.infcx .replace_late_bound_regions_with_nll_infer_vars(self.mir_def_id, &mut indices); } @@ -508,14 +507,14 @@ fn build(self) -> UniversalRegions<'tcx> { /// see `DefiningTy` for details. fn defining_ty(&self) -> DefiningTy<'tcx> { let tcx = self.infcx.tcx; - let closure_base_def_id = tcx.closure_base_def_id(self.mir_def_id); + let closure_base_def_id = tcx.closure_base_def_id(self.mir_def_id.to_def_id()); match tcx.hir().body_owner_kind(self.mir_hir_id) { BodyOwnerKind::Closure | BodyOwnerKind::Fn => { - let defining_ty = if self.mir_def_id == closure_base_def_id { + let defining_ty = if self.mir_def_id.to_def_id() == closure_base_def_id { tcx.type_of(closure_base_def_id) } else { - let tables = tcx.typeck_tables_of(self.mir_def_id.expect_local()); + let tables = tcx.typeck_tables_of(self.mir_def_id); tables.node_type(self.mir_hir_id) }; @@ -540,11 +539,11 @@ fn defining_ty(&self) -> DefiningTy<'tcx> { } BodyOwnerKind::Const | BodyOwnerKind::Static(..) => { - assert_eq!(closure_base_def_id, self.mir_def_id); + assert_eq!(self.mir_def_id.to_def_id(), closure_base_def_id); let identity_substs = InternalSubsts::identity_for_item(tcx, closure_base_def_id); let substs = self.infcx.replace_free_regions_with_nll_infer_vars(FR, &identity_substs); - DefiningTy::Const(self.mir_def_id, substs) + DefiningTy::Const(self.mir_def_id.to_def_id(), substs) } } } @@ -559,7 +558,7 @@ fn compute_indices( defining_ty: DefiningTy<'tcx>, ) -> UniversalRegionIndices<'tcx> { let tcx = self.infcx.tcx; - let closure_base_def_id = tcx.closure_base_def_id(self.mir_def_id); + let closure_base_def_id = tcx.closure_base_def_id(self.mir_def_id.to_def_id()); let identity_substs = InternalSubsts::identity_for_item(tcx, closure_base_def_id); let fr_substs = match defining_ty { DefiningTy::Closure(_, ref substs) | DefiningTy::Generator(_, ref substs, _) => { @@ -593,7 +592,7 @@ fn compute_inputs_and_output( let tcx = self.infcx.tcx; match defining_ty { DefiningTy::Closure(def_id, substs) => { - assert_eq!(self.mir_def_id, def_id); + assert_eq!(self.mir_def_id.to_def_id(), def_id); let closure_sig = substs.as_closure().sig(); let inputs_and_output = closure_sig.inputs_and_output(); let closure_ty = tcx.closure_env_ty(def_id, substs).unwrap(); @@ -617,7 +616,7 @@ fn compute_inputs_and_output( } DefiningTy::Generator(def_id, substs, movability) => { - assert_eq!(self.mir_def_id, def_id); + assert_eq!(self.mir_def_id.to_def_id(), def_id); let resume_ty = substs.as_generator().resume_ty(); let output = substs.as_generator().return_ty(); let generator_ty = tcx.mk_generator(def_id, substs, movability); @@ -635,7 +634,7 @@ fn compute_inputs_and_output( DefiningTy::Const(def_id, _) => { // For a constant body, there are no inputs, and one // "output" (the type of the constant). - assert_eq!(self.mir_def_id, def_id); + assert_eq!(self.mir_def_id.to_def_id(), def_id); let ty = tcx.type_of(def_id); let ty = indices.fold_to_region_vids(tcx, &ty); ty::Binder::dummy(tcx.intern_type_list(&[ty])) @@ -656,7 +655,7 @@ fn replace_free_regions_with_nll_infer_vars( fn replace_bound_regions_with_nll_infer_vars( &self, origin: NLLRegionVariableOrigin, - all_outlive_scope: DefId, + all_outlive_scope: LocalDefId, value: &ty::Binder, indices: &mut UniversalRegionIndices<'tcx>, ) -> T @@ -665,7 +664,7 @@ fn replace_bound_regions_with_nll_infer_vars( fn replace_late_bound_regions_with_nll_infer_vars( &self, - mir_def_id: DefId, + mir_def_id: LocalDefId, indices: &mut UniversalRegionIndices<'tcx>, ); } @@ -685,7 +684,7 @@ fn replace_free_regions_with_nll_infer_vars( fn replace_bound_regions_with_nll_infer_vars( &self, origin: NLLRegionVariableOrigin, - all_outlive_scope: DefId, + all_outlive_scope: LocalDefId, value: &ty::Binder, indices: &mut UniversalRegionIndices<'tcx>, ) -> T @@ -699,7 +698,7 @@ fn replace_bound_regions_with_nll_infer_vars( let (value, _map) = self.tcx.replace_late_bound_regions(value, |br| { debug!("replace_bound_regions_with_nll_infer_vars: br={:?}", br); let liberated_region = self.tcx.mk_region(ty::ReFree(ty::FreeRegion { - scope: all_outlive_scope, + scope: all_outlive_scope.to_def_id(), bound_region: br, })); let region_vid = self.next_nll_region_var(origin); @@ -724,11 +723,11 @@ fn replace_bound_regions_with_nll_infer_vars( /// inputs vector. fn replace_late_bound_regions_with_nll_infer_vars( &self, - mir_def_id: DefId, + mir_def_id: LocalDefId, indices: &mut UniversalRegionIndices<'tcx>, ) { debug!("replace_late_bound_regions_with_nll_infer_vars(mir_def_id={:?})", mir_def_id); - let closure_base_def_id = self.tcx.closure_base_def_id(mir_def_id); + let closure_base_def_id = self.tcx.closure_base_def_id(mir_def_id.to_def_id()); for_each_late_bound_region_defined_on(self.tcx, closure_base_def_id, |r| { debug!("replace_late_bound_regions_with_nll_infer_vars: r={:?}", r); if !indices.indices.contains_key(&r) {