Skip to content

Commit 2d74e9b

Browse files
committed
Allocate inside lower_path_extra.
1 parent e569ada commit 2d74e9b

File tree

3 files changed

+20
-38
lines changed

3 files changed

+20
-38
lines changed

src/librustc/hir/lowering.rs

+10-14
Original file line numberDiff line numberDiff line change
@@ -1800,8 +1800,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
18001800
p: &Path,
18011801
param_mode: ParamMode,
18021802
explicit_owner: Option<NodeId>,
1803-
) -> hir::Path<'hir> {
1804-
hir::Path {
1803+
) -> &'hir hir::Path<'hir> {
1804+
self.arena.alloc(hir::Path {
18051805
res,
18061806
segments: self.arena.alloc_from_iter(p.segments.iter().map(|segment| {
18071807
self.lower_path_segment(
@@ -1815,10 +1815,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
18151815
)
18161816
})),
18171817
span: p.span,
1818-
}
1818+
})
18191819
}
18201820

1821-
fn lower_path(&mut self, id: NodeId, p: &Path, param_mode: ParamMode) -> hir::Path<'hir> {
1821+
fn lower_path(&mut self, id: NodeId, p: &Path, param_mode: ParamMode) -> &'hir hir::Path<'hir> {
18221822
let res = self.expect_full_res(id);
18231823
let res = self.lower_res(res);
18241824
self.lower_path_extra(res, p, param_mode, None)
@@ -2396,12 +2396,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
23962396
});
23972397

23982398
// ::std::future::Future<future_params>
2399-
let future_path = self.arena.alloc(self.std_path(
2400-
span,
2401-
&[sym::future, sym::Future],
2402-
Some(future_params),
2403-
false,
2404-
));
2399+
let future_path =
2400+
self.std_path(span, &[sym::future, sym::Future], Some(future_params), false);
24052401

24062402
hir::GenericBound::Trait(
24072403
hir::PolyTraitRef {
@@ -3048,7 +3044,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
30483044
subpats: &'hir [&'hir hir::Pat<'hir>],
30493045
) -> &'hir hir::Pat<'hir> {
30503046
let path = self.std_path(span, components, None, true);
3051-
let qpath = hir::QPath::Resolved(None, self.arena.alloc(path));
3047+
let qpath = hir::QPath::Resolved(None, path);
30523048
let pt = if subpats.is_empty() {
30533049
hir::PatKind::Path(qpath)
30543050
} else {
@@ -3096,7 +3092,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
30963092
components: &[Symbol],
30973093
params: Option<&'hir hir::GenericArgs<'hir>>,
30983094
is_value: bool,
3099-
) -> hir::Path<'hir> {
3095+
) -> &'hir hir::Path<'hir> {
31003096
let ns = if is_value { Namespace::ValueNS } else { Namespace::TypeNS };
31013097
let (path, res) = self.resolver.resolve_str_path(span, self.crate_root, components, ns);
31023098

@@ -3116,11 +3112,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
31163112
.collect();
31173113
segments.last_mut().unwrap().args = params;
31183114

3119-
hir::Path {
3115+
self.arena.alloc(hir::Path {
31203116
span,
31213117
res: res.map_id(|_| panic!("unexpected `NodeId`")),
31223118
segments: self.arena.alloc_from_iter(segments),
3123-
}
3119+
})
31243120
}
31253121

31263122
fn ty_path(

src/librustc/hir/lowering/expr.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
827827
let is_unit = fields.is_empty();
828828
let struct_path = [sym::ops, path];
829829
let struct_path = self.std_path(span, &struct_path, None, is_unit);
830-
let struct_path = hir::QPath::Resolved(None, self.arena.alloc(struct_path));
830+
let struct_path = hir::QPath::Resolved(None, struct_path);
831831

832832
if is_unit {
833833
hir::ExprKind::Path(struct_path)
@@ -1336,7 +1336,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
13361336
assoc_fn_name: &str,
13371337
args: &'hir [hir::Expr<'hir>],
13381338
) -> hir::ExprKind<'hir> {
1339-
let ty_path = self.arena.alloc(self.std_path(span, ty_path_components, None, false));
1339+
let ty_path = self.std_path(span, ty_path_components, None, false);
13401340
let ty =
13411341
self.arena.alloc(self.ty_path(ty_path_id, span, hir::QPath::Resolved(None, ty_path)));
13421342
let fn_seg = self.arena.alloc(hir::PathSegment::from_ident(Ident::from_str(assoc_fn_name)));
@@ -1354,11 +1354,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
13541354
attrs: AttrVec,
13551355
) -> hir::Expr<'hir> {
13561356
let path = self.std_path(span, components, params, true);
1357-
self.expr(
1358-
span,
1359-
hir::ExprKind::Path(hir::QPath::Resolved(None, self.arena.alloc(path))),
1360-
attrs,
1361-
)
1357+
self.expr(span, hir::ExprKind::Path(hir::QPath::Resolved(None, path)), attrs)
13621358
}
13631359

