提交 2d74e9ba 编写于 作者: C Camille GILLOT

Allocate inside lower_path_extra.

上级 e569ada5
......@@ -1800,8 +1800,8 @@ fn lower_path_extra(
p: &Path,
param_mode: ParamMode,
explicit_owner: Option<NodeId>,
) -> hir::Path<'hir> {
hir::Path {
) -> &'hir hir::Path<'hir> {
self.arena.alloc(hir::Path {
res,
segments: self.arena.alloc_from_iter(p.segments.iter().map(|segment| {
self.lower_path_segment(
......@@ -1815,10 +1815,10 @@ fn lower_path_extra(
)
})),
span: p.span,
}
})
}
fn lower_path(&mut self, id: NodeId, p: &Path, param_mode: ParamMode) -> hir::Path<'hir> {
fn lower_path(&mut self, id: NodeId, p: &Path, param_mode: ParamMode) -> &'hir hir::Path<'hir> {
let res = self.expect_full_res(id);
let res = self.lower_res(res);
self.lower_path_extra(res, p, param_mode, None)
......@@ -2396,12 +2396,8 @@ fn lower_async_fn_output_type_to_future_bound(
});
// ::std::future::Future<future_params>
let future_path = self.arena.alloc(self.std_path(
span,
&[sym::future, sym::Future],
Some(future_params),
false,
));
let future_path =
self.std_path(span, &[sym::future, sym::Future], Some(future_params), false);
hir::GenericBound::Trait(
hir::PolyTraitRef {
......@@ -3048,7 +3044,7 @@ fn pat_std_enum(
subpats: &'hir [&'hir hir::Pat<'hir>],
) -> &'hir hir::Pat<'hir> {
let path = self.std_path(span, components, None, true);
let qpath = hir::QPath::Resolved(None, self.arena.alloc(path));
let qpath = hir::QPath::Resolved(None, path);
let pt = if subpats.is_empty() {
hir::PatKind::Path(qpath)
} else {
......@@ -3096,7 +3092,7 @@ fn std_path(
components: &[Symbol],
params: Option<&'hir hir::GenericArgs<'hir>>,
is_value: bool,
) -> hir::Path<'hir> {
) -> &'hir hir::Path<'hir> {
let ns = if is_value { Namespace::ValueNS } else { Namespace::TypeNS };
let (path, res) = self.resolver.resolve_str_path(span, self.crate_root, components, ns);
......@@ -3116,11 +3112,11 @@ fn std_path(
.collect();
segments.last_mut().unwrap().args = params;
hir::Path {
self.arena.alloc(hir::Path {
span,
res: res.map_id(|_| panic!("unexpected `NodeId`")),
segments: self.arena.alloc_from_iter(segments),
}
})
}
fn ty_path(
......
......@@ -827,7 +827,7 @@ fn lower_expr_range(
let is_unit = fields.is_empty();
let struct_path = [sym::ops, path];
let struct_path = self.std_path(span, &struct_path, None, is_unit);
let struct_path = hir::QPath::Resolved(None, self.arena.alloc(struct_path));
let struct_path = hir::QPath::Resolved(None, struct_path);
if is_unit {
hir::ExprKind::Path(struct_path)
......@@ -1336,7 +1336,7 @@ fn expr_call_std_assoc_fn(
assoc_fn_name: &str,
args: &'hir [hir::Expr<'hir>],
) -> hir::ExprKind<'hir> {
let ty_path = self.arena.alloc(self.std_path(span, ty_path_components, None, false));
let ty_path = self.std_path(span, ty_path_components, None, false);
let ty =
self.arena.alloc(self.ty_path(ty_path_id, span, hir::QPath::Resolved(None, ty_path)));
let fn_seg = self.arena.alloc(hir::PathSegment::from_ident(Ident::from_str(assoc_fn_name)));
......@@ -1354,11 +1354,7 @@ fn expr_std_path(
attrs: AttrVec,
) -> hir::Expr<'hir> {
let path = self.std_path(span, components, params, true);
self.expr(
span,
hir::ExprKind::Path(hir::QPath::Resolved(None, self.arena.alloc(path))),
attrs,
)
self.expr(span, hir::ExprKind::Path(hir::QPath::Resolved(None, path)), attrs)
}
pub(super) fn expr_ident(
......
......@@ -507,7 +507,7 @@ fn lower_use_tree(
let new_id = this.lower_node_id(new_node_id);
let res = this.lower_res(res);
let path = this.lower_path_extra(res, &path, ParamMode::Explicit, None);
let kind = hir::ItemKind::Use(this.arena.alloc(path), hir::UseKind::Single);
let kind = hir::ItemKind::Use(path, hir::UseKind::Single);
let vis = this.rebuild_vis(&vis);
this.insert_item(hir::Item {
......@@ -522,15 +522,11 @@ fn lower_use_tree(
}
let path = self.lower_path_extra(ret_res, &path, ParamMode::Explicit, None);
let path = self.arena.alloc(path);
hir::ItemKind::Use(path, hir::UseKind::Single)
}
UseTreeKind::Glob => {
let path = self.arena.alloc(self.lower_path(
id,
&Path { segments, span: path.span },
ParamMode::Explicit,
));
let path =
self.lower_path(id, &Path { segments, span: path.span }, ParamMode::Explicit);
hir::ItemKind::Use(path, hir::UseKind::Glob)
}
UseTreeKind::Nested(ref trees) => {
......@@ -618,7 +614,6 @@ fn lower_use_tree(
let res = self.expect_full_res_from_use(id).next().unwrap_or(Res::Err);
let res = self.lower_res(res);
let path = self.lower_path_extra(res, &prefix, ParamMode::Explicit, None);
let path = self.arena.alloc(path);
hir::ItemKind::Use(path, hir::UseKind::ListStem)
}
}
......@@ -627,7 +622,7 @@ fn lower_use_tree(
/// Paths like the visibility path in `pub(super) use foo::{bar, baz}` are repeated
/// many times in the HIR tree; for each occurrence, we need to assign distinct
/// `NodeId`s. (See, e.g., #56128.)
fn rebuild_use_path(&mut self, path: &hir::Path<'hir>) -> hir::Path<'hir> {
fn rebuild_use_path(&mut self, path: &hir::Path<'hir>) -> &'hir hir::Path<'hir> {
debug!("rebuild_use_path(path = {:?})", path);
let segments =
self.arena.alloc_from_iter(path.segments.iter().map(|seg| hir::PathSegment {
......@@ -637,7 +632,7 @@ fn rebuild_use_path(&mut self, path: &hir::Path<'hir>) -> hir::Path<'hir> {
args: None,
infer_args: seg.infer_args,
}));
hir::Path { span: path.span, res: path.res, segments }
self.arena.alloc(hir::Path { span: path.span, res: path.res, segments })
}
fn rebuild_vis(&mut self, vis: &hir::Visibility<'hir>) -> hir::Visibility<'hir> {
......@@ -647,7 +642,7 @@ fn rebuild_vis(&mut self, vis: &hir::Visibility<'hir>) -> hir::Visibility<'hir>
hir::VisibilityKind::Inherited => hir::VisibilityKind::Inherited,
hir::VisibilityKind::Restricted { ref path, hir_id: _ } => {
hir::VisibilityKind::Restricted {
path: self.arena.alloc(self.rebuild_use_path(path)),
path: self.rebuild_use_path(path),
hir_id: self.next_id(),
}
}
......@@ -944,12 +939,7 @@ fn lower_visibility(
let res = self.expect_full_res(id);
let res = self.lower_res(res);
hir::VisibilityKind::Restricted {
path: self.arena.alloc(self.lower_path_extra(
res,
path,
ParamMode::Explicit,
explicit_owner,
)),
path: self.lower_path_extra(res, path, ParamMode::Explicit, explicit_owner),
hir_id: lowered_id,
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册