Skip to content
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

Allow expanding a tuple type T in a list of types with ..T. #10769

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
4 changes: 2 additions & 2 deletions src/librustc/metadata/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1080,8 +1080,8 @@ fn encode_info_for_item(ecx: &EncodeContext,
encode_name(ecx, ebml_w, item.ident);
encode_attributes(ebml_w, item.attrs);
match ty.node {
ast::ty_path(ref path, ref bounds, _) if path.segments
.len() == 1 => {
ast::ty_path(_, ref path, ref bounds, _) if path.segments
.len() == 1 => {
assert!(bounds.is_none());
encode_impl_type_basename(ecx, ebml_w,
ast_util::path_to_ident(path));
Expand Down
5 changes: 4 additions & 1 deletion src/librustc/metadata/tyencode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,10 @@ fn enc_sty(w: @mut MemWriter, cx: @ctxt, st: &ty::sty) {
ty::ty_infer(_) => {
cx.diag.handler().bug("Cannot encode inference variable types");
}
ty::ty_param(param_ty {idx: id, def_id: did}) => {
ty::ty_param(expand, param_ty {idx: id, def_id: did}) => {
if expand {
cx.tcx.sess.bug("found unexpanded ty_param in tyencode::enc_sty");
}
mywrite!(w, "p{}|{}", (cx.ds)(did), id);
}
ty::ty_self(did) => {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/dead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ impl Visitor<()> for MarkSymbolVisitor {

fn visit_ty(&mut self, typ: &ast::Ty, _: ()) {
match typ.node {
ast::ty_path(_, _, ref id) => {
ast::ty_path(_, _, _, ref id) => {
self.lookup_and_handle_definition(id, typ.span);
}
_ => visit::walk_ty(self, typ, ()),
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/middle/kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ fn check_impl_of_trait(cx: &mut Context, it: @item, trait_ref: &trait_ref, self_
// If this is a destructor, check kinds.
if cx.tcx.lang_items.drop_trait() == Some(trait_def_id) {
match self_type.node {
ty_path(_, ref bounds, path_node_id) => {
ty_path(_, _, ref bounds, path_node_id) => {
assert!(bounds.is_none());
let struct_def = cx.tcx.def_map.get_copy(&path_node_id);
let struct_did = ast_util::def_id_of_def(struct_def);
Expand Down Expand Up @@ -325,7 +325,7 @@ pub fn check_expr(cx: &mut Context, e: @Expr) {

fn check_ty(cx: &mut Context, aty: &Ty) {
match aty.node {
ty_path(_, _, id) => {
ty_path(_, _, _, id) => {
let r = cx.tcx.node_type_substs.find(&id);
for ts in r.iter() {
let did = ast_util::def_id_of_def(cx.tcx.def_map.get_copy(&id));
Expand Down Expand Up @@ -554,7 +554,7 @@ pub fn check_cast_for_escaping_regions(

|ty| {
match ty::get(ty).sty {
ty::ty_param(source_param) => {
ty::ty_param(_, source_param) => {
if target_params.iter().any(|x| x == &source_param) {
/* case (2) */
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ fn check_type_limits(cx: &Context, e: &ast::Expr) {
fn check_item_ctypes(cx: &Context, it: &ast::item) {
fn check_ty(cx: &Context, ty: &ast::Ty) {
match ty.node {
ast::ty_path(_, _, id) => {
ast::ty_path(_, _, _, id) => {
match cx.tcx.def_map.get_copy(&id) {
ast::DefPrimTy(ast::ty_int(ast::ty_i)) => {
cx.span_lint(ctypes, ty.span,
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/privacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ impl<'self> Visitor<()> for EmbargoVisitor<'self> {
// * Private trait impls for private types can be completely ignored
ast::item_impl(_, _, ref ty, ref methods) => {
let public_ty = match ty.node {
ast::ty_path(_, _, id) => {
ast::ty_path(_, _, _, id) => {
match self.tcx.def_map.get_copy(&id) {
ast::DefPrimTy(..) => true,
def => {
Expand Down Expand Up @@ -699,7 +699,7 @@ impl<'self> Visitor<()> for PrivacyVisitor<'self> {

fn visit_ty(&mut self, t: &ast::Ty, _: ()) {
match t.node {
ast::ty_path(ref path, _, id) => self.check_path(t.span, id, path),
ast::ty_path(_, ref path, _, id) => self.check_path(t.span, id, path),
_ => {}
}
visit::walk_ty(self, t, ());
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1236,7 +1236,7 @@ impl Resolver {

// Create the module and add all methods.
match ty.node {
ty_path(ref path, _, _) if path.segments.len() == 1 => {
ty_path(_, ref path, _, _) if path.segments.len() == 1 => {
let name = path_to_ident(path);

let new_parent = match parent.children.find(&name.name) {
Expand Down Expand Up @@ -4129,7 +4129,7 @@ impl Resolver {
// Like path expressions, the interpretation of path types depends
// on whether the path has multiple elements in it or not.

ty_path(ref path, ref bounds, path_id) => {
ty_path(_, ref path, ref bounds, path_id) => {
// This is a path in the type namespace. Walk through scopes
// scopes looking for it.
let mut result_def = None;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/subst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl<'self> TypeFolder for SubstFolder<'self> {
}

match ty::get(t).sty {
ty::ty_param(p) => {
ty::ty_param(_, p) => {
self.substs.tps[p.idx]
}
ty::ty_self(_) => {
Expand Down
7 changes: 6 additions & 1 deletion src/librustc/middle/trans/reflect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,12 @@ impl Reflector {
// Miscellaneous extra types
ty::ty_infer(_) => self.leaf("infer"),
ty::ty_err => self.leaf("err"),
ty::ty_param(ref p) => {
ty::ty_param(expand, ref p) => {
if expand {
tcx.sess.bug(format!(
"found unexpanded ty_param `{}` in reflect::visit_ty",
ty_to_str(tcx, t)));
}
let extra = ~[self.c_uint(p.idx)];
self.visit("param", extra)
}
Expand Down
31 changes: 18 additions & 13 deletions src/librustc/middle/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ pub enum sty {
ty_struct(DefId, substs),
ty_tup(~[t]),

ty_param(param_ty), // type parameter
ty_param(bool /* expand */, param_ty), // type parameter
ty_self(DefId), /* special, implicit `self` type parameter;
* def_id is the id of the trait */

Expand Down Expand Up @@ -1088,7 +1088,7 @@ pub fn mk_t(cx: ctxt, st: sty) -> t {
// so we're doing it this way.
&ty_bot => flags |= has_ty_bot as uint,
&ty_err => flags |= has_ty_err as uint,
&ty_param(_) => flags |= has_params as uint,
&ty_param(..) => flags |= has_params as uint,
&ty_infer(_) => flags |= needs_infer as uint,
&ty_self(_) => flags |= has_self as uint,
&ty_enum(_, ref substs) | &ty_struct(_, ref substs) |
Expand Down Expand Up @@ -1342,7 +1342,7 @@ pub fn mk_infer(cx: ctxt, it: InferTy) -> t { mk_t(cx, ty_infer(it)) }
pub fn mk_self(cx: ctxt, did: ast::DefId) -> t { mk_t(cx, ty_self(did)) }

pub fn mk_param(cx: ctxt, n: uint, k: DefId) -> t {
mk_t(cx, ty_param(param_ty { idx: n, def_id: k }))
mk_t(cx, ty_param(false, param_ty { idx: n, def_id: k }))
}

pub fn mk_type(cx: ctxt) -> t { mk_t(cx, ty_type) }
Expand All @@ -1364,7 +1364,7 @@ pub fn maybe_walk_ty(ty: t, f: |t| -> bool) {
match get(ty).sty {
ty_nil | ty_bot | ty_bool | ty_char | ty_int(_) | ty_uint(_) | ty_float(_) |
ty_estr(_) | ty_type | ty_opaque_box | ty_self(_) |
ty_opaque_closure_ptr(_) | ty_infer(_) | ty_param(_) | ty_err => {
ty_opaque_closure_ptr(_) | ty_infer(_) | ty_param(..) | ty_err => {
}
ty_box(ref tm) | ty_evec(ref tm, _) | ty_unboxed_vec(ref tm) |
ty_ptr(ref tm) | ty_rptr(_, ref tm) | ty_uniq(ref tm) => {
Expand Down Expand Up @@ -1428,7 +1428,7 @@ pub fn subst_tps(tcx: ctxt, tps: &[t], self_ty_opt: Option<t>, typ: t) -> t {
}

match ty::get(t).sty {
ty_param(p) => {
ty_param(_, p) => {
self.tps[p.idx]
}

Expand Down Expand Up @@ -2068,7 +2068,7 @@ pub fn type_contents(cx: ctxt, ty: t) -> TypeContents {
apply_attributes(cx, did, res)
}

ty_param(p) => {
ty_param(_, p) => {
// We only ever ask for the kind of types that are defined in
// the current crate; therefore, the only type parameters that
// could be in scope are those defined in the current crate.
Expand Down Expand Up @@ -2281,7 +2281,7 @@ pub fn is_instantiable(cx: ctxt, r_ty: t) -> bool {
ty_closure(_) |
ty_infer(_) |
ty_err |
ty_param(_) |
ty_param(..) |
ty_self(_) |
ty_type |
ty_opaque_box |
Expand Down Expand Up @@ -2486,7 +2486,7 @@ pub fn type_is_pod(cx: ctxt, ty: t) -> bool {
ty_evec(ref mt, vstore_fixed(_)) | ty_unboxed_vec(ref mt) => {
result = type_is_pod(cx, mt.ty);
}
ty_param(_) => result = false,
ty_param(..) => result = false,
ty_opaque_closure_ptr(_) => result = true,
ty_struct(did, ref substs) => {
let fields = lookup_struct_fields(cx, did);
Expand Down Expand Up @@ -2520,7 +2520,7 @@ pub fn type_is_enum(ty: t) -> bool {
pub fn type_is_sized(cx: ctxt, ty: ty::t) -> bool {
match get(ty).sty {
// FIXME(#6308) add trait, vec, str, etc here.
ty_param(p) => {
ty_param(_, p) => {
let param_def = cx.ty_param_defs.get(&p.def_id.node);
if param_def.bounds.builtin_bounds.contains_elem(BoundSized) {
return true;
Expand Down Expand Up @@ -2549,7 +2549,7 @@ pub fn type_is_c_like_enum(cx: ctxt, ty: t) -> bool {

pub fn type_param(ty: t) -> Option<uint> {
match get(ty).sty {
ty_param(p) => return Some(p.idx),
ty_param(_, p) => return Some(p.idx),
_ => {/* fall through */ }
}
return None;
Expand Down Expand Up @@ -3219,7 +3219,7 @@ pub fn param_tys_in_type(ty: t) -> ~[param_ty] {
let mut rslt = ~[];
walk_ty(ty, |ty| {
match get(ty).sty {
ty_param(p) => {
ty_param(_, p) => {
rslt.push(p);
}
_ => ()
Expand Down Expand Up @@ -3282,7 +3282,7 @@ pub fn ty_sort_str(cx: ctxt, t: t) -> ~str {
ty_infer(TyVar(_)) => ~"inferred type",
ty_infer(IntVar(_)) => ~"integral variable",
ty_infer(FloatVar(_)) => ~"floating-point variable",
ty_param(_) => ~"type parameter",
ty_param(..) => ~"type parameter",
ty_self(_) => ~"self",
ty_err => ~"type error"
}
Expand Down Expand Up @@ -4668,8 +4668,13 @@ pub fn hash_crate_independent(tcx: ctxt, t: t, local_hash: @str) -> u64 {
hash.input([19]);
iter(&mut hash, &inner.len());
}
ty_param(p) => {
ty_param(expand, p) => {
hash.input([20]);
if expand {
tcx.sess.bug(format!(
"found unexpanded ty_param `{}` in ty::hash_crate_independent",
ty_to_str(tcx, t)));
}
iter(&mut hash, &p.idx);
did(&mut hash, p.def_id);
}
Expand Down
21 changes: 19 additions & 2 deletions src/librustc/middle/ty_fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// Generalized type folding mechanism.

use middle::ty;
use util::ppaux::Repr;
use util::ppaux::{Repr, ty_to_str};

pub trait TypeFolder {
fn tcx(&self) -> ty::ctxt;
Expand Down Expand Up @@ -87,7 +87,24 @@ pub fn fold_opt_ty<T:TypeFolder>(this: &mut T,
pub fn fold_ty_vec<T:TypeFolder>(this: &mut T,
tys: &[ty::t])
-> ~[ty::t] {
tys.map(|t| this.fold_ty(*t))
tys.flat_map(|&t| {
let folded = this.fold_ty(t);

match ty::get(t).sty {
ty::ty_param(true, _) => {
match ty::get(folded).sty {
ty::ty_nil => ~[], // FIXME #10784 DRY.
ty::ty_tup(ref fields) => fields.clone(),
_ => {
this.tcx().sess.err(format!("cannot expand non-tuple type `{}`",
ty_to_str(this.tcx(), t)));
~[]
}
}
}
_ => ~[folded]
}
})
}

pub fn super_fold_ty<T:TypeFolder>(this: &mut T,
Expand Down
Loading