Skip to content

Paren sugar #18622

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/librustc/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ register_diagnostics!(
E0044,
E0045,
E0046,
E0047,
E0049,
E0050,
E0051,
Expand Down Expand Up @@ -111,7 +110,6 @@ register_diagnostics!(
E0108,
E0109,
E0110,
E0113,
E0116,
E0117,
E0118,
Expand Down Expand Up @@ -145,5 +143,6 @@ register_diagnostics!(
E0163,
E0164,
E0165,
E0166
E0166,
E0167
)
2 changes: 1 addition & 1 deletion src/librustc/middle/check_const.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ fn check_expr(v: &mut CheckCrateVisitor, e: &Expr) -> bool {
// to handle on-demand instantiation of functions via
// foo::<bar> in a const. Currently that is only done on
// a path in trans::callee that only works in block contexts.
if !pth.segments.iter().all(|segment| segment.types.is_empty()) {
if !pth.segments.iter().all(|segment| segment.parameters.is_empty()) {
span_err!(v.tcx.sess, e.span, E0013,
"paths in constants may only refer to items without \
type parameters");
Expand Down
4 changes: 1 addition & 3 deletions src/librustc/middle/pat_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use std::collections::HashMap;
use syntax::ast::*;
use syntax::ast_util::{walk_pat};
use syntax::codemap::{Span, DUMMY_SP};
use syntax::owned_slice::OwnedSlice;

pub type PatIdMap = HashMap<Ident, NodeId>;

Expand Down Expand Up @@ -133,8 +132,7 @@ pub fn def_to_path(tcx: &ty::ctxt, id: DefId) -> Path {
global: false,
segments: path.last().map(|elem| PathSegment {
identifier: Ident::new(elem.name()),
lifetimes: vec!(),
types: OwnedSlice::empty()
parameters: PathParameters::none(),
}).into_iter().collect(),
span: DUMMY_SP,
})
Expand Down
4 changes: 1 addition & 3 deletions src/librustc/middle/privacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ use syntax::ast_map;
use syntax::ast_util::{is_local, local_def, PostExpansionMethod};
use syntax::codemap::Span;
use syntax::parse::token;
use syntax::owned_slice::OwnedSlice;
use syntax::visit;
use syntax::visit::Visitor;

Expand Down Expand Up @@ -945,8 +944,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> {
debug!("privacy - ident item {}", id);
let seg = ast::PathSegment {
identifier: name,
lifetimes: Vec::new(),
types: OwnedSlice::empty(),
parameters: ast::PathParameters::none(),
};
let segs = vec![seg];
let path = ast::Path {
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/middle/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4951,12 +4951,12 @@ impl<'a> Resolver<'a> {

if path.segments
.iter()
.any(|s| !s.lifetimes.is_empty()) {
.any(|s| s.parameters.has_lifetimes()) {
span_err!(self.session, path.span, E0157,
"lifetime parameters are not allowed on this type");
} else if path.segments
.iter()
.any(|s| s.types.len() > 0) {
.any(|s| !s.parameters.is_empty()) {
span_err!(self.session, path.span, E0153,
"type parameters are not allowed on this type");
}
Expand Down Expand Up @@ -5234,7 +5234,7 @@ impl<'a> Resolver<'a> {
// Check the types in the path pattern.
for ty in path.segments
.iter()
.flat_map(|s| s.types.iter()) {
.flat_map(|s| s.parameters.types().into_iter()) {
self.resolve_type(&**ty);
}
}
Expand Down Expand Up @@ -5340,7 +5340,7 @@ impl<'a> Resolver<'a> {
namespace: Namespace,
check_ribs: bool) -> Option<(Def, LastPrivate)> {
// First, resolve the types.
for ty in path.segments.iter().flat_map(|s| s.types.iter()) {
for ty in path.segments.iter().flat_map(|s| s.parameters.types().into_iter()) {
self.resolve_type(&**ty);
}

Expand Down
6 changes: 1 addition & 5 deletions src/librustc/middle/trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1835,11 +1835,7 @@ pub fn trans_closure(ccx: &CrateContext,
NotUnboxedClosure => monomorphized_arg_types,

// Tuple up closure argument types for the "rust-call" ABI.
IsUnboxedClosure => vec![if monomorphized_arg_types.is_empty() {
ty::mk_nil()
} else {
ty::mk_tup(ccx.tcx(), monomorphized_arg_types)
}]
IsUnboxedClosure => vec![ty::mk_tup_or_nil(ccx.tcx(), monomorphized_arg_types)]
};
for monomorphized_arg_type in monomorphized_arg_types.iter() {
debug!("trans_closure: monomorphized_arg_type: {}",
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/trans/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ fn const_expr_unadjusted(cx: &CrateContext, e: &ast::Expr) -> ValueRef {
}
ast::ExprPath(ref pth) => {
// Assert that there are no type parameters in this path.
assert!(pth.segments.iter().all(|seg| seg.types.is_empty()));
assert!(pth.segments.iter().all(|seg| !seg.parameters.has_types()));

let opt_def = cx.tcx().def_map.borrow().find_copy(&e.id);
match opt_def {
Expand Down
8 changes: 8 additions & 0 deletions src/librustc/middle/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1838,6 +1838,14 @@ pub fn mk_slice(cx: &ctxt, r: Region, tm: mt) -> t {

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

pub fn mk_tup_or_nil(cx: &ctxt, ts: Vec<t>) -> t {
if ts.len() == 0 {
ty::mk_nil()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We ought to investigate the cost of interning ty_tup(Vec::new()).
Actually, one idea I had (interning everything referenced by Ty in the arena) would result in ty_tup(&'tcx [Ty<'tcx>]) which allows a statically declared ty_nil as ty_tup(&[]).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eddyb see also #18614

} else {
mk_t(cx, ty_tup(ts))
}
}

pub fn mk_closure(cx: &ctxt, fty: ClosureTy) -> t {
mk_t(cx, ty_closure(box fty))
}
Expand Down
Loading