Skip to content

Commit 40b940b

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

File tree

36 files changed

+276
-312
lines changed

36 files changed

+276
-312
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};
@@ -701,8 +702,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
701702
pub(super) fn maybe_forward_track_caller(
702703
&mut self,
703704
span: Span,
704-
outer_hir_id: hir::HirId,
705-
inner_hir_id: hir::HirId,
705+
outer_hir_id: HirId,
706+
inner_hir_id: HirId,
706707
) {
707708
if self.tcx.features().async_fn_track_caller
708709
&& let Some(attrs) = self.attrs.get(&outer_hir_id.local_id)
@@ -1048,7 +1049,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
10481049
binder: &ClosureBinder,
10491050
capture_clause: CaptureBy,
10501051
closure_id: NodeId,
1051-
closure_hir_id: hir::HirId,
1052+
closure_hir_id: HirId,
10521053
coroutine_kind: CoroutineKind,
10531054
decl: &FnDecl,
10541055
body: &Expr,
@@ -2036,7 +2037,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
20362037
&mut self,
20372038
sp: Span,
20382039
ident: Ident,
2039-
binding: hir::HirId,
2040+
binding: HirId,
20402041
) -> &'hir hir::Expr<'hir> {
20412042
self.arena.alloc(self.expr_ident_mut(sp, ident, binding))
20422043
}
@@ -2045,7 +2046,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
20452046
&mut self,
20462047
span: Span,
20472048
ident: Ident,
2048-
binding: hir::HirId,
2049+
binding: HirId,
20492050
) -> hir::Expr<'hir> {
20502051
let hir_id = self.next_id();
20512052
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::ZERO);
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) {
@@ -2421,11 +2419,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
24212419
self.pat(span, hir::PatKind::Struct(qpath, fields, false))
24222420
}
24232421

2424-
fn pat_ident(&mut self, span: Span, ident: Ident) -> (&'hir hir::Pat<'hir>, hir::HirId) {
2422+
fn pat_ident(&mut self, span: Span, ident: Ident) -> (&'hir hir::Pat<'hir>, HirId) {
24252423
self.pat_ident_binding_mode(span, ident, hir::BindingAnnotation::NONE)
24262424
}
24272425

2428-
fn pat_ident_mut(&mut self, span: Span, ident: Ident) -> (hir::Pat<'hir>, hir::HirId) {
2426+
fn pat_ident_mut(&mut self, span: Span, ident: Ident) -> (hir::Pat<'hir>, HirId) {
24292427
self.pat_ident_binding_mode_mut(span, ident, hir::BindingAnnotation::NONE)
24302428
}
24312429

@@ -2434,7 +2432,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
24342432
span: Span,
24352433
ident: Ident,
24362434
bm: hir::BindingAnnotation,
2437-
) -> (&'hir hir::Pat<'hir>, hir::HirId) {
2435+
) -> (&'hir hir::Pat<'hir>, HirId) {
24382436
let (pat, hir_id) = self.pat_ident_binding_mode_mut(span, ident, bm);
24392437
(self.arena.alloc(pat), hir_id)
24402438
}
@@ -2444,7 +2442,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
24442442
span: Span,
24452443
ident: Ident,
24462444
bm: hir::BindingAnnotation,
2447-
) -> (hir::Pat<'hir>, hir::HirId) {
2445+
) -> (hir::Pat<'hir>, HirId) {
24482446
let hir_id = self.next_id();
24492447

24502448
(
@@ -2476,12 +2474,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
24762474
}
24772475
}
24782476

