Skip to content

Commit 083a7ea

Browse files
committed
Add path parameters to std_path
1 parent d814160 commit 083a7ea

File tree

2 files changed

+63
-35
lines changed

2 files changed

+63
-35
lines changed

src/librustc/hir/lowering.rs

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ pub trait Resolver {
168168
span: Span,
169169
crate_root: Option<&str>,
170170
components: &[&str],
171+
params: Option<P<hir::PathParameters>>
171172
is_value: bool,
172173
) -> hir::Path;
173174
}
@@ -876,7 +877,7 @@ impl<'a> LoweringContext<'a> {
876877

877878
let unstable_span = self.allow_internal_unstable(CompilerDesugaringKind::Async, span);
878879
let gen_future = self.expr_std_path(
879-
unstable_span, &["raw", "future_from_generator"], ThinVec::new());
880+
unstable_span, &["raw", "future_from_generator"], None, ThinVec::new());
880881
hir::ExprCall(P(gen_future), hir_vec![generator])
881882
}
882883

@@ -2115,24 +2116,21 @@ impl<'a> LoweringContext<'a> {
21152116
}
21162117
};
21172118

2118-
let hir::Path { def, segments, .. } = this.std_path(span, &["future", "Future"], false);
2119-
let future_path = hir::Path {
2120-
segments: segments.map_slice(|mut v| {
2121-
v.last_mut().unwrap().parameters = Some(P(hir::PathParameters {
2122-
lifetimes: hir_vec![],
2123-
types: hir_vec![],
2124-
bindings: hir_vec![hir::TypeBinding {
2125-
name: Symbol::intern(FN_OUTPUT_NAME),
2126-
ty: output_ty,
2127-
id: this.next_id().node_id,
2128-
span,
2129-
}],
2130-
parenthesized: false,
2131-
}));
2132-
v
2133-
}),
2134-
def, span
2135-
};
2119+
// "<Output = T>"
2120+
let future_params = P(hir::PathParameters {
2121+
lifetimes: hir_vec![],
2122+
types: hir_vec![],
2123+
bindings: hir_vec![hir::TypeBinding {
2124+
name: Symbol::intern(FN_OUTPUT_NAME),
2125+
ty: output_ty,
2126+
id: this.next_id().node_id,
2127+
span,
2128+
}],
2129+
parenthesized: false,
2130+
});
2131+
2132+
let let future_path =
2133+
this.std_path(span, &["future", "Future"], Some(future_params), false);
21362134

