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<Sized? X: Share>(x: X) {} ```
This commit is contained in:
@@ -66,8 +66,8 @@ pub trait AstBuilder {
|
||||
fn typaram(&self,
|
||||
span: Span,
|
||||
id: ast::Ident,
|
||||
sized: ast::Sized,
|
||||
bounds: OwnedSlice<ast::TyParamBound>,
|
||||
unbound: Option<ast::TyParamBound>,
|
||||
default: Option<P<ast::Ty>>) -> 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<ast::TyParamBound>,
|
||||
unbound: Option<ast::TyParamBound>,
|
||||
default: Option<P<ast::Ty>>) -> 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,
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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<ast::TyParamBound>,
|
||||
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<ast::Lifetime> , ty_params: Vec<ast::TyParam> ) -> Generics {
|
||||
fn mk_generics(lifetimes: Vec<ast::Lifetime>, ty_params: Vec<ast::TyParam> ) -> Generics {
|
||||
Generics {
|
||||
lifetimes: lifetimes,
|
||||
ty_params: OwnedSlice::from_vec(ty_params)
|
||||
@@ -208,7 +209,7 @@ fn mk_generics(lifetimes: Vec<ast::Lifetime> , ty_params: Vec<ast::TyParam> ) -
|
||||
/// Lifetimes and bounds on type parameters
|
||||
pub struct LifetimeBounds<'a> {
|
||||
pub lifetimes: Vec<&'a str>,
|
||||
pub bounds: Vec<(&'a str, ast::Sized, Vec<Path<'a>>)>,
|
||||
pub bounds: Vec<(&'a str, Option<ast::TyParamBound>, Vec<Path<'a>>)>,
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
@@ -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"))
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user