2479-
fn ty_path(
2480-
&mut self,
2481-
mut hir_id: hir::HirId,
2482-
span: Span,
2483-
qpath: hir::QPath<'hir>,
2484-
) -> hir::Ty<'hir> {
2477+
fn ty_path(&mut self, mut hir_id: HirId, span: Span, qpath: hir::QPath<'hir>) -> hir::Ty<'hir> {
24852478
let kind = match qpath {
24862479
hir::QPath::Resolved(None, path) => {
24872480
// Turn trait object paths into `TyKind::TraitObject` instead.

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;
@@ -107,7 +107,7 @@ enum Scope<'a> {
107107
/// queried later. However, if we enter an elision scope, we have to
108108
/// later append the elided bound vars to the list and need to know what
109109
/// to append to.
110-
hir_id: hir::HirId,
110+
hir_id: HirId,
111111

112112
s: ScopeRef<'a>,
113113

@@ -781,7 +781,7 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
781781
}
782782
}
783783

784-
fn visit_path(&mut self, path: &hir::Path<'tcx>, hir_id: hir::HirId) {
784+
fn visit_path(&mut self, path: &hir::Path<'tcx>, hir_id: HirId) {
785785
for (i, segment) in path.segments.iter().enumerate() {
786786
let depth = path.segments.len() - i - 1;
787787
if let Some(args) = segment.args {
@@ -983,7 +983,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
983983
}
984984
}
985985

986-
fn record_late_bound_vars(&mut self, hir_id: hir::HirId, binder: Vec<ty::BoundVariableKind>) {
986+
fn record_late_bound_vars(&mut self, hir_id: HirId, binder: Vec<ty::BoundVariableKind>) {
987987
if let Some(old) = self.map.late_bound_vars.insert(hir_id, binder) {
988988
bug!(
989989
"overwrote bound vars for {hir_id:?}:\nold={old:?}\nnew={:?}",
@@ -1010,12 +1010,8 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
10101010
/// already in scope (for a fn item, that will be 0, but for a method it might not be). Late
10111011
/// bound lifetimes are resolved by name and associated with a binder ID (`binder_id`), so the
10121012
/// ordering is not important there.
1013-
fn visit_early_late<F>(
1014-
&mut self,
1015-
hir_id: hir::HirId,
1016-
generics: &'tcx hir::Generics<'tcx>,
1017-
walk: F,
1018-
) where
1013+
fn visit_early_late<F>(&mut self, hir_id: HirId, generics: &'tcx hir::Generics<'tcx>, walk: F)
1014+
where
10191015
F: for<'b, 'c> FnOnce(&'b mut BoundVarContext<'c, 'tcx>),
10201016
{
10211017
let mut named_late_bound_vars = 0;
@@ -1062,7 +1058,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
10621058
self.with(scope, walk);
10631059
}
10641060

1065-
fn visit_early<F>(&mut self, hir_id: hir::HirId, generics: &'tcx hir::Generics<'tcx>, walk: F)
1061+
fn visit_early<F>(&mut self, hir_id: HirId, generics: &'tcx hir::Generics<'tcx>, walk: F)
10661062
where
10671063
F: for<'b, 'c> FnOnce(&'b mut BoundVarContext<'c, 'tcx>),
10681064
{
@@ -1288,7 +1284,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
12881284
);
12891285
}
12901286

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

compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

+12-25
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use rustc_hir as hir;
3535
use rustc_hir::def::{CtorOf, DefKind, Namespace, Res};
3636
use rustc_hir::def_id::{DefId, LocalDefId};
3737
use rustc_hir::intravisit::{walk_generics, Visitor as _};
38-
use rustc_hir::{GenericArg, GenericArgs};
38+
use rustc_hir::{GenericArg, GenericArgs, HirId};
3939
use rustc_infer::infer::{InferCtxt, TyCtxtInferExt};
4040
use rustc_infer::traits::ObligationCause;
4141
use rustc_middle::middle::stability::AllowUnstable;
@@ -158,7 +158,7 @@ pub trait HirTyLowerer<'tcx> {
158158
fn probe_adt(&self, span: Span, ty: Ty<'tcx>) -> Option<ty::AdtDef<'tcx>>;
159159

160160
/// Record the lowered type of a HIR node in this context.
161-
fn record_ty(&self, hir_id: hir::HirId, ty: Ty<'tcx>, span: Span);
161+
fn record_ty(&self, hir_id: HirId, ty: Ty<'tcx>, span: Span);
162162

163163
/// The inference context of the lowering context if applicable.
164164
fn infcx(&self) -> Option<&InferCtxt<'tcx>>;
@@ -999,7 +999,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
999999
#[instrument(level = "debug", skip_all, ret)]
10001000
pub fn lower_assoc_path(
10011001
&self,
1002-
hir_ref_id: hir::HirId,
1002+
hir_ref_id: HirId,
10031003
span: Span,
10041004
qself_ty: Ty<'tcx>,
10051005
qself: &'tcx hir::Ty<'tcx>,
@@ -1200,7 +1200,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
12001200
segment: &hir::PathSegment<'tcx>,
12011201
adt_did: DefId,
12021202
self_ty: Ty<'tcx>,
1203-
block: hir::HirId,
1203+
block: HirId,
12041204
span: Span,
12051205
) -> Result<Option<(Ty<'tcx>, DefId)>, ErrorGuaranteed> {
12061206
let tcx = self.tcx();
@@ -1349,13 +1349,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
13491349
}
13501350
}
13511351

1352-
fn probe_assoc_ty(
1353-
&self,
1354-
name: Ident,
1355-
block: hir::HirId,
1356-
span: Span,
1357-
scope: DefId,
1358-
) -> Option<DefId> {
1352+
fn probe_assoc_ty(&self, name: Ident, block: HirId, span: Span, scope: DefId) -> Option<DefId> {
13591353
let (item, def_scope) = self.probe_assoc_ty_unchecked(name, block, scope)?;
13601354
self.check_assoc_ty(item, name, def_scope, block, span);
13611355
Some(item)
@@ -1364,7 +1358,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
13641358
fn probe_assoc_ty_unchecked(
13651359
&self,
13661360
name: Ident,
1367-
block: hir::HirId,
1361+
block: HirId,
13681362
scope: DefId,
13691363
) -> Option<(DefId, DefId)> {
13701364
let tcx = self.tcx();
@@ -1381,14 +1375,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
13811375
Some((item.def_id, def_scope))
13821376
}
13831377

1384-
fn check_assoc_ty(
1385-
&self,
1386-
item: DefId,
1387-
name: Ident,
1388-
def_scope: DefId,
1389-
block: hir::HirId,
1390-
span: Span,
1391-
) {
1378+
fn check_assoc_ty(&self, item: DefId, name: Ident, def_scope: DefId, block: HirId, span: Span) {
13921379
let tcx = self.tcx();
13931380
let kind = DefKind::AssocTy;
13941381

@@ -1714,7 +1701,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
17141701
&self,
17151702
opt_self_ty: Option<Ty<'tcx>>,
17161703
path: &hir::Path<'tcx>,
1717-
hir_id: hir::HirId,
1704+
hir_id: HirId,
17181705
permit_variants: bool,
17191706
) -> Ty<'tcx> {
17201707
debug!(?path.res, ?opt_self_ty, ?path.segments);
@@ -1887,7 +1874,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
18871874
///
18881875
/// Early-bound type parameters get lowered to [`ty::Param`]
18891876
/// and late-bound ones to [`ty::Bound`].
1890-
pub(crate) fn lower_ty_param(&self, hir_id: hir::HirId) -> Ty<'tcx> {
1877+
pub(crate) fn lower_ty_param(&self, hir_id: HirId) -> Ty<'tcx> {
18911878
let tcx = self.tcx();
18921879
match tcx.named_bound_var(hir_id) {
18931880
Some(rbv::ResolvedArg::LateBound(debruijn, index, def_id)) => {
@@ -1914,7 +1901,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
19141901
///
19151902
/// Early-bound const parameters get lowered to [`ty::ConstKind::Param`]
19161903
/// and late-bound ones to [`ty::ConstKind::Bound`].
1917-
pub(crate) fn lower_const_param(&self, hir_id: hir::HirId, param_ty: Ty<'tcx>) -> Const<'tcx> {
1904+
pub(crate) fn lower_const_param(&self, hir_id: HirId, param_ty: Ty<'tcx>) -> Const<'tcx> {
19181905
let tcx = self.tcx();
19191906
match tcx.named_bound_var(hir_id) {
19201907
Some(rbv::ResolvedArg::EarlyBound(def_id)) => {
@@ -2341,7 +2328,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
23412328
#[instrument(level = "debug", skip(self, hir_id, unsafety, abi, decl, generics, hir_ty), ret)]
23422329
pub fn lower_fn_ty(
23432330
&self,
2344-
hir_id: hir::HirId,
2331+
hir_id: HirId,
23452332
unsafety: hir::Unsafety,
23462333
abi: abi::Abi,
23472334
decl: &hir::FnDecl<'tcx>,
@@ -2469,7 +2456,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
24692456
/// corresponds to the return type.
24702457
fn suggest_trait_fn_ty_for_impl_fn_infer(
24712458
&self,
2472-
fn_hir_id: hir::HirId,
2459+
fn_hir_id: HirId,
24732460
arg_idx: Option<usize>,
24742461
) -> Option<Ty<'tcx>> {
24752462
let tcx = self.tcx();

0 commit comments

Comments
 (0)