21372135
// FIXME(cramertj) collect input lifetimes to function and add them to
21382136
// the output `impl Trait` type here.
@@ -3665,7 +3663,7 @@ impl<'a> LoweringContext<'a> {
36653663
let id = self.next_id();
36663664
let e1 = self.lower_expr(e1);
36673665
let e2 = self.lower_expr(e2);
3668-
let ty_path = P(self.std_path(span, &["ops", "RangeInclusive"], false));
3666+
let ty_path = P(self.std_path(span, &["ops", "RangeInclusive"], None, false));
36693667
let ty = self.ty_path(id, span, hir::QPath::Resolved(None, ty_path));
36703668
let new_seg = P(hir::PathSegment::from_name(Symbol::intern("new")));
36713669
let new_path = hir::QPath::TypeRelative(ty, new_seg);
@@ -3705,7 +3703,7 @@ impl<'a> LoweringContext<'a> {
37053703
let struct_path = iter::once("ops")
37063704
.chain(iter::once(path))
37073705
.collect::<Vec<_>>();
3708-
let struct_path = self.std_path(unstable_span, &struct_path, is_unit);
3706+
let struct_path = self.std_path(unstable_span, &struct_path, None, is_unit);
37093707
let struct_path = hir::QPath::Resolved(None, P(struct_path));
37103708

37113709
let LoweredNodeId { node_id, hir_id } = self.lower_node_id(e.id);
@@ -3982,7 +3980,7 @@ impl<'a> LoweringContext<'a> {
39823980
let iter = P(self.expr_ident(head_sp, iter, iter_pat.id));
39833981
let ref_mut_iter = self.expr_mut_addr_of(head_sp, iter);
39843982
let next_path = &["iter", "Iterator", "next"];
3985-
let next_path = P(self.expr_std_path(head_sp, next_path, ThinVec::new()));
3983+
let next_path = P(self.expr_std_path(head_sp, next_path, None, ThinVec::new()));
39863984
let next_expr = P(self.expr_call(head_sp, next_path, hir_vec![ref_mut_iter]));
39873985
let arms = hir_vec![pat_arm, break_arm];
39883986

@@ -4040,7 +4038,8 @@ impl<'a> LoweringContext<'a> {
40404038
// `match ::std::iter::IntoIterator::into_iter(<head>) { ... }`
40414039
let into_iter_expr = {
40424040
let into_iter_path = &["iter", "IntoIterator", "into_iter"];
4043-
let into_iter = P(self.expr_std_path(head_sp, into_iter_path, ThinVec::new()));
4041+
let into_iter = P(self.expr_std_path(
4042+
head_sp, into_iter_path, None, ThinVec::new()));
40444043
P(self.expr_call(head_sp, into_iter, hir_vec![head]))
40454044
};
40464045

@@ -4086,7 +4085,8 @@ impl<'a> LoweringContext<'a> {
40864085
let sub_expr = self.lower_expr(sub_expr);
40874086

40884087
let path = &["ops", "Try", "into_result"];
4089-
let path = P(self.expr_std_path(unstable_span, path, ThinVec::new()));
4088+
let path = P(self.expr_std_path(
4089+
unstable_span, path, None, ThinVec::new()));
40904090
P(self.expr_call(e.span, path, hir_vec![sub_expr]))
40914091
};
40924092

@@ -4125,7 +4125,8 @@ impl<'a> LoweringContext<'a> {
41254125
let err_local = self.pat_ident(e.span, err_ident);
41264126
let from_expr = {
41274127
let path = &["convert", "From", "from"];
4128-
let from = P(self.expr_std_path(e.span, path, ThinVec::new()));
4128+
let from = P(self.expr_std_path(
4129+
e.span, path, None, ThinVec::new()));
41294130
let err_expr = self.expr_ident(e.span, err_ident, err_local.id);
41304131

41314132
self.expr_call(e.span, from, hir_vec![err_expr])
@@ -4365,9 +4366,10 @@ impl<'a> LoweringContext<'a> {
43654366
&mut self,
43664367
span: Span,
43674368
components: &[&str],
4369+
params: Option<P<hir::PathParameters>>,
43684370
attrs: ThinVec<Attribute>,
43694371
) -> hir::Expr {
4370-
let path = self.std_path(span, components, true);
4372+
let path = self.std_path(span, components, params, true);
43714373
self.expr(
43724374
span,
43734375
hir::ExprPath(hir::QPath::Resolved(None, P(path))),
@@ -4492,7 +4494,7 @@ impl<'a> LoweringContext<'a> {
44924494
components: &[&str],
44934495
subpats: hir::HirVec<P<hir::Pat>>,
44944496
) -> P<hir::Pat> {
4495-
let path = self.std_path(span, components, true);
4497+
let path = self.std_path(span, components, None, true);
44964498
let qpath = hir::QPath::Resolved(None, P(path));
44974499
let pt = if subpats.is_empty() {
44984500
hir::PatKind::Path(qpath)
@@ -4539,9 +4541,15 @@ impl<'a> LoweringContext<'a> {
45394541
/// Given suffix ["b","c","d"], returns path `::std::b::c::d` when
45404542
/// `fld.cx.use_std`, and `::core::b::c::d` otherwise.
45414543
/// The path is also resolved according to `is_value`.
4542-
fn std_path(&mut self, span: Span, components: &[&str], is_value: bool) -> hir::Path {
4544+
fn std_path(
4545+
&mut self,
4546+
span: Span,
4547+
components: &[&str],
4548+
params: Option<P<hir::PathParameters>>,
4549+
is_value: bool
4550+
) -> hir::Path {
45434551
self.resolver
4544-
.resolve_str_path(span, self.crate_root, components, is_value)
4552+
.resolve_str_path(span, self.crate_root, components, params, is_value)
45454553
}
45464554

45474555
fn ty_path(&mut self, id: LoweredNodeId, span: Span, qpath: hir::QPath) -> P<hir::Ty> {
@@ -4673,7 +4681,7 @@ impl<'a> LoweringContext<'a> {
46734681
unstable_span: Span,
46744682
) -> P<hir::Expr> {
46754683
let path = &["ops", "Try", method];
4676-
let from_err = P(self.expr_std_path(unstable_span, path,
4684+
let from_err = P(self.expr_std_path(unstable_span, path, None,
46774685
ThinVec::new()));
46784686
P(self.expr_call(e.span, from_err, hir_vec![e]))
46794687
}

src/librustc_resolve/lib.rs

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1489,14 +1489,34 @@ impl<'a> hir::lowering::Resolver for Resolver<'a> {
14891489
|resolver, span, error| resolve_error(resolver, span, error))
14901490
}
14911491

1492-
fn resolve_str_path(&mut self, span: Span, crate_root: Option<&str>,
1493-
components: &[&str], is_value: bool) -> hir::Path {
1492+
fn resolve_str_path(
1493+
&mut self,
1494+
span: Span,
1495+
crate_root: Option<&str>,
1496+
components: &[&str],
1497+
params: Option<hir::PathParameters>,
1498+
is_value: bool
1499+
) -> hir::Path {
1500+
let mut segments = iter::once(keywords::CrateRoot.name())
1501+
.chain(
1502+
crate_root.into_iter()
1503+
.chain(components.iter().cloned())
1504+
.map(Symbol::intern)
1505+
).map(hir::PathSegment::from_name).collect::<Vec<_>>();
1506+
1507+
if let Some(parameters) = params {
1508+
let last_name = segments.last().unwrap().name;
1509+
*segments.last_mut().unwrap() = hir::PathSegment {
1510+
name,
1511+
parameters,
1512+
infer_types: true,
1513+
};
1514+
}
1515+
14941516
let mut path = hir::Path {
14951517
span,
14961518
def: Def::Err,
1497-
segments: iter::once(keywords::CrateRoot.name()).chain({
1498-
crate_root.into_iter().chain(components.iter().cloned()).map(Symbol::intern)
1499-
}).map(hir::PathSegment::from_name).collect(),
1519+
segments: segments.into(),
15001520
};
15011521

15021522
self.resolve_hir_path(&mut path, is_value);

0 commit comments

Comments
 (0)