Allocate inside lower_path_extra.

This commit is contained in:
Camille GILLOT 2019-12-04 19:45:50 +01:00
parent e569ada528
commit 2d74e9ba13
3 changed files with 20 additions and 38 deletions

View file

@ -1800,8 +1800,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
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 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
)
})),
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 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
});
// ::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 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
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 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
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 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
.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(

View file

@ -827,7 +827,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
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 @@ impl<'hir> LoweringContext<'_, 'hir> {
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 @@ impl<'hir> LoweringContext<'_, 'hir> {
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(

View file

@ -507,7 +507,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
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 @@ impl<'hir> LoweringContext<'_, 'hir> {
}
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 @@ impl<'hir> LoweringContext<'_, 'hir> {
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 @@ impl<'hir> LoweringContext<'_, 'hir> {
/// 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 @@ impl<'hir> LoweringContext<'_, '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 @@ impl<'hir> LoweringContext<'_, '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 @@ impl<'hir> LoweringContext<'_, 'hir> {
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,
}
}