From a0cfda53c4b7367f6494e3d746b35cea644ee50d Mon Sep 17 00:00:00 2001 From: Nick Cameron Date: Tue, 8 Jul 2014 14:26:02 +1200 Subject: Change DST syntax: type -> Sized? closes #13367 [breaking-change] Use `Sized?` to indicate a dynamically sized type parameter or trait (used to be `type`). E.g., ``` trait Tr for Sized? {} fn foo(x: X) {} ``` --- src/libsyntax/ext/build.rs | 8 ++++---- src/libsyntax/ext/deriving/decodable.rs | 5 ++--- src/libsyntax/ext/deriving/encodable.rs | 5 ++--- src/libsyntax/ext/deriving/generic/mod.rs | 2 +- src/libsyntax/ext/deriving/generic/ty.rs | 13 +++++++------ src/libsyntax/ext/deriving/hash.rs | 3 +-- src/libsyntax/ext/deriving/rand.rs | 2 +- 7 files changed, 18 insertions(+), 20 deletions(-) (limited to 'src/libsyntax/ext') diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index 46bc4ec11ce..4d79ff3257a 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -66,8 +66,8 @@ pub trait AstBuilder { fn typaram(&self, span: Span, id: ast::Ident, - sized: ast::Sized, bounds: OwnedSlice, + unbound: Option, default: Option>) -> ast::TyParam; fn trait_ref(&self, path: ast::Path) -> ast::TraitRef; @@ -396,14 +396,14 @@ impl<'a> AstBuilder for ExtCtxt<'a> { fn typaram(&self, span: Span, id: ast::Ident, - sized: ast::Sized, bounds: OwnedSlice, + unbound: Option, default: Option>) -> ast::TyParam { ast::TyParam { ident: id, id: ast::DUMMY_NODE_ID, - sized: sized, bounds: bounds, + unbound: unbound, default: default, span: span } @@ -423,7 +423,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { fn strip_bounds(&self, generics: &Generics) -> Generics { let new_params = generics.ty_params.map(|ty_param| { - ast::TyParam { bounds: OwnedSlice::empty(), ..*ty_param } + ast::TyParam { bounds: OwnedSlice::empty(), unbound: None, ..*ty_param } }); Generics { ty_params: new_params, diff --git a/src/libsyntax/ext/deriving/decodable.rs b/src/libsyntax/ext/deriving/decodable.rs index 0c23d65fde0..6da5f1e2700 100644 --- a/src/libsyntax/ext/deriving/decodable.rs +++ b/src/libsyntax/ext/deriving/decodable.rs @@ -13,7 +13,6 @@ The compiler code necessary for `#[deriving(Decodable)]`. See encodable.rs for more. */ -use ast; use ast::{MetaItem, Item, Expr, MutMutable, Ident}; use codemap::Span; use ext::base::ExtCtxt; @@ -39,10 +38,10 @@ pub fn expand_deriving_decodable(cx: &mut ExtCtxt, additional_bounds: Vec::new(), generics: LifetimeBounds { lifetimes: Vec::new(), - bounds: vec!(("__D", ast::StaticSize, vec!(Path::new_( + bounds: vec!(("__D", None, vec!(Path::new_( vec!("serialize", "Decoder"), None, vec!(box Literal(Path::new_local("__E"))), true))), - ("__E", ast::StaticSize, vec!())) + ("__E", None, vec!())) }, methods: vec!( MethodDef { diff --git a/src/libsyntax/ext/deriving/encodable.rs b/src/libsyntax/ext/deriving/encodable.rs index f57670af199..652d593c004 100644 --- a/src/libsyntax/ext/deriving/encodable.rs +++ b/src/libsyntax/ext/deriving/encodable.rs @@ -82,7 +82,6 @@ would yield functions like: ``` */ -use ast; use ast::{MetaItem, Item, Expr, ExprRet, MutMutable, LitNil}; use codemap::Span; use ext::base::ExtCtxt; @@ -107,10 +106,10 @@ pub fn expand_deriving_encodable(cx: &mut ExtCtxt, additional_bounds: Vec::new(), generics: LifetimeBounds { lifetimes: Vec::new(), - bounds: vec!(("__S", ast::StaticSize, vec!(Path::new_( + bounds: vec!(("__S", None, vec!(Path::new_( vec!("serialize", "Encoder"), None, vec!(box Literal(Path::new_local("__E"))), true))), - ("__E", ast::StaticSize, vec!())) + ("__E", None, vec!())) }, methods: vec!( MethodDef { diff --git a/src/libsyntax/ext/deriving/generic/mod.rs b/src/libsyntax/ext/deriving/generic/mod.rs index 157b64fb47c..7ad11b186f5 100644 --- a/src/libsyntax/ext/deriving/generic/mod.rs +++ b/src/libsyntax/ext/deriving/generic/mod.rs @@ -406,8 +406,8 @@ impl<'a> TraitDef<'a> { cx.typaram(self.span, ty_param.ident, - ty_param.sized, OwnedSlice::from_vec(bounds), + ty_param.unbound.clone(), None) })); let trait_generics = Generics { diff --git a/src/libsyntax/ext/deriving/generic/ty.rs b/src/libsyntax/ext/deriving/generic/ty.rs index 7501b950770..28f39a4cb8c 100644 --- a/src/libsyntax/ext/deriving/generic/ty.rs +++ b/src/libsyntax/ext/deriving/generic/ty.rs @@ -188,17 +188,18 @@ impl<'a> Ty<'a> { } -fn mk_ty_param(cx: &ExtCtxt, span: Span, name: &str, sized: ast::Sized, bounds: &[Path], +fn mk_ty_param(cx: &ExtCtxt, span: Span, name: &str, + bounds: &[Path], unbound: Option, self_ident: Ident, self_generics: &Generics) -> ast::TyParam { let bounds = bounds.iter().map(|b| { let path = b.to_path(cx, span, self_ident, self_generics); cx.typarambound(path) }).collect(); - cx.typaram(span, cx.ident_of(name), sized, bounds, None) + cx.typaram(span, cx.ident_of(name), bounds, unbound, None) } -fn mk_generics(lifetimes: Vec , ty_params: Vec ) -> Generics { +fn mk_generics(lifetimes: Vec, ty_params: Vec ) -> Generics { Generics { lifetimes: lifetimes, ty_params: OwnedSlice::from_vec(ty_params) @@ -208,7 +209,7 @@ fn mk_generics(lifetimes: Vec , ty_params: Vec ) - /// Lifetimes and bounds on type parameters pub struct LifetimeBounds<'a> { pub lifetimes: Vec<&'a str>, - pub bounds: Vec<(&'a str, ast::Sized, Vec>)>, + pub bounds: Vec<(&'a str, Option, Vec>)>, } impl<'a> LifetimeBounds<'a> { @@ -228,12 +229,12 @@ impl<'a> LifetimeBounds<'a> { }).collect(); let ty_params = self.bounds.iter().map(|t| { match t { - &(ref name, sized, ref bounds) => { + &(ref name, ref unbound, ref bounds) => { mk_ty_param(cx, span, *name, - sized, bounds.as_slice(), + unbound.clone(), self_ty, self_generics) } diff --git a/src/libsyntax/ext/deriving/hash.rs b/src/libsyntax/ext/deriving/hash.rs index 77fb013b269..1b3ac47092a 100644 --- a/src/libsyntax/ext/deriving/hash.rs +++ b/src/libsyntax/ext/deriving/hash.rs @@ -8,7 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use ast; use ast::{MetaItem, Item, Expr, MutMutable}; use codemap::Span; use ext::base::ExtCtxt; @@ -30,7 +29,7 @@ pub fn expand_deriving_hash(cx: &mut ExtCtxt, vec!(box Literal(Path::new_local("__S"))), true), LifetimeBounds { lifetimes: Vec::new(), - bounds: vec!(("__S", ast::StaticSize, + bounds: vec!(("__S", None, vec!(Path::new(vec!("std", "hash", "Writer"))))), }, Path::new_local("__S")) diff --git a/src/libsyntax/ext/deriving/rand.rs b/src/libsyntax/ext/deriving/rand.rs index f6a15ea917e..34b5f120d6a 100644 --- a/src/libsyntax/ext/deriving/rand.rs +++ b/src/libsyntax/ext/deriving/rand.rs @@ -35,7 +35,7 @@ pub fn expand_deriving_rand(cx: &mut ExtCtxt, generics: LifetimeBounds { lifetimes: Vec::new(), bounds: vec!(("R", - ast::StaticSize, + None, vec!( Path::new(vec!("std", "rand", "Rng")) ))) }, explicit_self: None, -- cgit 1.4.1-3-g733a5