hir: HirIdify Impl&TraitItemId
This commit is contained in:
parent
fb22315f08
commit
fa61c67fe6
12 changed files with 55 additions and 73 deletions
|
@ -469,8 +469,8 @@ impl<'a> LoweringContext<'a> {
|
||||||
|
|
||||||
fn visit_trait_item(&mut self, item: &'lcx TraitItem) {
|
fn visit_trait_item(&mut self, item: &'lcx TraitItem) {
|
||||||
self.lctx.with_hir_id_owner(item.id, |lctx| {
|
self.lctx.with_hir_id_owner(item.id, |lctx| {
|
||||||
let id = hir::TraitItemId { node_id: item.id };
|
|
||||||
let hir_item = lctx.lower_trait_item(item);
|
let hir_item = lctx.lower_trait_item(item);
|
||||||
|
let id = hir::TraitItemId { hir_id: hir_item.hir_id };
|
||||||
lctx.trait_items.insert(id, hir_item);
|
lctx.trait_items.insert(id, hir_item);
|
||||||
lctx.modules.get_mut(&lctx.current_module).unwrap().trait_items.insert(id);
|
lctx.modules.get_mut(&lctx.current_module).unwrap().trait_items.insert(id);
|
||||||
});
|
});
|
||||||
|
@ -480,8 +480,8 @@ impl<'a> LoweringContext<'a> {
|
||||||
|
|
||||||
fn visit_impl_item(&mut self, item: &'lcx ImplItem) {
|
fn visit_impl_item(&mut self, item: &'lcx ImplItem) {
|
||||||
self.lctx.with_hir_id_owner(item.id, |lctx| {
|
self.lctx.with_hir_id_owner(item.id, |lctx| {
|
||||||
let id = hir::ImplItemId { node_id: item.id };
|
|
||||||
let hir_item = lctx.lower_impl_item(item);
|
let hir_item = lctx.lower_impl_item(item);
|
||||||
|
let id = hir::ImplItemId { hir_id: hir_item.hir_id };
|
||||||
lctx.impl_items.insert(id, hir_item);
|
lctx.impl_items.insert(id, hir_item);
|
||||||
lctx.modules.get_mut(&lctx.current_module).unwrap().impl_items.insert(id);
|
lctx.modules.get_mut(&lctx.current_module).unwrap().impl_items.insert(id);
|
||||||
});
|
});
|
||||||
|
@ -3363,7 +3363,7 @@ impl<'a> LoweringContext<'a> {
|
||||||
TraitItemKind::Macro(..) => unimplemented!(),
|
TraitItemKind::Macro(..) => unimplemented!(),
|
||||||
};
|
};
|
||||||
hir::TraitItemRef {
|
hir::TraitItemRef {
|
||||||
id: hir::TraitItemId { node_id: i.id },
|
id: hir::TraitItemId { hir_id: self.lower_node_id(i.id).hir_id },
|
||||||
ident: i.ident,
|
ident: i.ident,
|
||||||
span: i.span,
|
span: i.span,
|
||||||
defaultness: self.lower_defaultness(Defaultness::Default, has_default),
|
defaultness: self.lower_defaultness(Defaultness::Default, has_default),
|
||||||
|
@ -3427,7 +3427,7 @@ impl<'a> LoweringContext<'a> {
|
||||||
|
|
||||||
fn lower_impl_item_ref(&mut self, i: &ImplItem) -> hir::ImplItemRef {
|
fn lower_impl_item_ref(&mut self, i: &ImplItem) -> hir::ImplItemRef {
|
||||||
hir::ImplItemRef {
|
hir::ImplItemRef {
|
||||||
id: hir::ImplItemId { node_id: i.id },
|
id: hir::ImplItemId { hir_id: self.lower_node_id(i.id).hir_id },
|
||||||
ident: i.ident,
|
ident: i.ident,
|
||||||
span: i.span,
|
span: i.span,
|
||||||
vis: self.lower_visibility(&i.vis, Some(i.id)),
|
vis: self.lower_visibility(&i.vis, Some(i.id)),
|
||||||
|
|
|
@ -427,7 +427,7 @@ impl<'hir> Map<'hir> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn trait_item(&self, id: TraitItemId) -> &'hir TraitItem {
|
pub fn trait_item(&self, id: TraitItemId) -> &'hir TraitItem {
|
||||||
self.read(id.node_id);
|
self.read_by_hir_id(id.hir_id);
|
||||||
|
|
||||||
// N.B., intentionally bypass `self.forest.krate()` so that we
|
// N.B., intentionally bypass `self.forest.krate()` so that we
|
||||||
// do not trigger a read of the whole krate here
|
// do not trigger a read of the whole krate here
|
||||||
|
@ -435,7 +435,7 @@ impl<'hir> Map<'hir> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn impl_item(&self, id: ImplItemId) -> &'hir ImplItem {
|
pub fn impl_item(&self, id: ImplItemId) -> &'hir ImplItem {
|
||||||
self.read(id.node_id);
|
self.read_by_hir_id(id.hir_id);
|
||||||
|
|
||||||
// N.B., intentionally bypass `self.forest.krate()` so that we
|
// N.B., intentionally bypass `self.forest.krate()` so that we
|
||||||
// do not trigger a read of the whole krate here
|
// do not trigger a read of the whole krate here
|
||||||
|
@ -618,11 +618,11 @@ impl<'hir> Map<'hir> {
|
||||||
}
|
}
|
||||||
|
|
||||||
for id in &module.trait_items {
|
for id in &module.trait_items {
|
||||||
visitor.visit_trait_item(self.expect_trait_item(id.node_id));
|
visitor.visit_trait_item(self.expect_trait_item_by_hir_id(id.hir_id));
|
||||||
}
|
}
|
||||||
|
|
||||||
for id in &module.impl_items {
|
for id in &module.impl_items {
|
||||||
visitor.visit_impl_item(self.expect_impl_item(id.node_id));
|
visitor.visit_impl_item(self.expect_impl_item_by_hir_id(id.hir_id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1657,7 +1657,7 @@ pub struct MethodSig {
|
||||||
// so it can fetched later.
|
// so it can fetched later.
|
||||||
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, RustcEncodable, RustcDecodable, Debug)]
|
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, RustcEncodable, RustcDecodable, Debug)]
|
||||||
pub struct TraitItemId {
|
pub struct TraitItemId {
|
||||||
pub node_id: NodeId,
|
pub hir_id: HirId,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Represents an item declaration within a trait declaration,
|
/// Represents an item declaration within a trait declaration,
|
||||||
|
@ -1702,7 +1702,7 @@ pub enum TraitItemKind {
|
||||||
// so it can fetched later.
|
// so it can fetched later.
|
||||||
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, RustcEncodable, RustcDecodable, Debug)]
|
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, RustcEncodable, RustcDecodable, Debug)]
|
||||||
pub struct ImplItemId {
|
pub struct ImplItemId {
|
||||||
pub node_id: NodeId,
|
pub hir_id: HirId,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Represents anything within an `impl` block
|
/// Represents anything within an `impl` block
|
||||||
|
|
|
@ -116,11 +116,11 @@ impl<'a> HashStable<StableHashingContext<'a>> for hir::TraitItemId {
|
||||||
hcx: &mut StableHashingContext<'a>,
|
hcx: &mut StableHashingContext<'a>,
|
||||||
hasher: &mut StableHasher<W>) {
|
hasher: &mut StableHasher<W>) {
|
||||||
let hir::TraitItemId {
|
let hir::TraitItemId {
|
||||||
node_id
|
hir_id
|
||||||
} = * self;
|
} = * self;
|
||||||
|
|
||||||
hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
|
hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
|
||||||
node_id.hash_stable(hcx, hasher);
|
hir_id.hash_stable(hcx, hasher);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -130,11 +130,11 @@ impl<'a> HashStable<StableHashingContext<'a>> for hir::ImplItemId {
|
||||||
hcx: &mut StableHashingContext<'a>,
|
hcx: &mut StableHashingContext<'a>,
|
||||||
hasher: &mut StableHasher<W>) {
|
hasher: &mut StableHasher<W>) {
|
||||||
let hir::ImplItemId {
|
let hir::ImplItemId {
|
||||||
node_id
|
hir_id
|
||||||
} = * self;
|
} = * self;
|
||||||
|
|
||||||
hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
|
hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
|
||||||
node_id.hash_stable(hcx, hasher);
|
hir_id.hash_stable(hcx, hasher);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -376,7 +376,7 @@ impl<'v, 'k, 'tcx> ItemLikeVisitor<'v> for LifeSeeder<'k, 'tcx> {
|
||||||
has_allow_dead_code_or_lang_attr(self.tcx,
|
has_allow_dead_code_or_lang_attr(self.tcx,
|
||||||
impl_item.hir_id,
|
impl_item.hir_id,
|
||||||
&impl_item.attrs) {
|
&impl_item.attrs) {
|
||||||
self.worklist.push(self.tcx.hir().node_to_hir_id(impl_item_ref.id.node_id));
|
self.worklist.push(impl_item_ref.id.hir_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -355,11 +355,7 @@ impl<'a, 'tcx: 'a> ItemLikeVisitor<'tcx> for CollectPrivateImplItemsVisitor<'a,
|
||||||
if let hir::ItemKind::Impl(.., Some(ref trait_ref), _, ref impl_item_refs) = item.node {
|
if let hir::ItemKind::Impl(.., Some(ref trait_ref), _, ref impl_item_refs) = item.node {
|
||||||
let node_id = self.tcx.hir().hir_to_node_id(item.hir_id);
|
let node_id = self.tcx.hir().hir_to_node_id(item.hir_id);
|
||||||
if !self.access_levels.is_reachable(node_id) {
|
if !self.access_levels.is_reachable(node_id) {
|
||||||
// FIXME(@ljedrz): rework back to a nice extend when item Ids contain HirId
|
self.worklist.extend(impl_item_refs.iter().map(|ii_ref| ii_ref.id.hir_id));
|
||||||
for impl_item_ref in impl_item_refs {
|
|
||||||
let hir_id = self.tcx.hir().node_to_hir_id(impl_item_ref.id.node_id);
|
|
||||||
self.worklist.push(hir_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
let trait_def_id = match trait_ref.path.def {
|
let trait_def_id = match trait_ref.path.def {
|
||||||
Def::Trait(def_id) => def_id,
|
Def::Trait(def_id) => def_id,
|
||||||
|
|
|
@ -671,13 +671,14 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
|
||||||
// In the future, this should be fixed and this error should be removed.
|
// In the future, this should be fixed and this error should be removed.
|
||||||
let def = self.map.defs.get(&lifetime.hir_id).cloned();
|
let def = self.map.defs.get(&lifetime.hir_id).cloned();
|
||||||
if let Some(Region::LateBound(_, def_id, _)) = def {
|
if let Some(Region::LateBound(_, def_id, _)) = def {
|
||||||
if let Some(node_id) = self.tcx.hir().as_local_node_id(def_id) {
|
if let Some(hir_id) = self.tcx.hir().as_local_hir_id(def_id) {
|
||||||
// Ensure that the parent of the def is an item, not HRTB
|
// Ensure that the parent of the def is an item, not HRTB
|
||||||
let parent_id = self.tcx.hir().get_parent_node(node_id);
|
let parent_id = self.tcx.hir().get_parent_node_by_hir_id(hir_id);
|
||||||
let parent_impl_id = hir::ImplItemId { node_id: parent_id };
|
let parent_impl_id = hir::ImplItemId { hir_id: parent_id };
|
||||||
let parent_trait_id = hir::TraitItemId { node_id: parent_id };
|
let parent_trait_id = hir::TraitItemId { hir_id: parent_id };
|
||||||
let krate = self.tcx.hir().forest.krate();
|
let krate = self.tcx.hir().forest.krate();
|
||||||
if !(krate.items.contains_key(&parent_id)
|
let parent_node_id = self.tcx.hir().hir_to_node_id(parent_id);
|
||||||
|
if !(krate.items.contains_key(&parent_node_id)
|
||||||
|| krate.impl_items.contains_key(&parent_impl_id)
|
|| krate.impl_items.contains_key(&parent_impl_id)
|
||||||
|| krate.trait_items.contains_key(&parent_trait_id))
|
|| krate.trait_items.contains_key(&parent_trait_id))
|
||||||
{
|
{
|
||||||
|
@ -2072,10 +2073,9 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
|
||||||
.expect_item_by_hir_id(self.tcx.hir().get_parent_item(parent))
|
.expect_item_by_hir_id(self.tcx.hir().get_parent_item(parent))
|
||||||
.node
|
.node
|
||||||
{
|
{
|
||||||
let parent_node_id = self.tcx.hir().hir_to_node_id(parent);
|
|
||||||
assoc_item_kind = trait_items
|
assoc_item_kind = trait_items
|
||||||
.iter()
|
.iter()
|
||||||
.find(|ti| ti.id.node_id == parent_node_id)
|
.find(|ti| ti.id.hir_id == parent)
|
||||||
.map(|ti| ti.kind);
|
.map(|ti| ti.kind);
|
||||||
}
|
}
|
||||||
match *m {
|
match *m {
|
||||||
|
@ -2094,10 +2094,9 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
|
||||||
.node
|
.node
|
||||||
{
|
{
|
||||||
impl_self = Some(self_ty);
|
impl_self = Some(self_ty);
|
||||||
let parent_node_id = self.tcx.hir().hir_to_node_id(parent);
|
|
||||||
assoc_item_kind = impl_items
|
assoc_item_kind = impl_items
|
||||||
.iter()
|
.iter()
|
||||||
.find(|ii| ii.id.node_id == parent_node_id)
|
.find(|ii| ii.id.hir_id == parent)
|
||||||
.map(|ii| ii.kind);
|
.map(|ii| ii.kind);
|
||||||
}
|
}
|
||||||
Some(body)
|
Some(body)
|
||||||
|
|
|
@ -2727,7 +2727,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
||||||
parent_vis: &hir::Visibility,
|
parent_vis: &hir::Visibility,
|
||||||
trait_item_ref: &hir::TraitItemRef)
|
trait_item_ref: &hir::TraitItemRef)
|
||||||
-> AssociatedItem {
|
-> AssociatedItem {
|
||||||
let def_id = self.hir().local_def_id(trait_item_ref.id.node_id);
|
let def_id = self.hir().local_def_id_from_hir_id(trait_item_ref.id.hir_id);
|
||||||
let (kind, has_self) = match trait_item_ref.kind {
|
let (kind, has_self) = match trait_item_ref.kind {
|
||||||
hir::AssociatedItemKind::Const => (ty::AssociatedKind::Const, false),
|
hir::AssociatedItemKind::Const => (ty::AssociatedKind::Const, false),
|
||||||
hir::AssociatedItemKind::Method { has_self } => {
|
hir::AssociatedItemKind::Method { has_self } => {
|
||||||
|
@ -2737,13 +2737,11 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
||||||
hir::AssociatedItemKind::Existential => bug!("only impls can have existentials"),
|
hir::AssociatedItemKind::Existential => bug!("only impls can have existentials"),
|
||||||
};
|
};
|
||||||
|
|
||||||
let hir_id = self.hir().node_to_hir_id(trait_item_ref.id.node_id);
|
|
||||||
|
|
||||||
AssociatedItem {
|
AssociatedItem {
|
||||||
ident: trait_item_ref.ident,
|
ident: trait_item_ref.ident,
|
||||||
kind,
|
kind,
|
||||||
// Visibility of trait items is inherited from their traits.
|
// Visibility of trait items is inherited from their traits.
|
||||||
vis: Visibility::from_hir(parent_vis, hir_id, self),
|
vis: Visibility::from_hir(parent_vis, trait_item_ref.id.hir_id, self),
|
||||||
defaultness: trait_item_ref.defaultness,
|
defaultness: trait_item_ref.defaultness,
|
||||||
def_id,
|
def_id,
|
||||||
container: TraitContainer(parent_def_id),
|
container: TraitContainer(parent_def_id),
|
||||||
|
@ -2755,7 +2753,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
||||||
parent_def_id: DefId,
|
parent_def_id: DefId,
|
||||||
impl_item_ref: &hir::ImplItemRef)
|
impl_item_ref: &hir::ImplItemRef)
|
||||||
-> AssociatedItem {
|
-> AssociatedItem {
|
||||||
let def_id = self.hir().local_def_id(impl_item_ref.id.node_id);
|
let def_id = self.hir().local_def_id_from_hir_id(impl_item_ref.id.hir_id);
|
||||||
let (kind, has_self) = match impl_item_ref.kind {
|
let (kind, has_self) = match impl_item_ref.kind {
|
||||||
hir::AssociatedItemKind::Const => (ty::AssociatedKind::Const, false),
|
hir::AssociatedItemKind::Const => (ty::AssociatedKind::Const, false),
|
||||||
hir::AssociatedItemKind::Method { has_self } => {
|
hir::AssociatedItemKind::Method { has_self } => {
|
||||||
|
@ -2765,13 +2763,11 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
||||||
hir::AssociatedItemKind::Existential => (ty::AssociatedKind::Existential, false),
|
hir::AssociatedItemKind::Existential => (ty::AssociatedKind::Existential, false),
|
||||||
};
|
};
|
||||||
|
|
||||||
let hir_id = self.hir().node_to_hir_id(impl_item_ref.id.node_id);
|
|
||||||
|
|
||||||
AssociatedItem {
|
AssociatedItem {
|
||||||
ident: impl_item_ref.ident,
|
ident: impl_item_ref.ident,
|
||||||
kind,
|
kind,
|
||||||
// Visibility of trait impl items doesn't matter.
|
// Visibility of trait impl items doesn't matter.
|
||||||
vis: ty::Visibility::from_hir(&impl_item_ref.vis, hir_id, self),
|
vis: ty::Visibility::from_hir(&impl_item_ref.vis, impl_item_ref.id.hir_id, self),
|
||||||
defaultness: impl_item_ref.defaultness,
|
defaultness: impl_item_ref.defaultness,
|
||||||
def_id,
|
def_id,
|
||||||
container: ImplContainer(parent_def_id),
|
container: ImplContainer(parent_def_id),
|
||||||
|
@ -3041,13 +3037,13 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn associated_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> AssociatedItem {
|
fn associated_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> AssociatedItem {
|
||||||
let id = tcx.hir().as_local_node_id(def_id).unwrap();
|
let id = tcx.hir().as_local_hir_id(def_id).unwrap();
|
||||||
let parent_id = tcx.hir().get_parent(id);
|
let parent_id = tcx.hir().get_parent_item(id);
|
||||||
let parent_def_id = tcx.hir().local_def_id(parent_id);
|
let parent_def_id = tcx.hir().local_def_id_from_hir_id(parent_id);
|
||||||
let parent_item = tcx.hir().expect_item(parent_id);
|
let parent_item = tcx.hir().expect_item_by_hir_id(parent_id);
|
||||||
match parent_item.node {
|
match parent_item.node {
|
||||||
hir::ItemKind::Impl(.., ref impl_item_refs) => {
|
hir::ItemKind::Impl(.., ref impl_item_refs) => {
|
||||||
if let Some(impl_item_ref) = impl_item_refs.iter().find(|i| i.id.node_id == id) {
|
if let Some(impl_item_ref) = impl_item_refs.iter().find(|i| i.id.hir_id == id) {
|
||||||
let assoc_item = tcx.associated_item_from_impl_item_ref(parent_def_id,
|
let assoc_item = tcx.associated_item_from_impl_item_ref(parent_def_id,
|
||||||
impl_item_ref);
|
impl_item_ref);
|
||||||
debug_assert_eq!(assoc_item.def_id, def_id);
|
debug_assert_eq!(assoc_item.def_id, def_id);
|
||||||
|
@ -3056,7 +3052,7 @@ fn associated_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Asso
|
||||||
}
|
}
|
||||||
|
|
||||||
hir::ItemKind::Trait(.., ref trait_item_refs) => {
|
hir::ItemKind::Trait(.., ref trait_item_refs) => {
|
||||||
if let Some(trait_item_ref) = trait_item_refs.iter().find(|i| i.id.node_id == id) {
|
if let Some(trait_item_ref) = trait_item_refs.iter().find(|i| i.id.hir_id == id) {
|
||||||
let assoc_item = tcx.associated_item_from_trait_item_ref(parent_def_id,
|
let assoc_item = tcx.associated_item_from_trait_item_ref(parent_def_id,
|
||||||
&parent_item.vis,
|
&parent_item.vis,
|
||||||
trait_item_ref);
|
trait_item_ref);
|
||||||
|
@ -3110,13 +3106,13 @@ fn associated_item_def_ids<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||||
hir::ItemKind::Trait(.., ref trait_item_refs) => {
|
hir::ItemKind::Trait(.., ref trait_item_refs) => {
|
||||||
trait_item_refs.iter()
|
trait_item_refs.iter()
|
||||||
.map(|trait_item_ref| trait_item_ref.id)
|
.map(|trait_item_ref| trait_item_ref.id)
|
||||||
.map(|id| tcx.hir().local_def_id(id.node_id))
|
.map(|id| tcx.hir().local_def_id_from_hir_id(id.hir_id))
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
hir::ItemKind::Impl(.., ref impl_item_refs) => {
|
hir::ItemKind::Impl(.., ref impl_item_refs) => {
|
||||||
impl_item_refs.iter()
|
impl_item_refs.iter()
|
||||||
.map(|impl_item_ref| impl_item_ref.id)
|
.map(|impl_item_ref| impl_item_ref.id)
|
||||||
.map(|id| tcx.hir().local_def_id(id.node_id))
|
.map(|id| tcx.hir().local_def_id_from_hir_id(id.hir_id))
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
hir::ItemKind::TraitAlias(..) => vec![],
|
hir::ItemKind::TraitAlias(..) => vec![],
|
||||||
|
|
|
@ -447,8 +447,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
|
||||||
if let hir::VisibilityKind::Inherited = it.vis.node {
|
if let hir::VisibilityKind::Inherited = it.vis.node {
|
||||||
self.private_traits.insert(it.hir_id);
|
self.private_traits.insert(it.hir_id);
|
||||||
for trait_item_ref in trait_item_refs {
|
for trait_item_ref in trait_item_refs {
|
||||||
let hir_id = cx.tcx.hir().node_to_hir_id(trait_item_ref.id.node_id);
|
self.private_traits.insert(trait_item_ref.id.hir_id);
|
||||||
self.private_traits.insert(hir_id);
|
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -464,9 +463,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
|
||||||
Some(Node::Item(item)) => {
|
Some(Node::Item(item)) => {
|
||||||
if let hir::VisibilityKind::Inherited = item.vis.node {
|
if let hir::VisibilityKind::Inherited = item.vis.node {
|
||||||
for impl_item_ref in impl_item_refs {
|
for impl_item_ref in impl_item_refs {
|
||||||
let hir_id = cx.tcx.hir().node_to_hir_id(
|
self.private_traits.insert(impl_item_ref.id.hir_id);
|
||||||
impl_item_ref.id.node_id);
|
|
||||||
self.private_traits.insert(hir_id);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -515,15 +515,13 @@ impl<'a, 'tcx> Visitor<'tcx> for EmbargoVisitor<'a, 'tcx> {
|
||||||
hir::ItemKind::Impl(.., ref trait_ref, _, ref impl_item_refs) => {
|
hir::ItemKind::Impl(.., ref trait_ref, _, ref impl_item_refs) => {
|
||||||
for impl_item_ref in impl_item_refs {
|
for impl_item_ref in impl_item_refs {
|
||||||
if trait_ref.is_some() || impl_item_ref.vis.node.is_pub() {
|
if trait_ref.is_some() || impl_item_ref.vis.node.is_pub() {
|
||||||
let hir_id = self.tcx.hir().node_to_hir_id(impl_item_ref.id.node_id);
|
self.update(impl_item_ref.id.hir_id, item_level);
|
||||||
self.update(hir_id, item_level);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
hir::ItemKind::Trait(.., ref trait_item_refs) => {
|
hir::ItemKind::Trait(.., ref trait_item_refs) => {
|
||||||
for trait_item_ref in trait_item_refs {
|
for trait_item_ref in trait_item_refs {
|
||||||
let hir_id = self.tcx.hir().node_to_hir_id(trait_item_ref.id.node_id);
|
self.update(trait_item_ref.id.hir_id, item_level);
|
||||||
self.update(hir_id, item_level);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
hir::ItemKind::Struct(ref def, _) | hir::ItemKind::Union(ref def, _) => {
|
hir::ItemKind::Struct(ref def, _) | hir::ItemKind::Union(ref def, _) => {
|
||||||
|
@ -590,8 +588,7 @@ impl<'a, 'tcx> Visitor<'tcx> for EmbargoVisitor<'a, 'tcx> {
|
||||||
self.reach(item.hir_id, item_level).generics().predicates();
|
self.reach(item.hir_id, item_level).generics().predicates();
|
||||||
|
|
||||||
for trait_item_ref in trait_item_refs {
|
for trait_item_ref in trait_item_refs {
|
||||||
let hir_id = self.tcx.hir().node_to_hir_id(trait_item_ref.id.node_id);
|
let mut reach = self.reach(trait_item_ref.id.hir_id, item_level);
|
||||||
let mut reach = self.reach(hir_id, item_level);
|
|
||||||
reach.generics().predicates();
|
reach.generics().predicates();
|
||||||
|
|
||||||
if trait_item_ref.kind == AssociatedItemKind::Type &&
|
if trait_item_ref.kind == AssociatedItemKind::Type &&
|
||||||
|
@ -614,10 +611,9 @@ impl<'a, 'tcx> Visitor<'tcx> for EmbargoVisitor<'a, 'tcx> {
|
||||||
self.reach(item.hir_id, item_level).generics().predicates().ty().trait_ref();
|
self.reach(item.hir_id, item_level).generics().predicates().ty().trait_ref();
|
||||||
|
|
||||||
for impl_item_ref in impl_item_refs {
|
for impl_item_ref in impl_item_refs {
|
||||||
let hir_id = self.tcx.hir().node_to_hir_id(impl_item_ref.id.node_id);
|
let impl_item_level = self.get(impl_item_ref.id.hir_id);
|
||||||
let impl_item_level = self.get(hir_id);
|
|
||||||
if impl_item_level.is_some() {
|
if impl_item_level.is_some() {
|
||||||
self.reach(hir_id, impl_item_level)
|
self.reach(impl_item_ref.id.hir_id, impl_item_level)
|
||||||
.generics().predicates().ty();
|
.generics().predicates().ty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1326,7 +1322,8 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> {
|
||||||
hir::ImplItemKind::Const(..) |
|
hir::ImplItemKind::Const(..) |
|
||||||
hir::ImplItemKind::Method(..) => {
|
hir::ImplItemKind::Method(..) => {
|
||||||
self.access_levels.is_reachable(
|
self.access_levels.is_reachable(
|
||||||
impl_item_ref.id.node_id)
|
self.tcx.hir().hir_to_node_id(
|
||||||
|
impl_item_ref.id.hir_id))
|
||||||
}
|
}
|
||||||
hir::ImplItemKind::Existential(..) |
|
hir::ImplItemKind::Existential(..) |
|
||||||
hir::ImplItemKind::Type(_) => false,
|
hir::ImplItemKind::Type(_) => false,
|
||||||
|
@ -1392,8 +1389,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> {
|
||||||
// methods will be visible as `Public::foo`.
|
// methods will be visible as `Public::foo`.
|
||||||
let mut found_pub_static = false;
|
let mut found_pub_static = false;
|
||||||
for impl_item_ref in impl_item_refs {
|
for impl_item_ref in impl_item_refs {
|
||||||
let hir_id = self.tcx.hir().node_to_hir_id(impl_item_ref.id.node_id);
|
if self.item_is_public(&impl_item_ref.id.hir_id, &impl_item_ref.vis) {
|
||||||
if self.item_is_public(&hir_id, &impl_item_ref.vis) {
|
|
||||||
let impl_item = self.tcx.hir().impl_item(impl_item_ref.id);
|
let impl_item = self.tcx.hir().impl_item(impl_item_ref.id);
|
||||||
match impl_item_ref.kind {
|
match impl_item_ref.kind {
|
||||||
AssociatedItemKind::Const => {
|
AssociatedItemKind::Const => {
|
||||||
|
@ -1704,8 +1700,7 @@ impl<'a, 'tcx> Visitor<'tcx> for PrivateItemsInPublicInterfacesVisitor<'a, 'tcx>
|
||||||
self.check(item.hir_id, item_visibility).generics().predicates();
|
self.check(item.hir_id, item_visibility).generics().predicates();
|
||||||
|
|
||||||
for trait_item_ref in trait_item_refs {
|
for trait_item_ref in trait_item_refs {
|
||||||
let hir_id = tcx.hir().node_to_hir_id(trait_item_ref.id.node_id);
|
self.check_trait_or_impl_item(trait_item_ref.id.hir_id, trait_item_ref.kind,
|
||||||
self.check_trait_or_impl_item(hir_id, trait_item_ref.kind,
|
|
||||||
trait_item_ref.defaultness, item_visibility);
|
trait_item_ref.defaultness, item_visibility);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1754,8 +1749,7 @@ impl<'a, 'tcx> Visitor<'tcx> for PrivateItemsInPublicInterfacesVisitor<'a, 'tcx>
|
||||||
} else {
|
} else {
|
||||||
impl_vis
|
impl_vis
|
||||||
};
|
};
|
||||||
let hir_id = tcx.hir().node_to_hir_id(impl_item_ref.id.node_id);
|
self.check_trait_or_impl_item(impl_item_ref.id.hir_id, impl_item_ref.kind,
|
||||||
self.check_trait_or_impl_item(hir_id, impl_item_ref.kind,
|
|
||||||
impl_item_ref.defaultness, impl_item_vis);
|
impl_item_ref.defaultness, impl_item_vis);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -760,11 +760,11 @@ fn compare_synthetic_generics<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||||
.source_map()
|
.source_map()
|
||||||
.span_to_snippet(trait_span)
|
.span_to_snippet(trait_span)
|
||||||
.ok()?;
|
.ok()?;
|
||||||
let trait_m = tcx.hir().as_local_node_id(trait_m.def_id)?;
|
let trait_m = tcx.hir().as_local_hir_id(trait_m.def_id)?;
|
||||||
let trait_m = tcx.hir().trait_item(hir::TraitItemId { node_id: trait_m });
|
let trait_m = tcx.hir().trait_item(hir::TraitItemId { hir_id: trait_m });
|
||||||
|
|
||||||
let impl_m = tcx.hir().as_local_node_id(impl_m.def_id)?;
|
let impl_m = tcx.hir().as_local_hir_id(impl_m.def_id)?;
|
||||||
let impl_m = tcx.hir().impl_item(hir::ImplItemId { node_id: impl_m });
|
let impl_m = tcx.hir().impl_item(hir::ImplItemId { hir_id: impl_m });
|
||||||
|
|
||||||
// in case there are no generics, take the spot between the function name
|
// in case there are no generics, take the spot between the function name
|
||||||
// and the opening paren of the argument list
|
// and the opening paren of the argument list
|
||||||
|
@ -805,8 +805,8 @@ fn compare_synthetic_generics<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||||
(None, Some(hir::SyntheticTyParamKind::ImplTrait)) => {
|
(None, Some(hir::SyntheticTyParamKind::ImplTrait)) => {
|
||||||
err.span_label(impl_span, "expected `impl Trait`, found generic parameter");
|
err.span_label(impl_span, "expected `impl Trait`, found generic parameter");
|
||||||
(|| {
|
(|| {
|
||||||
let impl_m = tcx.hir().as_local_node_id(impl_m.def_id)?;
|
let impl_m = tcx.hir().as_local_hir_id(impl_m.def_id)?;
|
||||||
let impl_m = tcx.hir().impl_item(hir::ImplItemId { node_id: impl_m });
|
let impl_m = tcx.hir().impl_item(hir::ImplItemId { hir_id: impl_m });
|
||||||
let input_tys = match impl_m.node {
|
let input_tys = match impl_m.node {
|
||||||
hir::ImplItemKind::Method(ref sig, _) => &sig.decl.inputs,
|
hir::ImplItemKind::Method(ref sig, _) => &sig.decl.inputs,
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
|
|
|
@ -108,7 +108,7 @@ fn enforce_impl_params_are_constrained<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||||
|
|
||||||
// Disallow unconstrained lifetimes, but only if they appear in assoc types.
|
// Disallow unconstrained lifetimes, but only if they appear in assoc types.
|
||||||
let lifetimes_in_associated_types: FxHashSet<_> = impl_item_refs.iter()
|
let lifetimes_in_associated_types: FxHashSet<_> = impl_item_refs.iter()
|
||||||
.map(|item_ref| tcx.hir().local_def_id(item_ref.id.node_id))
|
.map(|item_ref| tcx.hir().local_def_id_from_hir_id(item_ref.id.hir_id))
|
||||||
.filter(|&def_id| {
|
.filter(|&def_id| {
|
||||||
let item = tcx.associated_item(def_id);
|
let item = tcx.associated_item(def_id);
|
||||||
item.kind == ty::AssociatedKind::Type && item.defaultness.has_value()
|
item.kind == ty::AssociatedKind::Type && item.defaultness.has_value()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue