Avoid lots of hir::HirId{,Map,Set} qualifiers.

Because they're a bit redundant.
This commit is contained in:
Nicholas Nethercote 2024-03-06 17:24:13 +11:00
parent e93f754289
commit 4b27cc8b7a
36 changed files with 276 additions and 312 deletions

View File

@ -14,6 +14,7 @@ use rustc_ast::*;
use rustc_data_structures::stack::ensure_sufficient_stack; use rustc_data_structures::stack::ensure_sufficient_stack;
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::HirId;
use rustc_middle::span_bug; use rustc_middle::span_bug;
use rustc_session::errors::report_lit_error; use rustc_session::errors::report_lit_error;
use rustc_span::source_map::{respan, Spanned}; use rustc_span::source_map::{respan, Spanned};
@ -701,8 +702,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
pub(super) fn maybe_forward_track_caller( pub(super) fn maybe_forward_track_caller(
&mut self, &mut self,
span: Span, span: Span,
outer_hir_id: hir::HirId, outer_hir_id: HirId,
inner_hir_id: hir::HirId, inner_hir_id: HirId,
) { ) {
if self.tcx.features().async_fn_track_caller if self.tcx.features().async_fn_track_caller
&& let Some(attrs) = self.attrs.get(&outer_hir_id.local_id) && let Some(attrs) = self.attrs.get(&outer_hir_id.local_id)
@ -1048,7 +1049,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
binder: &ClosureBinder, binder: &ClosureBinder,
capture_clause: CaptureBy, capture_clause: CaptureBy,
closure_id: NodeId, closure_id: NodeId,
closure_hir_id: hir::HirId, closure_hir_id: HirId,
coroutine_kind: CoroutineKind, coroutine_kind: CoroutineKind,
decl: &FnDecl, decl: &FnDecl,
body: &Expr, body: &Expr,
@ -2036,7 +2037,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
&mut self, &mut self,
sp: Span, sp: Span,
ident: Ident, ident: Ident,
binding: hir::HirId, binding: HirId,
) -> &'hir hir::Expr<'hir> { ) -> &'hir hir::Expr<'hir> {
self.arena.alloc(self.expr_ident_mut(sp, ident, binding)) self.arena.alloc(self.expr_ident_mut(sp, ident, binding))
} }
@ -2045,7 +2046,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
&mut self, &mut self,
span: Span, span: Span,
ident: Ident, ident: Ident,
binding: hir::HirId, binding: HirId,
) -> hir::Expr<'hir> { ) -> hir::Expr<'hir> {
let hir_id = self.next_id(); let hir_id = self.next_id();
let res = Res::Local(binding); let res = Res::Local(binding);

View File

@ -56,7 +56,7 @@ use rustc_hir as hir;
use rustc_hir::def::{DefKind, LifetimeRes, Namespace, PartialRes, PerNS, Res}; use rustc_hir::def::{DefKind, LifetimeRes, Namespace, PartialRes, PerNS, Res};
use rustc_hir::def_id::{LocalDefId, LocalDefIdMap, CRATE_DEF_ID, LOCAL_CRATE}; use rustc_hir::def_id::{LocalDefId, LocalDefIdMap, CRATE_DEF_ID, LOCAL_CRATE};
use rustc_hir::{ use rustc_hir::{
ConstArg, GenericArg, ItemLocalMap, MissingLifetimeKind, ParamName, TraitCandidate, ConstArg, GenericArg, HirId, ItemLocalMap, MissingLifetimeKind, ParamName, TraitCandidate,
}; };
use rustc_index::{Idx, IndexSlice, IndexVec}; use rustc_index::{Idx, IndexSlice, IndexVec};
use rustc_macros::extension; use rustc_macros::extension;
@ -107,7 +107,7 @@ struct LoweringContext<'a, 'hir> {
/// When inside an `async` context, this is the `HirId` of the /// When inside an `async` context, this is the `HirId` of the
/// `task_context` local bound to the resume argument of the coroutine. /// `task_context` local bound to the resume argument of the coroutine.
task_context: Option<hir::HirId>, task_context: Option<HirId>,
/// Used to get the current `fn`'s def span to point to when using `await` /// Used to get the current `fn`'s def span to point to when using `await`
/// outside of an `async fn`. /// outside of an `async fn`.
@ -661,18 +661,16 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
/// `HirIdValidator` later on, which makes sure that all `NodeId`s got mapped /// `HirIdValidator` later on, which makes sure that all `NodeId`s got mapped
/// properly. Calling the method twice with the same `NodeId` is fine though. /// properly. Calling the method twice with the same `NodeId` is fine though.
#[instrument(level = "debug", skip(self), ret)] #[instrument(level = "debug", skip(self), ret)]
fn lower_node_id(&mut self, ast_node_id: NodeId) -> hir::HirId { fn lower_node_id(&mut self, ast_node_id: NodeId) -> HirId {
assert_ne!(ast_node_id, DUMMY_NODE_ID); assert_ne!(ast_node_id, DUMMY_NODE_ID);
match self.node_id_to_local_id.entry(ast_node_id) { match self.node_id_to_local_id.entry(ast_node_id) {
Entry::Occupied(o) => { Entry::Occupied(o) => HirId { owner: self.current_hir_id_owner, local_id: *o.get() },
hir::HirId { owner: self.current_hir_id_owner, local_id: *o.get() }
}
Entry::Vacant(v) => { Entry::Vacant(v) => {
// Generate a new `HirId`. // Generate a new `HirId`.
let owner = self.current_hir_id_owner; let owner = self.current_hir_id_owner;
let local_id = self.item_local_id_counter; let local_id = self.item_local_id_counter;
let hir_id = hir::HirId { owner, local_id }; let hir_id = HirId { owner, local_id };
v.insert(local_id); v.insert(local_id);
self.item_local_id_counter.increment_by(1); self.item_local_id_counter.increment_by(1);
@ -693,12 +691,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
/// Generate a new `HirId` without a backing `NodeId`. /// Generate a new `HirId` without a backing `NodeId`.
#[instrument(level = "debug", skip(self), ret)] #[instrument(level = "debug", skip(self), ret)]
fn next_id(&mut self) -> hir::HirId { fn next_id(&mut self) -> HirId {
let owner = self.current_hir_id_owner; let owner = self.current_hir_id_owner;
let local_id = self.item_local_id_counter; let local_id = self.item_local_id_counter;
assert_ne!(local_id, hir::ItemLocalId::ZERO); assert_ne!(local_id, hir::ItemLocalId::ZERO);
self.item_local_id_counter.increment_by(1); self.item_local_id_counter.increment_by(1);
hir::HirId { owner, local_id } HirId { owner, local_id }
} }
#[instrument(level = "trace", skip(self))] #[instrument(level = "trace", skip(self))]
@ -706,7 +704,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
let res: Result<Res, ()> = res.apply_id(|id| { let res: Result<Res, ()> = res.apply_id(|id| {
let owner = self.current_hir_id_owner; let owner = self.current_hir_id_owner;
let local_id = self.node_id_to_local_id.get(&id).copied().ok_or(())?; let local_id = self.node_id_to_local_id.get(&id).copied().ok_or(())?;
Ok(hir::HirId { owner, local_id }) Ok(HirId { owner, local_id })
}); });
trace!(?res); trace!(?res);
@ -889,7 +887,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
ret ret
} }
fn lower_attrs(&mut self, id: hir::HirId, attrs: &[Attribute]) -> Option<&'hir [Attribute]> { fn lower_attrs(&mut self, id: HirId, attrs: &[Attribute]) -> Option<&'hir [Attribute]> {
if attrs.is_empty() { if attrs.is_empty() {
None None
} else { } else {
@ -921,7 +919,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
Attribute { kind, id: attr.id, style: attr.style, span: self.lower_span(attr.span) } Attribute { kind, id: attr.id, style: attr.style, span: self.lower_span(attr.span) }
} }
fn alias_attrs(&mut self, id: hir::HirId, target_id: hir::HirId) { fn alias_attrs(&mut self, id: HirId, target_id: HirId) {
debug_assert_eq!(id.owner, self.current_hir_id_owner); debug_assert_eq!(id.owner, self.current_hir_id_owner);
debug_assert_eq!(target_id.owner, self.current_hir_id_owner); debug_assert_eq!(target_id.owner, self.current_hir_id_owner);
if let Some(&a) = self.attrs.get(&target_id.local_id) { if let Some(&a) = self.attrs.get(&target_id.local_id) {
@ -2421,11 +2419,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
self.pat(span, hir::PatKind::Struct(qpath, fields, false)) self.pat(span, hir::PatKind::Struct(qpath, fields, false))
} }
fn pat_ident(&mut self, span: Span, ident: Ident) -> (&'hir hir::Pat<'hir>, hir::HirId) { fn pat_ident(&mut self, span: Span, ident: Ident) -> (&'hir hir::Pat<'hir>, HirId) {
self.pat_ident_binding_mode(span, ident, hir::BindingAnnotation::NONE) self.pat_ident_binding_mode(span, ident, hir::BindingAnnotation::NONE)
} }
fn pat_ident_mut(&mut self, span: Span, ident: Ident) -> (hir::Pat<'hir>, hir::HirId) { fn pat_ident_mut(&mut self, span: Span, ident: Ident) -> (hir::Pat<'hir>, HirId) {
self.pat_ident_binding_mode_mut(span, ident, hir::BindingAnnotation::NONE) self.pat_ident_binding_mode_mut(span, ident, hir::BindingAnnotation::NONE)
} }
@ -2434,7 +2432,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
span: Span, span: Span,
ident: Ident, ident: Ident,
bm: hir::BindingAnnotation, bm: hir::BindingAnnotation,
) -> (&'hir hir::Pat<'hir>, hir::HirId) { ) -> (&'hir hir::Pat<'hir>, HirId) {
let (pat, hir_id) = self.pat_ident_binding_mode_mut(span, ident, bm); let (pat, hir_id) = self.pat_ident_binding_mode_mut(span, ident, bm);
(self.arena.alloc(pat), hir_id) (self.arena.alloc(pat), hir_id)
} }
@ -2444,7 +2442,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
span: Span, span: Span,
ident: Ident, ident: Ident,
bm: hir::BindingAnnotation, bm: hir::BindingAnnotation,
) -> (hir::Pat<'hir>, hir::HirId) { ) -> (hir::Pat<'hir>, HirId) {
let hir_id = self.next_id(); let hir_id = self.next_id();
( (
@ -2476,12 +2474,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
} }
} }
fn ty_path( fn ty_path(&mut self, mut hir_id: HirId, span: Span, qpath: hir::QPath<'hir>) -> hir::Ty<'hir> {
&mut self,
mut hir_id: hir::HirId,
span: Span,
qpath: hir::QPath<'hir>,
) -> hir::Ty<'hir> {
let kind = match qpath { let kind = match qpath {
hir::QPath::Resolved(None, path) => { hir::QPath::Resolved(None, path) => {
// Turn trait object paths into `TyKind::TraitObject` instead. // Turn trait object paths into `TyKind::TraitObject` instead.

View File

@ -13,7 +13,7 @@ use rustc_hir as hir;
use rustc_hir::def::{DefKind, Res}; use rustc_hir::def::{DefKind, Res};
use rustc_hir::def_id::LocalDefId; use rustc_hir::def_id::LocalDefId;
use rustc_hir::intravisit::{self, Visitor}; use rustc_hir::intravisit::{self, Visitor};
use rustc_hir::{GenericArg, GenericParam, GenericParamKind, HirIdMap, LifetimeName, Node}; use rustc_hir::{GenericArg, GenericParam, GenericParamKind, HirId, HirIdMap, LifetimeName, Node};
use rustc_macros::extension; use rustc_macros::extension;
use rustc_middle::bug; use rustc_middle::bug;
use rustc_middle::hir::nested_filter; use rustc_middle::hir::nested_filter;
@ -107,7 +107,7 @@ enum Scope<'a> {
/// queried later. However, if we enter an elision scope, we have to /// queried later. However, if we enter an elision scope, we have to
/// later append the elided bound vars to the list and need to know what /// later append the elided bound vars to the list and need to know what
/// to append to. /// to append to.
hir_id: hir::HirId, hir_id: HirId,
s: ScopeRef<'a>, s: ScopeRef<'a>,
@ -781,7 +781,7 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
} }
} }
fn visit_path(&mut self, path: &hir::Path<'tcx>, hir_id: hir::HirId) { fn visit_path(&mut self, path: &hir::Path<'tcx>, hir_id: HirId) {
for (i, segment) in path.segments.iter().enumerate() { for (i, segment) in path.segments.iter().enumerate() {
let depth = path.segments.len() - i - 1; let depth = path.segments.len() - i - 1;
if let Some(args) = segment.args { if let Some(args) = segment.args {
@ -983,7 +983,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
} }
} }
fn record_late_bound_vars(&mut self, hir_id: hir::HirId, binder: Vec<ty::BoundVariableKind>) { fn record_late_bound_vars(&mut self, hir_id: HirId, binder: Vec<ty::BoundVariableKind>) {
if let Some(old) = self.map.late_bound_vars.insert(hir_id, binder) { if let Some(old) = self.map.late_bound_vars.insert(hir_id, binder) {
bug!( bug!(
"overwrote bound vars for {hir_id:?}:\nold={old:?}\nnew={:?}", "overwrote bound vars for {hir_id:?}:\nold={old:?}\nnew={:?}",
@ -1010,12 +1010,8 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
/// already in scope (for a fn item, that will be 0, but for a method it might not be). Late /// already in scope (for a fn item, that will be 0, but for a method it might not be). Late
/// bound lifetimes are resolved by name and associated with a binder ID (`binder_id`), so the /// bound lifetimes are resolved by name and associated with a binder ID (`binder_id`), so the
/// ordering is not important there. /// ordering is not important there.
fn visit_early_late<F>( fn visit_early_late<F>(&mut self, hir_id: HirId, generics: &'tcx hir::Generics<'tcx>, walk: F)
&mut self, where
hir_id: hir::HirId,
generics: &'tcx hir::Generics<'tcx>,
walk: F,
) where
F: for<'b, 'c> FnOnce(&'b mut BoundVarContext<'c, 'tcx>), F: for<'b, 'c> FnOnce(&'b mut BoundVarContext<'c, 'tcx>),
{ {
let mut named_late_bound_vars = 0; let mut named_late_bound_vars = 0;
@ -1062,7 +1058,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
self.with(scope, walk); self.with(scope, walk);
} }
fn visit_early<F>(&mut self, hir_id: hir::HirId, generics: &'tcx hir::Generics<'tcx>, walk: F) fn visit_early<F>(&mut self, hir_id: HirId, generics: &'tcx hir::Generics<'tcx>, walk: F)
where where
F: for<'b, 'c> FnOnce(&'b mut BoundVarContext<'c, 'tcx>), F: for<'b, 'c> FnOnce(&'b mut BoundVarContext<'c, 'tcx>),
{ {
@ -1288,7 +1284,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
); );
} }
fn resolve_type_ref(&mut self, param_def_id: LocalDefId, hir_id: hir::HirId) { fn resolve_type_ref(&mut self, param_def_id: LocalDefId, hir_id: HirId) {
// Walk up the scope chain, tracking the number of fn scopes // Walk up the scope chain, tracking the number of fn scopes
// that we pass through, until we find a lifetime with the // that we pass through, until we find a lifetime with the
// given name or we run out of scopes. // given name or we run out of scopes.

View File

@ -35,7 +35,7 @@ use rustc_hir as hir;
use rustc_hir::def::{CtorOf, DefKind, Namespace, Res}; use rustc_hir::def::{CtorOf, DefKind, Namespace, Res};
use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_hir::intravisit::{walk_generics, Visitor as _}; use rustc_hir::intravisit::{walk_generics, Visitor as _};
use rustc_hir::{GenericArg, GenericArgs}; use rustc_hir::{GenericArg, GenericArgs, HirId};
use rustc_infer::infer::{InferCtxt, TyCtxtInferExt}; use rustc_infer::infer::{InferCtxt, TyCtxtInferExt};
use rustc_infer::traits::ObligationCause; use rustc_infer::traits::ObligationCause;
use rustc_middle::middle::stability::AllowUnstable; use rustc_middle::middle::stability::AllowUnstable;
@ -158,7 +158,7 @@ pub trait HirTyLowerer<'tcx> {
fn probe_adt(&self, span: Span, ty: Ty<'tcx>) -> Option<ty::AdtDef<'tcx>>; fn probe_adt(&self, span: Span, ty: Ty<'tcx>) -> Option<ty::AdtDef<'tcx>>;
/// Record the lowered type of a HIR node in this context. /// Record the lowered type of a HIR node in this context.
fn record_ty(&self, hir_id: hir::HirId, ty: Ty<'tcx>, span: Span); fn record_ty(&self, hir_id: HirId, ty: Ty<'tcx>, span: Span);
/// The inference context of the lowering context if applicable. /// The inference context of the lowering context if applicable.
fn infcx(&self) -> Option<&InferCtxt<'tcx>>; fn infcx(&self) -> Option<&InferCtxt<'tcx>>;
@ -999,7 +999,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
#[instrument(level = "debug", skip_all, ret)] #[instrument(level = "debug", skip_all, ret)]
pub fn lower_assoc_path( pub fn lower_assoc_path(
&self, &self,
hir_ref_id: hir::HirId, hir_ref_id: HirId,
span: Span, span: Span,
qself_ty: Ty<'tcx>, qself_ty: Ty<'tcx>,
qself: &'tcx hir::Ty<'tcx>, qself: &'tcx hir::Ty<'tcx>,
@ -1200,7 +1200,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
segment: &hir::PathSegment<'tcx>, segment: &hir::PathSegment<'tcx>,
adt_did: DefId, adt_did: DefId,
self_ty: Ty<'tcx>, self_ty: Ty<'tcx>,
block: hir::HirId, block: HirId,
span: Span, span: Span,
) -> Result<Option<(Ty<'tcx>, DefId)>, ErrorGuaranteed> { ) -> Result<Option<(Ty<'tcx>, DefId)>, ErrorGuaranteed> {
let tcx = self.tcx(); let tcx = self.tcx();
@ -1349,13 +1349,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
} }
} }
fn probe_assoc_ty( fn probe_assoc_ty(&self, name: Ident, block: HirId, span: Span, scope: DefId) -> Option<DefId> {
&self,
name: Ident,
block: hir::HirId,
span: Span,
scope: DefId,
) -> Option<DefId> {
let (item, def_scope) = self.probe_assoc_ty_unchecked(name, block, scope)?; let (item, def_scope) = self.probe_assoc_ty_unchecked(name, block, scope)?;
self.check_assoc_ty(item, name, def_scope, block, span); self.check_assoc_ty(item, name, def_scope, block, span);
Some(item) Some(item)
@ -1364,7 +1358,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
fn probe_assoc_ty_unchecked( fn probe_assoc_ty_unchecked(
&self, &self,
name: Ident, name: Ident,
block: hir::HirId, block: HirId,
scope: DefId, scope: DefId,
) -> Option<(DefId, DefId)> { ) -> Option<(DefId, DefId)> {
let tcx = self.tcx(); let tcx = self.tcx();
@ -1381,14 +1375,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
Some((item.def_id, def_scope)) Some((item.def_id, def_scope))
} }
fn check_assoc_ty( fn check_assoc_ty(&self, item: DefId, name: Ident, def_scope: DefId, block: HirId, span: Span) {
&self,
item: DefId,
name: Ident,
def_scope: DefId,
block: hir::HirId,
span: Span,
) {
let tcx = self.tcx(); let tcx = self.tcx();
let kind = DefKind::AssocTy; let kind = DefKind::AssocTy;
@ -1714,7 +1701,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
&self, &self,
opt_self_ty: Option<Ty<'tcx>>, opt_self_ty: Option<Ty<'tcx>>,
path: &hir::Path<'tcx>, path: &hir::Path<'tcx>,
hir_id: hir::HirId, hir_id: HirId,
permit_variants: bool, permit_variants: bool,
) -> Ty<'tcx> { ) -> Ty<'tcx> {
debug!(?path.res, ?opt_self_ty, ?path.segments); debug!(?path.res, ?opt_self_ty, ?path.segments);
@ -1887,7 +1874,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
/// ///
/// Early-bound type parameters get lowered to [`ty::Param`] /// Early-bound type parameters get lowered to [`ty::Param`]
/// and late-bound ones to [`ty::Bound`]. /// and late-bound ones to [`ty::Bound`].
pub(crate) fn lower_ty_param(&self, hir_id: hir::HirId) -> Ty<'tcx> { pub(crate) fn lower_ty_param(&self, hir_id: HirId) -> Ty<'tcx> {
let tcx = self.tcx(); let tcx = self.tcx();
match tcx.named_bound_var(hir_id) { match tcx.named_bound_var(hir_id) {
Some(rbv::ResolvedArg::LateBound(debruijn, index, def_id)) => { Some(rbv::ResolvedArg::LateBound(debruijn, index, def_id)) => {
@ -1914,7 +1901,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
/// ///
/// Early-bound const parameters get lowered to [`ty::ConstKind::Param`] /// Early-bound const parameters get lowered to [`ty::ConstKind::Param`]
/// and late-bound ones to [`ty::ConstKind::Bound`]. /// and late-bound ones to [`ty::ConstKind::Bound`].
pub(crate) fn lower_const_param(&self, hir_id: hir::HirId, param_ty: Ty<'tcx>) -> Const<'tcx> { pub(crate) fn lower_const_param(&self, hir_id: HirId, param_ty: Ty<'tcx>) -> Const<'tcx> {
let tcx = self.tcx(); let tcx = self.tcx();
match tcx.named_bound_var(hir_id) { match tcx.named_bound_var(hir_id) {
Some(rbv::ResolvedArg::EarlyBound(def_id)) => { Some(rbv::ResolvedArg::EarlyBound(def_id)) => {
@ -2341,7 +2328,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
#[instrument(level = "debug", skip(self, hir_id, unsafety, abi, decl, generics, hir_ty), ret)] #[instrument(level = "debug", skip(self, hir_id, unsafety, abi, decl, generics, hir_ty), ret)]
pub fn lower_fn_ty( pub fn lower_fn_ty(
&self, &self,
hir_id: hir::HirId, hir_id: HirId,
unsafety: hir::Unsafety, unsafety: hir::Unsafety,
abi: abi::Abi, abi: abi::Abi,
decl: &hir::FnDecl<'tcx>, decl: &hir::FnDecl<'tcx>,
@ -2469,7 +2456,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
/// corresponds to the return type. /// corresponds to the return type.
fn suggest_trait_fn_ty_for_impl_fn_infer( fn suggest_trait_fn_ty_for_impl_fn_infer(
&self, &self,
fn_hir_id: hir::HirId, fn_hir_id: HirId,
arg_idx: Option<usize>, arg_idx: Option<usize>,
) -> Option<Ty<'tcx>> { ) -> Option<Ty<'tcx>> {
let tcx = self.tcx(); let tcx = self.tcx();

View File

@ -9,9 +9,10 @@ use rustc_ast_pretty::pp::Breaks::{Consistent, Inconsistent};
use rustc_ast_pretty::pp::{self, Breaks}; use rustc_ast_pretty::pp::{self, Breaks};
use rustc_ast_pretty::pprust::{Comments, PrintState}; use rustc_ast_pretty::pprust::{Comments, PrintState};
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::LifetimeParamKind; use rustc_hir::{
use rustc_hir::{BindingAnnotation, ByRef, GenericArg, GenericParam, GenericParamKind, Node, Term}; BindingAnnotation, ByRef, GenericArg, GenericBound, GenericParam, GenericParamKind, HirId,
use rustc_hir::{GenericBound, PatKind, RangeEnd, TraitBoundModifier}; LifetimeParamKind, Node, PatKind, RangeEnd, Term, TraitBoundModifier,
};
use rustc_span::source_map::SourceMap; use rustc_span::source_map::SourceMap;
use rustc_span::symbol::{kw, Ident, Symbol}; use rustc_span::symbol::{kw, Ident, Symbol};
use rustc_span::FileName; use rustc_span::FileName;
@ -20,7 +21,7 @@ use rustc_target::spec::abi::Abi;
use std::cell::Cell; use std::cell::Cell;
use std::vec; use std::vec;
pub fn id_to_string(map: &dyn rustc_hir::intravisit::Map<'_>, hir_id: hir::HirId) -> String { pub fn id_to_string(map: &dyn rustc_hir::intravisit::Map<'_>, hir_id: HirId) -> String {
to_string(&map, |s| s.print_node(map.hir_node(hir_id))) to_string(&map, |s| s.print_node(map.hir_node(hir_id)))
} }
@ -28,7 +29,7 @@ pub enum AnnNode<'a> {
Name(&'a Symbol), Name(&'a Symbol),
Block(&'a hir::Block<'a>), Block(&'a hir::Block<'a>),
Item(&'a hir::Item<'a>), Item(&'a hir::Item<'a>),
SubItem(hir::HirId), SubItem(HirId),
Expr(&'a hir::Expr<'a>), Expr(&'a hir::Expr<'a>),
Pat(&'a hir::Pat<'a>), Pat(&'a hir::Pat<'a>),
Arm(&'a hir::Arm<'a>), Arm(&'a hir::Arm<'a>),
@ -65,12 +66,12 @@ impl PpAnn for &dyn rustc_hir::intravisit::Map<'_> {
pub struct State<'a> { pub struct State<'a> {
pub s: pp::Printer, pub s: pp::Printer,
comments: Option<Comments<'a>>, comments: Option<Comments<'a>>,
attrs: &'a dyn Fn(hir::HirId) -> &'a [ast::Attribute], attrs: &'a dyn Fn(HirId) -> &'a [ast::Attribute],
ann: &'a (dyn PpAnn + 'a), ann: &'a (dyn PpAnn + 'a),
} }
impl<'a> State<'a> { impl<'a> State<'a> {
fn attrs(&self, id: hir::HirId) -> &'a [ast::Attribute] { fn attrs(&self, id: HirId) -> &'a [ast::Attribute] {
(self.attrs)(id) (self.attrs)(id)
} }
@ -159,7 +160,7 @@ pub fn print_crate<'a>(
krate: &hir::Mod<'_>, krate: &hir::Mod<'_>,
filename: FileName, filename: FileName,
input: String, input: String,
attrs: &'a dyn Fn(hir::HirId) -> &'a [ast::Attribute], attrs: &'a dyn Fn(HirId) -> &'a [ast::Attribute],
ann: &'a dyn PpAnn, ann: &'a dyn PpAnn,
) -> String { ) -> String {
let mut s = State { let mut s = State {

View File

@ -2851,7 +2851,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
span: Span, span: Span,
base_ty: Ty<'tcx>, base_ty: Ty<'tcx>,
mod_id: DefId, mod_id: DefId,
hir_id: hir::HirId, hir_id: HirId,
) -> Vec<(Vec<&'tcx ty::FieldDef>, GenericArgsRef<'tcx>)> { ) -> Vec<(Vec<&'tcx ty::FieldDef>, GenericArgsRef<'tcx>)> {
debug!("get_field_candidates(span: {:?}, base_t: {:?}", span, base_ty); debug!("get_field_candidates(span: {:?}, base_t: {:?}", span, base_ty);

View File

@ -13,7 +13,7 @@ use rustc_data_structures::fx::FxIndexMap;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def::Res; use rustc_hir::def::Res;
use rustc_hir::def_id::LocalDefId; use rustc_hir::def_id::LocalDefId;
use rustc_hir::PatKind; use rustc_hir::{HirId, PatKind};
use rustc_infer::infer::InferCtxt; use rustc_infer::infer::InferCtxt;
use rustc_middle::hir::place::ProjectionKind; use rustc_middle::hir::place::ProjectionKind;
use rustc_middle::mir::FakeReadCause; use rustc_middle::mir::FakeReadCause;
@ -39,20 +39,20 @@ pub trait Delegate<'tcx> {
/// diagnostics. Around pattern matching such as `let pat = expr`, the diagnostic /// diagnostics. Around pattern matching such as `let pat = expr`, the diagnostic
/// id will be the id of the expression `expr` but the place itself will have /// id will be the id of the expression `expr` but the place itself will have
/// the id of the binding in the pattern `pat`. /// the id of the binding in the pattern `pat`.
fn consume(&mut self, place_with_id: &PlaceWithHirId<'tcx>, diag_expr_id: hir::HirId); fn consume(&mut self, place_with_id: &PlaceWithHirId<'tcx>, diag_expr_id: HirId);
/// The value found at `place` is being borrowed with kind `bk`. /// The value found at `place` is being borrowed with kind `bk`.
/// `diag_expr_id` is the id used for diagnostics (see `consume` for more details). /// `diag_expr_id` is the id used for diagnostics (see `consume` for more details).
fn borrow( fn borrow(
&mut self, &mut self,
place_with_id: &PlaceWithHirId<'tcx>, place_with_id: &PlaceWithHirId<'tcx>,
diag_expr_id: hir::HirId, diag_expr_id: HirId,
bk: ty::BorrowKind, bk: ty::BorrowKind,
); );
/// The value found at `place` is being copied. /// The value found at `place` is being copied.
/// `diag_expr_id` is the id used for diagnostics (see `consume` for more details). /// `diag_expr_id` is the id used for diagnostics (see `consume` for more details).
fn copy(&mut self, place_with_id: &PlaceWithHirId<'tcx>, diag_expr_id: hir::HirId) { fn copy(&mut self, place_with_id: &PlaceWithHirId<'tcx>, diag_expr_id: HirId) {
// In most cases, copying data from `x` is equivalent to doing `*&x`, so by default // In most cases, copying data from `x` is equivalent to doing `*&x`, so by default
// we treat a copy of `x` as a borrow of `x`. // we treat a copy of `x` as a borrow of `x`.
self.borrow(place_with_id, diag_expr_id, ty::BorrowKind::ImmBorrow) self.borrow(place_with_id, diag_expr_id, ty::BorrowKind::ImmBorrow)
@ -60,12 +60,12 @@ pub trait Delegate<'tcx> {
/// The path at `assignee_place` is being assigned to. /// The path at `assignee_place` is being assigned to.
/// `diag_expr_id` is the id used for diagnostics (see `consume` for more details). /// `diag_expr_id` is the id used for diagnostics (see `consume` for more details).
fn mutate(&mut self, assignee_place: &PlaceWithHirId<'tcx>, diag_expr_id: hir::HirId); fn mutate(&mut self, assignee_place: &PlaceWithHirId<'tcx>, diag_expr_id: HirId);
/// The path at `binding_place` is a binding that is being initialized. /// The path at `binding_place` is a binding that is being initialized.
/// ///
/// This covers cases such as `let x = 42;` /// This covers cases such as `let x = 42;`
fn bind(&mut self, binding_place: &PlaceWithHirId<'tcx>, diag_expr_id: hir::HirId) { fn bind(&mut self, binding_place: &PlaceWithHirId<'tcx>, diag_expr_id: HirId) {
// Bindings can normally be treated as a regular assignment, so by default we // Bindings can normally be treated as a regular assignment, so by default we
// forward this to the mutate callback. // forward this to the mutate callback.
self.mutate(binding_place, diag_expr_id) self.mutate(binding_place, diag_expr_id)
@ -76,7 +76,7 @@ pub trait Delegate<'tcx> {
&mut self, &mut self,
place_with_id: &PlaceWithHirId<'tcx>, place_with_id: &PlaceWithHirId<'tcx>,
cause: FakeReadCause, cause: FakeReadCause,
diag_expr_id: hir::HirId, diag_expr_id: HirId,
); );
} }
@ -154,7 +154,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
self.mc.tcx() self.mc.tcx()
} }
fn delegate_consume(&mut self, place_with_id: &PlaceWithHirId<'tcx>, diag_expr_id: hir::HirId) { fn delegate_consume(&mut self, place_with_id: &PlaceWithHirId<'tcx>, diag_expr_id: HirId) {
delegate_consume(&self.mc, self.delegate, place_with_id, diag_expr_id) delegate_consume(&self.mc, self.delegate, place_with_id, diag_expr_id)
} }
@ -775,8 +775,8 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
/// closure as the DefId. /// closure as the DefId.
fn walk_captures(&mut self, closure_expr: &hir::Closure<'_>) { fn walk_captures(&mut self, closure_expr: &hir::Closure<'_>) {
fn upvar_is_local_variable( fn upvar_is_local_variable(
upvars: Option<&FxIndexMap<hir::HirId, hir::Upvar>>, upvars: Option<&FxIndexMap<HirId, hir::Upvar>>,
upvar_id: hir::HirId, upvar_id: HirId,
body_owner_is_closure: bool, body_owner_is_closure: bool,
) -> bool { ) -> bool {
upvars.map(|upvars| !upvars.contains_key(&upvar_id)).unwrap_or(body_owner_is_closure) upvars.map(|upvars| !upvars.contains_key(&upvar_id)).unwrap_or(body_owner_is_closure)
@ -902,7 +902,7 @@ fn delegate_consume<'a, 'tcx>(
mc: &mc::MemCategorizationContext<'a, 'tcx>, mc: &mc::MemCategorizationContext<'a, 'tcx>,
delegate: &mut (dyn Delegate<'tcx> + 'a), delegate: &mut (dyn Delegate<'tcx> + 'a),
place_with_id: &PlaceWithHirId<'tcx>, place_with_id: &PlaceWithHirId<'tcx>,
diag_expr_id: hir::HirId, diag_expr_id: HirId,
) { ) {
debug!("delegate_consume(place_with_id={:?})", place_with_id); debug!("delegate_consume(place_with_id={:?})", place_with_id);

View File

@ -10,7 +10,7 @@ use rustc_hir as hir;
use rustc_hir::def::{CtorOf, DefKind, Res}; use rustc_hir::def::{CtorOf, DefKind, Res};
use rustc_hir::def_id::DefId; use rustc_hir::def_id::DefId;
use rustc_hir::lang_items::LangItem; use rustc_hir::lang_items::LangItem;
use rustc_hir::{ExprKind, GenericArg, Node, QPath}; use rustc_hir::{ExprKind, GenericArg, HirId, Node, QPath};
use rustc_hir_analysis::hir_ty_lowering::errors::GenericsArgsErrExtend; use rustc_hir_analysis::hir_ty_lowering::errors::GenericsArgsErrExtend;
use rustc_hir_analysis::hir_ty_lowering::generics::{ use rustc_hir_analysis::hir_ty_lowering::generics::{
check_generic_arg_count_for_call, lower_generic_args, check_generic_arg_count_for_call, lower_generic_args,
@ -47,7 +47,7 @@ use std::slice;
impl<'a, 'tcx> FnCtxt<'a, 'tcx> { impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
/// Produces warning on the given node, if the current point in the /// Produces warning on the given node, if the current point in the
/// function is unreachable, and there hasn't been another warning. /// function is unreachable, and there hasn't been another warning.
pub(in super::super) fn warn_if_unreachable(&self, id: hir::HirId, span: Span, kind: &str) { pub(in super::super) fn warn_if_unreachable(&self, id: HirId, span: Span, kind: &str) {
// FIXME: Combine these two 'if' expressions into one once // FIXME: Combine these two 'if' expressions into one once
// let chains are implemented // let chains are implemented
if let Diverges::Always { span: orig_span, custom_note } = self.diverges.get() { if let Diverges::Always { span: orig_span, custom_note } = self.diverges.get() {
@ -130,14 +130,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
format!("{self:p}") format!("{self:p}")
} }
pub fn local_ty(&self, span: Span, nid: hir::HirId) -> Ty<'tcx> { pub fn local_ty(&self, span: Span, nid: HirId) -> Ty<'tcx> {
self.locals.borrow().get(&nid).cloned().unwrap_or_else(|| { self.locals.borrow().get(&nid).cloned().unwrap_or_else(|| {
span_bug!(span, "no type for local variable {}", self.tcx.hir().node_to_string(nid)) span_bug!(span, "no type for local variable {}", self.tcx.hir().node_to_string(nid))
}) })
} }
#[inline] #[inline]
pub fn write_ty(&self, id: hir::HirId, ty: Ty<'tcx>) { pub fn write_ty(&self, id: HirId, ty: Ty<'tcx>) {
debug!("write_ty({:?}, {:?}) in fcx {}", id, self.resolve_vars_if_possible(ty), self.tag()); debug!("write_ty({:?}, {:?}) in fcx {}", id, self.resolve_vars_if_possible(ty), self.tag());
let mut typeck = self.typeck_results.borrow_mut(); let mut typeck = self.typeck_results.borrow_mut();
let mut node_ty = typeck.node_types_mut(); let mut node_ty = typeck.node_types_mut();
@ -161,7 +161,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
pub fn write_field_index( pub fn write_field_index(
&self, &self,
hir_id: hir::HirId, hir_id: HirId,
index: FieldIdx, index: FieldIdx,
nested_fields: Vec<(Ty<'tcx>, FieldIdx)>, nested_fields: Vec<(Ty<'tcx>, FieldIdx)>,
) { ) {
@ -174,7 +174,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
#[instrument(level = "debug", skip(self))] #[instrument(level = "debug", skip(self))]
pub(in super::super) fn write_resolution( pub(in super::super) fn write_resolution(
&self, &self,
hir_id: hir::HirId, hir_id: HirId,
r: Result<(DefKind, DefId), ErrorGuaranteed>, r: Result<(DefKind, DefId), ErrorGuaranteed>,
) { ) {
self.typeck_results.borrow_mut().type_dependent_defs_mut().insert(hir_id, r); self.typeck_results.borrow_mut().type_dependent_defs_mut().insert(hir_id, r);
@ -183,7 +183,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
#[instrument(level = "debug", skip(self))] #[instrument(level = "debug", skip(self))]
pub fn write_method_call_and_enforce_effects( pub fn write_method_call_and_enforce_effects(
&self, &self,
hir_id: hir::HirId, hir_id: HirId,
span: Span, span: Span,
method: MethodCallee<'tcx>, method: MethodCallee<'tcx>,
) { ) {
@ -192,7 +192,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self.write_args(hir_id, method.args); self.write_args(hir_id, method.args);
} }
pub fn write_args(&self, node_id: hir::HirId, args: GenericArgsRef<'tcx>) { pub fn write_args(&self, node_id: HirId, args: GenericArgsRef<'tcx>) {
if !args.is_empty() { if !args.is_empty() {
debug!("write_args({:?}, {:?}) in fcx {}", node_id, args, self.tag()); debug!("write_args({:?}, {:?}) in fcx {}", node_id, args, self.tag());
@ -210,7 +210,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
#[instrument(skip(self), level = "debug")] #[instrument(skip(self), level = "debug")]
pub fn write_user_type_annotation_from_args( pub fn write_user_type_annotation_from_args(
&self, &self,
hir_id: hir::HirId, hir_id: HirId,
def_id: DefId, def_id: DefId,
args: GenericArgsRef<'tcx>, args: GenericArgsRef<'tcx>,
user_self_ty: Option<UserSelfTy<'tcx>>, user_self_ty: Option<UserSelfTy<'tcx>>,
@ -230,7 +230,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
#[instrument(skip(self), level = "debug")] #[instrument(skip(self), level = "debug")]
pub fn write_user_type_annotation( pub fn write_user_type_annotation(
&self, &self,
hir_id: hir::HirId, hir_id: HirId,
canonical_user_type_annotation: CanonicalUserType<'tcx>, canonical_user_type_annotation: CanonicalUserType<'tcx>,
) { ) {
debug!("fcx {}", self.tag()); debug!("fcx {}", self.tag());
@ -464,7 +464,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
t.has_free_regions() || t.has_aliases() || t.has_infer_types() t.has_free_regions() || t.has_aliases() || t.has_infer_types()
} }
pub fn node_ty(&self, id: hir::HirId) -> Ty<'tcx> { pub fn node_ty(&self, id: HirId) -> Ty<'tcx> {
match self.typeck_results.borrow().node_types().get(id) { match self.typeck_results.borrow().node_types().get(id) {
Some(&t) => t, Some(&t) => t,
None if let Some(e) = self.tainted_by_errors() => Ty::new_error(self.tcx, e), None if let Some(e) = self.tainted_by_errors() => Ty::new_error(self.tcx, e),
@ -478,7 +478,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} }
} }
pub fn node_ty_opt(&self, id: hir::HirId) -> Option<Ty<'tcx>> { pub fn node_ty_opt(&self, id: HirId) -> Option<Ty<'tcx>> {
match self.typeck_results.borrow().node_types().get(id) { match self.typeck_results.borrow().node_types().get(id) {
Some(&t) => Some(t), Some(&t) => Some(t),
None if let Some(e) = self.tainted_by_errors() => Some(Ty::new_error(self.tcx, e)), None if let Some(e) = self.tainted_by_errors() => Some(Ty::new_error(self.tcx, e)),
@ -742,7 +742,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
&self, &self,
lang_item: hir::LangItem, lang_item: hir::LangItem,
span: Span, span: Span,
hir_id: hir::HirId, hir_id: HirId,
) -> (Res, Ty<'tcx>) { ) -> (Res, Ty<'tcx>) {
let def_id = self.tcx.require_lang_item(lang_item, Some(span)); let def_id = self.tcx.require_lang_item(lang_item, Some(span));
let def_kind = self.tcx.def_kind(def_id); let def_kind = self.tcx.def_kind(def_id);
@ -790,7 +790,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
pub fn resolve_ty_and_res_fully_qualified_call( pub fn resolve_ty_and_res_fully_qualified_call(
&self, &self,
qpath: &'tcx QPath<'tcx>, qpath: &'tcx QPath<'tcx>,
hir_id: hir::HirId, hir_id: HirId,
span: Span, span: Span,
args: Option<&'tcx [hir::Expr<'tcx>]>, args: Option<&'tcx [hir::Expr<'tcx>]>,
) -> (Res, Option<LoweredTy<'tcx>>, &'tcx [hir::PathSegment<'tcx>]) { ) -> (Res, Option<LoweredTy<'tcx>>, &'tcx [hir::PathSegment<'tcx>]) {
@ -984,7 +984,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
/// suggestion can be made, `None` otherwise. /// suggestion can be made, `None` otherwise.
pub fn get_fn_decl( pub fn get_fn_decl(
&self, &self,
blk_id: hir::HirId, blk_id: HirId,
) -> Option<(LocalDefId, &'tcx hir::FnDecl<'tcx>, bool)> { ) -> Option<(LocalDefId, &'tcx hir::FnDecl<'tcx>, bool)> {
// Get enclosing Fn, if it is a function or a trait method, unless there's a `loop` or // Get enclosing Fn, if it is a function or a trait method, unless there's a `loop` or
// `while` before reaching it, as block tail returns are not available in them. // `while` before reaching it, as block tail returns are not available in them.
@ -1080,7 +1080,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
res: Res, res: Res,
span: Span, span: Span,
path_span: Span, path_span: Span,
hir_id: hir::HirId, hir_id: HirId,
) -> (Ty<'tcx>, Res) { ) -> (Ty<'tcx>, Res) {
let tcx = self.tcx; let tcx = self.tcx;
@ -1450,7 +1450,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
span: Span, span: Span,
def_id: DefId, def_id: DefId,
args: GenericArgsRef<'tcx>, args: GenericArgsRef<'tcx>,
hir_id: hir::HirId, hir_id: HirId,
) { ) {
self.add_required_obligations_with_code(span, def_id, args, |idx, span| { self.add_required_obligations_with_code(span, def_id, args, |idx, span| {
if span.is_dummy() { if span.is_dummy() {
@ -1541,7 +1541,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
pub(in super::super) fn with_breakable_ctxt<F: FnOnce() -> R, R>( pub(in super::super) fn with_breakable_ctxt<F: FnOnce() -> R, R>(
&self, &self,
id: hir::HirId, id: HirId,
ctxt: BreakableCtxt<'tcx>, ctxt: BreakableCtxt<'tcx>,
f: F, f: F,
) -> (BreakableCtxt<'tcx>, R) { ) -> (BreakableCtxt<'tcx>, R) {
@ -1580,7 +1580,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} }
/// Returns `true` if an expression is contained inside the LHS of an assignment expression. /// Returns `true` if an expression is contained inside the LHS of an assignment expression.
pub(in super::super) fn expr_in_place(&self, mut expr_id: hir::HirId) -> bool { pub(in super::super) fn expr_in_place(&self, mut expr_id: HirId) -> bool {
let mut contained_in_place = false; let mut contained_in_place = false;
while let hir::Node::Expr(parent_expr) = self.tcx.parent_hir_node(expr_id) { while let hir::Node::Expr(parent_expr) = self.tcx.parent_hir_node(expr_id) {

View File

@ -24,7 +24,7 @@ use rustc_hir as hir;
use rustc_hir::def::{CtorOf, DefKind, Res}; use rustc_hir::def::{CtorOf, DefKind, Res};
use rustc_hir::def_id::DefId; use rustc_hir::def_id::DefId;
use rustc_hir::intravisit::Visitor; use rustc_hir::intravisit::Visitor;
use rustc_hir::{ExprKind, Node, QPath}; use rustc_hir::{ExprKind, HirId, Node, QPath};
use rustc_hir_analysis::check::intrinsicck::InlineAsmCtxt; use rustc_hir_analysis::check::intrinsicck::InlineAsmCtxt;
use rustc_hir_analysis::check::potentially_plural_count; use rustc_hir_analysis::check::potentially_plural_count;
use rustc_hir_analysis::hir_ty_lowering::HirTyLowerer; use rustc_hir_analysis::hir_ty_lowering::HirTyLowerer;
@ -1489,7 +1489,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
pub fn check_struct_path( pub fn check_struct_path(
&self, &self,
qpath: &QPath<'tcx>, qpath: &QPath<'tcx>,
hir_id: hir::HirId, hir_id: HirId,
) -> Result<(&'tcx ty::VariantDef, Ty<'tcx>), ErrorGuaranteed> { ) -> Result<(&'tcx ty::VariantDef, Ty<'tcx>), ErrorGuaranteed> {
let path_span = qpath.span(); let path_span = qpath.span();
let (def, ty) = self.finish_resolving_struct_path(qpath, path_span, hir_id); let (def, ty) = self.finish_resolving_struct_path(qpath, path_span, hir_id);
@ -1554,7 +1554,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
pub fn check_decl_initializer( pub fn check_decl_initializer(
&self, &self,
hir_id: hir::HirId, hir_id: HirId,
pat: &'tcx hir::Pat<'tcx>, pat: &'tcx hir::Pat<'tcx>,
init: &'tcx hir::Expr<'tcx>, init: &'tcx hir::Expr<'tcx>,
) -> Ty<'tcx> { ) -> Ty<'tcx> {
@ -1879,7 +1879,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
ty ty
} }
fn parent_item_span(&self, id: hir::HirId) -> Option<Span> { fn parent_item_span(&self, id: HirId) -> Option<Span> {
let node = self.tcx.hir_node_by_def_id(self.tcx.hir().get_parent_item(id).def_id); let node = self.tcx.hir_node_by_def_id(self.tcx.hir().get_parent_item(id).def_id);
match node { match node {
Node::Item(&hir::Item { kind: hir::ItemKind::Fn(_, _, body_id), .. }) Node::Item(&hir::Item { kind: hir::ItemKind::Fn(_, _, body_id), .. })
@ -1897,7 +1897,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
/// Given a function block's `HirId`, returns its `FnDecl` if it exists, or `None` otherwise. /// Given a function block's `HirId`, returns its `FnDecl` if it exists, or `None` otherwise.
pub(crate) fn get_parent_fn_decl( pub(crate) fn get_parent_fn_decl(
&self, &self,
blk_id: hir::HirId, blk_id: HirId,
) -> Option<(&'tcx hir::FnDecl<'tcx>, Ident)> { ) -> Option<(&'tcx hir::FnDecl<'tcx>, Ident)> {
let parent = self.tcx.hir_node_by_def_id(self.tcx.hir().get_parent_item(blk_id).def_id); let parent = self.tcx.hir_node_by_def_id(self.tcx.hir().get_parent_item(blk_id).def_id);
self.get_node_fn_decl(parent).map(|(_, fn_decl, ident, _)| (fn_decl, ident)) self.get_node_fn_decl(parent).map(|(_, fn_decl, ident, _)| (fn_decl, ident))
@ -1939,12 +1939,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
expr.span expr.span
} }
fn overwrite_local_ty_if_err( fn overwrite_local_ty_if_err(&self, hir_id: HirId, pat: &'tcx hir::Pat<'tcx>, ty: Ty<'tcx>) {
&self,
hir_id: hir::HirId,
pat: &'tcx hir::Pat<'tcx>,
ty: Ty<'tcx>,
) {
if let Err(guar) = ty.error_reported() { if let Err(guar) = ty.error_reported() {
struct OverwritePatternsWithError { struct OverwritePatternsWithError {
pat_hir_ids: Vec<hir::HirId>, pat_hir_ids: Vec<hir::HirId>,
@ -1977,7 +1972,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
&self, &self,
qpath: &QPath<'tcx>, qpath: &QPath<'tcx>,
path_span: Span, path_span: Span,
hir_id: hir::HirId, hir_id: HirId,
) -> (Res, LoweredTy<'tcx>) { ) -> (Res, LoweredTy<'tcx>) {
match *qpath { match *qpath {
QPath::Resolved(ref maybe_qself, path) => { QPath::Resolved(ref maybe_qself, path) => {

View File

@ -71,7 +71,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
expr: &'tcx hir::Expr<'tcx>, expr: &'tcx hir::Expr<'tcx>,
expected: Ty<'tcx>, expected: Ty<'tcx>,
found: Ty<'tcx>, found: Ty<'tcx>,
blk_id: hir::HirId, blk_id: HirId,
) -> bool { ) -> bool {
let expr = expr.peel_drop_temps(); let expr = expr.peel_drop_temps();
let mut pointing_at_return_type = false; let mut pointing_at_return_type = false;
@ -1031,7 +1031,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
fn_decl: &hir::FnDecl<'tcx>, fn_decl: &hir::FnDecl<'tcx>,
expected: Ty<'tcx>, expected: Ty<'tcx>,
found: Ty<'tcx>, found: Ty<'tcx>,
id: hir::HirId, id: HirId,
fn_id: LocalDefId, fn_id: LocalDefId,
) { ) {
if !expected.is_unit() { if !expected.is_unit() {
@ -1600,12 +1600,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} }
} }
fn is_loop(&self, id: hir::HirId) -> bool { fn is_loop(&self, id: HirId) -> bool {
let node = self.tcx.hir_node(id); let node = self.tcx.hir_node(id);
matches!(node, Node::Expr(Expr { kind: ExprKind::Loop(..), .. })) matches!(node, Node::Expr(Expr { kind: ExprKind::Loop(..), .. }))
} }
fn is_local_statement(&self, id: hir::HirId) -> bool { fn is_local_statement(&self, id: HirId) -> bool {
let node = self.tcx.hir_node(id); let node = self.tcx.hir_node(id);
matches!(node, Node::Stmt(Stmt { kind: StmtKind::Let(..), .. })) matches!(node, Node::Stmt(Stmt { kind: StmtKind::Let(..), .. }))
} }

View File

@ -1,7 +1,7 @@
use crate::FnCtxt; use crate::FnCtxt;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::intravisit::{self, Visitor}; use rustc_hir::intravisit::{self, Visitor};
use rustc_hir::PatKind; use rustc_hir::{HirId, PatKind};
use rustc_infer::infer::type_variable::TypeVariableOrigin; use rustc_infer::infer::type_variable::TypeVariableOrigin;
use rustc_middle::ty::Ty; use rustc_middle::ty::Ty;
use rustc_middle::ty::UserType; use rustc_middle::ty::UserType;
@ -33,7 +33,7 @@ impl<'a> DeclOrigin<'a> {
/// ///
/// It must have a hir_id, as this is how we connect gather_locals to the check functions. /// It must have a hir_id, as this is how we connect gather_locals to the check functions.
pub(super) struct Declaration<'a> { pub(super) struct Declaration<'a> {
pub hir_id: hir::HirId, pub hir_id: HirId,
pub pat: &'a hir::Pat<'a>, pub pat: &'a hir::Pat<'a>,
pub ty: Option<&'a hir::Ty<'a>>, pub ty: Option<&'a hir::Ty<'a>>,
pub span: Span, pub span: Span,
@ -48,8 +48,8 @@ impl<'a> From<&'a hir::LetStmt<'a>> for Declaration<'a> {
} }
} }
impl<'a> From<(&'a hir::LetExpr<'a>, hir::HirId)> for Declaration<'a> { impl<'a> From<(&'a hir::LetExpr<'a>, HirId)> for Declaration<'a> {
fn from((let_expr, hir_id): (&'a hir::LetExpr<'a>, hir::HirId)) -> Self { fn from((let_expr, hir_id): (&'a hir::LetExpr<'a>, HirId)) -> Self {
let hir::LetExpr { pat, ty, span, init, is_recovered: _ } = *let_expr; let hir::LetExpr { pat, ty, span, init, is_recovered: _ } = *let_expr;
Declaration { hir_id, pat, ty, span, init: Some(init), origin: DeclOrigin::LetExpr } Declaration { hir_id, pat, ty, span, init: Some(init), origin: DeclOrigin::LetExpr }
} }
@ -60,7 +60,7 @@ pub(super) struct GatherLocalsVisitor<'a, 'tcx> {
// parameters are special cases of patterns, but we want to handle them as // parameters are special cases of patterns, but we want to handle them as
// *distinct* cases. so track when we are hitting a pattern *within* an fn // *distinct* cases. so track when we are hitting a pattern *within* an fn
// parameter. // parameter.
outermost_fn_param_pat: Option<(Span, hir::HirId)>, outermost_fn_param_pat: Option<(Span, HirId)>,
} }
impl<'a, 'tcx> GatherLocalsVisitor<'a, 'tcx> { impl<'a, 'tcx> GatherLocalsVisitor<'a, 'tcx> {
@ -68,7 +68,7 @@ impl<'a, 'tcx> GatherLocalsVisitor<'a, 'tcx> {
Self { fcx, outermost_fn_param_pat: None } Self { fcx, outermost_fn_param_pat: None }
} }
fn assign(&mut self, span: Span, nid: hir::HirId, ty_opt: Option<Ty<'tcx>>) -> Ty<'tcx> { fn assign(&mut self, span: Span, nid: HirId, ty_opt: Option<Ty<'tcx>>) -> Ty<'tcx> {
match ty_opt { match ty_opt {
None => { None => {
// Infer the variable's type. // Infer the variable's type.

View File

@ -57,7 +57,7 @@ use rustc_errors::{codes::*, struct_span_code_err, ErrorGuaranteed};
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::intravisit::Visitor; use rustc_hir::intravisit::Visitor;
use rustc_hir::{HirIdMap, Node}; use rustc_hir::{HirId, HirIdMap, Node};
use rustc_hir_analysis::check::check_abi; use rustc_hir_analysis::check::check_abi;
use rustc_hir_analysis::hir_ty_lowering::HirTyLowerer; use rustc_hir_analysis::hir_ty_lowering::HirTyLowerer;
use rustc_infer::infer::type_variable::TypeVariableOrigin; use rustc_infer::infer::type_variable::TypeVariableOrigin;
@ -339,13 +339,13 @@ pub struct EnclosingBreakables<'tcx> {
} }
impl<'tcx> EnclosingBreakables<'tcx> { impl<'tcx> EnclosingBreakables<'tcx> {
fn find_breakable(&mut self, target_id: hir::HirId) -> &mut BreakableCtxt<'tcx> { fn find_breakable(&mut self, target_id: HirId) -> &mut BreakableCtxt<'tcx> {
self.opt_find_breakable(target_id).unwrap_or_else(|| { self.opt_find_breakable(target_id).unwrap_or_else(|| {
bug!("could not find enclosing breakable with id {}", target_id); bug!("could not find enclosing breakable with id {}", target_id);
}) })
} }
fn opt_find_breakable(&mut self, target_id: hir::HirId) -> Option<&mut BreakableCtxt<'tcx>> { fn opt_find_breakable(&mut self, target_id: HirId) -> Option<&mut BreakableCtxt<'tcx>> {
match self.by_id.get(&target_id) { match self.by_id.get(&target_id) {
Some(ix) => Some(&mut self.stack[*ix]), Some(ix) => Some(&mut self.stack[*ix]),
None => None, None => None,

View File

@ -58,24 +58,24 @@ use rustc_hir as hir;
use rustc_hir::def::{CtorOf, DefKind, Res}; use rustc_hir::def::{CtorOf, DefKind, Res};
use rustc_hir::def_id::LocalDefId; use rustc_hir::def_id::LocalDefId;
use rustc_hir::pat_util::EnumerateAndAdjustIterator; use rustc_hir::pat_util::EnumerateAndAdjustIterator;
use rustc_hir::PatKind; use rustc_hir::{HirId, PatKind};
use rustc_infer::infer::InferCtxt; use rustc_infer::infer::InferCtxt;
use rustc_span::Span; use rustc_span::Span;
use rustc_target::abi::{FieldIdx, VariantIdx, FIRST_VARIANT}; use rustc_target::abi::{FieldIdx, VariantIdx, FIRST_VARIANT};
use rustc_trait_selection::infer::InferCtxtExt; use rustc_trait_selection::infer::InferCtxtExt;
pub(crate) trait HirNode { pub(crate) trait HirNode {
fn hir_id(&self) -> hir::HirId; fn hir_id(&self) -> HirId;
} }
impl HirNode for hir::Expr<'_> { impl HirNode for hir::Expr<'_> {
fn hir_id(&self) -> hir::HirId { fn hir_id(&self) -> HirId {
self.hir_id self.hir_id
} }
} }
impl HirNode for hir::Pat<'_> { impl HirNode for hir::Pat<'_> {
fn hir_id(&self) -> hir::HirId { fn hir_id(&self) -> HirId {
self.hir_id self.hir_id
} }
} }
@ -86,7 +86,7 @@ pub(crate) struct MemCategorizationContext<'a, 'tcx> {
infcx: &'a InferCtxt<'tcx>, infcx: &'a InferCtxt<'tcx>,
param_env: ty::ParamEnv<'tcx>, param_env: ty::ParamEnv<'tcx>,
body_owner: LocalDefId, body_owner: LocalDefId,
upvars: Option<&'tcx FxIndexMap<hir::HirId, hir::Upvar>>, upvars: Option<&'tcx FxIndexMap<HirId, hir::Upvar>>,
} }
pub(crate) type McResult<T> = Result<T, ()>; pub(crate) type McResult<T> = Result<T, ()>;
@ -127,11 +127,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
self.infcx.tainted_by_errors().is_some() self.infcx.tainted_by_errors().is_some()
} }
fn resolve_type_vars_or_error( fn resolve_type_vars_or_error(&self, id: HirId, ty: Option<Ty<'tcx>>) -> McResult<Ty<'tcx>> {
&self,
id: hir::HirId,
ty: Option<Ty<'tcx>>,
) -> McResult<Ty<'tcx>> {
match ty { match ty {
Some(ty) => { Some(ty) => {
let ty = self.resolve_vars_if_possible(ty); let ty = self.resolve_vars_if_possible(ty);
@ -153,7 +149,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
} }
} }
pub(crate) fn node_ty(&self, hir_id: hir::HirId) -> McResult<Ty<'tcx>> { pub(crate) fn node_ty(&self, hir_id: HirId) -> McResult<Ty<'tcx>> {
self.resolve_type_vars_or_error(hir_id, self.typeck_results.node_type_opt(hir_id)) self.resolve_type_vars_or_error(hir_id, self.typeck_results.node_type_opt(hir_id))
} }
@ -377,7 +373,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
#[instrument(level = "debug", skip(self, span), ret)] #[instrument(level = "debug", skip(self, span), ret)]
pub(crate) fn cat_res( pub(crate) fn cat_res(
&self, &self,
hir_id: hir::HirId, hir_id: HirId,
span: Span, span: Span,
expr_ty: Ty<'tcx>, expr_ty: Ty<'tcx>,
res: Res, res: Res,
@ -416,7 +412,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
/// environment and upvar reference as appropriate. Only regionck cares /// environment and upvar reference as appropriate. Only regionck cares
/// about these dereferences, so we let it compute them as needed. /// about these dereferences, so we let it compute them as needed.
#[instrument(level = "debug", skip(self), ret)] #[instrument(level = "debug", skip(self), ret)]
fn cat_upvar(&self, hir_id: hir::HirId, var_id: hir::HirId) -> McResult<PlaceWithHirId<'tcx>> { fn cat_upvar(&self, hir_id: HirId, var_id: HirId) -> McResult<PlaceWithHirId<'tcx>> {
let closure_expr_def_id = self.body_owner; let closure_expr_def_id = self.body_owner;
let upvar_id = ty::UpvarId { let upvar_id = ty::UpvarId {
@ -429,7 +425,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
} }
#[instrument(level = "debug", skip(self), ret)] #[instrument(level = "debug", skip(self), ret)]
pub(crate) fn cat_rvalue(&self, hir_id: hir::HirId, expr_ty: Ty<'tcx>) -> PlaceWithHirId<'tcx> { pub(crate) fn cat_rvalue(&self, hir_id: HirId, expr_ty: Ty<'tcx>) -> PlaceWithHirId<'tcx> {
PlaceWithHirId::new(hir_id, expr_ty, PlaceBase::Rvalue, Vec::new()) PlaceWithHirId::new(hir_id, expr_ty, PlaceBase::Rvalue, Vec::new())
} }
@ -523,7 +519,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
fn variant_index_for_adt( fn variant_index_for_adt(
&self, &self,
qpath: &hir::QPath<'_>, qpath: &hir::QPath<'_>,
pat_hir_id: hir::HirId, pat_hir_id: HirId,
span: Span, span: Span,
) -> McResult<VariantIdx> { ) -> McResult<VariantIdx> {
let res = self.typeck_results.qpath_res(qpath, pat_hir_id); let res = self.typeck_results.qpath_res(qpath, pat_hir_id);
@ -556,7 +552,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
/// Here `pat_hir_id` is the HirId of the pattern itself. /// Here `pat_hir_id` is the HirId of the pattern itself.
fn total_fields_in_adt_variant( fn total_fields_in_adt_variant(
&self, &self,
pat_hir_id: hir::HirId, pat_hir_id: HirId,
variant_index: VariantIdx, variant_index: VariantIdx,
span: Span, span: Span,
) -> McResult<usize> { ) -> McResult<usize> {
@ -573,7 +569,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
/// Returns the total number of fields in a tuple used within a Tuple pattern. /// Returns the total number of fields in a tuple used within a Tuple pattern.
/// Here `pat_hir_id` is the HirId of the pattern itself. /// Here `pat_hir_id` is the HirId of the pattern itself.
fn total_fields_in_tuple(&self, pat_hir_id: hir::HirId, span: Span) -> McResult<usize> { fn total_fields_in_tuple(&self, pat_hir_id: HirId, span: Span) -> McResult<usize> {
let ty = self.typeck_results.node_type(pat_hir_id); let ty = self.typeck_results.node_type(pat_hir_id);
match ty.kind() { match ty.kind() {
ty::Tuple(args) => Ok(args.len()), ty::Tuple(args) => Ok(args.len()),

View File

@ -8,6 +8,7 @@ use rustc_data_structures::fx::FxHashSet;
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def::DefKind; use rustc_hir::def::DefKind;
use rustc_hir::HirId;
use rustc_hir_analysis::autoderef::{self, Autoderef}; use rustc_hir_analysis::autoderef::{self, Autoderef};
use rustc_infer::infer::canonical::OriginalQueryValues; use rustc_infer::infer::canonical::OriginalQueryValues;
use rustc_infer::infer::canonical::{Canonical, QueryResponse}; use rustc_infer::infer::canonical::{Canonical, QueryResponse};
@ -86,7 +87,7 @@ pub(crate) struct ProbeContext<'a, 'tcx> {
Vec<(ty::Predicate<'tcx>, Option<ty::Predicate<'tcx>>, Option<ObligationCause<'tcx>>)>, Vec<(ty::Predicate<'tcx>, Option<ty::Predicate<'tcx>>, Option<ObligationCause<'tcx>>)>,
>, >,
scope_expr_id: hir::HirId, scope_expr_id: HirId,
} }
impl<'a, 'tcx> Deref for ProbeContext<'a, 'tcx> { impl<'a, 'tcx> Deref for ProbeContext<'a, 'tcx> {
@ -263,7 +264,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
mode: Mode, mode: Mode,
return_type: Ty<'tcx>, return_type: Ty<'tcx>,
self_ty: Ty<'tcx>, self_ty: Ty<'tcx>,
scope_expr_id: hir::HirId, scope_expr_id: HirId,
candidate_filter: impl Fn(&ty::AssocItem) -> bool, candidate_filter: impl Fn(&ty::AssocItem) -> bool,
) -> Vec<ty::AssocItem> { ) -> Vec<ty::AssocItem> {
let method_names = self let method_names = self
@ -307,7 +308,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
return_type: Option<Ty<'tcx>>, return_type: Option<Ty<'tcx>>,
is_suggestion: IsSuggestion, is_suggestion: IsSuggestion,
self_ty: Ty<'tcx>, self_ty: Ty<'tcx>,
scope_expr_id: hir::HirId, scope_expr_id: HirId,
scope: ProbeScope, scope: ProbeScope,
) -> PickResult<'tcx> { ) -> PickResult<'tcx> {
self.probe_op( self.probe_op(
@ -331,7 +332,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
return_type: Option<Ty<'tcx>>, return_type: Option<Ty<'tcx>>,
is_suggestion: IsSuggestion, is_suggestion: IsSuggestion,
self_ty: Ty<'tcx>, self_ty: Ty<'tcx>,
scope_expr_id: hir::HirId, scope_expr_id: HirId,
scope: ProbeScope, scope: ProbeScope,
) -> Vec<Candidate<'tcx>> { ) -> Vec<Candidate<'tcx>> {
self.probe_op( self.probe_op(
@ -362,7 +363,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
return_type: Option<Ty<'tcx>>, return_type: Option<Ty<'tcx>>,
is_suggestion: IsSuggestion, is_suggestion: IsSuggestion,
self_ty: Ty<'tcx>, self_ty: Ty<'tcx>,
scope_expr_id: hir::HirId, scope_expr_id: HirId,
scope: ProbeScope, scope: ProbeScope,
op: OP, op: OP,
) -> Result<R, MethodError<'tcx>> ) -> Result<R, MethodError<'tcx>>
@ -589,7 +590,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
return_type: Option<Ty<'tcx>>, return_type: Option<Ty<'tcx>>,
orig_steps_var_values: &'a OriginalQueryValues<'tcx>, orig_steps_var_values: &'a OriginalQueryValues<'tcx>,
steps: &'tcx [CandidateStep<'tcx>], steps: &'tcx [CandidateStep<'tcx>],
scope_expr_id: hir::HirId, scope_expr_id: HirId,
) -> ProbeContext<'a, 'tcx> { ) -> ProbeContext<'a, 'tcx> {
ProbeContext { ProbeContext {
fcx, fcx,
@ -1381,7 +1382,7 @@ impl<'tcx> Pick<'tcx> {
&self, &self,
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
span: Span, span: Span,
scope_expr_id: hir::HirId, scope_expr_id: HirId,
) { ) {
if self.unstable_candidates.is_empty() { if self.unstable_candidates.is_empty() {
return; return;

View File

@ -3,7 +3,7 @@ use super::callee::DeferredCallResolution;
use rustc_data_structures::unord::{UnordMap, UnordSet}; use rustc_data_structures::unord::{UnordMap, UnordSet};
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def_id::LocalDefId; use rustc_hir::def_id::LocalDefId;
use rustc_hir::HirIdMap; use rustc_hir::{HirId, HirIdMap};
use rustc_infer::infer::{InferCtxt, InferOk, TyCtxtInferExt}; use rustc_infer::infer::{InferCtxt, InferOk, TyCtxtInferExt};
use rustc_middle::ty::visit::TypeVisitableExt; use rustc_middle::ty::visit::TypeVisitableExt;
use rustc_middle::ty::{self, Ty, TyCtxt}; use rustc_middle::ty::{self, Ty, TyCtxt};
@ -52,9 +52,9 @@ pub(crate) struct TypeckRootCtxt<'tcx> {
pub(super) deferred_cast_checks: RefCell<Vec<super::cast::CastCheck<'tcx>>>, pub(super) deferred_cast_checks: RefCell<Vec<super::cast::CastCheck<'tcx>>>,
pub(super) deferred_transmute_checks: RefCell<Vec<(Ty<'tcx>, Ty<'tcx>, hir::HirId)>>, pub(super) deferred_transmute_checks: RefCell<Vec<(Ty<'tcx>, Ty<'tcx>, HirId)>>,
pub(super) deferred_asm_checks: RefCell<Vec<(&'tcx hir::InlineAsm<'tcx>, hir::HirId)>>, pub(super) deferred_asm_checks: RefCell<Vec<(&'tcx hir::InlineAsm<'tcx>, HirId)>>,
pub(super) deferred_coroutine_interiors: RefCell<Vec<(LocalDefId, hir::BodyId, Ty<'tcx>)>>, pub(super) deferred_coroutine_interiors: RefCell<Vec<(LocalDefId, hir::BodyId, Ty<'tcx>)>>,

View File

@ -38,6 +38,7 @@ use rustc_errors::{Applicability, MultiSpan};
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def_id::LocalDefId; use rustc_hir::def_id::LocalDefId;
use rustc_hir::intravisit::{self, Visitor}; use rustc_hir::intravisit::{self, Visitor};
use rustc_hir::HirId;
use rustc_infer::infer::UpvarRegion; use rustc_infer::infer::UpvarRegion;
use rustc_middle::hir::place::{Place, PlaceBase, PlaceWithHirId, Projection, ProjectionKind}; use rustc_middle::hir::place::{Place, PlaceBase, PlaceWithHirId, Projection, ProjectionKind};
use rustc_middle::mir::FakeReadCause; use rustc_middle::mir::FakeReadCause;
@ -88,7 +89,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
enum UpvarMigrationInfo { enum UpvarMigrationInfo {
/// We previously captured all of `x`, but now we capture some sub-path. /// We previously captured all of `x`, but now we capture some sub-path.
CapturingPrecise { source_expr: Option<hir::HirId>, var_name: String }, CapturingPrecise { source_expr: Option<HirId>, var_name: String },
CapturingNothing { CapturingNothing {
// where the variable appears in the closure (but is not captured) // where the variable appears in the closure (but is not captured)
use_span: Span, use_span: Span,
@ -131,7 +132,7 @@ struct MigrationLintNote {
/// Intermediate format to store the hir id of the root variable and a HashSet containing /// Intermediate format to store the hir id of the root variable and a HashSet containing
/// information on why the root variable should be fully captured /// information on why the root variable should be fully captured
struct NeededMigration { struct NeededMigration {
var_hir_id: hir::HirId, var_hir_id: HirId,
diagnostics_info: Vec<MigrationLintNote>, diagnostics_info: Vec<MigrationLintNote>,
} }
@ -163,7 +164,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
#[instrument(skip(self, body), level = "debug")] #[instrument(skip(self, body), level = "debug")]
fn analyze_closure( fn analyze_closure(
&self, &self,
closure_hir_id: hir::HirId, closure_hir_id: HirId,
span: Span, span: Span,
body_id: hir::BodyId, body_id: hir::BodyId,
body: &'tcx hir::Body<'tcx>, body: &'tcx hir::Body<'tcx>,
@ -1098,7 +1099,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
fn compute_2229_migrations_for_trait( fn compute_2229_migrations_for_trait(
&self, &self,
min_captures: Option<&ty::RootVariableMinCaptureList<'tcx>>, min_captures: Option<&ty::RootVariableMinCaptureList<'tcx>>,
var_hir_id: hir::HirId, var_hir_id: HirId,
closure_clause: hir::CaptureBy, closure_clause: hir::CaptureBy,
) -> Option<FxIndexMap<UpvarMigrationInfo, UnordSet<&'static str>>> { ) -> Option<FxIndexMap<UpvarMigrationInfo, UnordSet<&'static str>>> {
let auto_traits_def_id = [ let auto_traits_def_id = [
@ -1210,7 +1211,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
closure_span: Span, closure_span: Span,
min_captures: Option<&ty::RootVariableMinCaptureList<'tcx>>, min_captures: Option<&ty::RootVariableMinCaptureList<'tcx>>,
closure_clause: hir::CaptureBy, closure_clause: hir::CaptureBy,
var_hir_id: hir::HirId, var_hir_id: HirId,
) -> Option<FxIndexSet<UpvarMigrationInfo>> { ) -> Option<FxIndexSet<UpvarMigrationInfo>> {
let ty = self.resolve_vars_if_possible(self.node_ty(var_hir_id)); let ty = self.resolve_vars_if_possible(self.node_ty(var_hir_id));
@ -1650,7 +1651,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
fn place_for_root_variable( fn place_for_root_variable(
&self, &self,
closure_def_id: LocalDefId, closure_def_id: LocalDefId,
var_hir_id: hir::HirId, var_hir_id: HirId,
) -> Place<'tcx> { ) -> Place<'tcx> {
let upvar_id = ty::UpvarId::new(var_hir_id, closure_def_id); let upvar_id = ty::UpvarId::new(var_hir_id, closure_def_id);
@ -1881,7 +1882,7 @@ fn apply_capture_kind_on_capture_ty<'tcx>(
} }
/// Returns the Span of where the value with the provided HirId would be dropped /// Returns the Span of where the value with the provided HirId would be dropped
fn drop_location_span(tcx: TyCtxt<'_>, hir_id: hir::HirId) -> Span { fn drop_location_span(tcx: TyCtxt<'_>, hir_id: HirId) -> Span {
let owner_id = tcx.hir().get_enclosing_scope(hir_id).unwrap(); let owner_id = tcx.hir().get_enclosing_scope(hir_id).unwrap();
let owner_node = tcx.hir_node(owner_id); let owner_node = tcx.hir_node(owner_id);
@ -1933,7 +1934,7 @@ struct InferBorrowKind<'tcx> {
/// Place { V1, [ProjectionKind::Field(Index=1, Variant=0)] } : CaptureKind { E2, MutableBorrow } /// Place { V1, [ProjectionKind::Field(Index=1, Variant=0)] } : CaptureKind { E2, MutableBorrow }
/// ``` /// ```
capture_information: InferredCaptureInformation<'tcx>, capture_information: InferredCaptureInformation<'tcx>,
fake_reads: Vec<(Place<'tcx>, FakeReadCause, hir::HirId)>, fake_reads: Vec<(Place<'tcx>, FakeReadCause, HirId)>,
} }
impl<'tcx> euv::Delegate<'tcx> for InferBorrowKind<'tcx> { impl<'tcx> euv::Delegate<'tcx> for InferBorrowKind<'tcx> {
@ -1941,7 +1942,7 @@ impl<'tcx> euv::Delegate<'tcx> for InferBorrowKind<'tcx> {
&mut self, &mut self,
place: &PlaceWithHirId<'tcx>, place: &PlaceWithHirId<'tcx>,
cause: FakeReadCause, cause: FakeReadCause,
diag_expr_id: hir::HirId, diag_expr_id: HirId,
) { ) {
let PlaceBase::Upvar(_) = place.place.base else { return }; let PlaceBase::Upvar(_) = place.place.base else { return };
@ -1956,7 +1957,7 @@ impl<'tcx> euv::Delegate<'tcx> for InferBorrowKind<'tcx> {
} }
#[instrument(skip(self), level = "debug")] #[instrument(skip(self), level = "debug")]
fn consume(&mut self, place_with_id: &PlaceWithHirId<'tcx>, diag_expr_id: hir::HirId) { fn consume(&mut self, place_with_id: &PlaceWithHirId<'tcx>, diag_expr_id: HirId) {
let PlaceBase::Upvar(upvar_id) = place_with_id.place.base else { return }; let PlaceBase::Upvar(upvar_id) = place_with_id.place.base else { return };
assert_eq!(self.closure_def_id, upvar_id.closure_expr_id); assert_eq!(self.closure_def_id, upvar_id.closure_expr_id);
@ -1974,7 +1975,7 @@ impl<'tcx> euv::Delegate<'tcx> for InferBorrowKind<'tcx> {
fn borrow( fn borrow(
&mut self, &mut self,
place_with_id: &PlaceWithHirId<'tcx>, place_with_id: &PlaceWithHirId<'tcx>,
diag_expr_id: hir::HirId, diag_expr_id: HirId,
bk: ty::BorrowKind, bk: ty::BorrowKind,
) { ) {
let PlaceBase::Upvar(upvar_id) = place_with_id.place.base else { return }; let PlaceBase::Upvar(upvar_id) = place_with_id.place.base else { return };
@ -2005,7 +2006,7 @@ impl<'tcx> euv::Delegate<'tcx> for InferBorrowKind<'tcx> {
} }
#[instrument(skip(self), level = "debug")] #[instrument(skip(self), level = "debug")]
fn mutate(&mut self, assignee_place: &PlaceWithHirId<'tcx>, diag_expr_id: hir::HirId) { fn mutate(&mut self, assignee_place: &PlaceWithHirId<'tcx>, diag_expr_id: HirId) {
self.borrow(assignee_place, diag_expr_id, ty::BorrowKind::MutBorrow); self.borrow(assignee_place, diag_expr_id, ty::BorrowKind::MutBorrow);
} }
} }
@ -2192,14 +2193,14 @@ fn construct_capture_info_string<'tcx>(
format!("{place_str} -> {capture_kind_str}") format!("{place_str} -> {capture_kind_str}")
} }
fn var_name(tcx: TyCtxt<'_>, var_hir_id: hir::HirId) -> Symbol { fn var_name(tcx: TyCtxt<'_>, var_hir_id: HirId) -> Symbol {
tcx.hir().name(var_hir_id) tcx.hir().name(var_hir_id)
} }
#[instrument(level = "debug", skip(tcx))] #[instrument(level = "debug", skip(tcx))]
fn should_do_rust_2021_incompatible_closure_captures_analysis( fn should_do_rust_2021_incompatible_closure_captures_analysis(
tcx: TyCtxt<'_>, tcx: TyCtxt<'_>,
closure_id: hir::HirId, closure_id: HirId,
) -> bool { ) -> bool {
if tcx.sess.at_least_rust_2021() { if tcx.sess.at_least_rust_2021() {
return false; return false;

View File

@ -7,6 +7,7 @@ use rustc_data_structures::unord::ExtendUnord;
use rustc_errors::{ErrorGuaranteed, StashKey}; use rustc_errors::{ErrorGuaranteed, StashKey};
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::intravisit::{self, Visitor}; use rustc_hir::intravisit::{self, Visitor};
use rustc_hir::HirId;
use rustc_infer::infer::error_reporting::TypeAnnotationNeeded::E0282; use rustc_infer::infer::error_reporting::TypeAnnotationNeeded::E0282;
use rustc_middle::traits::ObligationCause; use rustc_middle::traits::ObligationCause;
use rustc_middle::ty::adjustment::{Adjust, Adjustment, PointerCoercion}; use rustc_middle::ty::adjustment::{Adjust, Adjustment, PointerCoercion};
@ -134,7 +135,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
self.fcx.tcx self.fcx.tcx
} }
fn write_ty_to_typeck_results(&mut self, hir_id: hir::HirId, ty: Ty<'tcx>) { fn write_ty_to_typeck_results(&mut self, hir_id: HirId, ty: Ty<'tcx>) {
debug!("write_ty_to_typeck_results({:?}, {:?})", hir_id, ty); debug!("write_ty_to_typeck_results({:?}, {:?})", hir_id, ty);
assert!( assert!(
!ty.has_infer() && !ty.has_placeholders() && !ty.has_free_regions(), !ty.has_infer() && !ty.has_placeholders() && !ty.has_free_regions(),
@ -461,7 +462,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
fcx_typeck_results.closure_kind_origins().items_in_stable_order(); fcx_typeck_results.closure_kind_origins().items_in_stable_order();
for (local_id, origin) in fcx_closure_kind_origins { for (local_id, origin) in fcx_closure_kind_origins {
let hir_id = hir::HirId { owner: common_hir_owner, local_id }; let hir_id = HirId { owner: common_hir_owner, local_id };
let place_span = origin.0; let place_span = origin.0;
let place = self.resolve(origin.1.clone(), &place_span); let place = self.resolve(origin.1.clone(), &place_span);
self.typeck_results.closure_kind_origins_mut().insert(hir_id, (place_span, place)); self.typeck_results.closure_kind_origins_mut().insert(hir_id, (place_span, place));
@ -490,7 +491,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
let mut errors_buffer = Vec::new(); let mut errors_buffer = Vec::new();
for (local_id, c_ty) in sorted_user_provided_types { for (local_id, c_ty) in sorted_user_provided_types {
let hir_id = hir::HirId { owner: common_hir_owner, local_id }; let hir_id = HirId { owner: common_hir_owner, local_id };
if let ty::UserType::TypeOf(_, user_args) = c_ty.value { if let ty::UserType::TypeOf(_, user_args) = c_ty.value {
// This is a unit-testing mechanism. // This is a unit-testing mechanism.
@ -513,7 +514,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
self.typeck_results.user_provided_types_mut().extend( self.typeck_results.user_provided_types_mut().extend(
fcx_typeck_results.user_provided_types().items().map(|(local_id, c_ty)| { fcx_typeck_results.user_provided_types().items().map(|(local_id, c_ty)| {
let hir_id = hir::HirId { owner: common_hir_owner, local_id }; let hir_id = HirId { owner: common_hir_owner, local_id };
if cfg!(debug_assertions) && c_ty.has_infer() { if cfg!(debug_assertions) && c_ty.has_infer() {
span_bug!( span_bug!(
@ -604,7 +605,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
} }
} }
fn visit_field_id(&mut self, hir_id: hir::HirId) { fn visit_field_id(&mut self, hir_id: HirId) {
if let Some(index) = self.fcx.typeck_results.borrow_mut().field_indices_mut().remove(hir_id) if let Some(index) = self.fcx.typeck_results.borrow_mut().field_indices_mut().remove(hir_id)
{ {
self.typeck_results.field_indices_mut().insert(hir_id, index); self.typeck_results.field_indices_mut().insert(hir_id, index);
@ -617,7 +618,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
} }
#[instrument(skip(self, span), level = "debug")] #[instrument(skip(self, span), level = "debug")]
fn visit_node_id(&mut self, span: Span, hir_id: hir::HirId) { fn visit_node_id(&mut self, span: Span, hir_id: HirId) {
// Export associated path extensions and method resolutions. // Export associated path extensions and method resolutions.
if let Some(def) = if let Some(def) =
self.fcx.typeck_results.borrow_mut().type_dependent_defs_mut().remove(hir_id) self.fcx.typeck_results.borrow_mut().type_dependent_defs_mut().remove(hir_id)
@ -644,7 +645,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
} }
#[instrument(skip(self, span), level = "debug")] #[instrument(skip(self, span), level = "debug")]
fn visit_adjustments(&mut self, span: Span, hir_id: hir::HirId) { fn visit_adjustments(&mut self, span: Span, hir_id: HirId) {
let adjustment = self.fcx.typeck_results.borrow_mut().adjustments_mut().remove(hir_id); let adjustment = self.fcx.typeck_results.borrow_mut().adjustments_mut().remove(hir_id);
match adjustment { match adjustment {
None => { None => {
@ -660,7 +661,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
} }
#[instrument(skip(self, span), level = "debug")] #[instrument(skip(self, span), level = "debug")]
fn visit_pat_adjustments(&mut self, span: Span, hir_id: hir::HirId) { fn visit_pat_adjustments(&mut self, span: Span, hir_id: HirId) {
let adjustment = self.fcx.typeck_results.borrow_mut().pat_adjustments_mut().remove(hir_id); let adjustment = self.fcx.typeck_results.borrow_mut().pat_adjustments_mut().remove(hir_id);
match adjustment { match adjustment {
None => { None => {
@ -691,7 +692,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
let fcx_liberated_fn_sigs = fcx_typeck_results.liberated_fn_sigs().items_in_stable_order(); let fcx_liberated_fn_sigs = fcx_typeck_results.liberated_fn_sigs().items_in_stable_order();
for (local_id, &fn_sig) in fcx_liberated_fn_sigs { for (local_id, &fn_sig) in fcx_liberated_fn_sigs {
let hir_id = hir::HirId { owner: common_hir_owner, local_id }; let hir_id = HirId { owner: common_hir_owner, local_id };
let fn_sig = self.resolve(fn_sig, &hir_id); let fn_sig = self.resolve(fn_sig, &hir_id);
self.typeck_results.liberated_fn_sigs_mut().insert(hir_id, fn_sig); self.typeck_results.liberated_fn_sigs_mut().insert(hir_id, fn_sig);
} }
@ -705,7 +706,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
let fcx_fru_field_types = fcx_typeck_results.fru_field_types().items_in_stable_order(); let fcx_fru_field_types = fcx_typeck_results.fru_field_types().items_in_stable_order();
for (local_id, ftys) in fcx_fru_field_types { for (local_id, ftys) in fcx_fru_field_types {
let hir_id = hir::HirId { owner: common_hir_owner, local_id }; let hir_id = HirId { owner: common_hir_owner, local_id };
let ftys = self.resolve(ftys.clone(), &hir_id); let ftys = self.resolve(ftys.clone(), &hir_id);
self.typeck_results.fru_field_types_mut().insert(hir_id, ftys); self.typeck_results.fru_field_types_mut().insert(hir_id, ftys);
} }
@ -719,7 +720,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
for (local_id, &(container, ref indices)) in for (local_id, &(container, ref indices)) in
fcx_typeck_results.offset_of_data().items_in_stable_order() fcx_typeck_results.offset_of_data().items_in_stable_order()
{ {
let hir_id = hir::HirId { owner: common_hir_owner, local_id }; let hir_id = HirId { owner: common_hir_owner, local_id };
let container = self.resolve(container, &hir_id); let container = self.resolve(container, &hir_id);
self.typeck_results.offset_of_data_mut().insert(hir_id, (container, indices.clone())); self.typeck_results.offset_of_data_mut().insert(hir_id, (container, indices.clone()));
} }
@ -754,7 +755,7 @@ impl Locatable for Span {
} }
} }
impl Locatable for hir::HirId { impl Locatable for HirId {
fn to_span(&self, tcx: TyCtxt<'_>) -> Span { fn to_span(&self, tcx: TyCtxt<'_>) -> Span {
tcx.hir().span(*self) tcx.hir().span(*self)
} }

View File

@ -20,6 +20,7 @@ use rustc_data_structures::sync::{join, Lrc};
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def_id::{LocalDefId, LocalModDefId}; use rustc_hir::def_id::{LocalDefId, LocalModDefId};
use rustc_hir::intravisit as hir_visit; use rustc_hir::intravisit as hir_visit;
use rustc_hir::HirId;
use rustc_middle::hir::nested_filter; use rustc_middle::hir::nested_filter;
use rustc_middle::ty::{self, TyCtxt}; use rustc_middle::ty::{self, TyCtxt};
use rustc_session::lint::LintPass; use rustc_session::lint::LintPass;
@ -53,7 +54,7 @@ impl<'tcx, T: LateLintPass<'tcx>> LateContextAndPass<'tcx, T> {
/// Merge the lints specified by any lint attributes into the /// Merge the lints specified by any lint attributes into the
/// current lint context, call the provided function, then reset the /// current lint context, call the provided function, then reset the
/// lints in effect to their previous state. /// lints in effect to their previous state.
fn with_lint_attrs<F>(&mut self, id: hir::HirId, f: F) fn with_lint_attrs<F>(&mut self, id: HirId, f: F)
where where
F: FnOnce(&mut Self), F: FnOnce(&mut Self),
{ {
@ -81,7 +82,7 @@ impl<'tcx, T: LateLintPass<'tcx>> LateContextAndPass<'tcx, T> {
self.context.param_env = old_param_env; self.context.param_env = old_param_env;
} }
fn process_mod(&mut self, m: &'tcx hir::Mod<'tcx>, n: hir::HirId) { fn process_mod(&mut self, m: &'tcx hir::Mod<'tcx>, n: HirId) {
lint_callback!(self, check_mod, m, n); lint_callback!(self, check_mod, m, n);
hir_visit::walk_mod(self, m, n); hir_visit::walk_mod(self, m, n);
} }
@ -231,7 +232,7 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
hir_visit::walk_inf(self, inf); hir_visit::walk_inf(self, inf);
} }
fn visit_mod(&mut self, m: &'tcx hir::Mod<'tcx>, _: Span, n: hir::HirId) { fn visit_mod(&mut self, m: &'tcx hir::Mod<'tcx>, _: Span, n: HirId) {
if !self.context.only_module { if !self.context.only_module {
self.process_mod(m, n); self.process_mod(m, n);
} }
@ -305,7 +306,7 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
hir_visit::walk_lifetime(self, lt); hir_visit::walk_lifetime(self, lt);
} }
fn visit_path(&mut self, p: &hir::Path<'tcx>, id: hir::HirId) { fn visit_path(&mut self, p: &hir::Path<'tcx>, id: HirId) {
lint_callback!(self, check_path, p, id); lint_callback!(self, check_path, p, id);
hir_visit::walk_path(self, p); hir_visit::walk_path(self, p);
} }

View File

@ -10,7 +10,7 @@ use crate::ty::TyCtxt;
use rustc_data_structures::fx::FxIndexMap; use rustc_data_structures::fx::FxIndexMap;
use rustc_data_structures::unord::UnordMap; use rustc_data_structures::unord::UnordMap;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::{HirIdMap, Node}; use rustc_hir::{HirId, HirIdMap, Node};
use rustc_macros::HashStable; use rustc_macros::HashStable;
use rustc_span::{Span, DUMMY_SP}; use rustc_span::{Span, DUMMY_SP};
@ -164,10 +164,10 @@ impl Scope {
self.id self.id
} }
pub fn hir_id(&self, scope_tree: &ScopeTree) -> Option<hir::HirId> { pub fn hir_id(&self, scope_tree: &ScopeTree) -> Option<HirId> {
scope_tree scope_tree
.root_body .root_body
.map(|hir_id| hir::HirId { owner: hir_id.owner, local_id: self.item_local_id() }) .map(|hir_id| HirId { owner: hir_id.owner, local_id: self.item_local_id() })
} }
/// Returns the span of this `Scope`. Note that in general the /// Returns the span of this `Scope`. Note that in general the
@ -207,7 +207,7 @@ pub type ScopeDepth = u32;
#[derive(Default, Debug, HashStable)] #[derive(Default, Debug, HashStable)]
pub struct ScopeTree { pub struct ScopeTree {
/// If not empty, this body is the root of this region hierarchy. /// If not empty, this body is the root of this region hierarchy.
pub root_body: Option<hir::HirId>, pub root_body: Option<HirId>,
/// Maps from a scope ID to the enclosing scope id; /// Maps from a scope ID to the enclosing scope id;
/// this is usually corresponding to the lexical nesting, though /// this is usually corresponding to the lexical nesting, though
@ -341,11 +341,7 @@ impl ScopeTree {
self.var_map.insert(var, lifetime); self.var_map.insert(var, lifetime);
} }
pub fn record_rvalue_candidate( pub fn record_rvalue_candidate(&mut self, var: HirId, candidate_type: RvalueCandidateType) {
&mut self,
var: hir::HirId,
candidate_type: RvalueCandidateType,
) {
debug!("record_rvalue_candidate(var={var:?}, type={candidate_type:?})"); debug!("record_rvalue_candidate(var={var:?}, type={candidate_type:?})");
match &candidate_type { match &candidate_type {
RvalueCandidateType::Borrow { lifetime: Some(lifetime), .. } RvalueCandidateType::Borrow { lifetime: Some(lifetime), .. }

View File

@ -1545,7 +1545,7 @@ pub struct SourceScopeData<'tcx> {
#[derive(Clone, Debug, TyEncodable, TyDecodable, HashStable)] #[derive(Clone, Debug, TyEncodable, TyDecodable, HashStable)]
pub struct SourceScopeLocalData { pub struct SourceScopeLocalData {
/// An `HirId` with lint levels equivalent to this scope's lint levels. /// An `HirId` with lint levels equivalent to this scope's lint levels.
pub lint_root: hir::HirId, pub lint_root: HirId,
} }
/// A collection of projections into user types. /// A collection of projections into user types.

View File

@ -12,7 +12,7 @@ use rustc_ast::{InlineAsmOptions, InlineAsmTemplatePiece};
use rustc_errors::{DiagArgValue, IntoDiagArg}; use rustc_errors::{DiagArgValue, IntoDiagArg};
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def_id::DefId; use rustc_hir::def_id::DefId;
use rustc_hir::{BindingAnnotation, ByRef, MatchSource, RangeEnd}; use rustc_hir::{BindingAnnotation, ByRef, HirId, MatchSource, RangeEnd};
use rustc_index::newtype_index; use rustc_index::newtype_index;
use rustc_index::IndexVec; use rustc_index::IndexVec;
use rustc_middle::middle::region; use rustc_middle::middle::region;
@ -115,13 +115,13 @@ pub struct Param<'tcx> {
/// Whether this param is `self`, and how it is bound. /// Whether this param is `self`, and how it is bound.
pub self_kind: Option<hir::ImplicitSelfKind>, pub self_kind: Option<hir::ImplicitSelfKind>,
/// HirId for lints. /// HirId for lints.
pub hir_id: Option<hir::HirId>, pub hir_id: Option<HirId>,
} }
#[derive(Copy, Clone, Debug, HashStable)] #[derive(Copy, Clone, Debug, HashStable)]
pub enum LintLevel { pub enum LintLevel {
Inherited, Inherited,
Explicit(hir::HirId), Explicit(HirId),
} }
#[derive(Clone, Debug, HashStable)] #[derive(Clone, Debug, HashStable)]
@ -167,7 +167,7 @@ pub struct ClosureExpr<'tcx> {
pub args: UpvarArgs<'tcx>, pub args: UpvarArgs<'tcx>,
pub upvars: Box<[ExprId]>, pub upvars: Box<[ExprId]>,
pub movability: Option<hir::Movability>, pub movability: Option<hir::Movability>,
pub fake_reads: Vec<(ExprId, FakeReadCause, hir::HirId)>, pub fake_reads: Vec<(ExprId, FakeReadCause, HirId)>,
} }
#[derive(Clone, Debug, HashStable)] #[derive(Clone, Debug, HashStable)]
@ -184,7 +184,7 @@ pub enum BlockSafety {
/// A compiler-generated unsafe block /// A compiler-generated unsafe block
BuiltinUnsafe, BuiltinUnsafe,
/// An `unsafe` block. The `HirId` is the ID of the block. /// An `unsafe` block. The `HirId` is the ID of the block.
ExplicitUnsafe(hir::HirId), ExplicitUnsafe(HirId),
} }
#[derive(Clone, Debug, HashStable)] #[derive(Clone, Debug, HashStable)]
@ -233,7 +233,7 @@ pub enum StmtKind<'tcx> {
} }
#[derive(Clone, Debug, Copy, PartialEq, Eq, Hash, HashStable, TyEncodable, TyDecodable)] #[derive(Clone, Debug, Copy, PartialEq, Eq, Hash, HashStable, TyEncodable, TyDecodable)]
pub struct LocalVarId(pub hir::HirId); pub struct LocalVarId(pub HirId);
/// A THIR expression. /// A THIR expression.
#[derive(Clone, Debug, HashStable)] #[derive(Clone, Debug, HashStable)]
@ -356,7 +356,7 @@ pub enum ExprKind<'tcx> {
/// A `match` expression. /// A `match` expression.
Match { Match {
scrutinee: ExprId, scrutinee: ExprId,
scrutinee_hir_id: hir::HirId, scrutinee_hir_id: HirId,
arms: Box<[ArmId]>, arms: Box<[ArmId]>,
match_source: MatchSource, match_source: MatchSource,
}, },

View File

@ -19,6 +19,7 @@ use rustc_data_structures::sync::Lrc;
use rustc_errors::{Applicability, Diag, EmissionGuarantee}; use rustc_errors::{Applicability, Diag, EmissionGuarantee};
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def_id::DefId; use rustc_hir::def_id::DefId;
use rustc_hir::HirId;
use rustc_span::def_id::{LocalDefId, CRATE_DEF_ID}; use rustc_span::def_id::{LocalDefId, CRATE_DEF_ID};
use rustc_span::symbol::Symbol; use rustc_span::symbol::Symbol;
use rustc_span::{Span, DUMMY_SP}; use rustc_span::{Span, DUMMY_SP};
@ -262,10 +263,10 @@ pub enum ObligationCauseCode<'tcx> {
/// expression that caused the obligation, and the `usize` /// expression that caused the obligation, and the `usize`
/// indicates exactly which predicate it is in the list of /// indicates exactly which predicate it is in the list of
/// instantiated predicates. /// instantiated predicates.
ExprItemObligation(DefId, rustc_hir::HirId, usize), ExprItemObligation(DefId, HirId, usize),
/// Combines `ExprItemObligation` and `BindingObligation`. /// Combines `ExprItemObligation` and `BindingObligation`.
ExprBindingObligation(DefId, Span, rustc_hir::HirId, usize), ExprBindingObligation(DefId, Span, HirId, usize),
/// A type like `&'a T` is WF only if `T: 'a`. /// A type like `&'a T` is WF only if `T: 'a`.
ReferenceOutlivesReferent(Ty<'tcx>), ReferenceOutlivesReferent(Ty<'tcx>),
@ -287,9 +288,9 @@ pub enum ObligationCauseCode<'tcx> {
/// `S { ... }` must be `Sized`. /// `S { ... }` must be `Sized`.
StructInitializerSized, StructInitializerSized,
/// Type of each variable must be `Sized`. /// Type of each variable must be `Sized`.
VariableType(hir::HirId), VariableType(HirId),
/// Argument type must be `Sized`. /// Argument type must be `Sized`.
SizedArgumentType(Option<hir::HirId>), SizedArgumentType(Option<HirId>),
/// Return type must be `Sized`. /// Return type must be `Sized`.
SizedReturnType, SizedReturnType,
/// Return type of a call expression must be `Sized`. /// Return type of a call expression must be `Sized`.
@ -335,9 +336,9 @@ pub enum ObligationCauseCode<'tcx> {
FunctionArgumentObligation { FunctionArgumentObligation {
/// The node of the relevant argument in the function call. /// The node of the relevant argument in the function call.
arg_hir_id: hir::HirId, arg_hir_id: HirId,
/// The node of the function call. /// The node of the function call.
call_hir_id: hir::HirId, call_hir_id: HirId,
/// The obligation introduced by this argument. /// The obligation introduced by this argument.
parent_code: InternedObligationCauseCode<'tcx>, parent_code: InternedObligationCauseCode<'tcx>,
}, },
@ -402,18 +403,18 @@ pub enum ObligationCauseCode<'tcx> {
ReturnNoExpression, ReturnNoExpression,
/// `return` with an expression /// `return` with an expression
ReturnValue(hir::HirId), ReturnValue(HirId),
/// Opaque return type of this function /// Opaque return type of this function
OpaqueReturnType(Option<(Ty<'tcx>, Span)>), OpaqueReturnType(Option<(Ty<'tcx>, Span)>),
/// Block implicit return /// Block implicit return
BlockTailExpression(hir::HirId, hir::MatchSource), BlockTailExpression(HirId, hir::MatchSource),
/// #[feature(trivial_bounds)] is not enabled /// #[feature(trivial_bounds)] is not enabled
TrivialBound, TrivialBound,
AwaitableExpr(hir::HirId), AwaitableExpr(HirId),
ForLoopIterator, ForLoopIterator,
@ -431,8 +432,8 @@ pub enum ObligationCauseCode<'tcx> {
MatchImpl(ObligationCause<'tcx>, DefId), MatchImpl(ObligationCause<'tcx>, DefId),
BinOp { BinOp {
lhs_hir_id: hir::HirId, lhs_hir_id: HirId,
rhs_hir_id: Option<hir::HirId>, rhs_hir_id: Option<HirId>,
rhs_span: Option<Span>, rhs_span: Option<Span>,
rhs_is_lit: bool, rhs_is_lit: bool,
output_ty: Option<Ty<'tcx>>, output_ty: Option<Ty<'tcx>>,
@ -562,10 +563,10 @@ pub enum StatementAsExpression {
#[derive(Clone, Debug, PartialEq, Eq, HashStable, TyEncodable, TyDecodable)] #[derive(Clone, Debug, PartialEq, Eq, HashStable, TyEncodable, TyDecodable)]
#[derive(TypeVisitable, TypeFoldable)] #[derive(TypeVisitable, TypeFoldable)]
pub struct MatchExpressionArmCause<'tcx> { pub struct MatchExpressionArmCause<'tcx> {
pub arm_block_id: Option<hir::HirId>, pub arm_block_id: Option<HirId>,
pub arm_ty: Ty<'tcx>, pub arm_ty: Ty<'tcx>,
pub arm_span: Span, pub arm_span: Span,
pub prior_arm_block_id: Option<hir::HirId>, pub prior_arm_block_id: Option<HirId>,
pub prior_arm_ty: Ty<'tcx>, pub prior_arm_ty: Ty<'tcx>,
pub prior_arm_span: Span, pub prior_arm_span: Span,
pub scrut_span: Span, pub scrut_span: Span,
@ -578,8 +579,8 @@ pub struct MatchExpressionArmCause<'tcx> {
#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[derive(TypeFoldable, TypeVisitable, HashStable, TyEncodable, TyDecodable)] #[derive(TypeFoldable, TypeVisitable, HashStable, TyEncodable, TyDecodable)]
pub struct IfExpressionCause<'tcx> { pub struct IfExpressionCause<'tcx> {
pub then_id: hir::HirId, pub then_id: HirId,
pub else_id: hir::HirId, pub else_id: HirId,
pub then_ty: Ty<'tcx>, pub then_ty: Ty<'tcx>,
pub else_ty: Ty<'tcx>, pub else_ty: Ty<'tcx>,
pub outer_span: Option<Span>, pub outer_span: Option<Span>,

View File

@ -10,6 +10,7 @@ use rustc_data_structures::captures::Captures;
use rustc_data_structures::fx::FxIndexMap; use rustc_data_structures::fx::FxIndexMap;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def_id::LocalDefId; use rustc_hir::def_id::LocalDefId;
use rustc_hir::HirId;
use rustc_span::def_id::LocalDefIdMap; use rustc_span::def_id::LocalDefIdMap;
use rustc_span::symbol::Ident; use rustc_span::symbol::Ident;
use rustc_span::{Span, Symbol}; use rustc_span::{Span, Symbol};
@ -25,7 +26,7 @@ pub const CAPTURE_STRUCT_LOCAL: mir::Local = mir::Local::from_u32(1);
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, TyEncodable, TyDecodable, HashStable)] #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, TyEncodable, TyDecodable, HashStable)]
#[derive(TypeFoldable, TypeVisitable)] #[derive(TypeFoldable, TypeVisitable)]
pub struct UpvarPath { pub struct UpvarPath {
pub hir_id: hir::HirId, pub hir_id: HirId,
} }
/// Upvars do not get their own `NodeId`. Instead, we use the pair of /// Upvars do not get their own `NodeId`. Instead, we use the pair of
@ -39,7 +40,7 @@ pub struct UpvarId {
} }
impl UpvarId { impl UpvarId {
pub fn new(var_hir_id: hir::HirId, closure_def_id: LocalDefId) -> UpvarId { pub fn new(var_hir_id: HirId, closure_def_id: LocalDefId) -> UpvarId {
UpvarId { var_path: UpvarPath { hir_id: var_hir_id }, closure_expr_id: closure_def_id } UpvarId { var_path: UpvarPath { hir_id: var_hir_id }, closure_expr_id: closure_def_id }
} }
} }
@ -68,7 +69,7 @@ pub type MinCaptureInformationMap<'tcx> = LocalDefIdMap<RootVariableMinCaptureLi
/// ///
/// This provides a convenient and quick way of checking if a variable being used within /// This provides a convenient and quick way of checking if a variable being used within
/// a closure is a capture of a local variable. /// a closure is a capture of a local variable.
pub type RootVariableMinCaptureList<'tcx> = FxIndexMap<hir::HirId, MinCaptureList<'tcx>>; pub type RootVariableMinCaptureList<'tcx> = FxIndexMap<HirId, MinCaptureList<'tcx>>;
/// Part of `MinCaptureInformationMap`; List of `CapturePlace`s. /// Part of `MinCaptureInformationMap`; List of `CapturePlace`s.
pub type MinCaptureList<'tcx> = Vec<CapturedPlace<'tcx>>; pub type MinCaptureList<'tcx> = Vec<CapturedPlace<'tcx>>;
@ -135,7 +136,7 @@ impl<'tcx> CapturedPlace<'tcx> {
/// Returns the hir-id of the root variable for the captured place. /// Returns the hir-id of the root variable for the captured place.
/// e.g., if `a.b.c` was captured, would return the hir-id for `a`. /// e.g., if `a.b.c` was captured, would return the hir-id for `a`.
pub fn get_root_variable(&self) -> hir::HirId { pub fn get_root_variable(&self) -> HirId {
match self.place.base { match self.place.base {
HirPlaceBase::Upvar(upvar_id) => upvar_id.var_path.hir_id, HirPlaceBase::Upvar(upvar_id) => upvar_id.var_path.hir_id,
base => bug!("Expected upvar, found={:?}", base), base => bug!("Expected upvar, found={:?}", base),
@ -286,12 +287,12 @@ pub struct CaptureInfo {
/// ///
/// In this example, if `capture_disjoint_fields` is **not** set, then x will be captured, /// In this example, if `capture_disjoint_fields` is **not** set, then x will be captured,
/// but we won't see it being used during capture analysis, since it's essentially a discard. /// but we won't see it being used during capture analysis, since it's essentially a discard.
pub capture_kind_expr_id: Option<hir::HirId>, pub capture_kind_expr_id: Option<HirId>,
/// Expr Id pointing to use that resulted the corresponding place being captured /// Expr Id pointing to use that resulted the corresponding place being captured
/// ///
/// See `capture_kind_expr_id` for example. /// See `capture_kind_expr_id` for example.
/// ///
pub path_expr_id: Option<hir::HirId>, pub path_expr_id: Option<HirId>,
/// Capture mode that was selected /// Capture mode that was selected
pub capture_kind: UpvarCapture, pub capture_kind: UpvarCapture,

View File

@ -192,7 +192,7 @@ pub struct TypeckResults<'tcx> {
/// we never capture `t`. This becomes an issue when we build MIR as we require /// we never capture `t`. This becomes an issue when we build MIR as we require
/// information on `t` in order to create place `t.0` and `t.1`. We can solve this /// information on `t` in order to create place `t.0` and `t.1`. We can solve this
/// issue by fake reading `t`. /// issue by fake reading `t`.
pub closure_fake_reads: LocalDefIdMap<Vec<(HirPlace<'tcx>, FakeReadCause, hir::HirId)>>, pub closure_fake_reads: LocalDefIdMap<Vec<(HirPlace<'tcx>, FakeReadCause, HirId)>>,
/// Tracks the rvalue scoping rules which defines finer scoping for rvalue expressions /// Tracks the rvalue scoping rules which defines finer scoping for rvalue expressions
/// by applying extended parameter rules. /// by applying extended parameter rules.
@ -251,7 +251,7 @@ impl<'tcx> TypeckResults<'tcx> {
} }
/// Returns the final resolution of a `QPath` in an `Expr` or `Pat` node. /// Returns the final resolution of a `QPath` in an `Expr` or `Pat` node.
pub fn qpath_res(&self, qpath: &hir::QPath<'_>, id: hir::HirId) -> Res { pub fn qpath_res(&self, qpath: &hir::QPath<'_>, id: HirId) -> Res {
match *qpath { match *qpath {
hir::QPath::Resolved(_, path) => path.res, hir::QPath::Resolved(_, path) => path.res,
hir::QPath::TypeRelative(..) | hir::QPath::LangItem(..) => self hir::QPath::TypeRelative(..) | hir::QPath::LangItem(..) => self
@ -289,11 +289,11 @@ impl<'tcx> TypeckResults<'tcx> {
LocalTableInContextMut { hir_owner: self.hir_owner, data: &mut self.field_indices } LocalTableInContextMut { hir_owner: self.hir_owner, data: &mut self.field_indices }
} }
pub fn field_index(&self, id: hir::HirId) -> FieldIdx { pub fn field_index(&self, id: HirId) -> FieldIdx {
self.field_indices().get(id).cloned().expect("no index for a field") self.field_indices().get(id).cloned().expect("no index for a field")
} }
pub fn opt_field_index(&self, id: hir::HirId) -> Option<FieldIdx> { pub fn opt_field_index(&self, id: HirId) -> Option<FieldIdx> {
self.field_indices().get(id).cloned() self.field_indices().get(id).cloned()
} }
@ -305,7 +305,7 @@ impl<'tcx> TypeckResults<'tcx> {
LocalTableInContextMut { hir_owner: self.hir_owner, data: &mut self.nested_fields } LocalTableInContextMut { hir_owner: self.hir_owner, data: &mut self.nested_fields }
} }
pub fn nested_field_tys_and_indices(&self, id: hir::HirId) -> &[(Ty<'tcx>, FieldIdx)] { pub fn nested_field_tys_and_indices(&self, id: HirId) -> &[(Ty<'tcx>, FieldIdx)] {
self.nested_fields().get(id).map_or(&[], Vec::as_slice) self.nested_fields().get(id).map_or(&[], Vec::as_slice)
} }
@ -327,13 +327,13 @@ impl<'tcx> TypeckResults<'tcx> {
LocalTableInContextMut { hir_owner: self.hir_owner, data: &mut self.node_types } LocalTableInContextMut { hir_owner: self.hir_owner, data: &mut self.node_types }
} }
pub fn node_type(&self, id: hir::HirId) -> Ty<'tcx> { pub fn node_type(&self, id: HirId) -> Ty<'tcx> {
self.node_type_opt(id).unwrap_or_else(|| { self.node_type_opt(id).unwrap_or_else(|| {
bug!("node_type: no type for node {}", tls::with(|tcx| tcx.hir().node_to_string(id))) bug!("node_type: no type for node {}", tls::with(|tcx| tcx.hir().node_to_string(id)))
}) })
} }
pub fn node_type_opt(&self, id: hir::HirId) -> Option<Ty<'tcx>> { pub fn node_type_opt(&self, id: HirId) -> Option<Ty<'tcx>> {
validate_hir_id_for_typeck_results(self.hir_owner, id); validate_hir_id_for_typeck_results(self.hir_owner, id);
self.node_types.get(&id.local_id).cloned() self.node_types.get(&id.local_id).cloned()
} }
@ -342,12 +342,12 @@ impl<'tcx> TypeckResults<'tcx> {
LocalTableInContextMut { hir_owner: self.hir_owner, data: &mut self.node_args } LocalTableInContextMut { hir_owner: self.hir_owner, data: &mut self.node_args }
} }
pub fn node_args(&self, id: hir::HirId) -> GenericArgsRef<'tcx> { pub fn node_args(&self, id: HirId) -> GenericArgsRef<'tcx> {
validate_hir_id_for_typeck_results(self.hir_owner, id); validate_hir_id_for_typeck_results(self.hir_owner, id);
self.node_args.get(&id.local_id).cloned().unwrap_or_else(|| GenericArgs::empty()) self.node_args.get(&id.local_id).cloned().unwrap_or_else(|| GenericArgs::empty())
} }
pub fn node_args_opt(&self, id: hir::HirId) -> Option<GenericArgsRef<'tcx>> { pub fn node_args_opt(&self, id: HirId) -> Option<GenericArgsRef<'tcx>> {
validate_hir_id_for_typeck_results(self.hir_owner, id); validate_hir_id_for_typeck_results(self.hir_owner, id);
self.node_args.get(&id.local_id).cloned() self.node_args.get(&id.local_id).cloned()
} }
@ -512,7 +512,7 @@ impl<'tcx> TypeckResults<'tcx> {
LocalTableInContextMut { hir_owner: self.hir_owner, data: &mut self.fru_field_types } LocalTableInContextMut { hir_owner: self.hir_owner, data: &mut self.fru_field_types }
} }
pub fn is_coercion_cast(&self, hir_id: hir::HirId) -> bool { pub fn is_coercion_cast(&self, hir_id: HirId) -> bool {
validate_hir_id_for_typeck_results(self.hir_owner, hir_id); validate_hir_id_for_typeck_results(self.hir_owner, hir_id);
self.coercion_casts.contains(&hir_id.local_id) self.coercion_casts.contains(&hir_id.local_id)
} }
@ -546,7 +546,7 @@ impl<'tcx> TypeckResults<'tcx> {
/// would result in lookup errors, or worse, in silently wrong data being /// would result in lookup errors, or worse, in silently wrong data being
/// stored/returned. /// stored/returned.
#[inline] #[inline]
fn validate_hir_id_for_typeck_results(hir_owner: OwnerId, hir_id: hir::HirId) { fn validate_hir_id_for_typeck_results(hir_owner: OwnerId, hir_id: HirId) {
if hir_id.owner != hir_owner { if hir_id.owner != hir_owner {
invalid_hir_id_for_typeck_results(hir_owner, hir_id); invalid_hir_id_for_typeck_results(hir_owner, hir_id);
} }
@ -554,7 +554,7 @@ fn validate_hir_id_for_typeck_results(hir_owner: OwnerId, hir_id: hir::HirId) {
#[cold] #[cold]
#[inline(never)] #[inline(never)]
fn invalid_hir_id_for_typeck_results(hir_owner: OwnerId, hir_id: hir::HirId) { fn invalid_hir_id_for_typeck_results(hir_owner: OwnerId, hir_id: HirId) {
ty::tls::with(|tcx| { ty::tls::with(|tcx| {
bug!( bug!(
"node {} cannot be placed in TypeckResults with hir_owner {:?}", "node {} cannot be placed in TypeckResults with hir_owner {:?}",
@ -570,12 +570,12 @@ pub struct LocalTableInContext<'a, V> {
} }
impl<'a, V> LocalTableInContext<'a, V> { impl<'a, V> LocalTableInContext<'a, V> {
pub fn contains_key(&self, id: hir::HirId) -> bool { pub fn contains_key(&self, id: HirId) -> bool {
validate_hir_id_for_typeck_results(self.hir_owner, id); validate_hir_id_for_typeck_results(self.hir_owner, id);
self.data.contains_key(&id.local_id) self.data.contains_key(&id.local_id)
} }
pub fn get(&self, id: hir::HirId) -> Option<&'a V> { pub fn get(&self, id: HirId) -> Option<&'a V> {
validate_hir_id_for_typeck_results(self.hir_owner, id); validate_hir_id_for_typeck_results(self.hir_owner, id);
self.data.get(&id.local_id) self.data.get(&id.local_id)
} }
@ -592,10 +592,10 @@ impl<'a, V> LocalTableInContext<'a, V> {
} }
} }
impl<'a, V> ::std::ops::Index<hir::HirId> for LocalTableInContext<'a, V> { impl<'a, V> ::std::ops::Index<HirId> for LocalTableInContext<'a, V> {
type Output = V; type Output = V;
fn index(&self, key: hir::HirId) -> &V { fn index(&self, key: HirId) -> &V {
self.get(key).expect("LocalTableInContext: key not found") self.get(key).expect("LocalTableInContext: key not found")
} }
} }
@ -606,35 +606,32 @@ pub struct LocalTableInContextMut<'a, V> {
} }
impl<'a, V> LocalTableInContextMut<'a, V> { impl<'a, V> LocalTableInContextMut<'a, V> {
pub fn get_mut(&mut self, id: hir::HirId) -> Option<&mut V> { pub fn get_mut(&mut self, id: HirId) -> Option<&mut V> {
validate_hir_id_for_typeck_results(self.hir_owner, id); validate_hir_id_for_typeck_results(self.hir_owner, id);
self.data.get_mut(&id.local_id) self.data.get_mut(&id.local_id)
} }
pub fn get(&mut self, id: hir::HirId) -> Option<&V> { pub fn get(&mut self, id: HirId) -> Option<&V> {
validate_hir_id_for_typeck_results(self.hir_owner, id); validate_hir_id_for_typeck_results(self.hir_owner, id);
self.data.get(&id.local_id) self.data.get(&id.local_id)
} }
pub fn entry(&mut self, id: hir::HirId) -> Entry<'_, hir::ItemLocalId, V> { pub fn entry(&mut self, id: HirId) -> Entry<'_, hir::ItemLocalId, V> {
validate_hir_id_for_typeck_results(self.hir_owner, id); validate_hir_id_for_typeck_results(self.hir_owner, id);
self.data.entry(id.local_id) self.data.entry(id.local_id)
} }
pub fn insert(&mut self, id: hir::HirId, val: V) -> Option<V> { pub fn insert(&mut self, id: HirId, val: V) -> Option<V> {
validate_hir_id_for_typeck_results(self.hir_owner, id); validate_hir_id_for_typeck_results(self.hir_owner, id);
self.data.insert(id.local_id, val) self.data.insert(id.local_id, val)
} }
pub fn remove(&mut self, id: hir::HirId) -> Option<V> { pub fn remove(&mut self, id: HirId) -> Option<V> {
validate_hir_id_for_typeck_results(self.hir_owner, id); validate_hir_id_for_typeck_results(self.hir_owner, id);
self.data.remove(&id.local_id) self.data.remove(&id.local_id)
} }
pub fn extend( pub fn extend(&mut self, items: UnordItems<(HirId, V), impl Iterator<Item = (HirId, V)>>) {
&mut self,
items: UnordItems<(hir::HirId, V), impl Iterator<Item = (hir::HirId, V)>>,
) {
self.data.extend_unord(items.map(|(id, value)| { self.data.extend_unord(items.map(|(id, value)| {
validate_hir_id_for_typeck_results(self.hir_owner, id); validate_hir_id_for_typeck_results(self.hir_owner, id);
(id.local_id, value) (id.local_id, value)

View File

@ -9,7 +9,7 @@ use rustc_data_structures::sorted_map::SortedIndexMultiMap;
use rustc_errors::ErrorGuaranteed; use rustc_errors::ErrorGuaranteed;
use rustc_hir::def::DefKind; use rustc_hir::def::DefKind;
use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_hir::{self as hir, BindingAnnotation, ByRef, Node}; use rustc_hir::{self as hir, BindingAnnotation, ByRef, HirId, Node};
use rustc_index::bit_set::GrowableBitSet; use rustc_index::bit_set::GrowableBitSet;
use rustc_index::{Idx, IndexSlice, IndexVec}; use rustc_index::{Idx, IndexSlice, IndexVec};
use rustc_infer::infer::{InferCtxt, TyCtxtInferExt}; use rustc_infer::infer::{InferCtxt, TyCtxtInferExt};
@ -158,7 +158,7 @@ struct Builder<'a, 'tcx> {
cfg: CFG<'tcx>, cfg: CFG<'tcx>,
def_id: LocalDefId, def_id: LocalDefId,
hir_id: hir::HirId, hir_id: HirId,
parent_module: DefId, parent_module: DefId,
check_overflow: bool, check_overflow: bool,
fn_span: Span, fn_span: Span,
@ -222,7 +222,7 @@ struct Builder<'a, 'tcx> {
coverage_branch_info: Option<coverageinfo::BranchInfoBuilder>, coverage_branch_info: Option<coverageinfo::BranchInfoBuilder>,
} }
type CaptureMap<'tcx> = SortedIndexMultiMap<usize, hir::HirId, Capture<'tcx>>; type CaptureMap<'tcx> = SortedIndexMultiMap<usize, HirId, Capture<'tcx>>;
#[derive(Debug)] #[derive(Debug)]
struct Capture<'tcx> { struct Capture<'tcx> {
@ -721,7 +721,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
thir: &'a Thir<'tcx>, thir: &'a Thir<'tcx>,
infcx: InferCtxt<'tcx>, infcx: InferCtxt<'tcx>,
def: LocalDefId, def: LocalDefId,
hir_id: hir::HirId, hir_id: HirId,
span: Span, span: Span,
arg_count: usize, arg_count: usize,
return_ty: Ty<'tcx>, return_ty: Ty<'tcx>,
@ -981,7 +981,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
fn set_correct_source_scope_for_arg( fn set_correct_source_scope_for_arg(
&mut self, &mut self,
arg_hir_id: hir::HirId, arg_hir_id: HirId,
original_source_scope: SourceScope, original_source_scope: SourceScope,
pattern_span: Span, pattern_span: Span,
) { ) {

View File

@ -1,10 +1,8 @@
use std::borrow::Cow;
use crate::build::ExprCategory; use crate::build::ExprCategory;
use crate::errors::*; use crate::errors::*;
use rustc_errors::DiagArgValue; use rustc_errors::DiagArgValue;
use rustc_hir::{self as hir, BindingAnnotation, ByRef, Mutability}; use rustc_hir::{self as hir, BindingAnnotation, ByRef, HirId, Mutability};
use rustc_middle::mir::BorrowKind; use rustc_middle::mir::BorrowKind;
use rustc_middle::thir::visit::Visitor; use rustc_middle::thir::visit::Visitor;
use rustc_middle::thir::*; use rustc_middle::thir::*;
@ -16,6 +14,7 @@ use rustc_span::def_id::{DefId, LocalDefId};
use rustc_span::symbol::Symbol; use rustc_span::symbol::Symbol;
use rustc_span::{sym, Span}; use rustc_span::{sym, Span};
use std::borrow::Cow;
use std::mem; use std::mem;
use std::ops::Bound; use std::ops::Bound;
@ -24,7 +23,7 @@ struct UnsafetyVisitor<'a, 'tcx> {
thir: &'a Thir<'tcx>, thir: &'a Thir<'tcx>,
/// The `HirId` of the current scope, which would be the `HirId` /// The `HirId` of the current scope, which would be the `HirId`
/// of the current HIR node, modulo adjustments. Used for lint levels. /// of the current HIR node, modulo adjustments. Used for lint levels.
hir_context: hir::HirId, hir_context: HirId,
/// The current "safety context". This notably tracks whether we are in an /// The current "safety context". This notably tracks whether we are in an
/// `unsafe` block, and whether it has been used. /// `unsafe` block, and whether it has been used.
safety_context: SafetyContext, safety_context: SafetyContext,
@ -123,7 +122,7 @@ impl<'tcx> UnsafetyVisitor<'_, 'tcx> {
fn warn_unused_unsafe( fn warn_unused_unsafe(
&mut self, &mut self,
hir_id: hir::HirId, hir_id: HirId,
block_span: Span, block_span: Span,
enclosing_unsafe: Option<UnusedUnsafeEnclosing>, enclosing_unsafe: Option<UnusedUnsafeEnclosing>,
) { ) {
@ -537,22 +536,17 @@ enum SafetyContext {
Safe, Safe,
BuiltinUnsafeBlock, BuiltinUnsafeBlock,
UnsafeFn, UnsafeFn,
UnsafeBlock { UnsafeBlock { span: Span, hir_id: HirId, used: bool, nested_used_blocks: Vec<NestedUsedBlock> },
span: Span,
hir_id: hir::HirId,
used: bool,
nested_used_blocks: Vec<NestedUsedBlock>,
},
} }
#[derive(Clone, Copy)] #[derive(Clone, Copy)]
struct NestedUsedBlock { struct NestedUsedBlock {
hir_id: hir::HirId, hir_id: HirId,
span: Span, span: Span,
} }
struct UnusedUnsafeWarning { struct UnusedUnsafeWarning {
hir_id: hir::HirId, hir_id: HirId,
block_span: Span, block_span: Span,
enclosing_unsafe: Option<UnusedUnsafeEnclosing>, enclosing_unsafe: Option<UnusedUnsafeEnclosing>,
} }
@ -585,7 +579,7 @@ impl UnsafeOpKind {
pub fn emit_unsafe_op_in_unsafe_fn_lint( pub fn emit_unsafe_op_in_unsafe_fn_lint(
&self, &self,
tcx: TyCtxt<'_>, tcx: TyCtxt<'_>,
hir_id: hir::HirId, hir_id: HirId,
span: Span, span: Span,
suggest_unsafe_block: bool, suggest_unsafe_block: bool,
) { ) {
@ -726,7 +720,7 @@ impl UnsafeOpKind {
&self, &self,
tcx: TyCtxt<'_>, tcx: TyCtxt<'_>,
span: Span, span: Span,
hir_context: hir::HirId, hir_context: HirId,
unsafe_op_in_unsafe_fn_allowed: bool, unsafe_op_in_unsafe_fn_allowed: bool,
) { ) {
let note_non_inherited = tcx.hir().parent_iter(hir_context).find(|(id, node)| { let note_non_inherited = tcx.hir().parent_iter(hir_context).find(|(id, node)| {

View File

@ -389,7 +389,7 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> {
hir_visit::walk_fn(self, fk, fd, b, id) hir_visit::walk_fn(self, fk, fd, b, id)
} }
fn visit_use(&mut self, p: &'v hir::UsePath<'v>, hir_id: hir::HirId) { fn visit_use(&mut self, p: &'v hir::UsePath<'v>, hir_id: HirId) {
// This is `visit_use`, but the type is `Path` so record it that way. // This is `visit_use`, but the type is `Path` so record it that way.
self.record("Path", Id::None, p); self.record("Path", Id::None, p);
hir_visit::walk_use(self, p, hir_id) hir_visit::walk_use(self, p, hir_id)
@ -462,7 +462,7 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> {
hir_visit::walk_lifetime(self, lifetime) hir_visit::walk_lifetime(self, lifetime)
} }
fn visit_path(&mut self, path: &hir::Path<'v>, _id: hir::HirId) { fn visit_path(&mut self, path: &hir::Path<'v>, _id: HirId) {
self.record("Path", Id::None, path); self.record("Path", Id::None, path);
hir_visit::walk_path(self, path) hir_visit::walk_path(self, path)
} }

View File

@ -602,7 +602,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
String::from_utf8(wr).unwrap() String::from_utf8(wr).unwrap()
} }
fn log_liveness(&self, entry_ln: LiveNode, hir_id: hir::HirId) { fn log_liveness(&self, entry_ln: LiveNode, hir_id: HirId) {
// hack to skip the loop unless debug! is enabled: // hack to skip the loop unless debug! is enabled:
debug!( debug!(
"^^ liveness computation results for body {} (entry={:?})", "^^ liveness computation results for body {} (entry={:?})",

View File

@ -5,7 +5,7 @@ use rustc_hir as hir;
use rustc_hir::def::DefKind; use rustc_hir::def::DefKind;
use rustc_hir::def_id::{LocalDefId, LocalModDefId}; use rustc_hir::def_id::{LocalDefId, LocalModDefId};
use rustc_hir::intravisit::Visitor; use rustc_hir::intravisit::Visitor;
use rustc_hir::{ExprKind, InlineAsmOperand, StmtKind}; use rustc_hir::{ExprKind, HirIdSet, InlineAsmOperand, StmtKind};
use rustc_middle::query::Providers; use rustc_middle::query::Providers;
use rustc_middle::ty::TyCtxt; use rustc_middle::ty::TyCtxt;
use rustc_session::lint::builtin::UNDEFINED_NAKED_FUNCTION_ABI; use rustc_session::lint::builtin::UNDEFINED_NAKED_FUNCTION_ABI;
@ -94,7 +94,7 @@ fn check_no_patterns(tcx: TyCtxt<'_>, params: &[hir::Param<'_>]) {
/// Checks that function parameters aren't used in the function body. /// Checks that function parameters aren't used in the function body.
fn check_no_parameters_use<'tcx>(tcx: TyCtxt<'tcx>, body: &'tcx hir::Body<'tcx>) { fn check_no_parameters_use<'tcx>(tcx: TyCtxt<'tcx>, body: &'tcx hir::Body<'tcx>) {
let mut params = hir::HirIdSet::default(); let mut params = HirIdSet::default();
for param in body.params { for param in body.params {
param.pat.each_binding(|_binding_mode, hir_id, _span, _ident| { param.pat.each_binding(|_binding_mode, hir_id, _span, _ident| {
params.insert(hir_id); params.insert(hir_id);
@ -105,7 +105,7 @@ fn check_no_parameters_use<'tcx>(tcx: TyCtxt<'tcx>, body: &'tcx hir::Body<'tcx>)
struct CheckParameters<'tcx> { struct CheckParameters<'tcx> {
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
params: hir::HirIdSet, params: HirIdSet,
} }
impl<'tcx> Visitor<'tcx> for CheckParameters<'tcx> { impl<'tcx> Visitor<'tcx> for CheckParameters<'tcx> {

View File

@ -66,7 +66,7 @@ impl CaptureCollector<'_, '_> {
} }
impl<'tcx> Visitor<'tcx> for CaptureCollector<'_, 'tcx> { impl<'tcx> Visitor<'tcx> for CaptureCollector<'_, 'tcx> {
fn visit_path(&mut self, path: &hir::Path<'tcx>, _: hir::HirId) { fn visit_path(&mut self, path: &hir::Path<'tcx>, _: HirId) {
if let Res::Local(var_id) = path.res { if let Res::Local(var_id) = path.res {
self.visit_local_use(var_id, path.span); self.visit_local_use(var_id, path.span);
} }

View File

@ -4251,7 +4251,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
type_diffs: &[TypeError<'tcx>], type_diffs: &[TypeError<'tcx>],
span: Span, span: Span,
prev_ty: Ty<'tcx>, prev_ty: Ty<'tcx>,
body_id: hir::HirId, body_id: HirId,
param_env: ty::ParamEnv<'tcx>, param_env: ty::ParamEnv<'tcx>,
) -> Vec<Option<(Span, (DefId, Ty<'tcx>))>> { ) -> Vec<Option<(Span, (DefId, Ty<'tcx>))>> {
let ocx = ObligationCtxt::new(self.infcx); let ocx = ObligationCtxt::new(self.infcx);
@ -4757,7 +4757,7 @@ impl<'v> Visitor<'v> for ReturnsVisitor<'v> {
/// Collect all the awaited expressions within the input expression. /// Collect all the awaited expressions within the input expression.
#[derive(Default)] #[derive(Default)]
struct AwaitsVisitor { struct AwaitsVisitor {
awaits: Vec<hir::HirId>, awaits: Vec<HirId>,
} }
impl<'v> Visitor<'v> for AwaitsVisitor { impl<'v> Visitor<'v> for AwaitsVisitor {

View File

@ -1,4 +1,4 @@
use rustc_hir::{self as hir, intravisit, HirIdSet}; use rustc_hir::{self as hir, intravisit, HirId, HirIdSet};
use rustc_lint::LateContext; use rustc_lint::LateContext;
use rustc_middle::ty; use rustc_middle::ty;
use rustc_span::def_id::LocalDefId; use rustc_span::def_id::LocalDefId;
@ -74,7 +74,7 @@ fn check_raw_ptr<'tcx>(
} }
} }
fn raw_ptr_arg(cx: &LateContext<'_>, arg: &hir::Param<'_>) -> Option<hir::HirId> { fn raw_ptr_arg(cx: &LateContext<'_>, arg: &hir::Param<'_>) -> Option<HirId> {
if let (&hir::PatKind::Binding(_, id, _, _), Some(&ty::RawPtr(_, _))) = ( if let (&hir::PatKind::Binding(_, id, _, _), Some(&ty::RawPtr(_, _))) = (
&arg.pat.kind, &arg.pat.kind,
cx.maybe_typeck_results() cx.maybe_typeck_results()

View File

@ -7,6 +7,7 @@ use clippy_utils::{is_expn_of, is_lint_allowed, path_to_local};
use rustc_data_structures::fx::{FxHashSet, FxIndexMap}; use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::HirId;
use rustc_hir::intravisit::{self, Visitor}; use rustc_hir::intravisit::{self, Visitor};
use rustc_lint::{LateContext, LateLintPass}; use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::hir::nested_filter; use rustc_middle::hir::nested_filter;
@ -87,9 +88,9 @@ impl<'tcx> LateLintPass<'tcx> for IndexRefutableSlice {
extract_msrv_attr!(LateContext); extract_msrv_attr!(LateContext);
} }
fn find_slice_values(cx: &LateContext<'_>, pat: &hir::Pat<'_>) -> FxIndexMap<hir::HirId, SliceLintInformation> { fn find_slice_values(cx: &LateContext<'_>, pat: &hir::Pat<'_>) -> FxIndexMap<HirId, SliceLintInformation> {
let mut removed_pat: FxHashSet<hir::HirId> = FxHashSet::default(); let mut removed_pat: FxHashSet<HirId> = FxHashSet::default();
let mut slices: FxIndexMap<hir::HirId, SliceLintInformation> = FxIndexMap::default(); let mut slices: FxIndexMap<HirId, SliceLintInformation> = FxIndexMap::default();
pat.walk_always(|pat| { pat.walk_always(|pat| {
// We'll just ignore mut and ref mut for simplicity sake right now // We'll just ignore mut and ref mut for simplicity sake right now
if let hir::PatKind::Binding( if let hir::PatKind::Binding(
@ -206,10 +207,10 @@ impl SliceLintInformation {
fn filter_lintable_slices<'tcx>( fn filter_lintable_slices<'tcx>(
cx: &LateContext<'tcx>, cx: &LateContext<'tcx>,
slice_lint_info: FxIndexMap<hir::HirId, SliceLintInformation>, slice_lint_info: FxIndexMap<HirId, SliceLintInformation>,
max_suggested_slice: u64, max_suggested_slice: u64,
scope: &'tcx hir::Expr<'tcx>, scope: &'tcx hir::Expr<'tcx>,
) -> FxIndexMap<hir::HirId, SliceLintInformation> { ) -> FxIndexMap<HirId, SliceLintInformation> {
let mut visitor = SliceIndexLintingVisitor { let mut visitor = SliceIndexLintingVisitor {
cx, cx,
slice_lint_info, slice_lint_info,
@ -223,7 +224,7 @@ fn filter_lintable_slices<'tcx>(
struct SliceIndexLintingVisitor<'a, 'tcx> { struct SliceIndexLintingVisitor<'a, 'tcx> {
cx: &'a LateContext<'tcx>, cx: &'a LateContext<'tcx>,
slice_lint_info: FxIndexMap<hir::HirId, SliceLintInformation>, slice_lint_info: FxIndexMap<HirId, SliceLintInformation>,
max_suggested_slice: u64, max_suggested_slice: u64,
} }

View File

@ -6,6 +6,7 @@ use clippy_utils::{binop_traits, eq_expr_value, trait_ref_of_method};
use core::ops::ControlFlow; use core::ops::ControlFlow;
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::{HirId, HirIdSet};
use rustc_hir_typeck::expr_use_visitor::{Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId}; use rustc_hir_typeck::expr_use_visitor::{Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId};
use rustc_lint::LateContext; use rustc_lint::LateContext;
use rustc_middle::mir::FakeReadCause; use rustc_middle::mir::FakeReadCause;
@ -98,10 +99,10 @@ pub(super) fn check<'tcx>(
} }
} }
fn imm_borrows_in_expr(cx: &LateContext<'_>, e: &hir::Expr<'_>) -> hir::HirIdSet { fn imm_borrows_in_expr(cx: &LateContext<'_>, e: &hir::Expr<'_>) -> HirIdSet {
struct S(hir::HirIdSet); struct S(HirIdSet);
impl Delegate<'_> for S { impl Delegate<'_> for S {
fn borrow(&mut self, place: &PlaceWithHirId<'_>, _: hir::HirId, kind: BorrowKind) { fn borrow(&mut self, place: &PlaceWithHirId<'_>, _: HirId, kind: BorrowKind) {
if matches!(kind, BorrowKind::ImmBorrow | BorrowKind::UniqueImmBorrow) { if matches!(kind, BorrowKind::ImmBorrow | BorrowKind::UniqueImmBorrow) {
self.0.insert(match place.place.base { self.0.insert(match place.place.base {
PlaceBase::Local(id) => id, PlaceBase::Local(id) => id,
@ -111,13 +112,13 @@ fn imm_borrows_in_expr(cx: &LateContext<'_>, e: &hir::Expr<'_>) -> hir::HirIdSet
} }
} }
fn consume(&mut self, _: &PlaceWithHirId<'_>, _: hir::HirId) {} fn consume(&mut self, _: &PlaceWithHirId<'_>, _: HirId) {}
fn mutate(&mut self, _: &PlaceWithHirId<'_>, _: hir::HirId) {} fn mutate(&mut self, _: &PlaceWithHirId<'_>, _: HirId) {}
fn fake_read(&mut self, _: &PlaceWithHirId<'_>, _: FakeReadCause, _: hir::HirId) {} fn fake_read(&mut self, _: &PlaceWithHirId<'_>, _: FakeReadCause, _: HirId) {}
fn copy(&mut self, _: &PlaceWithHirId<'_>, _: hir::HirId) {} fn copy(&mut self, _: &PlaceWithHirId<'_>, _: HirId) {}
} }
let mut s = S(hir::HirIdSet::default()); let mut s = S(HirIdSet::default());
let infcx = cx.tcx.infer_ctxt().build(); let infcx = cx.tcx.infer_ctxt().build();
let mut v = ExprUseVisitor::new( let mut v = ExprUseVisitor::new(
&mut s, &mut s,
@ -130,10 +131,10 @@ fn imm_borrows_in_expr(cx: &LateContext<'_>, e: &hir::Expr<'_>) -> hir::HirIdSet
s.0 s.0
} }
fn mut_borrows_in_expr(cx: &LateContext<'_>, e: &hir::Expr<'_>) -> hir::HirIdSet { fn mut_borrows_in_expr(cx: &LateContext<'_>, e: &hir::Expr<'_>) -> HirIdSet {
struct S(hir::HirIdSet); struct S(HirIdSet);
impl Delegate<'_> for S { impl Delegate<'_> for S {
fn borrow(&mut self, place: &PlaceWithHirId<'_>, _: hir::HirId, kind: BorrowKind) { fn borrow(&mut self, place: &PlaceWithHirId<'_>, _: HirId, kind: BorrowKind) {
if matches!(kind, BorrowKind::MutBorrow) { if matches!(kind, BorrowKind::MutBorrow) {
self.0.insert(match place.place.base { self.0.insert(match place.place.base {
PlaceBase::Local(id) => id, PlaceBase::Local(id) => id,
@ -143,13 +144,13 @@ fn mut_borrows_in_expr(cx: &LateContext<'_>, e: &hir::Expr<'_>) -> hir::HirIdSet
} }
} }
fn consume(&mut self, _: &PlaceWithHirId<'_>, _: hir::HirId) {} fn consume(&mut self, _: &PlaceWithHirId<'_>, _: HirId) {}
fn mutate(&mut self, _: &PlaceWithHirId<'_>, _: hir::HirId) {} fn mutate(&mut self, _: &PlaceWithHirId<'_>, _: HirId) {}
fn fake_read(&mut self, _: &PlaceWithHirId<'_>, _: FakeReadCause, _: hir::HirId) {} fn fake_read(&mut self, _: &PlaceWithHirId<'_>, _: FakeReadCause, _: HirId) {}
fn copy(&mut self, _: &PlaceWithHirId<'_>, _: hir::HirId) {} fn copy(&mut self, _: &PlaceWithHirId<'_>, _: HirId) {}
} }
let mut s = S(hir::HirIdSet::default()); let mut s = S(HirIdSet::default());
let infcx = cx.tcx.infer_ctxt().build(); let infcx = cx.tcx.infer_ctxt().build();
let mut v = ExprUseVisitor::new( let mut v = ExprUseVisitor::new(
&mut s, &mut s,

View File

@ -8,7 +8,7 @@ use clippy_utils::{get_expr_use_or_unification_node, is_lint_allowed, path_def_i
use hir::LifetimeName; use hir::LifetimeName;
use rustc_errors::{Applicability, MultiSpan}; use rustc_errors::{Applicability, MultiSpan};
use rustc_hir::def_id::DefId; use rustc_hir::def_id::DefId;
use rustc_hir::hir_id::HirIdMap; use rustc_hir::hir_id::{HirId, HirIdMap};
use rustc_hir::intravisit::{walk_expr, Visitor}; use rustc_hir::intravisit::{walk_expr, Visitor};
use rustc_hir::{ use rustc_hir::{
self as hir, AnonConst, BinOpKind, BindingAnnotation, Body, Expr, ExprKind, FnRetTy, FnSig, GenericArg, self as hir, AnonConst, BinOpKind, BindingAnnotation, Body, Expr, ExprKind, FnRetTy, FnSig, GenericArg,
@ -324,7 +324,7 @@ struct PtrArgReplacement {
struct PtrArg<'tcx> { struct PtrArg<'tcx> {
idx: usize, idx: usize,
emission_id: hir::HirId, emission_id: HirId,
span: Span, span: Span,
ty_did: DefId, ty_did: DefId,
ty_name: Symbol, ty_name: Symbol,

View File

@ -5,7 +5,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap};
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_hir::def::{DefKind, Res}; use rustc_hir::def::{DefKind, Res};
use rustc_hir::intravisit::{walk_expr, Visitor}; use rustc_hir::intravisit::{walk_expr, Visitor};
use rustc_hir::{self as hir}; use rustc_hir::{self as hir, HirId};
use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::ty::{GenericArgKind, Ty}; use rustc_middle::ty::{GenericArgKind, Ty};
use rustc_session::impl_lint_pass; use rustc_session::impl_lint_pass;
@ -55,7 +55,7 @@ impl_lint_pass!(SignificantDropTightening<'_> => [SIGNIFICANT_DROP_TIGHTENING]);
#[derive(Default)] #[derive(Default)]
pub struct SignificantDropTightening<'tcx> { pub struct SignificantDropTightening<'tcx> {
apas: FxIndexMap<hir::HirId, AuxParamsAttr>, apas: FxIndexMap<HirId, AuxParamsAttr>,
/// Auxiliary structure used to avoid having to verify the same type multiple times. /// Auxiliary structure used to avoid having to verify the same type multiple times.
seen_types: FxHashSet<Ty<'tcx>>, seen_types: FxHashSet<Ty<'tcx>>,
type_cache: FxHashMap<Ty<'tcx>, bool>, type_cache: FxHashMap<Ty<'tcx>, bool>,
@ -359,9 +359,9 @@ impl<'ap, 'lc, 'others, 'stmt, 'tcx> Visitor<'tcx> for StmtsChecker<'ap, 'lc, 'o
/// Auxiliary parameters used on each block check of an item /// Auxiliary parameters used on each block check of an item
struct AuxParams<'others, 'stmt, 'tcx> { struct AuxParams<'others, 'stmt, 'tcx> {
//// See [AuxParamsAttr]. //// See [AuxParamsAttr].
apas: &'others mut FxIndexMap<hir::HirId, AuxParamsAttr>, apas: &'others mut FxIndexMap<HirId, AuxParamsAttr>,
/// The current block identifier that is being visited. /// The current block identifier that is being visited.
curr_block_hir_id: hir::HirId, curr_block_hir_id: HirId,
/// The current block span that is being visited. /// The current block span that is being visited.
curr_block_span: Span, curr_block_span: Span,
/// The current statement that is being visited. /// The current statement that is being visited.
@ -369,10 +369,10 @@ struct AuxParams<'others, 'stmt, 'tcx> {
} }
impl<'others, 'stmt, 'tcx> AuxParams<'others, 'stmt, 'tcx> { impl<'others, 'stmt, 'tcx> AuxParams<'others, 'stmt, 'tcx> {
fn new(apas: &'others mut FxIndexMap<hir::HirId, AuxParamsAttr>, curr_stmt: &'stmt hir::Stmt<'tcx>) -> Self { fn new(apas: &'others mut FxIndexMap<HirId, AuxParamsAttr>, curr_stmt: &'stmt hir::Stmt<'tcx>) -> Self {
Self { Self {
apas, apas,
curr_block_hir_id: hir::HirId::INVALID, curr_block_hir_id: HirId::INVALID,
curr_block_span: DUMMY_SP, curr_block_span: DUMMY_SP,
curr_stmt: Cow::Borrowed(curr_stmt), curr_stmt: Cow::Borrowed(curr_stmt),
} }
@ -389,7 +389,7 @@ struct AuxParamsAttr {
has_expensive_expr_after_last_attr: bool, has_expensive_expr_after_last_attr: bool,
/// The identifier of the block that involves the first `#[has_significant_drop]`. /// The identifier of the block that involves the first `#[has_significant_drop]`.
first_block_hir_id: hir::HirId, first_block_hir_id: HirId,
/// The span of the block that involves the first `#[has_significant_drop]`. /// The span of the block that involves the first `#[has_significant_drop]`.
first_block_span: Span, first_block_span: Span,
/// The binding or variable that references the initial construction of the type marked with /// The binding or variable that references the initial construction of the type marked with
@ -414,7 +414,7 @@ impl Default for AuxParamsAttr {
Self { Self {
counter: 0, counter: 0,
has_expensive_expr_after_last_attr: false, has_expensive_expr_after_last_attr: false,
first_block_hir_id: hir::HirId::INVALID, first_block_hir_id: HirId::INVALID,
first_bind_ident: Ident::empty(), first_bind_ident: Ident::empty(),
first_block_span: DUMMY_SP, first_block_span: DUMMY_SP,
first_method_span: DUMMY_SP, first_method_span: DUMMY_SP,
@ -428,7 +428,7 @@ impl Default for AuxParamsAttr {
fn dummy_stmt_expr<'any>(expr: &'any hir::Expr<'any>) -> hir::Stmt<'any> { fn dummy_stmt_expr<'any>(expr: &'any hir::Expr<'any>) -> hir::Stmt<'any> {
hir::Stmt { hir::Stmt {
hir_id: hir::HirId::INVALID, hir_id: HirId::INVALID,
kind: hir::StmtKind::Expr(expr), kind: hir::StmtKind::Expr(expr),
span: DUMMY_SP, span: DUMMY_SP,
} }