mirror of https://github.com/rust-lang/rust.git
Use a `LocalDefId` for `HirTyLowerer::item_def_id`, since we only ever (can) use it for local items
This commit is contained in:
parent
a330e49593
commit
dc020ae5d8
|
@ -370,8 +370,8 @@ impl<'tcx> HirTyLowerer<'tcx> for ItemCtxt<'tcx> {
|
||||||
self.tcx
|
self.tcx
|
||||||
}
|
}
|
||||||
|
|
||||||
fn item_def_id(&self) -> DefId {
|
fn item_def_id(&self) -> LocalDefId {
|
||||||
self.item_def_id.to_def_id()
|
self.item_def_id
|
||||||
}
|
}
|
||||||
|
|
||||||
fn allow_infer(&self) -> bool {
|
fn allow_infer(&self) -> bool {
|
||||||
|
|
|
@ -117,7 +117,6 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
|
||||||
let mut is_trait = None;
|
let mut is_trait = None;
|
||||||
let mut is_default_impl_trait = None;
|
let mut is_default_impl_trait = None;
|
||||||
|
|
||||||
// FIXME: Should ItemCtxt take a LocalDefId?
|
|
||||||
let icx = ItemCtxt::new(tcx, def_id);
|
let icx = ItemCtxt::new(tcx, def_id);
|
||||||
|
|
||||||
const NO_GENERICS: &hir::Generics<'_> = hir::Generics::empty();
|
const NO_GENERICS: &hir::Generics<'_> = hir::Generics::empty();
|
||||||
|
|
|
@ -89,8 +89,8 @@ pub enum PredicateFilter {
|
||||||
pub trait HirTyLowerer<'tcx> {
|
pub trait HirTyLowerer<'tcx> {
|
||||||
fn tcx(&self) -> TyCtxt<'tcx>;
|
fn tcx(&self) -> TyCtxt<'tcx>;
|
||||||
|
|
||||||
/// Returns the [`DefId`] of the overarching item whose constituents get lowered.
|
/// Returns the [`LocalDefId`] of the overarching item whose constituents get lowered.
|
||||||
fn item_def_id(&self) -> DefId;
|
fn item_def_id(&self) -> LocalDefId;
|
||||||
|
|
||||||
/// Returns `true` if the current context allows the use of inference variables.
|
/// Returns `true` if the current context allows the use of inference variables.
|
||||||
fn allow_infer(&self) -> bool;
|
fn allow_infer(&self) -> bool;
|
||||||
|
@ -1493,16 +1493,15 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
||||||
let def_id = self.item_def_id();
|
let def_id = self.item_def_id();
|
||||||
debug!(item_def_id = ?def_id);
|
debug!(item_def_id = ?def_id);
|
||||||
|
|
||||||
let parent_def_id = def_id
|
// FIXME: document why/how this is different from `tcx.local_parent(def_id)`
|
||||||
.as_local()
|
let parent_def_id =
|
||||||
.map(|def_id| tcx.local_def_id_to_hir_id(def_id))
|
tcx.hir().get_parent_item(tcx.local_def_id_to_hir_id(def_id)).to_def_id();
|
||||||
.map(|hir_id| tcx.hir().get_parent_item(hir_id).to_def_id());
|
|
||||||
debug!(?parent_def_id);
|
debug!(?parent_def_id);
|
||||||
|
|
||||||
// If the trait in segment is the same as the trait defining the item,
|
// If the trait in segment is the same as the trait defining the item,
|
||||||
// use the `<Self as ..>` syntax in the error.
|
// use the `<Self as ..>` syntax in the error.
|
||||||
let is_part_of_self_trait_constraints = def_id == trait_def_id;
|
let is_part_of_self_trait_constraints = def_id.to_def_id() == trait_def_id;
|
||||||
let is_part_of_fn_in_self_trait = parent_def_id == Some(trait_def_id);
|
let is_part_of_fn_in_self_trait = parent_def_id == trait_def_id;
|
||||||
|
|
||||||
let type_names = if is_part_of_self_trait_constraints || is_part_of_fn_in_self_trait {
|
let type_names = if is_part_of_self_trait_constraints || is_part_of_fn_in_self_trait {
|
||||||
vec!["Self".to_string()]
|
vec!["Self".to_string()]
|
||||||
|
@ -1983,7 +1982,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
||||||
}
|
}
|
||||||
|
|
||||||
let sig_generics = self.tcx().generics_of(sig_id);
|
let sig_generics = self.tcx().generics_of(sig_id);
|
||||||
let parent = self.tcx().parent(self.item_def_id());
|
let parent = self.tcx().local_parent(self.item_def_id());
|
||||||
let parent_generics = self.tcx().generics_of(parent);
|
let parent_generics = self.tcx().generics_of(parent);
|
||||||
|
|
||||||
let parent_is_trait = (self.tcx().def_kind(parent) == DefKind::Trait) as usize;
|
let parent_is_trait = (self.tcx().def_kind(parent) == DefKind::Trait) as usize;
|
||||||
|
@ -2022,7 +2021,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
||||||
let sig = self.tcx().fn_sig(sig_id);
|
let sig = self.tcx().fn_sig(sig_id);
|
||||||
let sig_generics = self.tcx().generics_of(sig_id);
|
let sig_generics = self.tcx().generics_of(sig_id);
|
||||||
|
|
||||||
let parent = self.tcx().parent(self.item_def_id());
|
let parent = self.tcx().local_parent(self.item_def_id());
|
||||||
let parent_def_kind = self.tcx().def_kind(parent);
|
let parent_def_kind = self.tcx().def_kind(parent);
|
||||||
|
|
||||||
let sig = if let DefKind::Impl { .. } = parent_def_kind
|
let sig = if let DefKind::Impl { .. } = parent_def_kind
|
||||||
|
|
|
@ -218,8 +218,8 @@ impl<'a, 'tcx> HirTyLowerer<'tcx> for FnCtxt<'a, 'tcx> {
|
||||||
self.tcx
|
self.tcx
|
||||||
}
|
}
|
||||||
|
|
||||||
fn item_def_id(&self) -> DefId {
|
fn item_def_id(&self) -> LocalDefId {
|
||||||
self.body_id.to_def_id()
|
self.body_id
|
||||||
}
|
}
|
||||||
|
|
||||||
fn allow_infer(&self) -> bool {
|
fn allow_infer(&self) -> bool {
|
||||||
|
|
Loading…
Reference in New Issue