Skip to content

Commit 339c675

Browse files
committed
Support parenthesized paths Foo(A,B) -> C that expand to Foo<(A,B),C>. These paths also bind anonymous regions (or will, once HRTB is fully working).
Fixes #18423.
1 parent ae037bc commit 339c675

38 files changed

+840
-263
lines changed

src/librustc/diagnostics.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ register_diagnostics!(
5757
E0044,
5858
E0045,
5959
E0046,
60-
E0047,
6160
E0049,
6261
E0050,
6362
E0051,
@@ -111,7 +110,6 @@ register_diagnostics!(
111110
E0108,
112111
E0109,
113112
E0110,
114-
E0113,
115113
E0116,
116114
E0117,
117115
E0118,
@@ -145,5 +143,6 @@ register_diagnostics!(
145143
E0163,
146144
E0164,
147145
E0165,
148-
E0166
146+
E0166,
147+
E0167
149148
)

src/librustc/middle/check_const.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ fn check_expr(v: &mut CheckCrateVisitor, e: &Expr) -> bool {
138138
// to handle on-demand instantiation of functions via
139139
// foo::<bar> in a const. Currently that is only done on
140140
// a path in trans::callee that only works in block contexts.
141-
if !pth.segments.iter().all(|segment| segment.types.is_empty()) {
141+
if !pth.segments.iter().all(|segment| segment.parameters.is_empty()) {
142142
span_err!(v.tcx.sess, e.span, E0013,
143143
"paths in constants may only refer to items without \
144144
type parameters");

src/librustc/middle/pat_util.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use std::collections::HashMap;
1616
use syntax::ast::*;
1717
use syntax::ast_util::{walk_pat};
1818
use syntax::codemap::{Span, DUMMY_SP};
19-
use syntax::owned_slice::OwnedSlice;
2019

2120
pub type PatIdMap = HashMap<Ident, NodeId>;
2221

@@ -133,8 +132,7 @@ pub fn def_to_path(tcx: &ty::ctxt, id: DefId) -> Path {
133132
global: false,
134133
segments: path.last().map(|elem| PathSegment {
135134
identifier: Ident::new(elem.name()),
136-
lifetimes: vec!(),
137-
types: OwnedSlice::empty()
135+
parameters: PathParameters::none(),
138136
}).into_iter().collect(),
139137
span: DUMMY_SP,
140138
})

src/librustc/middle/privacy.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ use syntax::ast_map;
2727
use syntax::ast_util::{is_local, local_def, PostExpansionMethod};
2828
use syntax::codemap::Span;
2929
use syntax::parse::token;
30-
use syntax::owned_slice::OwnedSlice;
3130
use syntax::visit;
3231
use syntax::visit::Visitor;
3332

@@ -945,8 +944,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> {
945944
debug!("privacy - ident item {}", id);
946945
let seg = ast::PathSegment {
947946
identifier: name,
948-
lifetimes: Vec::new(),
949-
types: OwnedSlice::empty(),
947+
parameters: ast::PathParameters::none(),
950948
};
951949
let segs = vec![seg];
952950
let path = ast::Path {

src/librustc/middle/resolve.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -4951,12 +4951,12 @@ impl<'a> Resolver<'a> {
49514951

49524952
if path.segments
49534953
.iter()
4954-
.any(|s| !s.lifetimes.is_empty()) {
4954+
.any(|s| s.parameters.has_lifetimes()) {
49554955
span_err!(self.session, path.span, E0157,
49564956
"lifetime parameters are not allowed on this type");
49574957
} else if path.segments
49584958
.iter()
4959-
.any(|s| s.types.len() > 0) {
4959+
.any(|s| !s.parameters.is_empty()) {
49604960
span_err!(self.session, path.span, E0153,
49614961
"type parameters are not allowed on this type");
49624962
}
@@ -5234,7 +5234,7 @@ impl<'a> Resolver<'a> {
52345234
// Check the types in the path pattern.
52355235
for ty in path.segments
52365236
.iter()
5237-
.flat_map(|s| s.types.iter()) {
5237+
.flat_map(|s| s.parameters.types().into_iter()) {
52385238
self.resolve_type(&**ty);
52395239
}
52405240
}
@@ -5340,7 +5340,7 @@ impl<'a> Resolver<'a> {
53405340
namespace: Namespace,
53415341
check_ribs: bool) -> Option<(Def, LastPrivate)> {
53425342
// First, resolve the types.
5343-
for ty in path.segments.iter().flat_map(|s| s.types.iter()) {
5343+
for ty in path.segments.iter().flat_map(|s| s.parameters.types().into_iter()) {
53445344
self.resolve_type(&**ty);
53455345
}
53465346

src/librustc/middle/trans/base.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -1835,11 +1835,7 @@ pub fn trans_closure(ccx: &CrateContext,
18351835
NotUnboxedClosure => monomorphized_arg_types,
18361836

18371837
// Tuple up closure argument types for the "rust-call" ABI.
1838-
IsUnboxedClosure => vec![if monomorphized_arg_types.is_empty() {
1839-
ty::mk_nil()
1840-
} else {
1841-
ty::mk_tup(ccx.tcx(), monomorphized_arg_types)
1842-
}]
1838+
IsUnboxedClosure => vec![ty::mk_tup_or_nil(ccx.tcx(), monomorphized_arg_types)]
18431839
};
18441840
for monomorphized_arg_type in monomorphized_arg_types.iter() {
18451841
debug!("trans_closure: monomorphized_arg_type: {}",

src/librustc/middle/trans/consts.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ fn const_expr_unadjusted(cx: &CrateContext, e: &ast::Expr) -> ValueRef {
625625
}
626626
ast::ExprPath(ref pth) => {
627627
// Assert that there are no type parameters in this path.
628-
assert!(pth.segments.iter().all(|seg| seg.types.is_empty()));
628+
assert!(pth.segments.iter().all(|seg| !seg.parameters.has_types()));
629629

630630
let opt_def = cx.tcx().def_map.borrow().find_copy(&e.id);
631631
match opt_def {

src/librustc/middle/ty.rs

+8
Original file line numberDiff line numberDiff line change
@@ -1838,6 +1838,14 @@ pub fn mk_slice(cx: &ctxt, r: Region, tm: mt) -> t {
18381838

18391839
pub fn mk_tup(cx: &ctxt, ts: Vec<t>) -> t { mk_t(cx, ty_tup(ts)) }
18401840

1841+
pub fn mk_tup_or_nil(cx: &ctxt, ts: Vec<t>) -> t {
1842+
if ts.len() == 0 {
1843+
ty::mk_nil()
1844+
} else {
1845+
mk_t(cx, ty_tup(ts))
1846+
}
1847+
}
1848+
18411849
pub fn mk_closure(cx: &ctxt, fty: ClosureTy) -> t {
18421850
mk_t(cx, ty_closure(box fty))
18431851
}

0 commit comments

Comments
 (0)