mirror of
https://github.com/rust-lang/rust.git
synced 2024-10-30 14:01:51 +00:00
Remove HirId -> LocalDefId
map from HIR.
This commit is contained in:
parent
3175d03d3b
commit
15d6325747
@ -67,7 +67,6 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
|
|||||||
current_hir_id_owner: hir::CRATE_OWNER_ID,
|
current_hir_id_owner: hir::CRATE_OWNER_ID,
|
||||||
item_local_id_counter: hir::ItemLocalId::new(0),
|
item_local_id_counter: hir::ItemLocalId::new(0),
|
||||||
node_id_to_local_id: Default::default(),
|
node_id_to_local_id: Default::default(),
|
||||||
local_id_to_def_id: SortedMap::new(),
|
|
||||||
trait_map: Default::default(),
|
trait_map: Default::default(),
|
||||||
|
|
||||||
// Lowering state.
|
// Lowering state.
|
||||||
|
@ -119,7 +119,6 @@ struct LoweringContext<'a, 'hir> {
|
|||||||
|
|
||||||
current_hir_id_owner: hir::OwnerId,
|
current_hir_id_owner: hir::OwnerId,
|
||||||
item_local_id_counter: hir::ItemLocalId,
|
item_local_id_counter: hir::ItemLocalId,
|
||||||
local_id_to_def_id: SortedMap<ItemLocalId, LocalDefId>,
|
|
||||||
trait_map: FxHashMap<ItemLocalId, Box<[TraitCandidate]>>,
|
trait_map: FxHashMap<ItemLocalId, Box<[TraitCandidate]>>,
|
||||||
|
|
||||||
impl_trait_defs: Vec<hir::GenericParam<'hir>>,
|
impl_trait_defs: Vec<hir::GenericParam<'hir>>,
|
||||||
@ -567,7 +566,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||||||
let current_attrs = std::mem::take(&mut self.attrs);
|
let current_attrs = std::mem::take(&mut self.attrs);
|
||||||
let current_bodies = std::mem::take(&mut self.bodies);
|
let current_bodies = std::mem::take(&mut self.bodies);
|
||||||
let current_node_ids = std::mem::take(&mut self.node_id_to_local_id);
|
let current_node_ids = std::mem::take(&mut self.node_id_to_local_id);
|
||||||
let current_id_to_def_id = std::mem::take(&mut self.local_id_to_def_id);
|
|
||||||
let current_trait_map = std::mem::take(&mut self.trait_map);
|
let current_trait_map = std::mem::take(&mut self.trait_map);
|
||||||
let current_owner =
|
let current_owner =
|
||||||
std::mem::replace(&mut self.current_hir_id_owner, hir::OwnerId { def_id });
|
std::mem::replace(&mut self.current_hir_id_owner, hir::OwnerId { def_id });
|
||||||
@ -594,7 +592,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||||||
self.attrs = current_attrs;
|
self.attrs = current_attrs;
|
||||||
self.bodies = current_bodies;
|
self.bodies = current_bodies;
|
||||||
self.node_id_to_local_id = current_node_ids;
|
self.node_id_to_local_id = current_node_ids;
|
||||||
self.local_id_to_def_id = current_id_to_def_id;
|
|
||||||
self.trait_map = current_trait_map;
|
self.trait_map = current_trait_map;
|
||||||
self.current_hir_id_owner = current_owner;
|
self.current_hir_id_owner = current_owner;
|
||||||
self.item_local_id_counter = current_local_counter;
|
self.item_local_id_counter = current_local_counter;
|
||||||
@ -629,7 +626,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||||||
fn make_owner_info(&mut self, node: hir::OwnerNode<'hir>) -> &'hir hir::OwnerInfo<'hir> {
|
fn make_owner_info(&mut self, node: hir::OwnerNode<'hir>) -> &'hir hir::OwnerInfo<'hir> {
|
||||||
let attrs = std::mem::take(&mut self.attrs);
|
let attrs = std::mem::take(&mut self.attrs);
|
||||||
let mut bodies = std::mem::take(&mut self.bodies);
|
let mut bodies = std::mem::take(&mut self.bodies);
|
||||||
let local_id_to_def_id = std::mem::take(&mut self.local_id_to_def_id);
|
|
||||||
let trait_map = std::mem::take(&mut self.trait_map);
|
let trait_map = std::mem::take(&mut self.trait_map);
|
||||||
|
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
@ -645,13 +641,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||||||
let (hash_including_bodies, hash_without_bodies) = self.hash_owner(node, &bodies);
|
let (hash_including_bodies, hash_without_bodies) = self.hash_owner(node, &bodies);
|
||||||
let (nodes, parenting) =
|
let (nodes, parenting) =
|
||||||
index::index_hir(self.tcx.sess, &*self.tcx.definitions_untracked(), node, &bodies);
|
index::index_hir(self.tcx.sess, &*self.tcx.definitions_untracked(), node, &bodies);
|
||||||
let nodes = hir::OwnerNodes {
|
let nodes = hir::OwnerNodes { hash_including_bodies, hash_without_bodies, nodes, bodies };
|
||||||
hash_including_bodies,
|
|
||||||
hash_without_bodies,
|
|
||||||
nodes,
|
|
||||||
bodies,
|
|
||||||
local_id_to_def_id,
|
|
||||||
};
|
|
||||||
let attrs = {
|
let attrs = {
|
||||||
let hash = self.tcx.with_stable_hashing_context(|mut hcx| {
|
let hash = self.tcx.with_stable_hashing_context(|mut hcx| {
|
||||||
let mut stable_hasher = StableHasher::new();
|
let mut stable_hasher = StableHasher::new();
|
||||||
@ -710,7 +700,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||||||
assert_ne!(local_id, hir::ItemLocalId::new(0));
|
assert_ne!(local_id, hir::ItemLocalId::new(0));
|
||||||
if let Some(def_id) = self.opt_local_def_id(ast_node_id) {
|
if let Some(def_id) = self.opt_local_def_id(ast_node_id) {
|
||||||
self.children.push((def_id, hir::MaybeOwner::NonOwner(hir_id)));
|
self.children.push((def_id, hir::MaybeOwner::NonOwner(hir_id)));
|
||||||
self.local_id_to_def_id.insert(local_id, def_id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(traits) = self.resolver.trait_map.remove(&ast_node_id) {
|
if let Some(traits) = self.resolver.trait_map.remove(&ast_node_id) {
|
||||||
|
@ -831,8 +831,6 @@ pub struct OwnerNodes<'tcx> {
|
|||||||
pub nodes: IndexVec<ItemLocalId, Option<ParentedNode<'tcx>>>,
|
pub nodes: IndexVec<ItemLocalId, Option<ParentedNode<'tcx>>>,
|
||||||
/// Content of local bodies.
|
/// Content of local bodies.
|
||||||
pub bodies: SortedMap<ItemLocalId, &'tcx Body<'tcx>>,
|
pub bodies: SortedMap<ItemLocalId, &'tcx Body<'tcx>>,
|
||||||
/// Non-owning definitions contained in this owner.
|
|
||||||
pub local_id_to_def_id: SortedMap<ItemLocalId, LocalDefId>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> OwnerNodes<'tcx> {
|
impl<'tcx> OwnerNodes<'tcx> {
|
||||||
@ -862,7 +860,6 @@ impl fmt::Debug for OwnerNodes<'_> {
|
|||||||
.collect::<Vec<_>>(),
|
.collect::<Vec<_>>(),
|
||||||
)
|
)
|
||||||
.field("bodies", &self.bodies)
|
.field("bodies", &self.bodies)
|
||||||
.field("local_id_to_def_id", &self.local_id_to_def_id)
|
|
||||||
.field("hash_without_bodies", &self.hash_without_bodies)
|
.field("hash_without_bodies", &self.hash_without_bodies)
|
||||||
.field("hash_including_bodies", &self.hash_including_bodies)
|
.field("hash_including_bodies", &self.hash_including_bodies)
|
||||||
.finish()
|
.finish()
|
||||||
|
@ -100,13 +100,8 @@ impl<'tcx, HirCtx: crate::HashStableContext> HashStable<HirCtx> for OwnerNodes<'
|
|||||||
// `local_id_to_def_id` is also ignored because is dependent on the body, then just hashing
|
// `local_id_to_def_id` is also ignored because is dependent on the body, then just hashing
|
||||||
// the body satisfies the condition of two nodes being different have different
|
// the body satisfies the condition of two nodes being different have different
|
||||||
// `hash_stable` results.
|
// `hash_stable` results.
|
||||||
let OwnerNodes {
|
let OwnerNodes { hash_including_bodies, hash_without_bodies: _, nodes: _, bodies: _ } =
|
||||||
hash_including_bodies,
|
*self;
|
||||||
hash_without_bodies: _,
|
|
||||||
nodes: _,
|
|
||||||
bodies: _,
|
|
||||||
local_id_to_def_id: _,
|
|
||||||
} = *self;
|
|
||||||
hash_including_bodies.hash_stable(hcx, hasher);
|
hash_including_bodies.hash_stable(hcx, hasher);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -665,7 +665,7 @@ fn check_item_type(tcx: TyCtxt<'_>, id: hir::ItemId) {
|
|||||||
DefKind::GlobalAsm => {
|
DefKind::GlobalAsm => {
|
||||||
let it = tcx.hir().item(id);
|
let it = tcx.hir().item(id);
|
||||||
let hir::ItemKind::GlobalAsm(asm) = it.kind else { span_bug!(it.span, "DefKind::GlobalAsm but got {:#?}", it) };
|
let hir::ItemKind::GlobalAsm(asm) = it.kind else { span_bug!(it.span, "DefKind::GlobalAsm but got {:#?}", it) };
|
||||||
InlineAsmCtxt::new_global_asm(tcx).check_asm(asm, id.hir_id());
|
InlineAsmCtxt::new_global_asm(tcx).check_asm(asm, id.owner_id.def_id);
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ use rustc_data_structures::fx::FxHashSet;
|
|||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_middle::ty::{self, Article, FloatTy, IntTy, Ty, TyCtxt, TypeVisitable, UintTy};
|
use rustc_middle::ty::{self, Article, FloatTy, IntTy, Ty, TyCtxt, TypeVisitable, UintTy};
|
||||||
use rustc_session::lint;
|
use rustc_session::lint;
|
||||||
|
use rustc_span::def_id::LocalDefId;
|
||||||
use rustc_span::{Symbol, DUMMY_SP};
|
use rustc_span::{Symbol, DUMMY_SP};
|
||||||
use rustc_target::asm::{InlineAsmReg, InlineAsmRegClass, InlineAsmRegOrRegClass, InlineAsmType};
|
use rustc_target::asm::{InlineAsmReg, InlineAsmRegClass, InlineAsmRegOrRegClass, InlineAsmType};
|
||||||
|
|
||||||
@ -253,10 +254,8 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
|
|||||||
Some(asm_ty)
|
Some(asm_ty)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn check_asm(&self, asm: &hir::InlineAsm<'tcx>, enclosing_id: hir::HirId) {
|
pub fn check_asm(&self, asm: &hir::InlineAsm<'tcx>, enclosing_id: LocalDefId) {
|
||||||
let hir = self.tcx.hir();
|
let target_features = self.tcx.asm_target_features(enclosing_id.to_def_id());
|
||||||
let enclosing_def_id = hir.local_def_id(enclosing_id).to_def_id();
|
|
||||||
let target_features = self.tcx.asm_target_features(enclosing_def_id);
|
|
||||||
let Some(asm_arch) = self.tcx.sess.asm_arch else {
|
let Some(asm_arch) = self.tcx.sess.asm_arch else {
|
||||||
self.tcx.sess.delay_span_bug(DUMMY_SP, "target architecture does not support asm");
|
self.tcx.sess.delay_span_bug(DUMMY_SP, "target architecture does not support asm");
|
||||||
return;
|
return;
|
||||||
|
@ -391,7 +391,7 @@ fn check_gat_where_clauses(tcx: TyCtxt<'_>, associated_items: &[hir::TraitItemRe
|
|||||||
gather_gat_bounds(
|
gather_gat_bounds(
|
||||||
tcx,
|
tcx,
|
||||||
param_env,
|
param_env,
|
||||||
item_def_id.def_id,
|
item_def_id,
|
||||||
sig.inputs_and_output,
|
sig.inputs_and_output,
|
||||||
// We also assume that all of the function signature's parameter types
|
// We also assume that all of the function signature's parameter types
|
||||||
// are well formed.
|
// are well formed.
|
||||||
@ -413,7 +413,7 @@ fn check_gat_where_clauses(tcx: TyCtxt<'_>, associated_items: &[hir::TraitItemRe
|
|||||||
gather_gat_bounds(
|
gather_gat_bounds(
|
||||||
tcx,
|
tcx,
|
||||||
param_env,
|
param_env,
|
||||||
item_def_id.def_id,
|
item_def_id,
|
||||||
tcx.explicit_item_bounds(item_def_id).to_vec(),
|
tcx.explicit_item_bounds(item_def_id).to_vec(),
|
||||||
&FxIndexSet::default(),
|
&FxIndexSet::default(),
|
||||||
gat_def_id.def_id,
|
gat_def_id.def_id,
|
||||||
@ -563,7 +563,7 @@ fn augment_param_env<'tcx>(
|
|||||||
fn gather_gat_bounds<'tcx, T: TypeFoldable<'tcx>>(
|
fn gather_gat_bounds<'tcx, T: TypeFoldable<'tcx>>(
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
param_env: ty::ParamEnv<'tcx>,
|
param_env: ty::ParamEnv<'tcx>,
|
||||||
item_def_id: LocalDefId,
|
item_def_id: hir::OwnerId,
|
||||||
to_check: T,
|
to_check: T,
|
||||||
wf_tys: &FxIndexSet<Ty<'tcx>>,
|
wf_tys: &FxIndexSet<Ty<'tcx>>,
|
||||||
gat_def_id: LocalDefId,
|
gat_def_id: LocalDefId,
|
||||||
@ -596,7 +596,7 @@ fn gather_gat_bounds<'tcx, T: TypeFoldable<'tcx>>(
|
|||||||
// reflected in a where clause on the GAT itself.
|
// reflected in a where clause on the GAT itself.
|
||||||
for (ty, ty_idx) in &types {
|
for (ty, ty_idx) in &types {
|
||||||
// In our example, requires that `Self: 'a`
|
// In our example, requires that `Self: 'a`
|
||||||
if ty_known_to_outlive(tcx, item_def_id, param_env, &wf_tys, *ty, *region_a) {
|
if ty_known_to_outlive(tcx, item_def_id.def_id, param_env, &wf_tys, *ty, *region_a) {
|
||||||
debug!(?ty_idx, ?region_a_idx);
|
debug!(?ty_idx, ?region_a_idx);
|
||||||
debug!("required clause: {ty} must outlive {region_a}");
|
debug!("required clause: {ty} must outlive {region_a}");
|
||||||
// Translate into the generic parameters of the GAT. In
|
// Translate into the generic parameters of the GAT. In
|
||||||
@ -634,7 +634,14 @@ fn gather_gat_bounds<'tcx, T: TypeFoldable<'tcx>>(
|
|||||||
if ty::ReStatic == **region_b || region_a == region_b {
|
if ty::ReStatic == **region_b || region_a == region_b {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if region_known_to_outlive(tcx, item_def_id, param_env, &wf_tys, *region_a, *region_b) {
|
if region_known_to_outlive(
|
||||||
|
tcx,
|
||||||
|
item_def_id.def_id,
|
||||||
|
param_env,
|
||||||
|
&wf_tys,
|
||||||
|
*region_a,
|
||||||
|
*region_b,
|
||||||
|
) {
|
||||||
debug!(?region_a_idx, ?region_b_idx);
|
debug!(?region_a_idx, ?region_b_idx);
|
||||||
debug!("required clause: {region_a} must outlive {region_b}");
|
debug!("required clause: {region_a} must outlive {region_b}");
|
||||||
// Translate into the generic parameters of the GAT.
|
// Translate into the generic parameters of the GAT.
|
||||||
|
@ -1264,14 +1264,21 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
|
|||||||
} else if let Some(body_id) = outermost_body {
|
} else if let Some(body_id) = outermost_body {
|
||||||
let fn_id = self.tcx.hir().body_owner(body_id);
|
let fn_id = self.tcx.hir().body_owner(body_id);
|
||||||
match self.tcx.hir().get(fn_id) {
|
match self.tcx.hir().get(fn_id) {
|
||||||
Node::Item(hir::Item { kind: hir::ItemKind::Fn(..), .. })
|
Node::Item(hir::Item { owner_id, kind: hir::ItemKind::Fn(..), .. })
|
||||||
| Node::TraitItem(hir::TraitItem {
|
| Node::TraitItem(hir::TraitItem {
|
||||||
kind: hir::TraitItemKind::Fn(..), ..
|
owner_id,
|
||||||
|
kind: hir::TraitItemKind::Fn(..),
|
||||||
|
..
|
||||||
})
|
})
|
||||||
| Node::ImplItem(hir::ImplItem { kind: hir::ImplItemKind::Fn(..), .. })
|
| Node::ImplItem(hir::ImplItem {
|
||||||
| Node::Expr(hir::Expr { kind: hir::ExprKind::Closure(..), .. }) => {
|
owner_id,
|
||||||
let scope = self.tcx.hir().local_def_id(fn_id);
|
kind: hir::ImplItemKind::Fn(..),
|
||||||
def = Region::Free(scope.to_def_id(), def.id().unwrap());
|
..
|
||||||
|
}) => {
|
||||||
|
def = Region::Free(owner_id.to_def_id(), def.id().unwrap());
|
||||||
|
}
|
||||||
|
Node::Expr(hir::Expr { kind: hir::ExprKind::Closure(closure), .. }) => {
|
||||||
|
def = Region::Free(closure.def_id.to_def_id(), def.id().unwrap());
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
@ -1658,10 +1665,12 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
|
|||||||
/// "Constrained" basically means that it appears in any type but
|
/// "Constrained" basically means that it appears in any type but
|
||||||
/// not amongst the inputs to a projection. In other words, `<&'a
|
/// not amongst the inputs to a projection. In other words, `<&'a
|
||||||
/// T as Trait<''b>>::Foo` does not constrain `'a` or `'b`.
|
/// T as Trait<''b>>::Foo` does not constrain `'a` or `'b`.
|
||||||
fn is_late_bound_map(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<&FxIndexSet<LocalDefId>> {
|
fn is_late_bound_map(
|
||||||
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
|
tcx: TyCtxt<'_>,
|
||||||
let decl = tcx.hir().fn_decl_by_hir_id(hir_id)?;
|
owner_id: hir::OwnerId,
|
||||||
let generics = tcx.hir().get_generics(def_id)?;
|
) -> Option<&FxIndexSet<hir::ItemLocalId>> {
|
||||||
|
let decl = tcx.hir().fn_decl_by_hir_id(owner_id.into())?;
|
||||||
|
let generics = tcx.hir().get_generics(owner_id.def_id)?;
|
||||||
|
|
||||||
let mut late_bound = FxIndexSet::default();
|
let mut late_bound = FxIndexSet::default();
|
||||||
|
|
||||||
@ -1695,24 +1704,22 @@ fn is_late_bound_map(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<&FxIndexSet<
|
|||||||
hir::GenericParamKind::Type { .. } | hir::GenericParamKind::Const { .. } => continue,
|
hir::GenericParamKind::Type { .. } | hir::GenericParamKind::Const { .. } => continue,
|
||||||
}
|
}
|
||||||
|
|
||||||
let param_def_id = tcx.hir().local_def_id(param.hir_id);
|
|
||||||
|
|
||||||
// appears in the where clauses? early-bound.
|
// appears in the where clauses? early-bound.
|
||||||
if appears_in_where_clause.regions.contains(¶m_def_id) {
|
if appears_in_where_clause.regions.contains(¶m.def_id) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// does not appear in the inputs, but appears in the return type? early-bound.
|
// does not appear in the inputs, but appears in the return type? early-bound.
|
||||||
if !constrained_by_input.regions.contains(¶m_def_id)
|
if !constrained_by_input.regions.contains(¶m.def_id)
|
||||||
&& appears_in_output.regions.contains(¶m_def_id)
|
&& appears_in_output.regions.contains(¶m.def_id)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
debug!("lifetime {:?} with id {:?} is late-bound", param.name.ident(), param.hir_id);
|
debug!("lifetime {:?} with id {:?} is late-bound", param.name.ident(), param.def_id);
|
||||||
|
|
||||||
let inserted = late_bound.insert(param_def_id);
|
let inserted = late_bound.insert(param.hir_id.local_id);
|
||||||
assert!(inserted, "visited lifetime {:?} twice", param.hir_id);
|
assert!(inserted, "visited lifetime {:?} twice", param.def_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
debug!(?late_bound);
|
debug!(?late_bound);
|
||||||
|
@ -280,7 +280,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP
|
|||||||
}
|
}
|
||||||
|
|
||||||
let hir::GenericParamKind::Lifetime { .. } = duplicate.kind else { continue };
|
let hir::GenericParamKind::Lifetime { .. } = duplicate.kind else { continue };
|
||||||
let dup_def = tcx.hir().local_def_id(duplicate.hir_id).to_def_id();
|
let dup_def = duplicate.def_id.to_def_id();
|
||||||
|
|
||||||
let Some(dup_index) = generics.param_def_id_to_index(tcx, dup_def) else { bug!() };
|
let Some(dup_index) = generics.param_def_id_to_index(tcx, dup_def) else { bug!() };
|
||||||
|
|
||||||
|
@ -54,15 +54,14 @@ pub(super) fn opt_const_param_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<
|
|||||||
// ty which is a fully resolved projection.
|
// ty which is a fully resolved projection.
|
||||||
// For the code example above, this would mean converting Self::Assoc<3>
|
// For the code example above, this would mean converting Self::Assoc<3>
|
||||||
// into a ty::Alias(ty::Projection, <Self as Foo>::Assoc<3>)
|
// into a ty::Alias(ty::Projection, <Self as Foo>::Assoc<3>)
|
||||||
let item_hir_id = tcx
|
let item_def_id = tcx
|
||||||
.hir()
|
.hir()
|
||||||
.parent_iter(hir_id)
|
.parent_owner_iter(hir_id)
|
||||||
.filter(|(_, node)| matches!(node, Node::Item(_)))
|
.find(|(_, node)| matches!(node, OwnerNode::Item(_)))
|
||||||
.map(|(id, _)| id)
|
.unwrap()
|
||||||
.next()
|
.0
|
||||||
.unwrap();
|
.to_def_id();
|
||||||
let item_did = tcx.hir().local_def_id(item_hir_id).to_def_id();
|
let item_ctxt = &ItemCtxt::new(tcx, item_def_id) as &dyn crate::astconv::AstConv<'_>;
|
||||||
let item_ctxt = &ItemCtxt::new(tcx, item_did) as &dyn crate::astconv::AstConv<'_>;
|
|
||||||
let ty = item_ctxt.ast_ty_to_ty(hir_ty);
|
let ty = item_ctxt.ast_ty_to_ty(hir_ty);
|
||||||
|
|
||||||
// Iterate through the generics of the projection to find the one that corresponds to
|
// Iterate through the generics of the projection to find the one that corresponds to
|
||||||
|
@ -186,6 +186,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
prior_arm: Option<(Option<hir::HirId>, Ty<'tcx>, Span)>,
|
prior_arm: Option<(Option<hir::HirId>, Ty<'tcx>, Span)>,
|
||||||
) {
|
) {
|
||||||
let hir = self.tcx.hir();
|
let hir = self.tcx.hir();
|
||||||
|
|
||||||
// First, check that we're actually in the tail of a function.
|
// First, check that we're actually in the tail of a function.
|
||||||
let Some(body_id) = hir.maybe_body_owned_by(self.body_id) else { return; };
|
let Some(body_id) = hir.maybe_body_owned_by(self.body_id) else { return; };
|
||||||
let body = hir.body(body_id);
|
let body = hir.body(body_id);
|
||||||
|
@ -130,7 +130,12 @@ pub(super) fn check_fn<'a, 'tcx>(
|
|||||||
let gen_ty = if let (Some(_), Some(gen_kind)) = (can_be_generator, body.generator_kind) {
|
let gen_ty = if let (Some(_), Some(gen_kind)) = (can_be_generator, body.generator_kind) {
|
||||||
let interior = fcx
|
let interior = fcx
|
||||||
.next_ty_var(TypeVariableOrigin { kind: TypeVariableOriginKind::MiscVariable, span });
|
.next_ty_var(TypeVariableOrigin { kind: TypeVariableOriginKind::MiscVariable, span });
|
||||||
fcx.deferred_generator_interiors.borrow_mut().push((fn_id, body.id(), interior, gen_kind));
|
fcx.deferred_generator_interiors.borrow_mut().push((
|
||||||
|
fn_def_id,
|
||||||
|
body.id(),
|
||||||
|
interior,
|
||||||
|
gen_kind,
|
||||||
|
));
|
||||||
|
|
||||||
let (resume_ty, yield_ty) = fcx.resume_yield_tys.unwrap();
|
let (resume_ty, yield_ty) = fcx.resume_yield_tys.unwrap();
|
||||||
Some(GeneratorTypes {
|
Some(GeneratorTypes {
|
||||||
@ -167,12 +172,12 @@ pub(super) fn check_fn<'a, 'tcx>(
|
|||||||
|
|
||||||
// Check that a function marked as `#[panic_handler]` has signature `fn(&PanicInfo) -> !`
|
// Check that a function marked as `#[panic_handler]` has signature `fn(&PanicInfo) -> !`
|
||||||
if let Some(panic_impl_did) = tcx.lang_items().panic_impl()
|
if let Some(panic_impl_did) = tcx.lang_items().panic_impl()
|
||||||
&& panic_impl_did == hir.local_def_id(fn_id).to_def_id()
|
&& panic_impl_did == fn_def_id.to_def_id()
|
||||||
{
|
{
|
||||||
check_panic_info_fn(tcx, panic_impl_did.expect_local(), fn_sig, decl, declared_ret_ty);
|
check_panic_info_fn(tcx, panic_impl_did.expect_local(), fn_sig, decl, declared_ret_ty);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(lang_start_defid) = tcx.lang_items().start_fn() && lang_start_defid == hir.local_def_id(fn_id).to_def_id() {
|
if let Some(lang_start_defid) = tcx.lang_items().start_fn() && lang_start_defid == fn_def_id.to_def_id() {
|
||||||
check_lang_start_fn(tcx, fn_sig, decl, fn_def_id);
|
check_lang_start_fn(tcx, fn_sig, decl, fn_def_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -549,8 +549,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
let generators = std::mem::take(&mut *self.deferred_generator_interiors.borrow_mut());
|
let generators = std::mem::take(&mut *self.deferred_generator_interiors.borrow_mut());
|
||||||
debug!(?generators);
|
debug!(?generators);
|
||||||
|
|
||||||
for &(expr_hir_id, body_id, interior, _) in generators.iter() {
|
for &(expr_def_id, body_id, interior, _) in generators.iter() {
|
||||||
let expr_def_id = self.tcx.hir().local_def_id(expr_hir_id);
|
|
||||||
debug!(?expr_def_id);
|
debug!(?expr_def_id);
|
||||||
|
|
||||||
// Create the `GeneratorWitness` type that we will unify with `interior`.
|
// Create the `GeneratorWitness` type that we will unify with `interior`.
|
||||||
|
@ -79,7 +79,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
InlineAsmCtxt::new_in_fn(self.tcx, self.param_env, get_operand_ty)
|
InlineAsmCtxt::new_in_fn(self.tcx, self.param_env, get_operand_ty)
|
||||||
.check_asm(asm, self.tcx.hir().local_def_id_to_hir_id(enclosing_id));
|
.check_asm(asm, enclosing_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ pub struct Inherited<'tcx> {
|
|||||||
pub(super) deferred_asm_checks: RefCell<Vec<(&'tcx hir::InlineAsm<'tcx>, hir::HirId)>>,
|
pub(super) deferred_asm_checks: RefCell<Vec<(&'tcx hir::InlineAsm<'tcx>, hir::HirId)>>,
|
||||||
|
|
||||||
pub(super) deferred_generator_interiors:
|
pub(super) deferred_generator_interiors:
|
||||||
RefCell<Vec<(hir::HirId, hir::BodyId, Ty<'tcx>, hir::GeneratorKind)>>,
|
RefCell<Vec<(LocalDefId, hir::BodyId, Ty<'tcx>, hir::GeneratorKind)>>,
|
||||||
|
|
||||||
pub(super) body_id: Option<hir::BodyId>,
|
pub(super) body_id: Option<hir::BodyId>,
|
||||||
|
|
||||||
|
@ -40,8 +40,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
&self,
|
&self,
|
||||||
body: &'tcx hir::Body<'tcx>,
|
body: &'tcx hir::Body<'tcx>,
|
||||||
) -> &'tcx ty::TypeckResults<'tcx> {
|
) -> &'tcx ty::TypeckResults<'tcx> {
|
||||||
let item_id = self.tcx.hir().body_owner(body.id());
|
let item_def_id = self.tcx.hir().body_owner_def_id(body.id());
|
||||||
let item_def_id = self.tcx.hir().local_def_id(item_id);
|
|
||||||
|
|
||||||
// This attribute causes us to dump some writeback information
|
// This attribute causes us to dump some writeback information
|
||||||
// in the form of errors, which is used for unit tests.
|
// in the form of errors, which is used for unit tests.
|
||||||
@ -55,7 +54,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
// Type only exists for constants and statics, not functions.
|
// Type only exists for constants and statics, not functions.
|
||||||
match self.tcx.hir().body_owner_kind(item_def_id) {
|
match self.tcx.hir().body_owner_kind(item_def_id) {
|
||||||
hir::BodyOwnerKind::Const | hir::BodyOwnerKind::Static(_) => {
|
hir::BodyOwnerKind::Const | hir::BodyOwnerKind::Static(_) => {
|
||||||
wbcx.visit_node_id(body.value.span, item_id);
|
let item_hir_id = self.tcx.hir().local_def_id_to_hir_id(item_def_id);
|
||||||
|
wbcx.visit_node_id(body.value.span, item_hir_id);
|
||||||
}
|
}
|
||||||
hir::BodyOwnerKind::Closure | hir::BodyOwnerKind::Fn => (),
|
hir::BodyOwnerKind::Closure | hir::BodyOwnerKind::Fn => (),
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ use rustc_data_structures::fx::FxHashSet;
|
|||||||
use rustc_data_structures::graph::implementation::{Direction, NodeIndex, INCOMING, OUTGOING};
|
use rustc_data_structures::graph::implementation::{Direction, NodeIndex, INCOMING, OUTGOING};
|
||||||
use rustc_graphviz as dot;
|
use rustc_graphviz as dot;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def_id::DefId;
|
use rustc_hir::def_id::{DefId, LocalDefId, CRATE_DEF_ID};
|
||||||
use rustc_hir::intravisit::{self, Visitor};
|
use rustc_hir::intravisit::{self, Visitor};
|
||||||
use rustc_middle::dep_graph::{
|
use rustc_middle::dep_graph::{
|
||||||
DepGraphQuery, DepKind, DepNode, DepNodeExt, DepNodeFilter, EdgeFilter,
|
DepGraphQuery, DepKind, DepNode, DepNodeExt, DepNodeFilter, EdgeFilter,
|
||||||
@ -74,7 +74,7 @@ pub fn assert_dep_graph(tcx: TyCtxt<'_>) {
|
|||||||
let (if_this_changed, then_this_would_need) = {
|
let (if_this_changed, then_this_would_need) = {
|
||||||
let mut visitor =
|
let mut visitor =
|
||||||
IfThisChanged { tcx, if_this_changed: vec![], then_this_would_need: vec![] };
|
IfThisChanged { tcx, if_this_changed: vec![], then_this_would_need: vec![] };
|
||||||
visitor.process_attrs(hir::CRATE_HIR_ID);
|
visitor.process_attrs(CRATE_DEF_ID);
|
||||||
tcx.hir().visit_all_item_likes_in_crate(&mut visitor);
|
tcx.hir().visit_all_item_likes_in_crate(&mut visitor);
|
||||||
(visitor.if_this_changed, visitor.then_this_would_need)
|
(visitor.if_this_changed, visitor.then_this_would_need)
|
||||||
};
|
};
|
||||||
@ -119,9 +119,9 @@ impl<'tcx> IfThisChanged<'tcx> {
|
|||||||
value
|
value
|
||||||
}
|
}
|
||||||
|
|
||||||
fn process_attrs(&mut self, hir_id: hir::HirId) {
|
fn process_attrs(&mut self, def_id: LocalDefId) {
|
||||||
let def_id = self.tcx.hir().local_def_id(hir_id);
|
|
||||||
let def_path_hash = self.tcx.def_path_hash(def_id.to_def_id());
|
let def_path_hash = self.tcx.def_path_hash(def_id.to_def_id());
|
||||||
|
let hir_id = self.tcx.hir().local_def_id_to_hir_id(def_id);
|
||||||
let attrs = self.tcx.hir().attrs(hir_id);
|
let attrs = self.tcx.hir().attrs(hir_id);
|
||||||
for attr in attrs {
|
for attr in attrs {
|
||||||
if attr.has_name(sym::rustc_if_this_changed) {
|
if attr.has_name(sym::rustc_if_this_changed) {
|
||||||
@ -180,22 +180,22 @@ impl<'tcx> Visitor<'tcx> for IfThisChanged<'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) {
|
fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) {
|
||||||
self.process_attrs(item.hir_id());
|
self.process_attrs(item.owner_id.def_id);
|
||||||
intravisit::walk_item(self, item);
|
intravisit::walk_item(self, item);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem<'tcx>) {
|
fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem<'tcx>) {
|
||||||
self.process_attrs(trait_item.hir_id());
|
self.process_attrs(trait_item.owner_id.def_id);
|
||||||
intravisit::walk_trait_item(self, trait_item);
|
intravisit::walk_trait_item(self, trait_item);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem<'tcx>) {
|
fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem<'tcx>) {
|
||||||
self.process_attrs(impl_item.hir_id());
|
self.process_attrs(impl_item.owner_id.def_id);
|
||||||
intravisit::walk_impl_item(self, impl_item);
|
intravisit::walk_impl_item(self, impl_item);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_field_def(&mut self, s: &'tcx hir::FieldDef<'tcx>) {
|
fn visit_field_def(&mut self, s: &'tcx hir::FieldDef<'tcx>) {
|
||||||
self.process_attrs(s.hir_id);
|
self.process_attrs(s.def_id);
|
||||||
intravisit::walk_field_def(self, s);
|
intravisit::walk_field_def(self, s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -56,9 +56,7 @@ use rustc_hir as hir;
|
|||||||
use rustc_hir::def::{DefKind, Res};
|
use rustc_hir::def::{DefKind, Res};
|
||||||
use rustc_hir::def_id::{DefId, LocalDefId, LocalDefIdSet, CRATE_DEF_ID};
|
use rustc_hir::def_id::{DefId, LocalDefId, LocalDefIdSet, CRATE_DEF_ID};
|
||||||
use rustc_hir::intravisit::FnKind as HirFnKind;
|
use rustc_hir::intravisit::FnKind as HirFnKind;
|
||||||
use rustc_hir::{
|
use rustc_hir::{Body, FnDecl, ForeignItemKind, GenericParamKind, Node, PatKind, PredicateOrigin};
|
||||||
Body, FnDecl, ForeignItemKind, GenericParamKind, HirId, Node, PatKind, PredicateOrigin,
|
|
||||||
};
|
|
||||||
use rustc_index::vec::Idx;
|
use rustc_index::vec::Idx;
|
||||||
use rustc_middle::lint::in_external_macro;
|
use rustc_middle::lint::in_external_macro;
|
||||||
use rustc_middle::ty::layout::{LayoutError, LayoutOf};
|
use rustc_middle::ty::layout::{LayoutError, LayoutOf};
|
||||||
@ -2661,7 +2659,7 @@ pub struct ClashingExternDeclarations {
|
|||||||
/// the symbol should be reported as a clashing declaration.
|
/// the symbol should be reported as a clashing declaration.
|
||||||
// FIXME: Technically, we could just store a &'tcx str here without issue; however, the
|
// FIXME: Technically, we could just store a &'tcx str here without issue; however, the
|
||||||
// `impl_lint_pass` macro doesn't currently support lints parametric over a lifetime.
|
// `impl_lint_pass` macro doesn't currently support lints parametric over a lifetime.
|
||||||
seen_decls: FxHashMap<Symbol, HirId>,
|
seen_decls: FxHashMap<Symbol, hir::OwnerId>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Differentiate between whether the name for an extern decl came from the link_name attribute or
|
/// Differentiate between whether the name for an extern decl came from the link_name attribute or
|
||||||
@ -2687,19 +2685,20 @@ impl ClashingExternDeclarations {
|
|||||||
pub(crate) fn new() -> Self {
|
pub(crate) fn new() -> Self {
|
||||||
ClashingExternDeclarations { seen_decls: FxHashMap::default() }
|
ClashingExternDeclarations { seen_decls: FxHashMap::default() }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Insert a new foreign item into the seen set. If a symbol with the same name already exists
|
/// Insert a new foreign item into the seen set. If a symbol with the same name already exists
|
||||||
/// for the item, return its HirId without updating the set.
|
/// for the item, return its HirId without updating the set.
|
||||||
fn insert(&mut self, tcx: TyCtxt<'_>, fi: &hir::ForeignItem<'_>) -> Option<HirId> {
|
fn insert(&mut self, tcx: TyCtxt<'_>, fi: &hir::ForeignItem<'_>) -> Option<hir::OwnerId> {
|
||||||
let did = fi.owner_id.to_def_id();
|
let did = fi.owner_id.to_def_id();
|
||||||
let instance = Instance::new(did, ty::List::identity_for_item(tcx, did));
|
let instance = Instance::new(did, ty::List::identity_for_item(tcx, did));
|
||||||
let name = Symbol::intern(tcx.symbol_name(instance).name);
|
let name = Symbol::intern(tcx.symbol_name(instance).name);
|
||||||
if let Some(&hir_id) = self.seen_decls.get(&name) {
|
if let Some(&existing_id) = self.seen_decls.get(&name) {
|
||||||
// Avoid updating the map with the new entry when we do find a collision. We want to
|
// Avoid updating the map with the new entry when we do find a collision. We want to
|
||||||
// make sure we're always pointing to the first definition as the previous declaration.
|
// make sure we're always pointing to the first definition as the previous declaration.
|
||||||
// This lets us avoid emitting "knock-on" diagnostics.
|
// This lets us avoid emitting "knock-on" diagnostics.
|
||||||
Some(hir_id)
|
Some(existing_id)
|
||||||
} else {
|
} else {
|
||||||
self.seen_decls.insert(name, fi.hir_id())
|
self.seen_decls.insert(name, fi.owner_id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2926,16 +2925,16 @@ impl ClashingExternDeclarations {
|
|||||||
impl_lint_pass!(ClashingExternDeclarations => [CLASHING_EXTERN_DECLARATIONS]);
|
impl_lint_pass!(ClashingExternDeclarations => [CLASHING_EXTERN_DECLARATIONS]);
|
||||||
|
|
||||||
impl<'tcx> LateLintPass<'tcx> for ClashingExternDeclarations {
|
impl<'tcx> LateLintPass<'tcx> for ClashingExternDeclarations {
|
||||||
|
#[instrument(level = "trace", skip(self, cx))]
|
||||||
fn check_foreign_item(&mut self, cx: &LateContext<'tcx>, this_fi: &hir::ForeignItem<'_>) {
|
fn check_foreign_item(&mut self, cx: &LateContext<'tcx>, this_fi: &hir::ForeignItem<'_>) {
|
||||||
trace!("ClashingExternDeclarations: check_foreign_item: {:?}", this_fi);
|
|
||||||
if let ForeignItemKind::Fn(..) = this_fi.kind {
|
if let ForeignItemKind::Fn(..) = this_fi.kind {
|
||||||
let tcx = cx.tcx;
|
let tcx = cx.tcx;
|
||||||
if let Some(existing_hid) = self.insert(tcx, this_fi) {
|
if let Some(existing_did) = self.insert(tcx, this_fi) {
|
||||||
let existing_decl_ty = tcx.type_of(tcx.hir().local_def_id(existing_hid));
|
let existing_decl_ty = tcx.type_of(existing_did);
|
||||||
let this_decl_ty = tcx.type_of(this_fi.owner_id);
|
let this_decl_ty = tcx.type_of(this_fi.owner_id);
|
||||||
debug!(
|
debug!(
|
||||||
"ClashingExternDeclarations: Comparing existing {:?}: {:?} to this {:?}: {:?}",
|
"ClashingExternDeclarations: Comparing existing {:?}: {:?} to this {:?}: {:?}",
|
||||||
existing_hid, existing_decl_ty, this_fi.owner_id, this_decl_ty
|
existing_did, existing_decl_ty, this_fi.owner_id, this_decl_ty
|
||||||
);
|
);
|
||||||
// Check that the declarations match.
|
// Check that the declarations match.
|
||||||
if !Self::structurally_same_type(
|
if !Self::structurally_same_type(
|
||||||
@ -2944,7 +2943,7 @@ impl<'tcx> LateLintPass<'tcx> for ClashingExternDeclarations {
|
|||||||
this_decl_ty,
|
this_decl_ty,
|
||||||
CItemKind::Declaration,
|
CItemKind::Declaration,
|
||||||
) {
|
) {
|
||||||
let orig_fi = tcx.hir().expect_foreign_item(existing_hid.expect_owner());
|
let orig_fi = tcx.hir().expect_foreign_item(existing_did);
|
||||||
let orig = Self::name_of_extern_decl(tcx, orig_fi);
|
let orig = Self::name_of_extern_decl(tcx, orig_fi);
|
||||||
|
|
||||||
// We want to ensure that we use spans for both decls that include where the
|
// We want to ensure that we use spans for both decls that include where the
|
||||||
|
@ -66,13 +66,12 @@ impl<'tcx, T: LateLintPass<'tcx>> LateContextAndPass<'tcx, T> {
|
|||||||
self.context.last_node_with_lint_attrs = prev;
|
self.context.last_node_with_lint_attrs = prev;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn with_param_env<F>(&mut self, id: hir::HirId, f: F)
|
fn with_param_env<F>(&mut self, id: hir::OwnerId, f: F)
|
||||||
where
|
where
|
||||||
F: FnOnce(&mut Self),
|
F: FnOnce(&mut Self),
|
||||||
{
|
{
|
||||||
let old_param_env = self.context.param_env;
|
let old_param_env = self.context.param_env;
|
||||||
self.context.param_env =
|
self.context.param_env = self.context.tcx.param_env(id);
|
||||||
self.context.tcx.param_env(self.context.tcx.hir().local_def_id(id));
|
|
||||||
f(self);
|
f(self);
|
||||||
self.context.param_env = old_param_env;
|
self.context.param_env = old_param_env;
|
||||||
}
|
}
|
||||||
@ -132,7 +131,7 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
|
|||||||
let old_cached_typeck_results = self.context.cached_typeck_results.take();
|
let old_cached_typeck_results = self.context.cached_typeck_results.take();
|
||||||
let old_enclosing_body = self.context.enclosing_body.take();
|
let old_enclosing_body = self.context.enclosing_body.take();
|
||||||
self.with_lint_attrs(it.hir_id(), |cx| {
|
self.with_lint_attrs(it.hir_id(), |cx| {
|
||||||
cx.with_param_env(it.hir_id(), |cx| {
|
cx.with_param_env(it.owner_id, |cx| {
|
||||||
lint_callback!(cx, check_item, it);
|
lint_callback!(cx, check_item, it);
|
||||||
hir_visit::walk_item(cx, it);
|
hir_visit::walk_item(cx, it);
|
||||||
lint_callback!(cx, check_item_post, it);
|
lint_callback!(cx, check_item_post, it);
|
||||||
@ -145,7 +144,7 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
|
|||||||
|
|
||||||
fn visit_foreign_item(&mut self, it: &'tcx hir::ForeignItem<'tcx>) {
|
fn visit_foreign_item(&mut self, it: &'tcx hir::ForeignItem<'tcx>) {
|
||||||
self.with_lint_attrs(it.hir_id(), |cx| {
|
self.with_lint_attrs(it.hir_id(), |cx| {
|
||||||
cx.with_param_env(it.hir_id(), |cx| {
|
cx.with_param_env(it.owner_id, |cx| {
|
||||||
lint_callback!(cx, check_foreign_item, it);
|
lint_callback!(cx, check_foreign_item, it);
|
||||||
hir_visit::walk_foreign_item(cx, it);
|
hir_visit::walk_foreign_item(cx, it);
|
||||||
});
|
});
|
||||||
@ -268,7 +267,7 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
|
|||||||
let generics = self.context.generics.take();
|
let generics = self.context.generics.take();
|
||||||
self.context.generics = Some(&trait_item.generics);
|
self.context.generics = Some(&trait_item.generics);
|
||||||
self.with_lint_attrs(trait_item.hir_id(), |cx| {
|
self.with_lint_attrs(trait_item.hir_id(), |cx| {
|
||||||
cx.with_param_env(trait_item.hir_id(), |cx| {
|
cx.with_param_env(trait_item.owner_id, |cx| {
|
||||||
lint_callback!(cx, check_trait_item, trait_item);
|
lint_callback!(cx, check_trait_item, trait_item);
|
||||||
hir_visit::walk_trait_item(cx, trait_item);
|
hir_visit::walk_trait_item(cx, trait_item);
|
||||||
});
|
});
|
||||||
@ -280,7 +279,7 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
|
|||||||
let generics = self.context.generics.take();
|
let generics = self.context.generics.take();
|
||||||
self.context.generics = Some(&impl_item.generics);
|
self.context.generics = Some(&impl_item.generics);
|
||||||
self.with_lint_attrs(impl_item.hir_id(), |cx| {
|
self.with_lint_attrs(impl_item.hir_id(), |cx| {
|
||||||
cx.with_param_env(impl_item.hir_id(), |cx| {
|
cx.with_param_env(impl_item.owner_id, |cx| {
|
||||||
lint_callback!(cx, check_impl_item, impl_item);
|
lint_callback!(cx, check_impl_item, impl_item);
|
||||||
hir_visit::walk_impl_item(cx, impl_item);
|
hir_visit::walk_impl_item(cx, impl_item);
|
||||||
lint_callback!(cx, check_impl_item_post, impl_item);
|
lint_callback!(cx, check_impl_item_post, impl_item);
|
||||||
|
@ -22,8 +22,8 @@ pub enum MethodLateContext {
|
|||||||
PlainImpl,
|
PlainImpl,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn method_context(cx: &LateContext<'_>, def_id: LocalDefId) -> MethodLateContext {
|
pub fn method_context(cx: &LateContext<'_>, id: LocalDefId) -> MethodLateContext {
|
||||||
let item = cx.tcx.associated_item(def_id);
|
let item = cx.tcx.associated_item(id);
|
||||||
match item.container {
|
match item.container {
|
||||||
ty::TraitContainer => MethodLateContext::TraitAutoImpl,
|
ty::TraitContainer => MethodLateContext::TraitAutoImpl,
|
||||||
ty::ImplContainer => match cx.tcx.impl_trait_ref(item.container_id(cx.tcx)) {
|
ty::ImplContainer => match cx.tcx.impl_trait_ref(item.container_id(cx.tcx)) {
|
||||||
|
@ -1239,9 +1239,8 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_foreign_static(&mut self, id: hir::HirId, span: Span) {
|
fn check_foreign_static(&mut self, id: hir::OwnerId, span: Span) {
|
||||||
let def_id = self.cx.tcx.hir().local_def_id(id);
|
let ty = self.cx.tcx.type_of(id);
|
||||||
let ty = self.cx.tcx.type_of(def_id);
|
|
||||||
self.check_type_for_ffi_and_report_errors(span, ty, true, false);
|
self.check_type_for_ffi_and_report_errors(span, ty, true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1264,7 +1263,7 @@ impl<'tcx> LateLintPass<'tcx> for ImproperCTypesDeclarations {
|
|||||||
vis.check_foreign_fn(it.owner_id.def_id, decl);
|
vis.check_foreign_fn(it.owner_id.def_id, decl);
|
||||||
}
|
}
|
||||||
hir::ForeignItemKind::Static(ref ty, _) => {
|
hir::ForeignItemKind::Static(ref ty, _) => {
|
||||||
vis.check_foreign_static(it.hir_id(), ty.span);
|
vis.check_foreign_static(it.owner_id, ty.span);
|
||||||
}
|
}
|
||||||
hir::ForeignItemKind::Type => (),
|
hir::ForeignItemKind::Type => (),
|
||||||
}
|
}
|
||||||
|
@ -1310,8 +1310,8 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
|||||||
hir::ItemKind::Struct(ref vdata, _) => {
|
hir::ItemKind::Struct(ref vdata, _) => {
|
||||||
yield item_id.owner_id.def_id.local_def_index;
|
yield item_id.owner_id.def_id.local_def_index;
|
||||||
// Encode constructors which take a separate slot in value namespace.
|
// Encode constructors which take a separate slot in value namespace.
|
||||||
if let Some(ctor_hir_id) = vdata.ctor_hir_id() {
|
if let Some(ctor_def_id) = vdata.ctor_def_id() {
|
||||||
yield tcx.hir().local_def_id(ctor_hir_id).local_def_index;
|
yield ctor_def_id.local_def_index;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ if tcx.def_key(item_id.owner_id.to_def_id()).get_opt_name().is_some() => {
|
_ if tcx.def_key(item_id.owner_id.to_def_id()).get_opt_name().is_some() => {
|
||||||
|
@ -105,7 +105,7 @@ macro_rules! arena_types {
|
|||||||
// (during lowering) and the `librustc_middle` arena (for decoding MIR)
|
// (during lowering) and the `librustc_middle` arena (for decoding MIR)
|
||||||
[decode] asm_template: rustc_ast::InlineAsmTemplatePiece,
|
[decode] asm_template: rustc_ast::InlineAsmTemplatePiece,
|
||||||
[decode] used_trait_imports: rustc_data_structures::unord::UnordSet<rustc_hir::def_id::LocalDefId>,
|
[decode] used_trait_imports: rustc_data_structures::unord::UnordSet<rustc_hir::def_id::LocalDefId>,
|
||||||
[decode] is_late_bound_map: rustc_data_structures::fx::FxIndexSet<rustc_hir::def_id::LocalDefId>,
|
[decode] is_late_bound_map: rustc_data_structures::fx::FxIndexSet<rustc_hir::ItemLocalId>,
|
||||||
[decode] impl_source: rustc_middle::traits::ImplSource<'tcx, ()>,
|
[decode] impl_source: rustc_middle::traits::ImplSource<'tcx, ()>,
|
||||||
|
|
||||||
[] dep_kind: rustc_middle::dep_graph::DepKindStruct<'tcx>,
|
[] dep_kind: rustc_middle::dep_graph::DepKindStruct<'tcx>,
|
||||||
|
@ -18,24 +18,30 @@ use rustc_span::Span;
|
|||||||
use rustc_target::spec::abi::Abi;
|
use rustc_target::spec::abi::Abi;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn associated_body(node: Node<'_>) -> Option<BodyId> {
|
pub fn associated_body(node: Node<'_>) -> Option<(LocalDefId, BodyId)> {
|
||||||
match node {
|
match node {
|
||||||
Node::Item(Item {
|
Node::Item(Item {
|
||||||
|
owner_id,
|
||||||
kind: ItemKind::Const(_, body) | ItemKind::Static(.., body) | ItemKind::Fn(.., body),
|
kind: ItemKind::Const(_, body) | ItemKind::Static(.., body) | ItemKind::Fn(.., body),
|
||||||
..
|
..
|
||||||
})
|
})
|
||||||
| Node::TraitItem(TraitItem {
|
| Node::TraitItem(TraitItem {
|
||||||
|
owner_id,
|
||||||
kind:
|
kind:
|
||||||
TraitItemKind::Const(_, Some(body)) | TraitItemKind::Fn(_, TraitFn::Provided(body)),
|
TraitItemKind::Const(_, Some(body)) | TraitItemKind::Fn(_, TraitFn::Provided(body)),
|
||||||
..
|
..
|
||||||
})
|
})
|
||||||
| Node::ImplItem(ImplItem {
|
| Node::ImplItem(ImplItem {
|
||||||
|
owner_id,
|
||||||
kind: ImplItemKind::Const(_, body) | ImplItemKind::Fn(_, body),
|
kind: ImplItemKind::Const(_, body) | ImplItemKind::Fn(_, body),
|
||||||
..
|
..
|
||||||
})
|
}) => Some((owner_id.def_id, *body)),
|
||||||
| Node::Expr(Expr { kind: ExprKind::Closure(Closure { body, .. }), .. }) => Some(*body),
|
|
||||||
|
|
||||||
Node::AnonConst(constant) => Some(constant.body),
|
Node::Expr(Expr { kind: ExprKind::Closure(Closure { def_id, body, .. }), .. }) => {
|
||||||
|
Some((*def_id, *body))
|
||||||
|
}
|
||||||
|
|
||||||
|
Node::AnonConst(constant) => Some((constant.def_id, constant.body)),
|
||||||
|
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
@ -43,7 +49,7 @@ pub fn associated_body(node: Node<'_>) -> Option<BodyId> {
|
|||||||
|
|
||||||
fn is_body_owner(node: Node<'_>, hir_id: HirId) -> bool {
|
fn is_body_owner(node: Node<'_>, hir_id: HirId) -> bool {
|
||||||
match associated_body(node) {
|
match associated_body(node) {
|
||||||
Some(b) => b.hir_id == hir_id,
|
Some((_, b)) => b.hir_id == hir_id,
|
||||||
None => false,
|
None => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -154,10 +160,6 @@ impl<'hir> Map<'hir> {
|
|||||||
self.tcx.definitions_untracked().def_key(def_id)
|
self.tcx.definitions_untracked().def_key(def_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn def_path_from_hir_id(self, id: HirId) -> Option<DefPath> {
|
|
||||||
self.opt_local_def_id(id).map(|def_id| self.def_path(def_id))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn def_path(self, def_id: LocalDefId) -> DefPath {
|
pub fn def_path(self, def_id: LocalDefId) -> DefPath {
|
||||||
// Accessing the DefPath is ok, since it is part of DefPathHash.
|
// Accessing the DefPath is ok, since it is part of DefPathHash.
|
||||||
self.tcx.definitions_untracked().def_path(def_id)
|
self.tcx.definitions_untracked().def_path(def_id)
|
||||||
@ -169,32 +171,6 @@ impl<'hir> Map<'hir> {
|
|||||||
self.tcx.definitions_untracked().def_path_hash(def_id)
|
self.tcx.definitions_untracked().def_path_hash(def_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
|
||||||
#[track_caller]
|
|
||||||
pub fn local_def_id(self, hir_id: HirId) -> LocalDefId {
|
|
||||||
self.opt_local_def_id(hir_id).unwrap_or_else(|| {
|
|
||||||
bug!(
|
|
||||||
"local_def_id: no entry for `{:?}`, which has a map of `{:?}`",
|
|
||||||
hir_id,
|
|
||||||
self.find(hir_id)
|
|
||||||
)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn opt_local_def_id(self, hir_id: HirId) -> Option<LocalDefId> {
|
|
||||||
if hir_id.local_id == ItemLocalId::new(0) {
|
|
||||||
Some(hir_id.owner.def_id)
|
|
||||||
} else {
|
|
||||||
self.tcx
|
|
||||||
.hir_owner_nodes(hir_id.owner)
|
|
||||||
.as_owner()?
|
|
||||||
.local_id_to_def_id
|
|
||||||
.get(&hir_id.local_id)
|
|
||||||
.copied()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn local_def_id_to_hir_id(self, def_id: LocalDefId) -> HirId {
|
pub fn local_def_id_to_hir_id(self, def_id: LocalDefId) -> HirId {
|
||||||
self.tcx.local_def_id_to_hir_id(def_id)
|
self.tcx.local_def_id_to_hir_id(def_id)
|
||||||
@ -410,8 +386,8 @@ impl<'hir> Map<'hir> {
|
|||||||
#[track_caller]
|
#[track_caller]
|
||||||
pub fn enclosing_body_owner(self, hir_id: HirId) -> LocalDefId {
|
pub fn enclosing_body_owner(self, hir_id: HirId) -> LocalDefId {
|
||||||
for (_, node) in self.parent_iter(hir_id) {
|
for (_, node) in self.parent_iter(hir_id) {
|
||||||
if let Some(body) = associated_body(node) {
|
if let Some((def_id, _)) = associated_body(node) {
|
||||||
return self.body_owner_def_id(body);
|
return def_id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -427,14 +403,17 @@ impl<'hir> Map<'hir> {
|
|||||||
parent
|
parent
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn body_owner_def_id(self, id: BodyId) -> LocalDefId {
|
pub fn body_owner_def_id(self, BodyId { hir_id }: BodyId) -> LocalDefId {
|
||||||
self.local_def_id(self.body_owner(id))
|
let parent = self.parent_id(hir_id);
|
||||||
|
associated_body(self.get(parent)).unwrap().0
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Given a `LocalDefId`, returns the `BodyId` associated with it,
|
/// Given a `LocalDefId`, returns the `BodyId` associated with it,
|
||||||
/// if the node is a body owner, otherwise returns `None`.
|
/// if the node is a body owner, otherwise returns `None`.
|
||||||
pub fn maybe_body_owned_by(self, id: LocalDefId) -> Option<BodyId> {
|
pub fn maybe_body_owned_by(self, id: LocalDefId) -> Option<BodyId> {
|
||||||
self.find_by_def_id(id).and_then(associated_body)
|
let node = self.find_by_def_id(id)?;
|
||||||
|
let (_, body_id) = associated_body(node)?;
|
||||||
|
Some(body_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Given a body owner's id, returns the `BodyId` associated with it.
|
/// Given a body owner's id, returns the `BodyId` associated with it.
|
||||||
|
@ -2506,7 +2506,7 @@ impl<'tcx> ConstantKind<'tcx> {
|
|||||||
|
|
||||||
let hir_id = tcx.hir().local_def_id_to_hir_id(def.did);
|
let hir_id = tcx.hir().local_def_id_to_hir_id(def.did);
|
||||||
let parent_substs = if let Some(parent_hir_id) = tcx.hir().opt_parent_id(hir_id) {
|
let parent_substs = if let Some(parent_hir_id) = tcx.hir().opt_parent_id(hir_id) {
|
||||||
if let Some(parent_did) = tcx.hir().opt_local_def_id(parent_hir_id) {
|
if let Some(parent_did) = parent_hir_id.as_owner() {
|
||||||
InternalSubsts::identity_for_item(tcx, parent_did.to_def_id())
|
InternalSubsts::identity_for_item(tcx, parent_did.to_def_id())
|
||||||
} else {
|
} else {
|
||||||
tcx.mk_substs(Vec::<GenericArg<'tcx>>::new().into_iter())
|
tcx.mk_substs(Vec::<GenericArg<'tcx>>::new().into_iter())
|
||||||
|
@ -670,7 +670,7 @@ fn fn_span(tcx: TyCtxt<'_>, def_id: DefId) -> Span {
|
|||||||
|
|
||||||
fn hir_body(tcx: TyCtxt<'_>, def_id: DefId) -> Option<&rustc_hir::Body<'_>> {
|
fn hir_body(tcx: TyCtxt<'_>, def_id: DefId) -> Option<&rustc_hir::Body<'_>> {
|
||||||
let hir_node = tcx.hir().get_if_local(def_id).expect("expected DefId is local");
|
let hir_node = tcx.hir().get_if_local(def_id).expect("expected DefId is local");
|
||||||
hir::map::associated_body(hir_node).map(|fn_body_id| tcx.hir().body(fn_body_id))
|
hir::map::associated_body(hir_node).map(|(_, fn_body_id)| tcx.hir().body(fn_body_id))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn escape_html(s: &str) -> String {
|
fn escape_html(s: &str) -> String {
|
||||||
|
@ -1640,7 +1640,7 @@ rustc_queries! {
|
|||||||
Option<&'tcx FxHashMap<ItemLocalId, Region>> {
|
Option<&'tcx FxHashMap<ItemLocalId, Region>> {
|
||||||
desc { "looking up a named region" }
|
desc { "looking up a named region" }
|
||||||
}
|
}
|
||||||
query is_late_bound_map(_: LocalDefId) -> Option<&'tcx FxIndexSet<LocalDefId>> {
|
query is_late_bound_map(_: hir::OwnerId) -> Option<&'tcx FxIndexSet<ItemLocalId>> {
|
||||||
desc { "testing if a region is late bound" }
|
desc { "testing if a region is late bound" }
|
||||||
}
|
}
|
||||||
/// For a given item's generic parameter, gets the default lifetimes to be used
|
/// For a given item's generic parameter, gets the default lifetimes to be used
|
||||||
|
@ -2157,10 +2157,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_late_bound(self, id: HirId) -> bool {
|
pub fn is_late_bound(self, id: HirId) -> bool {
|
||||||
self.is_late_bound_map(id.owner.def_id).map_or(false, |set| {
|
self.is_late_bound_map(id.owner).map_or(false, |set| set.contains(&id.local_id))
|
||||||
let def_id = self.hir().local_def_id(id);
|
|
||||||
set.contains(&def_id)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn late_bound_vars(self, id: HirId) -> &'tcx List<ty::BoundVariableKind> {
|
pub fn late_bound_vars(self, id: HirId) -> &'tcx List<ty::BoundVariableKind> {
|
||||||
|
@ -118,6 +118,7 @@ fn copy<T: Copy>(x: &T) -> T {
|
|||||||
|
|
||||||
macro_rules! query_helper_param_ty {
|
macro_rules! query_helper_param_ty {
|
||||||
(DefId) => { impl IntoQueryParam<DefId> };
|
(DefId) => { impl IntoQueryParam<DefId> };
|
||||||
|
(LocalDefId) => { impl IntoQueryParam<LocalDefId> };
|
||||||
($K:ty) => { $K };
|
($K:ty) => { $K };
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -418,6 +419,13 @@ mod sealed {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl IntoQueryParam<LocalDefId> for OwnerId {
|
||||||
|
#[inline(always)]
|
||||||
|
fn into_query_param(self) -> LocalDefId {
|
||||||
|
self.def_id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl IntoQueryParam<DefId> for LocalDefId {
|
impl IntoQueryParam<DefId> for LocalDefId {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn into_query_param(self) -> DefId {
|
fn into_query_param(self) -> DefId {
|
||||||
|
@ -5,7 +5,6 @@ use rustc_middle::mir::{self, Field};
|
|||||||
use rustc_middle::thir::{FieldPat, Pat, PatKind};
|
use rustc_middle::thir::{FieldPat, Pat, PatKind};
|
||||||
use rustc_middle::ty::{self, Ty, TyCtxt};
|
use rustc_middle::ty::{self, Ty, TyCtxt};
|
||||||
use rustc_session::lint;
|
use rustc_session::lint;
|
||||||
use rustc_span::def_id::CRATE_DEF_ID;
|
|
||||||
use rustc_span::Span;
|
use rustc_span::Span;
|
||||||
use rustc_trait_selection::traits::predicate_for_trait_def;
|
use rustc_trait_selection::traits::predicate_for_trait_def;
|
||||||
use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt;
|
use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt;
|
||||||
@ -190,11 +189,10 @@ impl<'tcx> ConstToPat<'tcx> {
|
|||||||
// using `PartialEq::eq` in this scenario in the past.)
|
// using `PartialEq::eq` in this scenario in the past.)
|
||||||
let partial_eq_trait_id =
|
let partial_eq_trait_id =
|
||||||
self.tcx().require_lang_item(hir::LangItem::PartialEq, Some(self.span));
|
self.tcx().require_lang_item(hir::LangItem::PartialEq, Some(self.span));
|
||||||
let def_id = self.tcx().hir().opt_local_def_id(self.id).unwrap_or(CRATE_DEF_ID);
|
|
||||||
let obligation: PredicateObligation<'_> = predicate_for_trait_def(
|
let obligation: PredicateObligation<'_> = predicate_for_trait_def(
|
||||||
self.tcx(),
|
self.tcx(),
|
||||||
self.param_env,
|
self.param_env,
|
||||||
ObligationCause::misc(self.span, def_id),
|
ObligationCause::misc(self.span, self.id.owner.def_id),
|
||||||
partial_eq_trait_id,
|
partial_eq_trait_id,
|
||||||
0,
|
0,
|
||||||
[ty, ty],
|
[ty, ty],
|
||||||
|
@ -540,7 +540,8 @@ fn fn_sig_and_body(
|
|||||||
// FIXME(#79625): Consider improving MIR to provide the information needed, to avoid going back
|
// FIXME(#79625): Consider improving MIR to provide the information needed, to avoid going back
|
||||||
// to HIR for it.
|
// to HIR for it.
|
||||||
let hir_node = tcx.hir().get_if_local(def_id).expect("expected DefId is local");
|
let hir_node = tcx.hir().get_if_local(def_id).expect("expected DefId is local");
|
||||||
let fn_body_id = hir::map::associated_body(hir_node).expect("HIR node is a function with body");
|
let (_, fn_body_id) =
|
||||||
|
hir::map::associated_body(hir_node).expect("HIR node is a function with body");
|
||||||
(hir_node.fn_sig(), tcx.hir().body(fn_body_id))
|
(hir_node.fn_sig(), tcx.hir().body(fn_body_id))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -453,7 +453,9 @@ impl CheckAttrVisitor<'_> {
|
|||||||
/// Debugging aid for `object_lifetime_default` query.
|
/// Debugging aid for `object_lifetime_default` query.
|
||||||
fn check_object_lifetime_default(&self, hir_id: HirId) {
|
fn check_object_lifetime_default(&self, hir_id: HirId) {
|
||||||
let tcx = self.tcx;
|
let tcx = self.tcx;
|
||||||
if let Some(generics) = tcx.hir().get_generics(tcx.hir().local_def_id(hir_id)) {
|
if let Some(owner_id) = hir_id.as_owner()
|
||||||
|
&& let Some(generics) = tcx.hir().get_generics(owner_id.def_id)
|
||||||
|
{
|
||||||
for p in generics.params {
|
for p in generics.params {
|
||||||
let hir::GenericParamKind::Type { .. } = p.kind else { continue };
|
let hir::GenericParamKind::Type { .. } = p.kind else { continue };
|
||||||
let default = tcx.object_lifetime_default(p.def_id);
|
let default = tcx.object_lifetime_default(p.def_id);
|
||||||
@ -1943,7 +1945,7 @@ impl CheckAttrVisitor<'_> {
|
|||||||
) -> bool {
|
) -> bool {
|
||||||
match target {
|
match target {
|
||||||
Target::Fn | Target::Method(_)
|
Target::Fn | Target::Method(_)
|
||||||
if self.tcx.is_const_fn_raw(self.tcx.hir().local_def_id(hir_id).to_def_id()) =>
|
if self.tcx.is_const_fn_raw(hir_id.expect_owner().to_def_id()) =>
|
||||||
{
|
{
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
@ -451,29 +451,23 @@ impl<'tcx> Visitor<'tcx> for MarkSymbolVisitor<'tcx> {
|
|||||||
// referenced by it should be considered as used.
|
// referenced by it should be considered as used.
|
||||||
let in_pat = mem::replace(&mut self.in_pat, false);
|
let in_pat = mem::replace(&mut self.in_pat, false);
|
||||||
|
|
||||||
self.live_symbols.insert(self.tcx.hir().local_def_id(c.hir_id));
|
self.live_symbols.insert(c.def_id);
|
||||||
intravisit::walk_anon_const(self, c);
|
intravisit::walk_anon_const(self, c);
|
||||||
|
|
||||||
self.in_pat = in_pat;
|
self.in_pat = in_pat;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn has_allow_dead_code_or_lang_attr_helper(
|
fn has_allow_dead_code_or_lang_attr(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
|
||||||
tcx: TyCtxt<'_>,
|
if tcx.has_attr(def_id.to_def_id(), sym::lang) {
|
||||||
id: hir::HirId,
|
|
||||||
lint: &'static lint::Lint,
|
|
||||||
) -> bool {
|
|
||||||
let attrs = tcx.hir().attrs(id);
|
|
||||||
if tcx.sess.contains_name(attrs, sym::lang) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stable attribute for #[lang = "panic_impl"]
|
// Stable attribute for #[lang = "panic_impl"]
|
||||||
if tcx.sess.contains_name(attrs, sym::panic_handler) {
|
if tcx.has_attr(def_id.to_def_id(), sym::panic_handler) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
let def_id = tcx.hir().local_def_id(id);
|
|
||||||
if tcx.def_kind(def_id).has_codegen_attrs() {
|
if tcx.def_kind(def_id).has_codegen_attrs() {
|
||||||
let cg_attrs = tcx.codegen_fn_attrs(def_id);
|
let cg_attrs = tcx.codegen_fn_attrs(def_id);
|
||||||
|
|
||||||
@ -487,11 +481,8 @@ fn has_allow_dead_code_or_lang_attr_helper(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tcx.lint_level_at_node(lint, id).0 == lint::Allow
|
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
|
||||||
}
|
tcx.lint_level_at_node(lint::builtin::DEAD_CODE, hir_id).0 == lint::Allow
|
||||||
|
|
||||||
fn has_allow_dead_code_or_lang_attr(tcx: TyCtxt<'_>, id: hir::HirId) -> bool {
|
|
||||||
has_allow_dead_code_or_lang_attr_helper(tcx, id, lint::builtin::DEAD_CODE)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// These check_* functions seeds items that
|
// These check_* functions seeds items that
|
||||||
@ -513,7 +504,7 @@ fn check_item<'tcx>(
|
|||||||
struct_constructors: &mut FxHashMap<LocalDefId, LocalDefId>,
|
struct_constructors: &mut FxHashMap<LocalDefId, LocalDefId>,
|
||||||
id: hir::ItemId,
|
id: hir::ItemId,
|
||||||
) {
|
) {
|
||||||
let allow_dead_code = has_allow_dead_code_or_lang_attr(tcx, id.hir_id());
|
let allow_dead_code = has_allow_dead_code_or_lang_attr(tcx, id.owner_id.def_id);
|
||||||
if allow_dead_code {
|
if allow_dead_code {
|
||||||
worklist.push(id.owner_id.def_id);
|
worklist.push(id.owner_id.def_id);
|
||||||
}
|
}
|
||||||
@ -548,9 +539,7 @@ fn check_item<'tcx>(
|
|||||||
|
|
||||||
// And we access the Map here to get HirId from LocalDefId
|
// And we access the Map here to get HirId from LocalDefId
|
||||||
for id in local_def_ids {
|
for id in local_def_ids {
|
||||||
if of_trait.is_some()
|
if of_trait.is_some() || has_allow_dead_code_or_lang_attr(tcx, id) {
|
||||||
|| has_allow_dead_code_or_lang_attr(tcx, tcx.hir().local_def_id_to_hir_id(id))
|
|
||||||
{
|
|
||||||
worklist.push(id);
|
worklist.push(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -558,9 +547,9 @@ fn check_item<'tcx>(
|
|||||||
DefKind::Struct => {
|
DefKind::Struct => {
|
||||||
let item = tcx.hir().item(id);
|
let item = tcx.hir().item(id);
|
||||||
if let hir::ItemKind::Struct(ref variant_data, _) = item.kind
|
if let hir::ItemKind::Struct(ref variant_data, _) = item.kind
|
||||||
&& let Some(ctor_hir_id) = variant_data.ctor_hir_id()
|
&& let Some(ctor_def_id) = variant_data.ctor_def_id()
|
||||||
{
|
{
|
||||||
struct_constructors.insert(tcx.hir().local_def_id(ctor_hir_id), item.owner_id.def_id);
|
struct_constructors.insert(ctor_def_id, item.owner_id.def_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DefKind::GlobalAsm => {
|
DefKind::GlobalAsm => {
|
||||||
@ -576,7 +565,7 @@ fn check_trait_item(tcx: TyCtxt<'_>, worklist: &mut Vec<LocalDefId>, id: hir::Tr
|
|||||||
if matches!(tcx.def_kind(id.owner_id), DefKind::AssocConst | DefKind::AssocFn) {
|
if matches!(tcx.def_kind(id.owner_id), DefKind::AssocConst | DefKind::AssocFn) {
|
||||||
let trait_item = tcx.hir().trait_item(id);
|
let trait_item = tcx.hir().trait_item(id);
|
||||||
if matches!(trait_item.kind, Const(_, Some(_)) | Fn(_, hir::TraitFn::Provided(_)))
|
if matches!(trait_item.kind, Const(_, Some(_)) | Fn(_, hir::TraitFn::Provided(_)))
|
||||||
&& has_allow_dead_code_or_lang_attr(tcx, trait_item.hir_id())
|
&& has_allow_dead_code_or_lang_attr(tcx, trait_item.owner_id.def_id)
|
||||||
{
|
{
|
||||||
worklist.push(trait_item.owner_id.def_id);
|
worklist.push(trait_item.owner_id.def_id);
|
||||||
}
|
}
|
||||||
@ -585,7 +574,7 @@ fn check_trait_item(tcx: TyCtxt<'_>, worklist: &mut Vec<LocalDefId>, id: hir::Tr
|
|||||||
|
|
||||||
fn check_foreign_item(tcx: TyCtxt<'_>, worklist: &mut Vec<LocalDefId>, id: hir::ForeignItemId) {
|
fn check_foreign_item(tcx: TyCtxt<'_>, worklist: &mut Vec<LocalDefId>, id: hir::ForeignItemId) {
|
||||||
if matches!(tcx.def_kind(id.owner_id), DefKind::Static(_) | DefKind::Fn)
|
if matches!(tcx.def_kind(id.owner_id), DefKind::Static(_) | DefKind::Fn)
|
||||||
&& has_allow_dead_code_or_lang_attr(tcx, id.hir_id())
|
&& has_allow_dead_code_or_lang_attr(tcx, id.owner_id.def_id)
|
||||||
{
|
{
|
||||||
worklist.push(id.owner_id.def_id);
|
worklist.push(id.owner_id.def_id);
|
||||||
}
|
}
|
||||||
@ -806,8 +795,7 @@ impl<'tcx> DeadVisitor<'tcx> {
|
|||||||
if self.live_symbols.contains(&def_id) {
|
if self.live_symbols.contains(&def_id) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let hir_id = self.tcx.hir().local_def_id_to_hir_id(def_id);
|
if has_allow_dead_code_or_lang_attr(self.tcx, def_id) {
|
||||||
if has_allow_dead_code_or_lang_attr(self.tcx, hir_id) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let Some(name) = self.tcx.opt_item_name(def_id.to_def_id()) else {
|
let Some(name) = self.tcx.opt_item_name(def_id.to_def_id()) else {
|
||||||
|
@ -15,9 +15,9 @@ use crate::weak_lang_items;
|
|||||||
|
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def::DefKind;
|
use rustc_hir::def::DefKind;
|
||||||
use rustc_hir::def_id::DefId;
|
use rustc_hir::def_id::{DefId, LocalDefId};
|
||||||
use rustc_hir::lang_items::{extract, GenericRequirement};
|
use rustc_hir::lang_items::{extract, GenericRequirement};
|
||||||
use rustc_hir::{HirId, LangItem, LanguageItems, Target};
|
use rustc_hir::{LangItem, LanguageItems, Target};
|
||||||
use rustc_middle::ty::TyCtxt;
|
use rustc_middle::ty::TyCtxt;
|
||||||
use rustc_session::cstore::ExternCrate;
|
use rustc_session::cstore::ExternCrate;
|
||||||
use rustc_span::{symbol::kw::Empty, Span};
|
use rustc_span::{symbol::kw::Empty, Span};
|
||||||
@ -40,13 +40,13 @@ impl<'tcx> LanguageItemCollector<'tcx> {
|
|||||||
LanguageItemCollector { tcx, items: LanguageItems::new() }
|
LanguageItemCollector { tcx, items: LanguageItems::new() }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_for_lang(&mut self, actual_target: Target, hir_id: HirId) {
|
fn check_for_lang(&mut self, actual_target: Target, def_id: LocalDefId) {
|
||||||
let attrs = self.tcx.hir().attrs(hir_id);
|
let attrs = self.tcx.hir().attrs(self.tcx.hir().local_def_id_to_hir_id(def_id));
|
||||||
if let Some((name, span)) = extract(&attrs) {
|
if let Some((name, span)) = extract(&attrs) {
|
||||||
match LangItem::from_name(name) {
|
match LangItem::from_name(name) {
|
||||||
// Known lang item with attribute on correct target.
|
// Known lang item with attribute on correct target.
|
||||||
Some(lang_item) if actual_target == lang_item.target() => {
|
Some(lang_item) if actual_target == lang_item.target() => {
|
||||||
self.collect_item_extended(lang_item, hir_id, span);
|
self.collect_item_extended(lang_item, def_id, span);
|
||||||
}
|
}
|
||||||
// Known lang item with attribute on incorrect target.
|
// Known lang item with attribute on incorrect target.
|
||||||
Some(lang_item) => {
|
Some(lang_item) => {
|
||||||
@ -142,8 +142,7 @@ impl<'tcx> LanguageItemCollector<'tcx> {
|
|||||||
|
|
||||||
// Like collect_item() above, but also checks whether the lang item is declared
|
// Like collect_item() above, but also checks whether the lang item is declared
|
||||||
// with the right number of generic arguments.
|
// with the right number of generic arguments.
|
||||||
fn collect_item_extended(&mut self, lang_item: LangItem, hir_id: HirId, span: Span) {
|
fn collect_item_extended(&mut self, lang_item: LangItem, item_def_id: LocalDefId, span: Span) {
|
||||||
let item_def_id = self.tcx.hir().local_def_id(hir_id).to_def_id();
|
|
||||||
let name = lang_item.name();
|
let name = lang_item.name();
|
||||||
|
|
||||||
// Now check whether the lang_item has the expected number of generic
|
// Now check whether the lang_item has the expected number of generic
|
||||||
@ -154,7 +153,8 @@ impl<'tcx> LanguageItemCollector<'tcx> {
|
|||||||
// Some other types like Box and various functions like drop_in_place
|
// Some other types like Box and various functions like drop_in_place
|
||||||
// have minimum requirements.
|
// have minimum requirements.
|
||||||
|
|
||||||
if let hir::Node::Item(hir::Item { kind, span: item_span, .. }) = self.tcx.hir().get(hir_id)
|
if let hir::Node::Item(hir::Item { kind, span: item_span, .. }) =
|
||||||
|
self.tcx.hir().get_by_def_id(item_def_id)
|
||||||
{
|
{
|
||||||
let (actual_num, generics_span) = match kind.generics() {
|
let (actual_num, generics_span) = match kind.generics() {
|
||||||
Some(generics) => (generics.params.len(), generics.span),
|
Some(generics) => (generics.params.len(), generics.span),
|
||||||
@ -191,7 +191,7 @@ impl<'tcx> LanguageItemCollector<'tcx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.collect_item(lang_item, item_def_id);
|
self.collect_item(lang_item, item_def_id.to_def_id());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -211,13 +211,14 @@ fn get_lang_items(tcx: TyCtxt<'_>, (): ()) -> LanguageItems {
|
|||||||
let crate_items = tcx.hir_crate_items(());
|
let crate_items = tcx.hir_crate_items(());
|
||||||
|
|
||||||
for id in crate_items.items() {
|
for id in crate_items.items() {
|
||||||
collector.check_for_lang(Target::from_def_kind(tcx.def_kind(id.owner_id)), id.hir_id());
|
collector
|
||||||
|
.check_for_lang(Target::from_def_kind(tcx.def_kind(id.owner_id)), id.owner_id.def_id);
|
||||||
|
|
||||||
if matches!(tcx.def_kind(id.owner_id), DefKind::Enum) {
|
if matches!(tcx.def_kind(id.owner_id), DefKind::Enum) {
|
||||||
let item = tcx.hir().item(id);
|
let item = tcx.hir().item(id);
|
||||||
if let hir::ItemKind::Enum(def, ..) = &item.kind {
|
if let hir::ItemKind::Enum(def, ..) = &item.kind {
|
||||||
for variant in def.variants {
|
for variant in def.variants {
|
||||||
collector.check_for_lang(Target::Variant, variant.hir_id);
|
collector.check_for_lang(Target::Variant, variant.def_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -226,13 +227,13 @@ fn get_lang_items(tcx: TyCtxt<'_>, (): ()) -> LanguageItems {
|
|||||||
// FIXME: avoid calling trait_item() when possible
|
// FIXME: avoid calling trait_item() when possible
|
||||||
for id in crate_items.trait_items() {
|
for id in crate_items.trait_items() {
|
||||||
let item = tcx.hir().trait_item(id);
|
let item = tcx.hir().trait_item(id);
|
||||||
collector.check_for_lang(Target::from_trait_item(item), item.hir_id())
|
collector.check_for_lang(Target::from_trait_item(item), item.owner_id.def_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: avoid calling impl_item() when possible
|
// FIXME: avoid calling impl_item() when possible
|
||||||
for id in crate_items.impl_items() {
|
for id in crate_items.impl_items() {
|
||||||
let item = tcx.hir().impl_item(id);
|
let item = tcx.hir().impl_item(id);
|
||||||
collector.check_for_lang(target_from_impl_item(tcx, item), item.hir_id())
|
collector.check_for_lang(target_from_impl_item(tcx, item), item.owner_id.def_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extract out the found lang items.
|
// Extract out the found lang items.
|
||||||
|
@ -855,7 +855,8 @@ impl<'tcx> Visitor<'tcx> for Checker<'tcx> {
|
|||||||
/// See issue #94972 for details on why this is a special case
|
/// See issue #94972 for details on why this is a special case
|
||||||
fn is_unstable_reexport(tcx: TyCtxt<'_>, id: hir::HirId) -> bool {
|
fn is_unstable_reexport(tcx: TyCtxt<'_>, id: hir::HirId) -> bool {
|
||||||
// Get the LocalDefId so we can lookup the item to check the kind.
|
// Get the LocalDefId so we can lookup the item to check the kind.
|
||||||
let Some(def_id) = tcx.hir().opt_local_def_id(id) else { return false; };
|
let Some(owner) = id.as_owner() else { return false; };
|
||||||
|
let def_id = owner.def_id;
|
||||||
|
|
||||||
let Some(stab) = tcx.stability().local_stability(def_id) else {
|
let Some(stab) = tcx.stability().local_stability(def_id) else {
|
||||||
return false;
|
return false;
|
||||||
|
@ -18,7 +18,7 @@ use rustc_data_structures::fx::FxHashSet;
|
|||||||
use rustc_data_structures::intern::Interned;
|
use rustc_data_structures::intern::Interned;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def::{DefKind, Res};
|
use rustc_hir::def::{DefKind, Res};
|
||||||
use rustc_hir::def_id::{DefId, LocalDefId, LocalDefIdSet, CRATE_DEF_ID};
|
use rustc_hir::def_id::{DefId, LocalDefId, CRATE_DEF_ID};
|
||||||
use rustc_hir::intravisit::{self, Visitor};
|
use rustc_hir::intravisit::{self, Visitor};
|
||||||
use rustc_hir::{AssocItemKind, HirIdSet, ItemId, Node, PatKind};
|
use rustc_hir::{AssocItemKind, HirIdSet, ItemId, Node, PatKind};
|
||||||
use rustc_middle::bug;
|
use rustc_middle::bug;
|
||||||
@ -1879,7 +1879,7 @@ impl<'tcx> DefIdVisitor<'tcx> for SearchInterfaceForPrivateItemsVisitor<'tcx> {
|
|||||||
|
|
||||||
struct PrivateItemsInPublicInterfacesChecker<'tcx> {
|
struct PrivateItemsInPublicInterfacesChecker<'tcx> {
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
old_error_set_ancestry: LocalDefIdSet,
|
old_error_set_ancestry: HirIdSet,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> PrivateItemsInPublicInterfacesChecker<'tcx> {
|
impl<'tcx> PrivateItemsInPublicInterfacesChecker<'tcx> {
|
||||||
@ -1892,7 +1892,9 @@ impl<'tcx> PrivateItemsInPublicInterfacesChecker<'tcx> {
|
|||||||
tcx: self.tcx,
|
tcx: self.tcx,
|
||||||
item_def_id: def_id,
|
item_def_id: def_id,
|
||||||
required_visibility,
|
required_visibility,
|
||||||
has_old_errors: self.old_error_set_ancestry.contains(&def_id),
|
has_old_errors: self
|
||||||
|
.old_error_set_ancestry
|
||||||
|
.contains(&self.tcx.hir().local_def_id_to_hir_id(def_id)),
|
||||||
in_assoc_ty: false,
|
in_assoc_ty: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2158,15 +2160,7 @@ fn check_private_in_public(tcx: TyCtxt<'_>, (): ()) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check for private types and traits in public interfaces.
|
// Check for private types and traits in public interfaces.
|
||||||
let mut checker = PrivateItemsInPublicInterfacesChecker {
|
let mut checker = PrivateItemsInPublicInterfacesChecker { tcx, old_error_set_ancestry };
|
||||||
tcx,
|
|
||||||
// Only definition IDs are ever searched in `old_error_set_ancestry`,
|
|
||||||
// so we can filter away all non-definition IDs at this point.
|
|
||||||
old_error_set_ancestry: old_error_set_ancestry
|
|
||||||
.into_iter()
|
|
||||||
.filter_map(|hir_id| tcx.hir().opt_local_def_id(hir_id))
|
|
||||||
.collect(),
|
|
||||||
};
|
|
||||||
|
|
||||||
for id in tcx.hir().items() {
|
for id in tcx.hir().items() {
|
||||||
checker.check_item(id);
|
checker.check_item(id);
|
||||||
|
@ -211,7 +211,7 @@ impl<'tcx> DumpVisitor<'tcx> {
|
|||||||
None => continue,
|
None => continue,
|
||||||
};
|
};
|
||||||
if !self.span.filter_generated(ident.span) {
|
if !self.span.filter_generated(ident.span) {
|
||||||
let id = id_from_hir_id(hir_id, &self.save_ctxt);
|
let id = id_from_hir_id(hir_id);
|
||||||
let span = self.span_from_span(ident.span);
|
let span = self.span_from_span(ident.span);
|
||||||
|
|
||||||
self.dumper.dump_def(
|
self.dumper.dump_def(
|
||||||
@ -240,17 +240,17 @@ impl<'tcx> DumpVisitor<'tcx> {
|
|||||||
&mut self,
|
&mut self,
|
||||||
sig: &'tcx hir::FnSig<'tcx>,
|
sig: &'tcx hir::FnSig<'tcx>,
|
||||||
body: Option<hir::BodyId>,
|
body: Option<hir::BodyId>,
|
||||||
def_id: LocalDefId,
|
owner_id: hir::OwnerId,
|
||||||
ident: Ident,
|
ident: Ident,
|
||||||
generics: &'tcx hir::Generics<'tcx>,
|
generics: &'tcx hir::Generics<'tcx>,
|
||||||
span: Span,
|
span: Span,
|
||||||
) {
|
) {
|
||||||
debug!("process_method: {:?}:{}", def_id, ident);
|
debug!("process_method: {:?}:{}", owner_id, ident);
|
||||||
|
|
||||||
let map = self.tcx.hir();
|
let map = self.tcx.hir();
|
||||||
let hir_id = map.local_def_id_to_hir_id(def_id);
|
let hir_id: hir::HirId = owner_id.into();
|
||||||
self.nest_typeck_results(def_id, |v| {
|
self.nest_typeck_results(owner_id.def_id, |v| {
|
||||||
if let Some(mut method_data) = v.save_ctxt.get_method_data(hir_id, ident, span) {
|
if let Some(mut method_data) = v.save_ctxt.get_method_data(owner_id, ident, span) {
|
||||||
if let Some(body) = body {
|
if let Some(body) = body {
|
||||||
v.process_formals(map.body(body).params, &method_data.qualname);
|
v.process_formals(map.body(body).params, &method_data.qualname);
|
||||||
}
|
}
|
||||||
@ -258,9 +258,10 @@ impl<'tcx> DumpVisitor<'tcx> {
|
|||||||
|
|
||||||
method_data.value =
|
method_data.value =
|
||||||
fn_to_string(sig.decl, sig.header, Some(ident.name), generics, &[], None);
|
fn_to_string(sig.decl, sig.header, Some(ident.name), generics, &[], None);
|
||||||
method_data.sig = sig::method_signature(hir_id, ident, generics, sig, &v.save_ctxt);
|
method_data.sig =
|
||||||
|
sig::method_signature(owner_id, ident, generics, sig, &v.save_ctxt);
|
||||||
|
|
||||||
v.dumper.dump_def(&access_from!(v.save_ctxt, def_id), method_data);
|
v.dumper.dump_def(&access_from!(v.save_ctxt, owner_id.def_id), method_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
// walk arg and return types
|
// walk arg and return types
|
||||||
@ -282,14 +283,11 @@ impl<'tcx> DumpVisitor<'tcx> {
|
|||||||
fn process_struct_field_def(
|
fn process_struct_field_def(
|
||||||
&mut self,
|
&mut self,
|
||||||
field: &'tcx hir::FieldDef<'tcx>,
|
field: &'tcx hir::FieldDef<'tcx>,
|
||||||
parent_id: hir::HirId,
|
parent_id: LocalDefId,
|
||||||
) {
|
) {
|
||||||
let field_data = self.save_ctxt.get_field_data(field, parent_id);
|
let field_data = self.save_ctxt.get_field_data(field, parent_id);
|
||||||
if let Some(field_data) = field_data {
|
if let Some(field_data) = field_data {
|
||||||
self.dumper.dump_def(
|
self.dumper.dump_def(&access_from!(self.save_ctxt, field.def_id), field_data);
|
||||||
&access_from!(self.save_ctxt, self.tcx.hir().local_def_id(field.hir_id)),
|
|
||||||
field_data,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -309,7 +307,7 @@ impl<'tcx> DumpVisitor<'tcx> {
|
|||||||
// Append $id to name to make sure each one is unique.
|
// Append $id to name to make sure each one is unique.
|
||||||
let qualname = format!("{}::{}${}", prefix, name, id);
|
let qualname = format!("{}::{}${}", prefix, name, id);
|
||||||
if !self.span.filter_generated(param_ss) {
|
if !self.span.filter_generated(param_ss) {
|
||||||
let id = id_from_hir_id(param.hir_id, &self.save_ctxt);
|
let id = id_from_def_id(param.def_id.to_def_id());
|
||||||
let span = self.span_from_span(param_ss);
|
let span = self.span_from_span(param_ss);
|
||||||
|
|
||||||
self.dumper.dump_def(
|
self.dumper.dump_def(
|
||||||
@ -387,25 +385,24 @@ impl<'tcx> DumpVisitor<'tcx> {
|
|||||||
|
|
||||||
fn process_assoc_const(
|
fn process_assoc_const(
|
||||||
&mut self,
|
&mut self,
|
||||||
def_id: LocalDefId,
|
owner_id: hir::OwnerId,
|
||||||
ident: Ident,
|
ident: Ident,
|
||||||
typ: &'tcx hir::Ty<'tcx>,
|
typ: &'tcx hir::Ty<'tcx>,
|
||||||
expr: Option<&'tcx hir::Expr<'tcx>>,
|
expr: Option<&'tcx hir::Expr<'tcx>>,
|
||||||
parent_id: DefId,
|
parent_id: DefId,
|
||||||
attrs: &'tcx [ast::Attribute],
|
attrs: &'tcx [ast::Attribute],
|
||||||
) {
|
) {
|
||||||
let qualname = format!("::{}", self.tcx.def_path_str(def_id.to_def_id()));
|
let qualname = format!("::{}", self.tcx.def_path_str(owner_id.to_def_id()));
|
||||||
|
|
||||||
if !self.span.filter_generated(ident.span) {
|
if !self.span.filter_generated(ident.span) {
|
||||||
let hir_id = self.tcx.hir().local_def_id_to_hir_id(def_id);
|
let sig = sig::assoc_const_signature(owner_id, ident.name, typ, expr, &self.save_ctxt);
|
||||||
let sig = sig::assoc_const_signature(hir_id, ident.name, typ, expr, &self.save_ctxt);
|
|
||||||
let span = self.span_from_span(ident.span);
|
let span = self.span_from_span(ident.span);
|
||||||
|
|
||||||
self.dumper.dump_def(
|
self.dumper.dump_def(
|
||||||
&access_from!(self.save_ctxt, def_id),
|
&access_from!(self.save_ctxt, owner_id.def_id),
|
||||||
Def {
|
Def {
|
||||||
kind: DefKind::Const,
|
kind: DefKind::Const,
|
||||||
id: id_from_hir_id(hir_id, &self.save_ctxt),
|
id: id_from_def_id(owner_id.to_def_id()),
|
||||||
span,
|
span,
|
||||||
name: ident.name.to_string(),
|
name: ident.name.to_string(),
|
||||||
qualname,
|
qualname,
|
||||||
@ -421,7 +418,7 @@ impl<'tcx> DumpVisitor<'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// walk type and init value
|
// walk type and init value
|
||||||
self.nest_typeck_results(def_id, |v| {
|
self.nest_typeck_results(owner_id.def_id, |v| {
|
||||||
v.visit_ty(typ);
|
v.visit_ty(typ);
|
||||||
if let Some(expr) = expr {
|
if let Some(expr) = expr {
|
||||||
v.visit_expr(expr);
|
v.visit_expr(expr);
|
||||||
@ -456,8 +453,7 @@ impl<'tcx> DumpVisitor<'tcx> {
|
|||||||
if include_priv_fields {
|
if include_priv_fields {
|
||||||
return Some(f.ident.to_string());
|
return Some(f.ident.to_string());
|
||||||
}
|
}
|
||||||
let def_id = self.save_ctxt.tcx.hir().local_def_id(f.hir_id);
|
if self.save_ctxt.tcx.visibility(f.def_id).is_public() {
|
||||||
if self.save_ctxt.tcx.visibility(def_id).is_public() {
|
|
||||||
Some(f.ident.to_string())
|
Some(f.ident.to_string())
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
@ -466,7 +462,7 @@ impl<'tcx> DumpVisitor<'tcx> {
|
|||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.join(", ");
|
.join(", ");
|
||||||
let value = format!("{} {{ {} }}", name, fields_str);
|
let value = format!("{} {{ {} }}", name, fields_str);
|
||||||
(value, fields.iter().map(|f| id_from_hir_id(f.hir_id, &self.save_ctxt)).collect())
|
(value, fields.iter().map(|f| id_from_def_id(f.def_id.to_def_id())).collect())
|
||||||
}
|
}
|
||||||
_ => (String::new(), vec![]),
|
_ => (String::new(), vec![]),
|
||||||
};
|
};
|
||||||
@ -495,7 +491,7 @@ impl<'tcx> DumpVisitor<'tcx> {
|
|||||||
|
|
||||||
self.nest_typeck_results(item.owner_id.def_id, |v| {
|
self.nest_typeck_results(item.owner_id.def_id, |v| {
|
||||||
for field in def.fields() {
|
for field in def.fields() {
|
||||||
v.process_struct_field_def(field, item.hir_id());
|
v.process_struct_field_def(field, item.owner_id.def_id);
|
||||||
v.visit_ty(&field.ty);
|
v.visit_ty(&field.ty);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -529,7 +525,7 @@ impl<'tcx> DumpVisitor<'tcx> {
|
|||||||
let value = format!("{}::{} {{ {} }}", enum_data.name, name, fields_str);
|
let value = format!("{}::{} {{ {} }}", enum_data.name, name, fields_str);
|
||||||
if !self.span.filter_generated(name_span) {
|
if !self.span.filter_generated(name_span) {
|
||||||
let span = self.span_from_span(name_span);
|
let span = self.span_from_span(name_span);
|
||||||
let id = id_from_hir_id(variant.hir_id, &self.save_ctxt);
|
let id = id_from_def_id(variant.def_id.to_def_id());
|
||||||
let parent = Some(id_from_def_id(item.owner_id.to_def_id()));
|
let parent = Some(id_from_def_id(item.owner_id.to_def_id()));
|
||||||
let attrs = self.tcx.hir().attrs(variant.hir_id);
|
let attrs = self.tcx.hir().attrs(variant.hir_id);
|
||||||
|
|
||||||
@ -567,7 +563,7 @@ impl<'tcx> DumpVisitor<'tcx> {
|
|||||||
}
|
}
|
||||||
if !self.span.filter_generated(name_span) {
|
if !self.span.filter_generated(name_span) {
|
||||||
let span = self.span_from_span(name_span);
|
let span = self.span_from_span(name_span);
|
||||||
let id = id_from_hir_id(variant.hir_id, &self.save_ctxt);
|
let id = id_from_def_id(variant.def_id.to_def_id());
|
||||||
let parent = Some(id_from_def_id(item.owner_id.to_def_id()));
|
let parent = Some(id_from_def_id(item.owner_id.to_def_id()));
|
||||||
let attrs = self.tcx.hir().attrs(variant.hir_id);
|
let attrs = self.tcx.hir().attrs(variant.hir_id);
|
||||||
|
|
||||||
@ -593,7 +589,7 @@ impl<'tcx> DumpVisitor<'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for field in variant.data.fields() {
|
for field in variant.data.fields() {
|
||||||
self.process_struct_field_def(field, variant.hir_id);
|
self.process_struct_field_def(field, variant.def_id);
|
||||||
self.visit_ty(field.ty);
|
self.visit_ty(field.ty);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -883,7 +879,7 @@ impl<'tcx> DumpVisitor<'tcx> {
|
|||||||
// Rust uses the id of the pattern for var lookups, so we'll use it too.
|
// Rust uses the id of the pattern for var lookups, so we'll use it too.
|
||||||
if !self.span.filter_generated(ident.span) {
|
if !self.span.filter_generated(ident.span) {
|
||||||
let qualname = format!("{}${}", ident, hir_id);
|
let qualname = format!("{}${}", ident, hir_id);
|
||||||
let id = id_from_hir_id(hir_id, &self.save_ctxt);
|
let id = id_from_hir_id(hir_id);
|
||||||
let span = self.span_from_span(ident.span);
|
let span = self.span_from_span(ident.span);
|
||||||
|
|
||||||
self.dumper.dump_def(
|
self.dumper.dump_def(
|
||||||
@ -983,7 +979,7 @@ impl<'tcx> DumpVisitor<'tcx> {
|
|||||||
let body = body.map(|b| self.tcx.hir().body(b).value);
|
let body = body.map(|b| self.tcx.hir().body(b).value);
|
||||||
let attrs = self.tcx.hir().attrs(trait_item.hir_id());
|
let attrs = self.tcx.hir().attrs(trait_item.hir_id());
|
||||||
self.process_assoc_const(
|
self.process_assoc_const(
|
||||||
trait_item.owner_id.def_id,
|
trait_item.owner_id,
|
||||||
trait_item.ident,
|
trait_item.ident,
|
||||||
&ty,
|
&ty,
|
||||||
body,
|
body,
|
||||||
@ -997,7 +993,7 @@ impl<'tcx> DumpVisitor<'tcx> {
|
|||||||
self.process_method(
|
self.process_method(
|
||||||
sig,
|
sig,
|
||||||
body,
|
body,
|
||||||
trait_item.owner_id.def_id,
|
trait_item.owner_id,
|
||||||
trait_item.ident,
|
trait_item.ident,
|
||||||
&trait_item.generics,
|
&trait_item.generics,
|
||||||
trait_item.span,
|
trait_item.span,
|
||||||
@ -1028,7 +1024,7 @@ impl<'tcx> DumpVisitor<'tcx> {
|
|||||||
decl_id: None,
|
decl_id: None,
|
||||||
docs: self.save_ctxt.docs_for_attrs(attrs),
|
docs: self.save_ctxt.docs_for_attrs(attrs),
|
||||||
sig: sig::assoc_type_signature(
|
sig: sig::assoc_type_signature(
|
||||||
trait_item.hir_id(),
|
trait_item.owner_id,
|
||||||
trait_item.ident,
|
trait_item.ident,
|
||||||
Some(bounds),
|
Some(bounds),
|
||||||
default_ty.as_deref(),
|
default_ty.as_deref(),
|
||||||
@ -1053,7 +1049,7 @@ impl<'tcx> DumpVisitor<'tcx> {
|
|||||||
let body = self.tcx.hir().body(body);
|
let body = self.tcx.hir().body(body);
|
||||||
let attrs = self.tcx.hir().attrs(impl_item.hir_id());
|
let attrs = self.tcx.hir().attrs(impl_item.hir_id());
|
||||||
self.process_assoc_const(
|
self.process_assoc_const(
|
||||||
impl_item.owner_id.def_id,
|
impl_item.owner_id,
|
||||||
impl_item.ident,
|
impl_item.ident,
|
||||||
&ty,
|
&ty,
|
||||||
Some(&body.value),
|
Some(&body.value),
|
||||||
@ -1065,7 +1061,7 @@ impl<'tcx> DumpVisitor<'tcx> {
|
|||||||
self.process_method(
|
self.process_method(
|
||||||
sig,
|
sig,
|
||||||
Some(body),
|
Some(body),
|
||||||
impl_item.owner_id.def_id,
|
impl_item.owner_id,
|
||||||
impl_item.ident,
|
impl_item.ident,
|
||||||
&impl_item.generics,
|
&impl_item.generics,
|
||||||
impl_item.span,
|
impl_item.span,
|
||||||
@ -1081,18 +1077,16 @@ impl<'tcx> DumpVisitor<'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn process_crate(&mut self) {
|
pub(crate) fn process_crate(&mut self) {
|
||||||
let id = hir::CRATE_HIR_ID;
|
let qualname = format!("::{}", self.tcx.def_path_str(CRATE_DEF_ID.to_def_id()));
|
||||||
let qualname =
|
|
||||||
format!("::{}", self.tcx.def_path_str(self.tcx.hir().local_def_id(id).to_def_id()));
|
|
||||||
|
|
||||||
let sm = self.tcx.sess.source_map();
|
let sm = self.tcx.sess.source_map();
|
||||||
let krate_mod = self.tcx.hir().root_module();
|
let krate_mod = self.tcx.hir().root_module();
|
||||||
let filename = sm.span_to_filename(krate_mod.spans.inner_span);
|
let filename = sm.span_to_filename(krate_mod.spans.inner_span);
|
||||||
let data_id = id_from_hir_id(id, &self.save_ctxt);
|
let data_id = id_from_def_id(CRATE_DEF_ID.to_def_id());
|
||||||
let children =
|
let children =
|
||||||
krate_mod.item_ids.iter().map(|i| id_from_def_id(i.owner_id.to_def_id())).collect();
|
krate_mod.item_ids.iter().map(|i| id_from_def_id(i.owner_id.to_def_id())).collect();
|
||||||
let span = self.span_from_span(krate_mod.spans.inner_span);
|
let span = self.span_from_span(krate_mod.spans.inner_span);
|
||||||
let attrs = self.tcx.hir().attrs(id);
|
let attrs = self.tcx.hir().attrs(hir::CRATE_HIR_ID);
|
||||||
|
|
||||||
self.dumper.dump_def(
|
self.dumper.dump_def(
|
||||||
&Access { public: true, reachable: true },
|
&Access { public: true, reachable: true },
|
||||||
@ -1319,7 +1313,7 @@ impl<'tcx> Visitor<'tcx> for DumpVisitor<'tcx> {
|
|||||||
// output the inferred type here? :shrug:
|
// output the inferred type here? :shrug:
|
||||||
hir::ArrayLen::Infer(..) => {}
|
hir::ArrayLen::Infer(..) => {}
|
||||||
hir::ArrayLen::Body(anon_const) => self
|
hir::ArrayLen::Body(anon_const) => self
|
||||||
.nest_typeck_results(self.tcx.hir().local_def_id(anon_const.hir_id), |v| {
|
.nest_typeck_results(anon_const.def_id, |v| {
|
||||||
v.visit_expr(&map.body(anon_const.body).value)
|
v.visit_expr(&map.body(anon_const.body).value)
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
@ -1361,7 +1355,7 @@ impl<'tcx> Visitor<'tcx> for DumpVisitor<'tcx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
hir::ExprKind::Closure(&hir::Closure { ref fn_decl, body, .. }) => {
|
hir::ExprKind::Closure(&hir::Closure { ref fn_decl, body, def_id, .. }) => {
|
||||||
let id = format!("${}", ex.hir_id);
|
let id = format!("${}", ex.hir_id);
|
||||||
|
|
||||||
// walk arg and return types
|
// walk arg and return types
|
||||||
@ -1375,7 +1369,7 @@ impl<'tcx> Visitor<'tcx> for DumpVisitor<'tcx> {
|
|||||||
|
|
||||||
// walk the body
|
// walk the body
|
||||||
let map = self.tcx.hir();
|
let map = self.tcx.hir();
|
||||||
self.nest_typeck_results(self.tcx.hir().local_def_id(ex.hir_id), |v| {
|
self.nest_typeck_results(def_id, |v| {
|
||||||
let body = map.body(body);
|
let body = map.body(body);
|
||||||
v.process_formals(body.params, &id);
|
v.process_formals(body.params, &id);
|
||||||
v.visit_expr(&body.value)
|
v.visit_expr(&body.value)
|
||||||
@ -1389,7 +1383,7 @@ impl<'tcx> Visitor<'tcx> for DumpVisitor<'tcx> {
|
|||||||
// output the inferred type here? :shrug:
|
// output the inferred type here? :shrug:
|
||||||
hir::ArrayLen::Infer(..) => {}
|
hir::ArrayLen::Infer(..) => {}
|
||||||
hir::ArrayLen::Body(anon_const) => self
|
hir::ArrayLen::Body(anon_const) => self
|
||||||
.nest_typeck_results(self.tcx.hir().local_def_id(anon_const.hir_id), |v| {
|
.nest_typeck_results(anon_const.def_id, |v| {
|
||||||
v.visit_expr(&map.body(anon_const.body).value)
|
v.visit_expr(&map.body(anon_const.body).value)
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ use rustc_ast::util::comments::beautify_doc_string;
|
|||||||
use rustc_ast_pretty::pprust::attribute_to_string;
|
use rustc_ast_pretty::pprust::attribute_to_string;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def::{DefKind as HirDefKind, Res};
|
use rustc_hir::def::{DefKind as HirDefKind, Res};
|
||||||
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
|
use rustc_hir::def_id::{DefId, LocalDefId, LOCAL_CRATE};
|
||||||
use rustc_hir::intravisit::{self, Visitor};
|
use rustc_hir::intravisit::{self, Visitor};
|
||||||
use rustc_hir::Node;
|
use rustc_hir::Node;
|
||||||
use rustc_hir_pretty::{enum_def_to_string, fn_to_string, ty_to_string};
|
use rustc_hir_pretty::{enum_def_to_string, fn_to_string, ty_to_string};
|
||||||
@ -318,7 +318,7 @@ impl<'tcx> SaveContext<'tcx> {
|
|||||||
qualname,
|
qualname,
|
||||||
value,
|
value,
|
||||||
parent: None,
|
parent: None,
|
||||||
children: def.variants.iter().map(|v| id_from_hir_id(v.hir_id, self)).collect(),
|
children: def.variants.iter().map(|v| id_from_def_id(v.def_id.to_def_id())).collect(),
|
||||||
decl_id: None,
|
decl_id: None,
|
||||||
docs: self.docs_for_attrs(attrs),
|
docs: self.docs_for_attrs(attrs),
|
||||||
sig: sig::item_signature(item, self),
|
sig: sig::item_signature(item, self),
|
||||||
@ -379,12 +379,11 @@ impl<'tcx> SaveContext<'tcx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_field_data(&self, field: &hir::FieldDef<'_>, scope: hir::HirId) -> Option<Def> {
|
pub fn get_field_data(&self, field: &hir::FieldDef<'_>, scope: LocalDefId) -> Option<Def> {
|
||||||
let name = field.ident.to_string();
|
let name = field.ident.to_string();
|
||||||
let scope_def_id = self.tcx.hir().local_def_id(scope).to_def_id();
|
let qualname = format!("::{}::{}", self.tcx.def_path_str(scope.to_def_id()), field.ident);
|
||||||
let qualname = format!("::{}::{}", self.tcx.def_path_str(scope_def_id), field.ident);
|
|
||||||
filter!(self.span_utils, field.ident.span);
|
filter!(self.span_utils, field.ident.span);
|
||||||
let field_def_id = self.tcx.hir().local_def_id(field.hir_id).to_def_id();
|
let field_def_id = field.def_id.to_def_id();
|
||||||
let typ = self.tcx.type_of(field_def_id).to_string();
|
let typ = self.tcx.type_of(field_def_id).to_string();
|
||||||
|
|
||||||
let id = id_from_def_id(field_def_id);
|
let id = id_from_def_id(field_def_id);
|
||||||
@ -398,7 +397,7 @@ impl<'tcx> SaveContext<'tcx> {
|
|||||||
name,
|
name,
|
||||||
qualname,
|
qualname,
|
||||||
value: typ,
|
value: typ,
|
||||||
parent: Some(id_from_def_id(scope_def_id)),
|
parent: Some(id_from_def_id(scope.to_def_id())),
|
||||||
children: vec![],
|
children: vec![],
|
||||||
decl_id: None,
|
decl_id: None,
|
||||||
docs: self.docs_for_attrs(attrs),
|
docs: self.docs_for_attrs(attrs),
|
||||||
@ -409,12 +408,11 @@ impl<'tcx> SaveContext<'tcx> {
|
|||||||
|
|
||||||
// FIXME would be nice to take a MethodItem here, but the ast provides both
|
// FIXME would be nice to take a MethodItem here, but the ast provides both
|
||||||
// trait and impl flavours, so the caller must do the disassembly.
|
// trait and impl flavours, so the caller must do the disassembly.
|
||||||
pub fn get_method_data(&self, hir_id: hir::HirId, ident: Ident, span: Span) -> Option<Def> {
|
pub fn get_method_data(&self, owner_id: hir::OwnerId, ident: Ident, span: Span) -> Option<Def> {
|
||||||
// The qualname for a method is the trait name or name of the struct in an impl in
|
// The qualname for a method is the trait name or name of the struct in an impl in
|
||||||
// which the method is declared in, followed by the method's name.
|
// which the method is declared in, followed by the method's name.
|
||||||
let def_id = self.tcx.hir().local_def_id(hir_id).to_def_id();
|
|
||||||
let (qualname, parent_scope, decl_id, docs, attributes) =
|
let (qualname, parent_scope, decl_id, docs, attributes) =
|
||||||
match self.tcx.impl_of_method(def_id) {
|
match self.tcx.impl_of_method(owner_id.to_def_id()) {
|
||||||
Some(impl_id) => match self.tcx.hir().get_if_local(impl_id) {
|
Some(impl_id) => match self.tcx.hir().get_if_local(impl_id) {
|
||||||
Some(Node::Item(item)) => match item.kind {
|
Some(Node::Item(item)) => match item.kind {
|
||||||
hir::ItemKind::Impl(hir::Impl { ref self_ty, .. }) => {
|
hir::ItemKind::Impl(hir::Impl { ref self_ty, .. }) => {
|
||||||
@ -427,8 +425,8 @@ impl<'tcx> SaveContext<'tcx> {
|
|||||||
let trait_id = self.tcx.trait_id_of_impl(impl_id);
|
let trait_id = self.tcx.trait_id_of_impl(impl_id);
|
||||||
let mut docs = String::new();
|
let mut docs = String::new();
|
||||||
let mut attrs = vec![];
|
let mut attrs = vec![];
|
||||||
if let Some(Node::ImplItem(_)) = hir.find(hir_id) {
|
if let Some(Node::ImplItem(_)) = hir.find(owner_id.into()) {
|
||||||
attrs = self.tcx.hir().attrs(hir_id).to_vec();
|
attrs = self.tcx.hir().attrs(owner_id.into()).to_vec();
|
||||||
docs = self.docs_for_attrs(&attrs);
|
docs = self.docs_for_attrs(&attrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -452,29 +450,29 @@ impl<'tcx> SaveContext<'tcx> {
|
|||||||
_ => {
|
_ => {
|
||||||
span_bug!(
|
span_bug!(
|
||||||
span,
|
span,
|
||||||
"Container {:?} for method {} not an impl?",
|
"Container {:?} for method {:?} not an impl?",
|
||||||
impl_id,
|
impl_id,
|
||||||
hir_id
|
owner_id,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
r => {
|
r => {
|
||||||
span_bug!(
|
span_bug!(
|
||||||
span,
|
span,
|
||||||
"Container {:?} for method {} is not a node item {:?}",
|
"Container {:?} for method {:?} is not a node item {:?}",
|
||||||
impl_id,
|
impl_id,
|
||||||
hir_id,
|
owner_id,
|
||||||
r
|
r
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
None => match self.tcx.trait_of_item(def_id) {
|
None => match self.tcx.trait_of_item(owner_id.to_def_id()) {
|
||||||
Some(def_id) => {
|
Some(def_id) => {
|
||||||
let mut docs = String::new();
|
let mut docs = String::new();
|
||||||
let mut attrs = vec![];
|
let mut attrs = vec![];
|
||||||
|
|
||||||
if let Some(Node::TraitItem(_)) = self.tcx.hir().find(hir_id) {
|
if let Some(Node::TraitItem(_)) = self.tcx.hir().find(owner_id.into()) {
|
||||||
attrs = self.tcx.hir().attrs(hir_id).to_vec();
|
attrs = self.tcx.hir().attrs(owner_id.into()).to_vec();
|
||||||
docs = self.docs_for_attrs(&attrs);
|
docs = self.docs_for_attrs(&attrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -487,7 +485,7 @@ impl<'tcx> SaveContext<'tcx> {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
debug!("could not find container for method {} at {:?}", hir_id, span);
|
debug!("could not find container for method {:?} at {:?}", owner_id, span);
|
||||||
// This is not necessarily a bug, if there was a compilation error,
|
// This is not necessarily a bug, if there was a compilation error,
|
||||||
// the typeck results we need might not exist.
|
// the typeck results we need might not exist.
|
||||||
return None;
|
return None;
|
||||||
@ -501,7 +499,7 @@ impl<'tcx> SaveContext<'tcx> {
|
|||||||
|
|
||||||
Some(Def {
|
Some(Def {
|
||||||
kind: DefKind::Method,
|
kind: DefKind::Method,
|
||||||
id: id_from_def_id(def_id),
|
id: id_from_def_id(owner_id.to_def_id()),
|
||||||
span: self.span_from_span(ident.span),
|
span: self.span_from_span(ident.span),
|
||||||
name: ident.name.to_string(),
|
name: ident.name.to_string(),
|
||||||
qualname,
|
qualname,
|
||||||
@ -669,7 +667,7 @@ impl<'tcx> SaveContext<'tcx> {
|
|||||||
|
|
||||||
match res {
|
match res {
|
||||||
Res::Local(id) => {
|
Res::Local(id) => {
|
||||||
Some(Ref { kind: RefKind::Variable, span, ref_id: id_from_hir_id(id, self) })
|
Some(Ref { kind: RefKind::Variable, span, ref_id: id_from_hir_id(id) })
|
||||||
}
|
}
|
||||||
Res::Def(HirDefKind::Trait, def_id) if fn_type(path_seg) => {
|
Res::Def(HirDefKind::Trait, def_id) if fn_type(path_seg) => {
|
||||||
Some(Ref { kind: RefKind::Type, span, ref_id: id_from_def_id(def_id) })
|
Some(Ref { kind: RefKind::Type, span, ref_id: id_from_def_id(def_id) })
|
||||||
@ -1033,18 +1031,15 @@ fn id_from_def_id(id: DefId) -> rls_data::Id {
|
|||||||
rls_data::Id { krate: id.krate.as_u32(), index: id.index.as_u32() }
|
rls_data::Id { krate: id.krate.as_u32(), index: id.index.as_u32() }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn id_from_hir_id(id: hir::HirId, scx: &SaveContext<'_>) -> rls_data::Id {
|
fn id_from_hir_id(id: hir::HirId) -> rls_data::Id {
|
||||||
let def_id = scx.tcx.hir().opt_local_def_id(id);
|
// Create a *fake* `DefId` out of a `HirId` by combining the owner
|
||||||
def_id.map(|id| id_from_def_id(id.to_def_id())).unwrap_or_else(|| {
|
// `local_def_index` and the `local_id`.
|
||||||
// Create a *fake* `DefId` out of a `HirId` by combining the owner
|
// This will work unless you have *billions* of definitions in a single
|
||||||
// `local_def_index` and the `local_id`.
|
// crate (very unlikely to actually happen).
|
||||||
// This will work unless you have *billions* of definitions in a single
|
rls_data::Id {
|
||||||
// crate (very unlikely to actually happen).
|
krate: LOCAL_CRATE.as_u32(),
|
||||||
rls_data::Id {
|
index: id.owner.def_id.local_def_index.as_u32() | id.local_id.as_u32().reverse_bits(),
|
||||||
krate: LOCAL_CRATE.as_u32(),
|
}
|
||||||
index: id.owner.def_id.local_def_index.as_u32() | id.local_id.as_u32().reverse_bits(),
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn null_id() -> rls_data::Id {
|
fn null_id() -> rls_data::Id {
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
//
|
//
|
||||||
// FIXME where clauses need implementing, defs/refs in generics are mostly missing.
|
// FIXME where clauses need implementing, defs/refs in generics are mostly missing.
|
||||||
|
|
||||||
use crate::{id_from_def_id, id_from_hir_id, SaveContext};
|
use crate::{id_from_def_id, SaveContext};
|
||||||
|
|
||||||
use rls_data::{SigElement, Signature};
|
use rls_data::{SigElement, Signature};
|
||||||
|
|
||||||
@ -34,6 +34,7 @@ use rustc_hir as hir;
|
|||||||
use rustc_hir::def::{DefKind, Res};
|
use rustc_hir::def::{DefKind, Res};
|
||||||
use rustc_hir_pretty::id_to_string;
|
use rustc_hir_pretty::id_to_string;
|
||||||
use rustc_hir_pretty::{bounds_to_string, path_segment_to_string, path_to_string, ty_to_string};
|
use rustc_hir_pretty::{bounds_to_string, path_segment_to_string, path_to_string, ty_to_string};
|
||||||
|
use rustc_span::def_id::LocalDefId;
|
||||||
use rustc_span::symbol::{Ident, Symbol};
|
use rustc_span::symbol::{Ident, Symbol};
|
||||||
|
|
||||||
pub fn item_signature(item: &hir::Item<'_>, scx: &SaveContext<'_>) -> Option<Signature> {
|
pub fn item_signature(item: &hir::Item<'_>, scx: &SaveContext<'_>) -> Option<Signature> {
|
||||||
@ -71,7 +72,7 @@ pub fn variant_signature(variant: &hir::Variant<'_>, scx: &SaveContext<'_>) -> O
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn method_signature(
|
pub fn method_signature(
|
||||||
id: hir::HirId,
|
id: hir::OwnerId,
|
||||||
ident: Ident,
|
ident: Ident,
|
||||||
generics: &hir::Generics<'_>,
|
generics: &hir::Generics<'_>,
|
||||||
m: &hir::FnSig<'_>,
|
m: &hir::FnSig<'_>,
|
||||||
@ -84,7 +85,7 @@ pub fn method_signature(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn assoc_const_signature(
|
pub fn assoc_const_signature(
|
||||||
id: hir::HirId,
|
id: hir::OwnerId,
|
||||||
ident: Symbol,
|
ident: Symbol,
|
||||||
ty: &hir::Ty<'_>,
|
ty: &hir::Ty<'_>,
|
||||||
default: Option<&hir::Expr<'_>>,
|
default: Option<&hir::Expr<'_>>,
|
||||||
@ -97,7 +98,7 @@ pub fn assoc_const_signature(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn assoc_type_signature(
|
pub fn assoc_type_signature(
|
||||||
id: hir::HirId,
|
id: hir::OwnerId,
|
||||||
ident: Ident,
|
ident: Ident,
|
||||||
bounds: Option<hir::GenericBounds<'_>>,
|
bounds: Option<hir::GenericBounds<'_>>,
|
||||||
default: Option<&hir::Ty<'_>>,
|
default: Option<&hir::Ty<'_>>,
|
||||||
@ -112,7 +113,8 @@ pub fn assoc_type_signature(
|
|||||||
type Result = std::result::Result<Signature, &'static str>;
|
type Result = std::result::Result<Signature, &'static str>;
|
||||||
|
|
||||||
trait Sig {
|
trait Sig {
|
||||||
fn make(&self, offset: usize, id: Option<hir::HirId>, scx: &SaveContext<'_>) -> Result;
|
type Parent;
|
||||||
|
fn make(&self, offset: usize, id: Option<Self::Parent>, scx: &SaveContext<'_>) -> Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn extend_sig(
|
fn extend_sig(
|
||||||
@ -148,6 +150,7 @@ fn text_sig(text: String) -> Signature {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'hir> Sig for hir::Ty<'hir> {
|
impl<'hir> Sig for hir::Ty<'hir> {
|
||||||
|
type Parent = hir::HirId;
|
||||||
fn make(&self, offset: usize, _parent_id: Option<hir::HirId>, scx: &SaveContext<'_>) -> Result {
|
fn make(&self, offset: usize, _parent_id: Option<hir::HirId>, scx: &SaveContext<'_>) -> Result {
|
||||||
let id = Some(self.hir_id);
|
let id = Some(self.hir_id);
|
||||||
match self.kind {
|
match self.kind {
|
||||||
@ -326,6 +329,7 @@ impl<'hir> Sig for hir::Ty<'hir> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'hir> Sig for hir::Item<'hir> {
|
impl<'hir> Sig for hir::Item<'hir> {
|
||||||
|
type Parent = hir::HirId;
|
||||||
fn make(&self, offset: usize, _parent_id: Option<hir::HirId>, scx: &SaveContext<'_>) -> Result {
|
fn make(&self, offset: usize, _parent_id: Option<hir::HirId>, scx: &SaveContext<'_>) -> Result {
|
||||||
let id = Some(self.hir_id());
|
let id = Some(self.hir_id());
|
||||||
|
|
||||||
@ -391,7 +395,7 @@ impl<'hir> Sig for hir::Item<'hir> {
|
|||||||
text.push_str("fn ");
|
text.push_str("fn ");
|
||||||
|
|
||||||
let mut sig =
|
let mut sig =
|
||||||
name_and_generics(text, offset, generics, self.hir_id(), self.ident, scx)?;
|
name_and_generics(text, offset, generics, self.owner_id, self.ident, scx)?;
|
||||||
|
|
||||||
sig.text.push('(');
|
sig.text.push('(');
|
||||||
for i in decl.inputs {
|
for i in decl.inputs {
|
||||||
@ -441,7 +445,7 @@ impl<'hir> Sig for hir::Item<'hir> {
|
|||||||
hir::ItemKind::TyAlias(ref ty, ref generics) => {
|
hir::ItemKind::TyAlias(ref ty, ref generics) => {
|
||||||
let text = "type ".to_owned();
|
let text = "type ".to_owned();
|
||||||
let mut sig =
|
let mut sig =
|
||||||
name_and_generics(text, offset, generics, self.hir_id(), self.ident, scx)?;
|
name_and_generics(text, offset, generics, self.owner_id, self.ident, scx)?;
|
||||||
|
|
||||||
sig.text.push_str(" = ");
|
sig.text.push_str(" = ");
|
||||||
let ty = ty.make(offset + sig.text.len(), id, scx)?;
|
let ty = ty.make(offset + sig.text.len(), id, scx)?;
|
||||||
@ -453,21 +457,21 @@ impl<'hir> Sig for hir::Item<'hir> {
|
|||||||
hir::ItemKind::Enum(_, ref generics) => {
|
hir::ItemKind::Enum(_, ref generics) => {
|
||||||
let text = "enum ".to_owned();
|
let text = "enum ".to_owned();
|
||||||
let mut sig =
|
let mut sig =
|
||||||
name_and_generics(text, offset, generics, self.hir_id(), self.ident, scx)?;
|
name_and_generics(text, offset, generics, self.owner_id, self.ident, scx)?;
|
||||||
sig.text.push_str(" {}");
|
sig.text.push_str(" {}");
|
||||||
Ok(sig)
|
Ok(sig)
|
||||||
}
|
}
|
||||||
hir::ItemKind::Struct(_, ref generics) => {
|
hir::ItemKind::Struct(_, ref generics) => {
|
||||||
let text = "struct ".to_owned();
|
let text = "struct ".to_owned();
|
||||||
let mut sig =
|
let mut sig =
|
||||||
name_and_generics(text, offset, generics, self.hir_id(), self.ident, scx)?;
|
name_and_generics(text, offset, generics, self.owner_id, self.ident, scx)?;
|
||||||
sig.text.push_str(" {}");
|
sig.text.push_str(" {}");
|
||||||
Ok(sig)
|
Ok(sig)
|
||||||
}
|
}
|
||||||
hir::ItemKind::Union(_, ref generics) => {
|
hir::ItemKind::Union(_, ref generics) => {
|
||||||
let text = "union ".to_owned();
|
let text = "union ".to_owned();
|
||||||
let mut sig =
|
let mut sig =
|
||||||
name_and_generics(text, offset, generics, self.hir_id(), self.ident, scx)?;
|
name_and_generics(text, offset, generics, self.owner_id, self.ident, scx)?;
|
||||||
sig.text.push_str(" {}");
|
sig.text.push_str(" {}");
|
||||||
Ok(sig)
|
Ok(sig)
|
||||||
}
|
}
|
||||||
@ -483,7 +487,7 @@ impl<'hir> Sig for hir::Item<'hir> {
|
|||||||
}
|
}
|
||||||
text.push_str("trait ");
|
text.push_str("trait ");
|
||||||
let mut sig =
|
let mut sig =
|
||||||
name_and_generics(text, offset, generics, self.hir_id(), self.ident, scx)?;
|
name_and_generics(text, offset, generics, self.owner_id, self.ident, scx)?;
|
||||||
|
|
||||||
if !bounds.is_empty() {
|
if !bounds.is_empty() {
|
||||||
sig.text.push_str(": ");
|
sig.text.push_str(": ");
|
||||||
@ -498,7 +502,7 @@ impl<'hir> Sig for hir::Item<'hir> {
|
|||||||
let mut text = String::new();
|
let mut text = String::new();
|
||||||
text.push_str("trait ");
|
text.push_str("trait ");
|
||||||
let mut sig =
|
let mut sig =
|
||||||
name_and_generics(text, offset, generics, self.hir_id(), self.ident, scx)?;
|
name_and_generics(text, offset, generics, self.owner_id, self.ident, scx)?;
|
||||||
|
|
||||||
if !bounds.is_empty() {
|
if !bounds.is_empty() {
|
||||||
sig.text.push_str(" = ");
|
sig.text.push_str(" = ");
|
||||||
@ -532,7 +536,8 @@ impl<'hir> Sig for hir::Item<'hir> {
|
|||||||
text.push_str(" const");
|
text.push_str(" const");
|
||||||
}
|
}
|
||||||
|
|
||||||
let generics_sig = generics.make(offset + text.len(), id, scx)?;
|
let generics_sig =
|
||||||
|
generics.make(offset + text.len(), Some(self.owner_id.def_id), scx)?;
|
||||||
text.push_str(&generics_sig.text);
|
text.push_str(&generics_sig.text);
|
||||||
|
|
||||||
text.push(' ');
|
text.push(' ');
|
||||||
@ -575,6 +580,7 @@ impl<'hir> Sig for hir::Item<'hir> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'hir> Sig for hir::Path<'hir> {
|
impl<'hir> Sig for hir::Path<'hir> {
|
||||||
|
type Parent = hir::HirId;
|
||||||
fn make(&self, offset: usize, id: Option<hir::HirId>, scx: &SaveContext<'_>) -> Result {
|
fn make(&self, offset: usize, id: Option<hir::HirId>, scx: &SaveContext<'_>) -> Result {
|
||||||
let res = scx.get_path_res(id.ok_or("Missing id for Path")?);
|
let res = scx.get_path_res(id.ok_or("Missing id for Path")?);
|
||||||
|
|
||||||
@ -609,7 +615,8 @@ impl<'hir> Sig for hir::Path<'hir> {
|
|||||||
|
|
||||||
// This does not cover the where clause, which must be processed separately.
|
// This does not cover the where clause, which must be processed separately.
|
||||||
impl<'hir> Sig for hir::Generics<'hir> {
|
impl<'hir> Sig for hir::Generics<'hir> {
|
||||||
fn make(&self, offset: usize, _parent_id: Option<hir::HirId>, scx: &SaveContext<'_>) -> Result {
|
type Parent = LocalDefId;
|
||||||
|
fn make(&self, offset: usize, _parent_id: Option<LocalDefId>, scx: &SaveContext<'_>) -> Result {
|
||||||
if self.params.is_empty() {
|
if self.params.is_empty() {
|
||||||
return Ok(text_sig(String::new()));
|
return Ok(text_sig(String::new()));
|
||||||
}
|
}
|
||||||
@ -624,7 +631,7 @@ impl<'hir> Sig for hir::Generics<'hir> {
|
|||||||
}
|
}
|
||||||
param_text.push_str(param.name.ident().as_str());
|
param_text.push_str(param.name.ident().as_str());
|
||||||
defs.push(SigElement {
|
defs.push(SigElement {
|
||||||
id: id_from_hir_id(param.hir_id, scx),
|
id: id_from_def_id(param.def_id.to_def_id()),
|
||||||
start: offset + text.len(),
|
start: offset + text.len(),
|
||||||
end: offset + text.len() + param_text.as_str().len(),
|
end: offset + text.len() + param_text.as_str().len(),
|
||||||
});
|
});
|
||||||
@ -646,12 +653,13 @@ impl<'hir> Sig for hir::Generics<'hir> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'hir> Sig for hir::FieldDef<'hir> {
|
impl<'hir> Sig for hir::FieldDef<'hir> {
|
||||||
fn make(&self, offset: usize, _parent_id: Option<hir::HirId>, scx: &SaveContext<'_>) -> Result {
|
type Parent = LocalDefId;
|
||||||
|
fn make(&self, offset: usize, _parent_id: Option<LocalDefId>, scx: &SaveContext<'_>) -> Result {
|
||||||
let mut text = String::new();
|
let mut text = String::new();
|
||||||
|
|
||||||
text.push_str(&self.ident.to_string());
|
text.push_str(&self.ident.to_string());
|
||||||
let defs = Some(SigElement {
|
let defs = Some(SigElement {
|
||||||
id: id_from_hir_id(self.hir_id, scx),
|
id: id_from_def_id(self.def_id.to_def_id()),
|
||||||
start: offset,
|
start: offset,
|
||||||
end: offset + text.len(),
|
end: offset + text.len(),
|
||||||
});
|
});
|
||||||
@ -666,13 +674,14 @@ impl<'hir> Sig for hir::FieldDef<'hir> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'hir> Sig for hir::Variant<'hir> {
|
impl<'hir> Sig for hir::Variant<'hir> {
|
||||||
fn make(&self, offset: usize, parent_id: Option<hir::HirId>, scx: &SaveContext<'_>) -> Result {
|
type Parent = LocalDefId;
|
||||||
|
fn make(&self, offset: usize, parent_id: Option<LocalDefId>, scx: &SaveContext<'_>) -> Result {
|
||||||
let mut text = self.ident.to_string();
|
let mut text = self.ident.to_string();
|
||||||
match self.data {
|
match self.data {
|
||||||
hir::VariantData::Struct(fields, r) => {
|
hir::VariantData::Struct(fields, r) => {
|
||||||
let id = parent_id.ok_or("Missing id for Variant's parent")?;
|
let id = parent_id.ok_or("Missing id for Variant's parent")?;
|
||||||
let name_def = SigElement {
|
let name_def = SigElement {
|
||||||
id: id_from_hir_id(id, scx),
|
id: id_from_def_id(id.to_def_id()),
|
||||||
start: offset,
|
start: offset,
|
||||||
end: offset + text.len(),
|
end: offset + text.len(),
|
||||||
};
|
};
|
||||||
@ -693,9 +702,9 @@ impl<'hir> Sig for hir::Variant<'hir> {
|
|||||||
text.push('}');
|
text.push('}');
|
||||||
Ok(Signature { text, defs, refs })
|
Ok(Signature { text, defs, refs })
|
||||||
}
|
}
|
||||||
hir::VariantData::Tuple(fields, id, _) => {
|
hir::VariantData::Tuple(fields, _, def_id) => {
|
||||||
let name_def = SigElement {
|
let name_def = SigElement {
|
||||||
id: id_from_hir_id(id, scx),
|
id: id_from_def_id(def_id.to_def_id()),
|
||||||
start: offset,
|
start: offset,
|
||||||
end: offset + text.len(),
|
end: offset + text.len(),
|
||||||
};
|
};
|
||||||
@ -703,7 +712,7 @@ impl<'hir> Sig for hir::Variant<'hir> {
|
|||||||
let mut defs = vec![name_def];
|
let mut defs = vec![name_def];
|
||||||
let mut refs = vec![];
|
let mut refs = vec![];
|
||||||
for f in fields {
|
for f in fields {
|
||||||
let field_sig = f.make(offset + text.len(), Some(id), scx)?;
|
let field_sig = f.make(offset + text.len(), Some(def_id), scx)?;
|
||||||
text.push_str(&field_sig.text);
|
text.push_str(&field_sig.text);
|
||||||
text.push_str(", ");
|
text.push_str(", ");
|
||||||
defs.extend(field_sig.defs.into_iter());
|
defs.extend(field_sig.defs.into_iter());
|
||||||
@ -712,9 +721,9 @@ impl<'hir> Sig for hir::Variant<'hir> {
|
|||||||
text.push(')');
|
text.push(')');
|
||||||
Ok(Signature { text, defs, refs })
|
Ok(Signature { text, defs, refs })
|
||||||
}
|
}
|
||||||
hir::VariantData::Unit(id, _) => {
|
hir::VariantData::Unit(_, def_id) => {
|
||||||
let name_def = SigElement {
|
let name_def = SigElement {
|
||||||
id: id_from_hir_id(id, scx),
|
id: id_from_def_id(def_id.to_def_id()),
|
||||||
start: offset,
|
start: offset,
|
||||||
end: offset + text.len(),
|
end: offset + text.len(),
|
||||||
};
|
};
|
||||||
@ -725,6 +734,7 @@ impl<'hir> Sig for hir::Variant<'hir> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'hir> Sig for hir::ForeignItem<'hir> {
|
impl<'hir> Sig for hir::ForeignItem<'hir> {
|
||||||
|
type Parent = hir::HirId;
|
||||||
fn make(&self, offset: usize, _parent_id: Option<hir::HirId>, scx: &SaveContext<'_>) -> Result {
|
fn make(&self, offset: usize, _parent_id: Option<hir::HirId>, scx: &SaveContext<'_>) -> Result {
|
||||||
let id = Some(self.hir_id());
|
let id = Some(self.hir_id());
|
||||||
match self.kind {
|
match self.kind {
|
||||||
@ -733,7 +743,7 @@ impl<'hir> Sig for hir::ForeignItem<'hir> {
|
|||||||
text.push_str("fn ");
|
text.push_str("fn ");
|
||||||
|
|
||||||
let mut sig =
|
let mut sig =
|
||||||
name_and_generics(text, offset, generics, self.hir_id(), self.ident, scx)?;
|
name_and_generics(text, offset, generics, self.owner_id, self.ident, scx)?;
|
||||||
|
|
||||||
sig.text.push('(');
|
sig.text.push('(');
|
||||||
for i in decl.inputs {
|
for i in decl.inputs {
|
||||||
@ -797,25 +807,25 @@ fn name_and_generics(
|
|||||||
mut text: String,
|
mut text: String,
|
||||||
offset: usize,
|
offset: usize,
|
||||||
generics: &hir::Generics<'_>,
|
generics: &hir::Generics<'_>,
|
||||||
id: hir::HirId,
|
id: hir::OwnerId,
|
||||||
name: Ident,
|
name: Ident,
|
||||||
scx: &SaveContext<'_>,
|
scx: &SaveContext<'_>,
|
||||||
) -> Result {
|
) -> Result {
|
||||||
let name = name.to_string();
|
let name = name.to_string();
|
||||||
let def = SigElement {
|
let def = SigElement {
|
||||||
id: id_from_hir_id(id, scx),
|
id: id_from_def_id(id.to_def_id()),
|
||||||
start: offset + text.len(),
|
start: offset + text.len(),
|
||||||
end: offset + text.len() + name.len(),
|
end: offset + text.len() + name.len(),
|
||||||
};
|
};
|
||||||
text.push_str(&name);
|
text.push_str(&name);
|
||||||
let generics: Signature = generics.make(offset + text.len(), Some(id), scx)?;
|
let generics: Signature = generics.make(offset + text.len(), Some(id.def_id), scx)?;
|
||||||
// FIXME where clause
|
// FIXME where clause
|
||||||
let text = format!("{}{}", text, generics.text);
|
let text = format!("{}{}", text, generics.text);
|
||||||
Ok(extend_sig(generics, text, vec![def], vec![]))
|
Ok(extend_sig(generics, text, vec![def], vec![]))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn make_assoc_type_signature(
|
fn make_assoc_type_signature(
|
||||||
id: hir::HirId,
|
id: hir::OwnerId,
|
||||||
ident: Ident,
|
ident: Ident,
|
||||||
bounds: Option<hir::GenericBounds<'_>>,
|
bounds: Option<hir::GenericBounds<'_>>,
|
||||||
default: Option<&hir::Ty<'_>>,
|
default: Option<&hir::Ty<'_>>,
|
||||||
@ -824,7 +834,7 @@ fn make_assoc_type_signature(
|
|||||||
let mut text = "type ".to_owned();
|
let mut text = "type ".to_owned();
|
||||||
let name = ident.to_string();
|
let name = ident.to_string();
|
||||||
let mut defs = vec![SigElement {
|
let mut defs = vec![SigElement {
|
||||||
id: id_from_hir_id(id, scx),
|
id: id_from_def_id(id.to_def_id()),
|
||||||
start: text.len(),
|
start: text.len(),
|
||||||
end: text.len() + name.len(),
|
end: text.len() + name.len(),
|
||||||
}];
|
}];
|
||||||
@ -837,7 +847,7 @@ fn make_assoc_type_signature(
|
|||||||
}
|
}
|
||||||
if let Some(default) = default {
|
if let Some(default) = default {
|
||||||
text.push_str(" = ");
|
text.push_str(" = ");
|
||||||
let ty_sig = default.make(text.len(), Some(id), scx)?;
|
let ty_sig = default.make(text.len(), Some(id.into()), scx)?;
|
||||||
text.push_str(&ty_sig.text);
|
text.push_str(&ty_sig.text);
|
||||||
defs.extend(ty_sig.defs.into_iter());
|
defs.extend(ty_sig.defs.into_iter());
|
||||||
refs.extend(ty_sig.refs.into_iter());
|
refs.extend(ty_sig.refs.into_iter());
|
||||||
@ -847,7 +857,7 @@ fn make_assoc_type_signature(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn make_assoc_const_signature(
|
fn make_assoc_const_signature(
|
||||||
id: hir::HirId,
|
id: hir::OwnerId,
|
||||||
ident: Symbol,
|
ident: Symbol,
|
||||||
ty: &hir::Ty<'_>,
|
ty: &hir::Ty<'_>,
|
||||||
default: Option<&hir::Expr<'_>>,
|
default: Option<&hir::Expr<'_>>,
|
||||||
@ -856,7 +866,7 @@ fn make_assoc_const_signature(
|
|||||||
let mut text = "const ".to_owned();
|
let mut text = "const ".to_owned();
|
||||||
let name = ident.to_string();
|
let name = ident.to_string();
|
||||||
let mut defs = vec![SigElement {
|
let mut defs = vec![SigElement {
|
||||||
id: id_from_hir_id(id, scx),
|
id: id_from_def_id(id.to_def_id()),
|
||||||
start: text.len(),
|
start: text.len(),
|
||||||
end: text.len() + name.len(),
|
end: text.len() + name.len(),
|
||||||
}];
|
}];
|
||||||
@ -864,7 +874,7 @@ fn make_assoc_const_signature(
|
|||||||
text.push_str(&name);
|
text.push_str(&name);
|
||||||
text.push_str(": ");
|
text.push_str(": ");
|
||||||
|
|
||||||
let ty_sig = ty.make(text.len(), Some(id), scx)?;
|
let ty_sig = ty.make(text.len(), Some(id.into()), scx)?;
|
||||||
text.push_str(&ty_sig.text);
|
text.push_str(&ty_sig.text);
|
||||||
defs.extend(ty_sig.defs.into_iter());
|
defs.extend(ty_sig.defs.into_iter());
|
||||||
refs.extend(ty_sig.refs.into_iter());
|
refs.extend(ty_sig.refs.into_iter());
|
||||||
@ -878,7 +888,7 @@ fn make_assoc_const_signature(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn make_method_signature(
|
fn make_method_signature(
|
||||||
id: hir::HirId,
|
id: hir::OwnerId,
|
||||||
ident: Ident,
|
ident: Ident,
|
||||||
generics: &hir::Generics<'_>,
|
generics: &hir::Generics<'_>,
|
||||||
m: &hir::FnSig<'_>,
|
m: &hir::FnSig<'_>,
|
||||||
|
@ -399,7 +399,7 @@ fn predicate_constraint(generics: &hir::Generics<'_>, pred: ty::Predicate<'_>) -
|
|||||||
/// param for cleaner code.
|
/// param for cleaner code.
|
||||||
fn suggest_restriction<'tcx>(
|
fn suggest_restriction<'tcx>(
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
hir_id: HirId,
|
item_id: LocalDefId,
|
||||||
hir_generics: &hir::Generics<'tcx>,
|
hir_generics: &hir::Generics<'tcx>,
|
||||||
msg: &str,
|
msg: &str,
|
||||||
err: &mut Diagnostic,
|
err: &mut Diagnostic,
|
||||||
@ -418,7 +418,6 @@ fn suggest_restriction<'tcx>(
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let Some(item_id) = hir_id.as_owner() else { return; };
|
|
||||||
let generics = tcx.generics_of(item_id);
|
let generics = tcx.generics_of(item_id);
|
||||||
// Given `fn foo(t: impl Trait)` where `Trait` requires assoc type `A`...
|
// Given `fn foo(t: impl Trait)` where `Trait` requires assoc type `A`...
|
||||||
if let Some((param, bound_str, fn_sig)) =
|
if let Some((param, bound_str, fn_sig)) =
|
||||||
@ -523,7 +522,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||||||
mut err: &mut Diagnostic,
|
mut err: &mut Diagnostic,
|
||||||
trait_pred: ty::PolyTraitPredicate<'tcx>,
|
trait_pred: ty::PolyTraitPredicate<'tcx>,
|
||||||
associated_ty: Option<(&'static str, Ty<'tcx>)>,
|
associated_ty: Option<(&'static str, Ty<'tcx>)>,
|
||||||
body_id: LocalDefId,
|
mut body_id: LocalDefId,
|
||||||
) {
|
) {
|
||||||
let trait_pred = self.resolve_numeric_literals_with_default(trait_pred);
|
let trait_pred = self.resolve_numeric_literals_with_default(trait_pred);
|
||||||
|
|
||||||
@ -536,9 +535,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||||||
|
|
||||||
// FIXME: Add check for trait bound that is already present, particularly `?Sized` so we
|
// FIXME: Add check for trait bound that is already present, particularly `?Sized` so we
|
||||||
// don't suggest `T: Sized + ?Sized`.
|
// don't suggest `T: Sized + ?Sized`.
|
||||||
let mut body_id = body_id;
|
|
||||||
while let Some(node) = self.tcx.hir().find_by_def_id(body_id) {
|
while let Some(node) = self.tcx.hir().find_by_def_id(body_id) {
|
||||||
let hir_id = self.tcx.hir().local_def_id_to_hir_id(body_id);
|
|
||||||
match node {
|
match node {
|
||||||
hir::Node::Item(hir::Item {
|
hir::Node::Item(hir::Item {
|
||||||
ident,
|
ident,
|
||||||
@ -549,7 +546,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||||||
// Restricting `Self` for a single method.
|
// Restricting `Self` for a single method.
|
||||||
suggest_restriction(
|
suggest_restriction(
|
||||||
self.tcx,
|
self.tcx,
|
||||||
hir_id,
|
body_id,
|
||||||
&generics,
|
&generics,
|
||||||
"`Self`",
|
"`Self`",
|
||||||
err,
|
err,
|
||||||
@ -569,7 +566,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||||||
assert!(param_ty);
|
assert!(param_ty);
|
||||||
// Restricting `Self` for a single method.
|
// Restricting `Self` for a single method.
|
||||||
suggest_restriction(
|
suggest_restriction(
|
||||||
self.tcx, hir_id, &generics, "`Self`", err, None, projection, trait_pred,
|
self.tcx, body_id, &generics, "`Self`", err, None, projection, trait_pred,
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
@ -591,7 +588,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||||||
// Missing restriction on associated type of type parameter (unmet projection).
|
// Missing restriction on associated type of type parameter (unmet projection).
|
||||||
suggest_restriction(
|
suggest_restriction(
|
||||||
self.tcx,
|
self.tcx,
|
||||||
hir_id,
|
body_id,
|
||||||
&generics,
|
&generics,
|
||||||
"the associated type",
|
"the associated type",
|
||||||
err,
|
err,
|
||||||
@ -611,7 +608,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||||||
// Missing restriction on associated type of type parameter (unmet projection).
|
// Missing restriction on associated type of type parameter (unmet projection).
|
||||||
suggest_restriction(
|
suggest_restriction(
|
||||||
self.tcx,
|
self.tcx,
|
||||||
hir_id,
|
body_id,
|
||||||
&generics,
|
&generics,
|
||||||
"the associated type",
|
"the associated type",
|
||||||
err,
|
err,
|
||||||
|
@ -383,13 +383,10 @@ fn clean_middle_term<'tcx>(
|
|||||||
fn clean_hir_term<'tcx>(term: &hir::Term<'tcx>, cx: &mut DocContext<'tcx>) -> Term {
|
fn clean_hir_term<'tcx>(term: &hir::Term<'tcx>, cx: &mut DocContext<'tcx>) -> Term {
|
||||||
match term {
|
match term {
|
||||||
hir::Term::Ty(ty) => Term::Type(clean_ty(ty, cx)),
|
hir::Term::Ty(ty) => Term::Type(clean_ty(ty, cx)),
|
||||||
hir::Term::Const(c) => {
|
hir::Term::Const(c) => Term::Constant(clean_middle_const(
|
||||||
let def_id = cx.tcx.hir().local_def_id(c.hir_id);
|
ty::Binder::dummy(ty::Const::from_anon_const(cx.tcx, c.def_id)),
|
||||||
Term::Constant(clean_middle_const(
|
cx,
|
||||||
ty::Binder::dummy(ty::Const::from_anon_const(cx.tcx, def_id)),
|
)),
|
||||||
cx,
|
|
||||||
))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -524,12 +521,11 @@ fn clean_generic_param<'tcx>(
|
|||||||
generics: Option<&hir::Generics<'tcx>>,
|
generics: Option<&hir::Generics<'tcx>>,
|
||||||
param: &hir::GenericParam<'tcx>,
|
param: &hir::GenericParam<'tcx>,
|
||||||
) -> GenericParamDef {
|
) -> GenericParamDef {
|
||||||
let did = cx.tcx.hir().local_def_id(param.hir_id);
|
|
||||||
let (name, kind) = match param.kind {
|
let (name, kind) = match param.kind {
|
||||||
hir::GenericParamKind::Lifetime { .. } => {
|
hir::GenericParamKind::Lifetime { .. } => {
|
||||||
let outlives = if let Some(generics) = generics {
|
let outlives = if let Some(generics) = generics {
|
||||||
generics
|
generics
|
||||||
.outlives_for_param(did)
|
.outlives_for_param(param.def_id)
|
||||||
.filter(|bp| !bp.in_where_clause)
|
.filter(|bp| !bp.in_where_clause)
|
||||||
.flat_map(|bp| bp.bounds)
|
.flat_map(|bp| bp.bounds)
|
||||||
.map(|bound| match bound {
|
.map(|bound| match bound {
|
||||||
@ -545,7 +541,7 @@ fn clean_generic_param<'tcx>(
|
|||||||
hir::GenericParamKind::Type { ref default, synthetic } => {
|
hir::GenericParamKind::Type { ref default, synthetic } => {
|
||||||
let bounds = if let Some(generics) = generics {
|
let bounds = if let Some(generics) = generics {
|
||||||
generics
|
generics
|
||||||
.bounds_for_param(did)
|
.bounds_for_param(param.def_id)
|
||||||
.filter(|bp| bp.origin != PredicateOrigin::WhereClause)
|
.filter(|bp| bp.origin != PredicateOrigin::WhereClause)
|
||||||
.flat_map(|bp| bp.bounds)
|
.flat_map(|bp| bp.bounds)
|
||||||
.filter_map(|x| clean_generic_bound(x, cx))
|
.filter_map(|x| clean_generic_bound(x, cx))
|
||||||
@ -556,7 +552,7 @@ fn clean_generic_param<'tcx>(
|
|||||||
(
|
(
|
||||||
param.name.ident().name,
|
param.name.ident().name,
|
||||||
GenericParamDefKind::Type {
|
GenericParamDefKind::Type {
|
||||||
did: did.to_def_id(),
|
did: param.def_id.to_def_id(),
|
||||||
bounds,
|
bounds,
|
||||||
default: default.map(|t| clean_ty(t, cx)).map(Box::new),
|
default: default.map(|t| clean_ty(t, cx)).map(Box::new),
|
||||||
synthetic,
|
synthetic,
|
||||||
@ -566,12 +562,10 @@ fn clean_generic_param<'tcx>(
|
|||||||
hir::GenericParamKind::Const { ty, default } => (
|
hir::GenericParamKind::Const { ty, default } => (
|
||||||
param.name.ident().name,
|
param.name.ident().name,
|
||||||
GenericParamDefKind::Const {
|
GenericParamDefKind::Const {
|
||||||
did: did.to_def_id(),
|
did: param.def_id.to_def_id(),
|
||||||
ty: Box::new(clean_ty(ty, cx)),
|
ty: Box::new(clean_ty(ty, cx)),
|
||||||
default: default.map(|ct| {
|
default: default
|
||||||
let def_id = cx.tcx.hir().local_def_id(ct.hir_id);
|
.map(|ct| Box::new(ty::Const::from_anon_const(cx.tcx, ct.def_id).to_string())),
|
||||||
Box::new(ty::Const::from_anon_const(cx.tcx, def_id).to_string())
|
|
||||||
}),
|
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
@ -1548,18 +1542,16 @@ fn maybe_expand_private_type_alias<'tcx>(
|
|||||||
_ => None,
|
_ => None,
|
||||||
});
|
});
|
||||||
if let Some(lt) = lifetime {
|
if let Some(lt) = lifetime {
|
||||||
let lt_def_id = cx.tcx.hir().local_def_id(param.hir_id);
|
|
||||||
let cleaned = if !lt.is_anonymous() {
|
let cleaned = if !lt.is_anonymous() {
|
||||||
clean_lifetime(lt, cx)
|
clean_lifetime(lt, cx)
|
||||||
} else {
|
} else {
|
||||||
Lifetime::elided()
|
Lifetime::elided()
|
||||||
};
|
};
|
||||||
substs.insert(lt_def_id.to_def_id(), SubstParam::Lifetime(cleaned));
|
substs.insert(param.def_id.to_def_id(), SubstParam::Lifetime(cleaned));
|
||||||
}
|
}
|
||||||
indices.lifetimes += 1;
|
indices.lifetimes += 1;
|
||||||
}
|
}
|
||||||
hir::GenericParamKind::Type { ref default, .. } => {
|
hir::GenericParamKind::Type { ref default, .. } => {
|
||||||
let ty_param_def_id = cx.tcx.hir().local_def_id(param.hir_id);
|
|
||||||
let mut j = 0;
|
let mut j = 0;
|
||||||
let type_ = generic_args.args.iter().find_map(|arg| match arg {
|
let type_ = generic_args.args.iter().find_map(|arg| match arg {
|
||||||
hir::GenericArg::Type(ty) => {
|
hir::GenericArg::Type(ty) => {
|
||||||
@ -1572,17 +1564,14 @@ fn maybe_expand_private_type_alias<'tcx>(
|
|||||||
_ => None,
|
_ => None,
|
||||||
});
|
});
|
||||||
if let Some(ty) = type_ {
|
if let Some(ty) = type_ {
|
||||||
substs.insert(ty_param_def_id.to_def_id(), SubstParam::Type(clean_ty(ty, cx)));
|
substs.insert(param.def_id.to_def_id(), SubstParam::Type(clean_ty(ty, cx)));
|
||||||
} else if let Some(default) = *default {
|
} else if let Some(default) = *default {
|
||||||
substs.insert(
|
substs
|
||||||
ty_param_def_id.to_def_id(),
|
.insert(param.def_id.to_def_id(), SubstParam::Type(clean_ty(default, cx)));
|
||||||
SubstParam::Type(clean_ty(default, cx)),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
indices.types += 1;
|
indices.types += 1;
|
||||||
}
|
}
|
||||||
hir::GenericParamKind::Const { .. } => {
|
hir::GenericParamKind::Const { .. } => {
|
||||||
let const_param_def_id = cx.tcx.hir().local_def_id(param.hir_id);
|
|
||||||
let mut j = 0;
|
let mut j = 0;
|
||||||
let const_ = generic_args.args.iter().find_map(|arg| match arg {
|
let const_ = generic_args.args.iter().find_map(|arg| match arg {
|
||||||
hir::GenericArg::Const(ct) => {
|
hir::GenericArg::Const(ct) => {
|
||||||
@ -1596,7 +1585,7 @@ fn maybe_expand_private_type_alias<'tcx>(
|
|||||||
});
|
});
|
||||||
if let Some(ct) = const_ {
|
if let Some(ct) = const_ {
|
||||||
substs.insert(
|
substs.insert(
|
||||||
const_param_def_id.to_def_id(),
|
param.def_id.to_def_id(),
|
||||||
SubstParam::Constant(clean_const(ct, cx)),
|
SubstParam::Constant(clean_const(ct, cx)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -1624,7 +1613,6 @@ pub(crate) fn clean_ty<'tcx>(ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> T
|
|||||||
let length = match length {
|
let length = match length {
|
||||||
hir::ArrayLen::Infer(_, _) => "_".to_string(),
|
hir::ArrayLen::Infer(_, _) => "_".to_string(),
|
||||||
hir::ArrayLen::Body(anon_const) => {
|
hir::ArrayLen::Body(anon_const) => {
|
||||||
let def_id = cx.tcx.hir().local_def_id(anon_const.hir_id);
|
|
||||||
// NOTE(min_const_generics): We can't use `const_eval_poly` for constants
|
// NOTE(min_const_generics): We can't use `const_eval_poly` for constants
|
||||||
// as we currently do not supply the parent generics to anonymous constants
|
// as we currently do not supply the parent generics to anonymous constants
|
||||||
// but do allow `ConstKind::Param`.
|
// but do allow `ConstKind::Param`.
|
||||||
@ -1632,8 +1620,8 @@ pub(crate) fn clean_ty<'tcx>(ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> T
|
|||||||
// `const_eval_poly` tries to first substitute generic parameters which
|
// `const_eval_poly` tries to first substitute generic parameters which
|
||||||
// results in an ICE while manually constructing the constant and using `eval`
|
// results in an ICE while manually constructing the constant and using `eval`
|
||||||
// does nothing for `ConstKind::Param`.
|
// does nothing for `ConstKind::Param`.
|
||||||
let ct = ty::Const::from_anon_const(cx.tcx, def_id);
|
let ct = ty::Const::from_anon_const(cx.tcx, anon_const.def_id);
|
||||||
let param_env = cx.tcx.param_env(def_id);
|
let param_env = cx.tcx.param_env(anon_const.def_id);
|
||||||
print_const(cx, ct.eval(cx.tcx, param_env))
|
print_const(cx, ct.eval(cx.tcx, param_env))
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -1930,8 +1918,7 @@ fn clean_middle_opaque_bounds<'tcx>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn clean_field<'tcx>(field: &hir::FieldDef<'tcx>, cx: &mut DocContext<'tcx>) -> Item {
|
pub(crate) fn clean_field<'tcx>(field: &hir::FieldDef<'tcx>, cx: &mut DocContext<'tcx>) -> Item {
|
||||||
let def_id = cx.tcx.hir().local_def_id(field.hir_id).to_def_id();
|
clean_field_with_def_id(field.def_id.to_def_id(), field.ident.name, clean_ty(field.ty, cx), cx)
|
||||||
clean_field_with_def_id(def_id, field.ident.name, clean_ty(field.ty, cx), cx)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn clean_middle_field<'tcx>(field: &ty::FieldDef, cx: &mut DocContext<'tcx>) -> Item {
|
pub(crate) fn clean_middle_field<'tcx>(field: &ty::FieldDef, cx: &mut DocContext<'tcx>) -> Item {
|
||||||
@ -1981,10 +1968,8 @@ fn clean_variant_data<'tcx>(
|
|||||||
disr_expr: &Option<hir::AnonConst>,
|
disr_expr: &Option<hir::AnonConst>,
|
||||||
cx: &mut DocContext<'tcx>,
|
cx: &mut DocContext<'tcx>,
|
||||||
) -> Variant {
|
) -> Variant {
|
||||||
let discriminant = disr_expr.map(|disr| Discriminant {
|
let discriminant = disr_expr
|
||||||
expr: Some(disr.body),
|
.map(|disr| Discriminant { expr: Some(disr.body), value: disr.def_id.to_def_id() });
|
||||||
value: cx.tcx.hir().local_def_id(disr.hir_id).to_def_id(),
|
|
||||||
});
|
|
||||||
|
|
||||||
let kind = match variant {
|
let kind = match variant {
|
||||||
hir::VariantData::Struct(..) => VariantKind::Struct(VariantStruct {
|
hir::VariantData::Struct(..) => VariantKind::Struct(VariantStruct {
|
||||||
|
@ -778,20 +778,20 @@ fn walk_parents<'tcx>(
|
|||||||
|
|
||||||
Node::Expr(parent) if parent.span.ctxt() == ctxt => match parent.kind {
|
Node::Expr(parent) if parent.span.ctxt() == ctxt => match parent.kind {
|
||||||
ExprKind::Ret(_) => {
|
ExprKind::Ret(_) => {
|
||||||
let owner_id = cx.tcx.hir().body_owner(cx.enclosing_body.unwrap());
|
let owner_id = cx.tcx.hir().body_owner_def_id(cx.enclosing_body.unwrap());
|
||||||
Some(
|
Some(
|
||||||
if let Node::Expr(
|
if let Node::Expr(
|
||||||
closure_expr @ Expr {
|
closure_expr @ Expr {
|
||||||
kind: ExprKind::Closure(closure),
|
kind: ExprKind::Closure(closure),
|
||||||
..
|
..
|
||||||
},
|
},
|
||||||
) = cx.tcx.hir().get(owner_id)
|
) = cx.tcx.hir().get_by_def_id(owner_id)
|
||||||
{
|
{
|
||||||
closure_result_position(cx, closure, cx.typeck_results().expr_ty(closure_expr), precedence)
|
closure_result_position(cx, closure, cx.typeck_results().expr_ty(closure_expr), precedence)
|
||||||
} else {
|
} else {
|
||||||
let output = cx
|
let output = cx
|
||||||
.tcx
|
.tcx
|
||||||
.erase_late_bound_regions(cx.tcx.fn_sig(cx.tcx.hir().local_def_id(owner_id)).subst_identity().output());
|
.erase_late_bound_regions(cx.tcx.fn_sig(owner_id).subst_identity().output());
|
||||||
ty_auto_deref_stability(cx, output, precedence).position_for_result(cx)
|
ty_auto_deref_stability(cx, output, precedence).position_for_result(cx)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -157,7 +157,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualNonExhaustiveEnum {
|
|||||||
&& def.variants.len() > 1
|
&& def.variants.len() > 1
|
||||||
{
|
{
|
||||||
let mut iter = def.variants.iter().filter_map(|v| {
|
let mut iter = def.variants.iter().filter_map(|v| {
|
||||||
(matches!(v.data, hir::VariantData::Unit(..))
|
(matches!(v.data, hir::VariantData::Unit(_, _))
|
||||||
&& v.ident.as_str().starts_with('_')
|
&& v.ident.as_str().starts_with('_')
|
||||||
&& is_doc_hidden(cx.tcx.hir().attrs(v.hir_id)))
|
&& is_doc_hidden(cx.tcx.hir().attrs(v.hir_id)))
|
||||||
.then_some((v.def_id, v.span))
|
.then_some((v.def_id, v.span))
|
||||||
|
@ -11,8 +11,7 @@ use super::SUSPICIOUS_MAP;
|
|||||||
pub fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, count_recv: &hir::Expr<'_>, map_arg: &hir::Expr<'_>) {
|
pub fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, count_recv: &hir::Expr<'_>, map_arg: &hir::Expr<'_>) {
|
||||||
if_chain! {
|
if_chain! {
|
||||||
if is_trait_method(cx, count_recv, sym::Iterator);
|
if is_trait_method(cx, count_recv, sym::Iterator);
|
||||||
let closure = expr_or_init(cx, map_arg);
|
if let hir::ExprKind::Closure(closure) = expr_or_init(cx, map_arg).kind;
|
||||||
if let hir::ExprKind::Closure(closure) = closure.kind;
|
|
||||||
let closure_body = cx.tcx.hir().body(closure.body);
|
let closure_body = cx.tcx.hir().body(closure.body);
|
||||||
if !cx.typeck_results().expr_ty(closure_body.value).is_unit();
|
if !cx.typeck_results().expr_ty(closure_body.value).is_unit();
|
||||||
then {
|
then {
|
||||||
|
@ -1119,9 +1119,8 @@ pub fn can_move_expr_to_closure<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'
|
|||||||
self.captures.entry(l).and_modify(|e| *e |= cap).or_insert(cap);
|
self.captures.entry(l).and_modify(|e| *e |= cap).or_insert(cap);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
ExprKind::Closure { .. } => {
|
ExprKind::Closure(closure) => {
|
||||||
let closure_id = self.cx.tcx.hir().local_def_id(e.hir_id);
|
for capture in self.cx.typeck_results().closure_min_captures_flattened(closure.def_id) {
|
||||||
for capture in self.cx.typeck_results().closure_min_captures_flattened(closure_id) {
|
|
||||||
let local_id = match capture.place.base {
|
let local_id = match capture.place.base {
|
||||||
PlaceBase::Local(id) => id,
|
PlaceBase::Local(id) => id,
|
||||||
PlaceBase::Upvar(var) => var.var_path.hir_id,
|
PlaceBase::Upvar(var) => var.var_path.hir_id,
|
||||||
@ -1584,8 +1583,7 @@ pub fn return_ty<'tcx>(cx: &LateContext<'tcx>, fn_def_id: hir::OwnerId) -> Ty<'t
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Convenience function to get the nth argument type of a function.
|
/// Convenience function to get the nth argument type of a function.
|
||||||
pub fn nth_arg<'tcx>(cx: &LateContext<'tcx>, fn_item: hir::HirId, nth: usize) -> Ty<'tcx> {
|
pub fn nth_arg<'tcx>(cx: &LateContext<'tcx>, fn_def_id: hir::OwnerId, nth: usize) -> Ty<'tcx> {
|
||||||
let fn_def_id = cx.tcx.hir().local_def_id(fn_item);
|
|
||||||
let arg = cx.tcx.fn_sig(fn_def_id).subst_identity().input(nth);
|
let arg = cx.tcx.fn_sig(fn_def_id).subst_identity().input(nth);
|
||||||
cx.tcx.erase_late_bound_regions(arg)
|
cx.tcx.erase_late_bound_regions(arg)
|
||||||
}
|
}
|
||||||
|
@ -809,7 +809,7 @@ pub struct DerefClosure {
|
|||||||
///
|
///
|
||||||
/// note: this only works on single line immutable closures with exactly one input parameter.
|
/// note: this only works on single line immutable closures with exactly one input parameter.
|
||||||
pub fn deref_closure_args(cx: &LateContext<'_>, closure: &hir::Expr<'_>) -> Option<DerefClosure> {
|
pub fn deref_closure_args(cx: &LateContext<'_>, closure: &hir::Expr<'_>) -> Option<DerefClosure> {
|
||||||
if let hir::ExprKind::Closure(&Closure { fn_decl, body, .. }) = closure.kind {
|
if let hir::ExprKind::Closure(&Closure { fn_decl, def_id, body, .. }) = closure.kind {
|
||||||
let closure_body = cx.tcx.hir().body(body);
|
let closure_body = cx.tcx.hir().body(body);
|
||||||
// is closure arg a type annotated double reference (i.e.: `|x: &&i32| ...`)
|
// is closure arg a type annotated double reference (i.e.: `|x: &&i32| ...`)
|
||||||
// a type annotation is present if param `kind` is different from `TyKind::Infer`
|
// a type annotation is present if param `kind` is different from `TyKind::Infer`
|
||||||
@ -829,10 +829,8 @@ pub fn deref_closure_args(cx: &LateContext<'_>, closure: &hir::Expr<'_>) -> Opti
|
|||||||
applicability: Applicability::MachineApplicable,
|
applicability: Applicability::MachineApplicable,
|
||||||
};
|
};
|
||||||
|
|
||||||
let fn_def_id = cx.tcx.hir().local_def_id(closure.hir_id);
|
|
||||||
let infcx = cx.tcx.infer_ctxt().build();
|
let infcx = cx.tcx.infer_ctxt().build();
|
||||||
ExprUseVisitor::new(&mut visitor, &infcx, fn_def_id, cx.param_env, cx.typeck_results())
|
ExprUseVisitor::new(&mut visitor, &infcx, def_id, cx.param_env, cx.typeck_results()).consume_body(closure_body);
|
||||||
.consume_body(closure_body);
|
|
||||||
|
|
||||||
if !visitor.suggestion_start.is_empty() {
|
if !visitor.suggestion_start.is_empty() {
|
||||||
return Some(DerefClosure {
|
return Some(DerefClosure {
|
||||||
|
Loading…
Reference in New Issue
Block a user