Skip to content

Commit 55a92cf

Browse files
committed
Avoid lots of hir::HirId{,Map,Set} qualifiers.
Because they're a bit redundant.
1 parent eba9934 commit 55a92cf

File tree

39 files changed

+301
-337
lines changed

39 files changed

+301
-337
lines changed

compiler/rustc_ast_lowering/src/expr.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use rustc_ast::*;
1414
use rustc_data_structures::stack::ensure_sufficient_stack;
1515
use rustc_hir as hir;
1616
use rustc_hir::def::{DefKind, Res};
17+
use rustc_hir::HirId;
1718
use rustc_middle::span_bug;
1819
use rustc_session::errors::report_lit_error;
1920
use rustc_span::source_map::{respan, Spanned};
@@ -698,8 +699,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
698699
pub(super) fn maybe_forward_track_caller(
699700
&mut self,
700701
span: Span,
701-
outer_hir_id: hir::HirId,
702-
inner_hir_id: hir::HirId,
702+
outer_hir_id: HirId,
703+
inner_hir_id: HirId,
703704
) {
704705
if self.tcx.features().async_fn_track_caller
705706
&& let Some(attrs) = self.attrs.get(&outer_hir_id.local_id)
@@ -1045,7 +1046,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
10451046
binder: &ClosureBinder,
10461047
capture_clause: CaptureBy,
10471048
closure_id: NodeId,
1048-
closure_hir_id: hir::HirId,
1049+
closure_hir_id: HirId,
10491050
coroutine_kind: CoroutineKind,
10501051
decl: &FnDecl,
10511052
body: &Expr,
@@ -2033,7 +2034,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
20332034
&mut self,
20342035
sp: Span,
20352036
ident: Ident,
2036-
binding: hir::HirId,
2037+
binding: HirId,
20372038
) -> &'hir hir::Expr<'hir> {
20382039
self.arena.alloc(self.expr_ident_mut(sp, ident, binding))
20392040
}
@@ -2042,7 +2043,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
20422043
&mut self,
20432044
span: Span,
20442045
ident: Ident,
2045-
binding: hir::HirId,
2046+
binding: HirId,
20462047
) -> hir::Expr<'hir> {
20472048
let hir_id = self.next_id();
20482049
let res = Res::Local(binding);

compiler/rustc_ast_lowering/src/lib.rs