13641360
pub(super) fn expr_ident(

src/librustc/hir/lowering/item.rs

+7-17
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
507507
let new_id = this.lower_node_id(new_node_id);
508508
let res = this.lower_res(res);
509509
let path = this.lower_path_extra(res, &path, ParamMode::Explicit, None);
510-
let kind = hir::ItemKind::Use(this.arena.alloc(path), hir::UseKind::Single);
510+
let kind = hir::ItemKind::Use(path, hir::UseKind::Single);
511511
let vis = this.rebuild_vis(&vis);
512512

513513
this.insert_item(hir::Item {
@@ -522,15 +522,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
522522
}
523523

524524
let path = self.lower_path_extra(ret_res, &path, ParamMode::Explicit, None);
525-
let path = self.arena.alloc(path);
526525
hir::ItemKind::Use(path, hir::UseKind::Single)
527526
}
528527
UseTreeKind::Glob => {
529-
let path = self.arena.alloc(self.lower_path(
530-
id,
531-
&Path { segments, span: path.span },
532-
ParamMode::Explicit,
533-
));
528+
let path =
529+
self.lower_path(id, &Path { segments, span: path.span }, ParamMode::Explicit);
534530
hir::ItemKind::Use(path, hir::UseKind::Glob)
535531
}
536532
UseTreeKind::Nested(ref trees) => {
@@ -618,7 +614,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
618614
let res = self.expect_full_res_from_use(id).next().unwrap_or(Res::Err);
619615
let res = self.lower_res(res);
620616
let path = self.lower_path_extra(res, &prefix, ParamMode::Explicit, None);
621-
let path = self.arena.alloc(path);
622617
hir::ItemKind::Use(path, hir::UseKind::ListStem)
623618
}
624619
}
@@ -627,7 +622,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
627622
/// Paths like the visibility path in `pub(super) use foo::{bar, baz}` are repeated
628623
/// many times in the HIR tree; for each occurrence, we need to assign distinct
629624
/// `NodeId`s. (See, e.g., #56128.)
630-
fn rebuild_use_path(&mut self, path: &hir::Path<'hir>) -> hir::Path<'hir> {
625+
fn rebuild_use_path(&mut self, path: &hir::Path<'hir>) -> &'hir hir::Path<'hir> {
631626
debug!("rebuild_use_path(path = {:?})", path);
632627
let segments =
633628
self.arena.alloc_from_iter(path.segments.iter().map(|seg| hir::PathSegment {
@@ -637,7 +632,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
637632
args: None,
638633
infer_args: seg.infer_args,
639634
}));
640-
hir::Path { span: path.span, res: path.res, segments }
635+
self.arena.alloc(hir::Path { span: path.span, res: path.res, segments })
641636
}
642637

643638
fn rebuild_vis(&mut self, vis: &hir::Visibility<'hir>) -> hir::Visibility<'hir> {
@@ -647,7 +642,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
647642
hir::VisibilityKind::Inherited => hir::VisibilityKind::Inherited,
648643
hir::VisibilityKind::Restricted { ref path, hir_id: _ } => {
649644
hir::VisibilityKind::Restricted {
650-
path: self.arena.alloc(self.rebuild_use_path(path)),
645+
path: self.rebuild_use_path(path),
651646
hir_id: self.next_id(),
652647
}
653648
}
@@ -944,12 +939,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
944939
let res = self.expect_full_res(id);
945940
let res = self.lower_res(res);
946941
hir::VisibilityKind::Restricted {
947-
path: self.arena.alloc(self.lower_path_extra(
948-
res,
949-
path,
950-
ParamMode::Explicit,
951-
explicit_owner,
952-
)),
942+
path: self.lower_path_extra(res, path, ParamMode::Explicit, explicit_owner),
953943
hir_id: lowered_id,
954944
}
955945
}

0 commit comments

Comments
 (0)