Skip to content

Commit bb0ae3c

Browse files
committed
Make hir::PathSegment::hir_id non-optional.
1 parent 6d850d9 commit bb0ae3c

File tree

16 files changed

+103
-97
lines changed

16 files changed

+103
-97
lines changed

compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1776,13 +1776,14 @@ impl<'hir> LoweringContext<'_, 'hir> {
17761776
binding: hir::HirId,
17771777
attrs: AttrVec,
17781778
) -> hir::Expr<'hir> {
1779+
let hir_id = self.next_id();
17791780
let res = Res::Local(binding);
17801781
let expr_path = hir::ExprKind::Path(hir::QPath::Resolved(
17811782
None,
17821783
self.arena.alloc(hir::Path {
17831784
span: self.lower_span(span),
17841785
res,
1785-
segments: arena_vec![self; hir::PathSegment::from_ident(ident, res)],
1786+
segments: arena_vec![self; hir::PathSegment::from_ident(ident, hir_id, res)],
17861787
}),
17871788
));
17881789

compiler/rustc_ast_lowering/src/index.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
246246
}
247247

248248
fn visit_path_segment(&mut self, path_span: Span, path_segment: &'hir PathSegment<'hir>) {
249-
if let Some(hir_id) = path_segment.hir_id {
250-
self.insert(path_span, hir_id, Node::PathSegment(path_segment));
251-
}
249+
self.insert(path_span, path_segment.hir_id, Node::PathSegment(path_segment));
252250
intravisit::walk_path_segment(self, path_span, path_segment);
253251
}
254252

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1431,13 +1431,14 @@ impl<'hir> LoweringContext<'_, 'hir> {
14311431
GenericParamKind::Const { .. } => None,
14321432
GenericParamKind::Type { .. } => {
14331433
let def_id = self.local_def_id(id).to_def_id();
1434+
let hir_id = self.next_id();
14341435
let res = Res::Def(DefKind::TyParam, def_id);
14351436
let ty_path = self.arena.alloc(hir::Path {
14361437
span: param_span,
14371438
res,
14381439
segments: self
14391440
.arena
1440-
.alloc_from_iter([hir::PathSegment::from_ident(ident, res)]),
1441+
.alloc_from_iter([hir::PathSegment::from_ident(ident, hir_id, res)]),
14411442
});
14421443
let ty_id = self.next_id();
14431444
let bounded_ty =

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1260,6 +1260,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
12601260
return self.lower_path_ty(t, qself, path, ParamMode::Explicit, itctx);
12611261
}
12621262
TyKind::ImplicitSelf => {
1263+
let hir_id = self.lower_node_id(t.id);
12631264
let res = self.expect_full_res(t.id);
12641265
let res = self.lower_res(res);
12651266
hir::TyKind::Path(hir::QPath::Resolved(
@@ -1268,6 +1269,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
12681269
res,
12691270
segments: arena_vec![self; hir::PathSegment::from_ident(
12701271
Ident::with_dummy_span(kw::SelfUpper),
1272+
hir_id,
12711273
res
12721274
)],
12731275
span: self.lower_span(t.span),
@@ -2194,13 +2196,14 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
21942196
hir::PredicateOrigin::ImplTrait,
21952197
);
21962198

2199+
let hir_id = self.next_id();
21972200
let res = Res::Def(DefKind::TyParam, def_id.to_def_id());
21982201
let ty = hir::TyKind::Path(hir::QPath::Resolved(
21992202
None,
22002203
self.arena.alloc(hir::Path {
22012204
span: self.lower_span(span),
22022205
res,
2203-
segments: arena_vec![self; hir::PathSegment::from_ident(self.lower_ident(ident), res)],
2206+
segments: arena_vec![self; hir::PathSegment::from_ident(self.lower_ident(ident), hir_id, res)],
22042207
}),
22052208
));
22062209

compiler/rustc_ast_lowering/src/pat.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,13 +255,14 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
255255
)
256256
}
257257
Some(res) => {
258+
let hir_id = self.next_id();
258259
let res = self.lower_res(res);
259260
hir::PatKind::Path(hir::QPath::Resolved(
260261
None,
261262
self.arena.alloc(hir::Path {
262263
span: self.lower_span(ident.span),
263264
res,
264-
segments: arena_vec![self; hir::PathSegment::from_ident(self.lower_ident(ident), res)],
265+
segments: arena_vec![self; hir::PathSegment::from_ident(self.lower_ident(ident), hir_id, res)],
265266
}),
266267
))
267268
}