+15-22
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ use rustc_hir as hir;
5656
use rustc_hir::def::{DefKind, LifetimeRes, Namespace, PartialRes, PerNS, Res};
5757
use rustc_hir::def_id::{LocalDefId, LocalDefIdMap, CRATE_DEF_ID, LOCAL_CRATE};
5858
use rustc_hir::{
59-
ConstArg, GenericArg, ItemLocalMap, MissingLifetimeKind, ParamName, TraitCandidate,
59+
ConstArg, GenericArg, HirId, ItemLocalMap, MissingLifetimeKind, ParamName, TraitCandidate,
6060
};
6161
use rustc_index::{Idx, IndexSlice, IndexVec};
6262
use rustc_macros::extension;
@@ -107,7 +107,7 @@ struct LoweringContext<'a, 'hir> {
107107

108108
/// When inside an `async` context, this is the `HirId` of the
109109
/// `task_context` local bound to the resume argument of the coroutine.
110-
task_context: Option<hir::HirId>,
110+
task_context: Option<HirId>,
111111

112112
/// Used to get the current `fn`'s def span to point to when using `await`
113113
/// outside of an `async fn`.
@@ -661,18 +661,16 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
661661
/// `HirIdValidator` later on, which makes sure that all `NodeId`s got mapped
662662
/// properly. Calling the method twice with the same `NodeId` is fine though.
663663
#[instrument(level = "debug", skip(self), ret)]
664-
fn lower_node_id(&mut self, ast_node_id: NodeId) -> hir::HirId {
664+
fn lower_node_id(&mut self, ast_node_id: NodeId) -> HirId {
665665
assert_ne!(ast_node_id, DUMMY_NODE_ID);
666666

667667
match self.node_id_to_local_id.entry(ast_node_id) {
668-
Entry::Occupied(o) => {
669-
hir::HirId { owner: self.current_hir_id_owner, local_id: *o.get() }
670-
}
668+
Entry::Occupied(o) => HirId { owner: self.current_hir_id_owner, local_id: *o.get() },
671669
Entry::Vacant(v) => {
672670
// Generate a new `HirId`.
673671
let owner = self.current_hir_id_owner;
674672
let local_id = self.item_local_id_counter;
675-
let hir_id = hir::HirId { owner, local_id };
673+
let hir_id = HirId { owner, local_id };
676674

677675
v.insert(local_id);
678676
self.item_local_id_counter.increment_by(1);
@@ -693,20 +691,20 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
693691

694692
/// Generate a new `HirId` without a backing `NodeId`.
695693
#[instrument(level = "debug", skip(self), ret)]
696-
fn next_id(&mut self) -> hir::HirId {
694+
fn next_id(&mut self) -> HirId {
697695
let owner = self.current_hir_id_owner;
698696
let local_id = self.item_local_id_counter;
699697
assert_ne!(local_id, hir::ItemLocalId::new(0));
700698
self.item_local_id_counter.increment_by(1);
701-
hir::HirId { owner, local_id }
699+
HirId { owner, local_id }
702700
}
703701

704702
#[instrument(level = "trace", skip(self))]
705703
fn lower_res(&mut self, res: Res<NodeId>) -> Res {
706704
let res: Result<Res, ()> = res.apply_id(|id| {
707705
let owner = self.current_hir_id_owner;
708706
let local_id = self.node_id_to_local_id.get(&id).copied().ok_or(())?;
709-
Ok(hir::HirId { owner, local_id })
707+
Ok(HirId { owner, local_id })
710708
});
711709
trace!(?res);
712710

@@ -889,7 +887,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
889887
ret
890888
}
891889

892-
fn lower_attrs(&mut self, id: hir::HirId, attrs: &[Attribute]) -> Option<&'hir [Attribute]> {
890+
fn lower_attrs(&mut self, id: HirId, attrs: &[Attribute]) -> Option<&'hir [Attribute]> {
893891
if attrs.is_empty() {
894892
None
895893
} else {
@@ -921,7 +919,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
921919
Attribute { kind, id: attr.id, style: attr.style, span: self.lower_span(attr.span) }
922920
}
923921

924-
fn alias_attrs(&mut self, id: hir::HirId, target_id: hir::HirId) {
922+
fn alias_attrs(&mut self, id: HirId, target_id: HirId) {
925923
debug_assert_eq!(id.owner, self.current_hir_id_owner);
926924
debug_assert_eq!(target_id.owner, self.current_hir_id_owner);
927925
if let Some(&a) = self.attrs.get(&target_id.local_id) {
@@ -2418,11 +2416,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
24182416
self.pat(span, hir::PatKind::Struct(qpath, fields, false))
24192417
}
24202418

2421-
fn pat_ident(&mut self, span: Span, ident: Ident) -> (&'hir hir::Pat<'hir>, hir::HirId) {
2419+
fn pat_ident(&mut self, span: Span, ident: Ident) -> (&'hir hir::Pat<'hir>, HirId) {
24222420
self.pat_ident_binding_mode(span, ident, hir::BindingAnnotation::NONE)
24232421
}
24242422

2425-
fn pat_ident_mut(&mut self, span: Span, ident: Ident) -> (hir::Pat<'hir>, hir::HirId) {
2423+
fn pat_ident_mut(&mut self, span: Span, ident: Ident) -> (hir::Pat<'hir>, HirId) {
24262424
self.pat_ident_binding_mode_mut(span, ident, hir::BindingAnnotation::NONE)
24272425
}
24282426

@@ -2431,7 +2429,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
24312429
span: Span,
24322430
ident: Ident,
24332431
bm: hir::BindingAnnotation,
2434-
) -> (&'hir hir::Pat<'hir>, hir::HirId) {
2432+
) -> (&'hir hir::Pat<'hir>, HirId) {
24352433
let (pat, hir_id) = self.pat_ident_binding_mode_mut(span, ident, bm);
24362434
(self.arena.alloc(pat), hir_id)
24372435
}
@@ -2441,7 +2439,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
24412439
span: Span,
24422440
ident: Ident,
24432441
bm: hir::BindingAnnotation,
2444-
) -> (hir::Pat<'hir>, hir::HirId) {
2442+
) -> (hir::Pat<'hir>, HirId) {
24452443
let hir_id = self.next_id();
24462444

24472445
(
@@ -2473,12 +2471,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
24732471
}
24742472
}
24752473

2476-
fn ty_path(
2477-
&mut self,
2478-
mut hir_id: hir::HirId,
2479-
span: Span,
2480-
qpath: hir::QPath<'hir>,
2481-
) -> hir::Ty<'hir> {
2474+
fn ty_path(&mut self, mut hir_id: HirId, span: Span, qpath: hir::QPath<'hir>) -> hir::Ty<'hir> {
24822475
let kind = match qpath {
24832476
hir::QPath::Resolved(None, path) => {
24842477
// Turn trait object paths into `TyKind::TraitObject` instead.

compiler/rustc_hir_analysis/src/astconv/mod.rs

+12-23
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use rustc_hir as hir;
2424
use rustc_hir::def::{CtorOf, DefKind, Namespace, Res};
2525
use rustc_hir::def_id::{DefId, LocalDefId};
2626
use rustc_hir::intravisit::{walk_generics, Visitor as _};
27-
use rustc_hir::{GenericArg, GenericArgs};
27+
use rustc_hir::{GenericArg, GenericArgs, HirId};
2828
use rustc_infer::infer::{InferCtxt, TyCtxtInferExt};
2929
use rustc_infer::traits::ObligationCause;
3030
use rustc_middle::middle::stability::AllowUnstable;
@@ -137,7 +137,7 @@ pub trait AstConv<'tcx> {
137137
/// report.
138138
fn set_tainted_by_errors(&self, e: ErrorGuaranteed);
139139

140-
fn record_ty(&self, hir_id: hir::HirId, ty: Ty<'tcx>, span: Span);
140+
fn record_ty(&self, hir_id: HirId, ty: Ty<'tcx>, span: Span);
141141

142142
fn astconv(&self) -> &dyn AstConv<'tcx>
143143
where
@@ -943,7 +943,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
943943
#[instrument(level = "debug", skip(self, hir_ref_id, span, qself, assoc_segment), fields(assoc_ident=?assoc_segment.ident), ret)]
944944
pub fn associated_path_to_ty(
945945
&self,
946-
hir_ref_id: hir::HirId,
946+
hir_ref_id: HirId,
947947
span: Span,
948948
qself_ty: Ty<'tcx>,
949949
qself: &hir::Ty<'_>,
@@ -1226,7 +1226,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
12261226
segment: &hir::PathSegment<'tcx>,
12271227
adt_did: DefId,
12281228
self_ty: Ty<'tcx>,
1229-
block: hir::HirId,
1229+
block: HirId,
12301230
span: Span,
12311231
) -> Result<Option<(Ty<'tcx>, DefId)>, ErrorGuaranteed> {
12321232
let tcx = self.tcx();
@@ -1377,7 +1377,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
13771377
fn lookup_assoc_ty(
13781378
&self,
13791379
name: Ident,
1380-
block: hir::HirId,
1380+
block: HirId,
13811381
span: Span,
13821382
scope: DefId,
13831383
) -> Option<DefId> {
@@ -1389,7 +1389,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
13891389
fn lookup_assoc_ty_unchecked(
13901390
&self,
13911391
name: Ident,
1392-
block: hir::HirId,
1392+
block: HirId,
13931393
scope: DefId,
13941394
) -> Option<(DefId, DefId)> {
13951395
let tcx = self.tcx();
@@ -1406,14 +1406,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
14061406
Some((item.def_id, def_scope))
14071407
}
14081408

1409-
fn check_assoc_ty(
1410-
&self,
1411-
item: DefId,
1412-
name: Ident,
1413-
def_scope: DefId,
1414-
block: hir::HirId,
1415-
span: Span,
1416-
) {
1409+
fn check_assoc_ty(&self, item: DefId, name: Ident, def_scope: DefId, block: HirId, span: Span) {
14171410
let tcx = self.tcx();
14181411
let kind = DefKind::AssocTy;
14191412

@@ -1816,7 +1809,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
18161809
&self,
18171810
opt_self_ty: Option<Ty<'tcx>>,
18181811
path: &hir::Path<'tcx>,
1819-
hir_id: hir::HirId,
1812+
hir_id: HirId,
18201813
permit_variants: bool,
18211814
) -> Ty<'tcx> {
18221815
let tcx = self.tcx();
@@ -2054,7 +2047,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
20542047

20552048
// Converts a hir id corresponding to a type parameter to
20562049
// a early-bound `ty::Param` or late-bound `ty::Bound`.
2057-
pub(crate) fn hir_id_to_bound_ty(&self, hir_id: hir::HirId) -> Ty<'tcx> {
2050+
pub(crate) fn hir_id_to_bound_ty(&self, hir_id: HirId) -> Ty<'tcx> {
20582051
let tcx = self.tcx();
20592052
match tcx.named_bound_var(hir_id) {
20602053
Some(rbv::ResolvedArg::LateBound(debruijn, index, def_id)) => {
@@ -2079,11 +2072,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
20792072

20802073
// Converts a hir id corresponding to a const parameter to
20812074
// a early-bound `ConstKind::Param` or late-bound `ConstKind::Bound`.
2082-
pub(crate) fn hir_id_to_bound_const(
2083-
&self,
2084-
hir_id: hir::HirId,
2085-
param_ty: Ty<'tcx>,
2086-
) -> Const<'tcx> {
2075+
pub(crate) fn hir_id_to_bound_const(&self, hir_id: HirId, param_ty: Ty<'tcx>) -> Const<'tcx> {
20872076
let tcx = self.tcx();
20882077
match tcx.named_bound_var(hir_id) {
20892078
Some(rbv::ResolvedArg::EarlyBound(def_id)) => {
@@ -2417,7 +2406,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
24172406
#[instrument(level = "debug", skip(self, hir_id, unsafety, abi, decl, generics, hir_ty), ret)]
24182407
pub fn ty_of_fn(
24192408
&self,
2420-
hir_id: hir::HirId,
2409+
hir_id: HirId,
24212410
unsafety: hir::Unsafety,
24222411
abi: abi::Abi,
24232412
decl: &hir::FnDecl<'tcx>,
@@ -2551,7 +2540,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
25512540
/// corresponds to the return type.
25522541
fn suggest_trait_fn_ty_for_impl_fn_infer(
25532542
&self,
2554-
fn_hir_id: hir::HirId,
2543+
fn_hir_id: HirId,
25552544
arg_idx: Option<usize>,
25562545
) -> Option<Ty<'tcx>> {
25572546
let tcx = self.tcx();

compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs

+8-12
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_hir as hir;
1313
use rustc_hir::def::{DefKind, Res};
1414
use rustc_hir::def_id::LocalDefId;
1515
use rustc_hir::intravisit::{self, Visitor};
16-
use rustc_hir::{GenericArg, GenericParam, GenericParamKind, HirIdMap, LifetimeName, Node};
16+
use rustc_hir::{GenericArg, GenericParam, GenericParamKind, HirId, HirIdMap, LifetimeName, Node};
1717
use rustc_macros::extension;
1818
use rustc_middle::bug;
1919
use rustc_middle::hir::nested_filter;
@@ -108,7 +108,7 @@ enum Scope<'a> {
108108
/// queried later. However, if we enter an elision scope, we have to
109109
/// later append the elided bound vars to the list and need to know what
110110
/// to append to.
111-
hir_id: hir::HirId,
111+
hir_id: HirId,
112112

113113
s: ScopeRef<'a>,
114114

@@ -775,7 +775,7 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
775775
}
776776
}
777777

778-
fn visit_path(&mut self, path: &hir::Path<'tcx>, hir_id: hir::HirId) {
778+
fn visit_path(&mut self, path: &hir::Path<'tcx>, hir_id: HirId) {
779779
for (i, segment) in path.segments.iter().enumerate() {
780780
let depth = path.segments.len() - i - 1;
781781
if let Some(args) = segment.args {
@@ -994,7 +994,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
994994
}
995995
}
996996

997-
fn record_late_bound_vars(&mut self, hir_id: hir::HirId, binder: Vec<ty::BoundVariableKind>) {
997+
fn record_late_bound_vars(&mut self, hir_id: HirId, binder: Vec<ty::BoundVariableKind>) {
998998
if let Some(old) = self.map.late_bound_vars.insert(hir_id, binder) {
999999
bug!(
10001000
"overwrote bound vars for {hir_id:?}:\nold={old:?}\nnew={:?}",
@@ -1021,12 +1021,8 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
10211021
/// already in scope (for a fn item, that will be 0, but for a method it might not be). Late
10221022
/// bound lifetimes are resolved by name and associated with a binder ID (`binder_id`), so the
10231023
/// ordering is not important there.
1024-
fn visit_early_late<F>(
1025-
&mut self,
1026-
hir_id: hir::HirId,
1027-
generics: &'tcx hir::Generics<'tcx>,
1028-
walk: F,
1029-
) where
1024+
fn visit_early_late<F>(&mut self, hir_id: HirId, generics: &'tcx hir::Generics<'tcx>, walk: F)
1025+
where
10301026
F: for<'b, 'c> FnOnce(&'b mut BoundVarContext<'c, 'tcx>),
10311027
{
10321028
let mut named_late_bound_vars = 0;
@@ -1073,7 +1069,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
10731069
self.with(scope, walk);
10741070
}
10751071

1076-
fn visit_early<F>(&mut self, hir_id: hir::HirId, generics: &'tcx hir::Generics<'tcx>, walk: F)
1072+
fn visit_early<F>(&mut self, hir_id: HirId, generics: &'tcx hir::Generics<'tcx>, walk: F)
10771073
where
10781074
F: for<'b, 'c> FnOnce(&'b mut BoundVarContext<'c, 'tcx>),
10791075
{
@@ -1299,7 +1295,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
12991295
);
13001296
}
13011297

1302-
fn resolve_type_ref(&mut self, param_def_id: LocalDefId, hir_id: hir::HirId) {
1298+
fn resolve_type_ref(&mut self, param_def_id: LocalDefId, hir_id: HirId) {
13031299
// Walk up the scope chain, tracking the number of fn scopes
13041300
// that we pass through, until we find a lifetime with the
13051301
// given name or we run out of scopes.

0 commit comments

Comments
 (0)