1
Fork 0

Make hir::PathSegment::hir_id non-optional.

This commit is contained in:
Nicholas Nethercote 2022-08-30 16:54:42 +10:00
parent 6d850d936b
commit bb0ae3c446
16 changed files with 103 additions and 97 deletions

View file

@ -1776,13 +1776,14 @@ impl<'hir> LoweringContext<'_, 'hir> {
binding: hir::HirId,
attrs: AttrVec,
) -> hir::Expr<'hir> {
let hir_id = self.next_id();
let res = Res::Local(binding);
let expr_path = hir::ExprKind::Path(hir::QPath::Resolved(
None,
self.arena.alloc(hir::Path {
span: self.lower_span(span),
res,
segments: arena_vec![self; hir::PathSegment::from_ident(ident, res)],
segments: arena_vec![self; hir::PathSegment::from_ident(ident, hir_id, res)],
}),
));

View file

@ -246,9 +246,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
}
fn visit_path_segment(&mut self, path_span: Span, path_segment: &'hir PathSegment<'hir>) {
if let Some(hir_id) = path_segment.hir_id {
self.insert(path_span, hir_id, Node::PathSegment(path_segment));
}
self.insert(path_span, path_segment.hir_id, Node::PathSegment(path_segment));
intravisit::walk_path_segment(self, path_span, path_segment);
}

View file

@ -1431,13 +1431,14 @@ impl<'hir> LoweringContext<'_, 'hir> {
GenericParamKind::Const { .. } => None,
GenericParamKind::Type { .. } => {
let def_id = self.local_def_id(id).to_def_id();
let hir_id = self.next_id();
let res = Res::Def(DefKind::TyParam, def_id);
let ty_path = self.arena.alloc(hir::Path {
span: param_span,
res,
segments: self
.arena
.alloc_from_iter([hir::PathSegment::from_ident(ident, res)]),
.alloc_from_iter([hir::PathSegment::from_ident(ident, hir_id, res)]),
});
let ty_id = self.next_id();
let bounded_ty =

View file

@ -1260,6 +1260,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
return self.lower_path_ty(t, qself, path, ParamMode::Explicit, itctx);
}
TyKind::ImplicitSelf => {
let hir_id = self.lower_node_id(t.id);
let res = self.expect_full_res(t.id);
let res = self.lower_res(res);
hir::TyKind::Path(hir::QPath::Resolved(
@ -1268,6 +1269,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
res,
segments: arena_vec![self; hir::PathSegment::from_ident(
Ident::with_dummy_span(kw::SelfUpper),
hir_id,
res
)],
span: self.lower_span(t.span),
@ -2194,13 +2196,14 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
hir::PredicateOrigin::ImplTrait,
);
let hir_id = self.next_id();
let res = Res::Def(DefKind::TyParam, def_id.to_def_id());
let ty = hir::TyKind::Path(hir::QPath::Resolved(
None,
self.arena.alloc(hir::Path {
span: self.lower_span(span),
res,
segments: arena_vec![self; hir::PathSegment::from_ident(self.lower_ident(ident), res)],
segments: arena_vec![self; hir::PathSegment::from_ident(self.lower_ident(ident), hir_id, res)],
}),
));

View file

@ -255,13 +255,14 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
)
}
Some(res) => {
let hir_id = self.next_id();
let res = self.lower_res(res);
hir::PatKind::Path(hir::QPath::Resolved(
None,
self.arena.alloc(hir::Path {
span: self.lower_span(ident.span),
res,
segments: arena_vec![self; hir::PathSegment::from_ident(self.lower_ident(ident), res)],
segments: arena_vec![self; hir::PathSegment::from_ident(self.lower_ident(ident), hir_id, res)],
}),
))
}

View file

@ -250,15 +250,15 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
}
let res = self.expect_full_res(segment.id);
let id = self.lower_node_id(segment.id);
let hir_id = self.lower_node_id(segment.id);
debug!(
"lower_path_segment: ident={:?} original-id={:?} new-id={:?}",
segment.ident, segment.id, id,
segment.ident, segment.id, hir_id,
);
hir::PathSegment {
ident: self.lower_ident(segment.ident),
hir_id: Some(id),
hir_id,
res: self.lower_res(res),
infer_args,
args: if generic_args.is_empty() && generic_args.span.is_empty() {