compiler/rustc_ast_lowering/src/path.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,15 +250,15 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
250250
}
251251

252252
let res = self.expect_full_res(segment.id);
253-
let id = self.lower_node_id(segment.id);
253+
let hir_id = self.lower_node_id(segment.id);
254254
debug!(
255255
"lower_path_segment: ident={:?} original-id={:?} new-id={:?}",
256-
segment.ident, segment.id, id,
256+
segment.ident, segment.id, hir_id,
257257
);
258258

259259
hir::PathSegment {
260260
ident: self.lower_ident(segment.ident),
261-
hir_id: Some(id),
261+
hir_id,
262262
res: self.lower_res(res),
263263
infer_args,
264264
args: if generic_args.is_empty() && generic_args.span.is_empty() {

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -935,10 +935,11 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
935935
_,
936936
) = hir_map.body(fn_body_id).value.kind
937937
{
938-
let opt_suggestions = path_segment
939-
.hir_id
940-
.map(|path_hir_id| self.infcx.tcx.typeck(path_hir_id.owner))
941-
.and_then(|typeck| typeck.type_dependent_def_id(*hir_id))
938+
let opt_suggestions = self
939+
.infcx
940+
.tcx
941+
.typeck(path_segment.hir_id.owner)
942+
.type_dependent_def_id(*hir_id)
942943
.and_then(|def_id| self.infcx.tcx.impl_of_method(def_id))
943944
.map(|def_id| self.infcx.tcx.associated_items(def_id))
944945
.map(|assoc_items| {

compiler/rustc_hir/src/hir.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ pub struct PathSegment<'hir> {
203203
/// The identifier portion of this path segment.
204204
pub ident: Ident,
205205

206-
pub hir_id: Option<HirId>,
206+
pub hir_id: HirId,
207207

208208
pub res: Res,
209209

@@ -223,12 +223,12 @@ pub struct PathSegment<'hir> {
223223

224224
impl<'hir> PathSegment<'hir> {
225225
/// Converts an identifier to the corresponding segment.
226-
pub fn from_ident(ident: Ident, res: Res) -> PathSegment<'hir> {
227-
PathSegment { ident, hir_id: None, res, infer_args: true, args: None }
226+
pub fn from_ident(ident: Ident, hir_id: HirId, res: Res) -> PathSegment<'hir> {
227+
PathSegment { ident, hir_id, res, infer_args: true, args: None }
228228
}
229229

230230
pub fn invalid() -> Self {
231-
Self::from_ident(Ident::empty(), Res::Err)
231+
Self::from_ident(Ident::empty(), HirId::INVALID, Res::Err)
232232
}
233233

234234
pub fn args(&self) -> &GenericArgs<'hir> {

compiler/rustc_hir/src/hir_id.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ pub struct HirId {
2020
}
2121

2222
impl HirId {
23+
/// Signal local id which should never be used.
24+
pub const INVALID: HirId = HirId { owner: CRATE_DEF_ID, local_id: ItemLocalId::INVALID };
25+
2326
#[inline]
2427
pub fn expect_owner(self) -> LocalDefId {
2528
assert_eq!(self.local_id.index(), 0);

compiler/rustc_hir/src/intravisit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ pub fn walk_path_segment<'v, V: Visitor<'v>>(
724724
segment: &'v PathSegment<'v>,
725725
) {
726726
visitor.visit_ident(segment.ident);
727-
walk_list!(visitor, visit_id, segment.hir_id);
727+
visitor.visit_id(segment.hir_id);
728728
if let Some(ref args) = segment.args {
729729
visitor.visit_generic_args(path_span, args);
730730
}

0 commit comments

Comments
 (0)