Skip to content

Commit 0ce835d

Browse files
committed
---
yaml --- r: 134581 b: refs/heads/try c: 89b0944 h: refs/heads/master i: 134579: af59fae v: v3
1 parent d2ce50b commit 0ce835d

21 files changed

+183
-215
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 58413c09cd52ea4005d6ea7733ba1fb3a8f36589
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 437179ed8bf7f7672f84b19265df1ce569e70490
5-
refs/heads/try: 63cee1ada360fc7ee2199cfa77934a88006101fb
5+
refs/heads/try: 89b09440d87a8346c2e6206855ab4f0b90febe25
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/src/librustc/middle/resolve.rs

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4328,34 +4328,6 @@ impl<'a> Resolver<'a> {
43284328
self.resolve_trait_reference(id, tref, reference_type)
43294329
}
43304330
UnboxedFnTyParamBound(ref unboxed_function) => {
4331-
match self.resolve_path(unboxed_function.ref_id,
4332-
&unboxed_function.path,
4333-
TypeNS,
4334-
true) {
4335-
None => {
4336-
let path_str = self.path_idents_to_string(
4337-
&unboxed_function.path);
4338-
self.resolve_error(unboxed_function.path.span,
4339-
format!("unresolved trait `{}`",
4340-
path_str).as_slice())
4341-
}
4342-
Some(def) => {
4343-
match def {
4344-
(DefTrait(_), _) => {
4345-
self.record_def(unboxed_function.ref_id, def);
4346-
}
4347-
_ => {
4348-
let msg =
4349-
format!("`{}` is not a trait",
4350-
self.path_idents_to_string(
4351-
&unboxed_function.path));
4352-
self.resolve_error(unboxed_function.path.span,
4353-
msg.as_slice());
4354-
}
4355-
}
4356-
}
4357-
}
4358-
43594331
for argument in unboxed_function.decl.inputs.iter() {
43604332
self.resolve_type(&*argument.ty);
43614333
}

branches/try/src/librustc/middle/typeck/astconv.rs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -585,29 +585,32 @@ pub fn trait_ref_for_unboxed_function<'tcx, AC: AstConv<'tcx>,
585585
RS:RegionScope>(
586586
this: &AC,
587587
rscope: &RS,
588-
kind: ast::UnboxedClosureKind,
589-
decl: &ast::FnDecl,
588+
unboxed_function: &ast::UnboxedFnTy,
590589
self_ty: Option<ty::t>)
591590
-> ty::TraitRef {
592-
let lang_item = match kind {
591+
let lang_item = match unboxed_function.kind {
593592
ast::FnUnboxedClosureKind => FnTraitLangItem,
594593
ast::FnMutUnboxedClosureKind => FnMutTraitLangItem,
595594
ast::FnOnceUnboxedClosureKind => FnOnceTraitLangItem,
596595
};
597596
let trait_did = this.tcx().lang_items.require(lang_item).unwrap();
598-
let input_types = decl.inputs
599-
.iter()
600-
.map(|input| {
597+
let input_types =
598+
unboxed_function.decl
599+
.inputs
600+
.iter()
601+
.map(|input| {
601602
ast_ty_to_ty(this, rscope, &*input.ty)
602-
}).collect::<Vec<_>>();
603+
}).collect::<Vec<_>>();
603604
let input_tuple = if input_types.len() == 0 {
604605
ty::mk_nil()
605606
} else {
606607
ty::mk_tup(this.tcx(), input_types)
607608
};
608-
let output_type = ast_ty_to_ty(this, rscope, &*decl.output);
609+
let output_type = ast_ty_to_ty(this,
610+
rscope,
611+
&*unboxed_function.decl.output);
609612
let mut substs = Substs::new_type(vec!(input_tuple, output_type),
610-
Vec::new());
613+
Vec::new());
611614

612615
match self_ty {
613616
Some(s) => substs.types.push(SelfSpace, s),
@@ -645,8 +648,7 @@ fn mk_pointer<'tcx, AC: AstConv<'tcx>, RS: RegionScope>(
645648
substs
646649
} = trait_ref_for_unboxed_function(this,
647650
rscope,
648-
unboxed_function.kind,
649-
&*unboxed_function.decl,
651+
&**unboxed_function,
650652
None);
651653
let r = ptr_ty.default_region();
652654
let tr = ty::mk_trait(this.tcx(),
@@ -1508,7 +1510,7 @@ fn compute_region_bound<'tcx, AC: AstConv<'tcx>, RS:RegionScope>(
15081510
pub struct PartitionedBounds<'a> {
15091511
pub builtin_bounds: ty::BuiltinBounds,
15101512
pub trait_bounds: Vec<&'a ast::TraitRef>,
1511-
pub unboxed_fn_ty_bounds: Vec<&'a ast::UnboxedFnBound>,
1513+
pub unboxed_fn_ty_bounds: Vec<&'a ast::UnboxedFnTy>,
15121514
pub region_bounds: Vec<&'a ast::Lifetime>,
15131515
}
15141516

@@ -1572,7 +1574,7 @@ pub fn partition_bounds<'a>(tcx: &ty::ctxt,
15721574
region_bounds.push(l);
15731575
}
15741576
ast::UnboxedFnTyParamBound(ref unboxed_function) => {
1575-
unboxed_fn_ty_bounds.push(&**unboxed_function);
1577+
unboxed_fn_ty_bounds.push(unboxed_function);
15761578
}
15771579
}
15781580
}

branches/try/src/librustc/middle/typeck/collect.rs

Lines changed: 4 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1427,8 +1427,7 @@ pub fn instantiate_unboxed_fn_ty<'tcx,AC>(this: &AC,
14271427
let param_ty = param_ty.to_ty(this.tcx());
14281428
Rc::new(astconv::trait_ref_for_unboxed_function(this,
14291429
&rscope,
1430-
unboxed_function.kind,
1431-
&*unboxed_function.decl,
1430+
unboxed_function,
14321431
Some(param_ty)))
14331432
}
14341433

@@ -2166,42 +2165,9 @@ fn conv_param_bounds<'tcx,AC>(this: &AC,
21662165
region_bounds,
21672166
unboxed_fn_ty_bounds } =
21682167
astconv::partition_bounds(this.tcx(), span, all_bounds.as_slice());
2169-
2170-
let unboxed_fn_ty_bounds = unboxed_fn_ty_bounds.move_iter().map(|b| {
2171-
let trait_id = this.tcx().def_map.borrow().get(&b.ref_id).def_id();
2172-
let mut kind = None;
2173-
for &(lang_item, this_kind) in [
2174-
(this.tcx().lang_items.fn_trait(), ast::FnUnboxedClosureKind),
2175-
(this.tcx().lang_items.fn_mut_trait(),
2176-
ast::FnMutUnboxedClosureKind),
2177-
(this.tcx().lang_items.fn_once_trait(),
2178-
ast::FnOnceUnboxedClosureKind)
2179-
].iter() {
2180-
if Some(trait_id) == lang_item {
2181-
kind = Some(this_kind);
2182-
break
2183-
}
2184-
}
2185-
2186-
let kind = match kind {
2187-
Some(kind) => kind,
2188-
None => {
2189-
this.tcx().sess.span_err(b.path.span,
2190-
"unboxed function trait must be one \
2191-
of `Fn`, `FnMut`, or `FnOnce`");
2192-
ast::FnMutUnboxedClosureKind
2193-
}
2194-
};
2195-
2196-
let rscope = ExplicitRscope;
2197-
let param_ty = param_ty.to_ty(this.tcx());
2198-
Rc::new(astconv::trait_ref_for_unboxed_function(this,
2199-
&rscope,
2200-
kind,
2201-
&*b.decl,
2202-
Some(param_ty)))
2203-
});
2204-
2168+
let unboxed_fn_ty_bounds =
2169+
unboxed_fn_ty_bounds.into_iter()
2170+
.map(|b| instantiate_unboxed_fn_ty(this, b, param_ty));
22052171
let trait_bounds: Vec<Rc<ty::TraitRef>> =
22062172
trait_bounds.into_iter()
22072173
.map(|b| {

branches/try/src/libsyntax/ast.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -213,19 +213,12 @@ pub static DUMMY_NODE_ID: NodeId = -1;
213213
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
214214
pub enum TyParamBound {
215215
TraitTyParamBound(TraitRef),
216-
UnboxedFnTyParamBound(P<UnboxedFnBound>),
216+
UnboxedFnTyParamBound(UnboxedFnTy),
217217
RegionTyParamBound(Lifetime)
218218
}
219219

220220
pub type TyParamBounds = OwnedSlice<TyParamBound>;
221221

222-
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
223-
pub struct UnboxedFnBound {
224-
pub path: Path,
225-
pub decl: P<FnDecl>,
226-
pub ref_id: NodeId,
227-
}
228-
229222
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
230223
pub struct TyParam {
231224
pub ident: Ident,

branches/try/src/libsyntax/diagnostics/plugin.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use std::collections::HashMap;
1313
use ast;
1414
use ast::{Ident, Name, TokenTree};
1515
use codemap::Span;
16-
use ext::base::{ExtCtxt, MacExpr, MacItem, MacResult};
16+
use ext::base::{ExtCtxt, MacExpr, MacResult, MacItems};
1717
use ext::build::AstBuilder;
1818
use parse::token;
1919
use ptr::P;
@@ -102,7 +102,7 @@ pub fn expand_register_diagnostic<'cx>(ecx: &'cx mut ExtCtxt,
102102
let sym = Ident::new(token::gensym((
103103
"__register_diagnostic_".to_string() + token::get_ident(*code).get()
104104
).as_slice()));
105-
MacItem::new(quote_item!(ecx, mod $sym {}).unwrap())
105+
MacItems::new(vec![quote_item!(ecx, mod $sym {}).unwrap()].into_iter())
106106
}
107107

108108
pub fn expand_build_diagnostic_array<'cx>(ecx: &'cx mut ExtCtxt,
@@ -133,7 +133,7 @@ pub fn expand_build_diagnostic_array<'cx>(ecx: &'cx mut ExtCtxt,
133133
(descriptions.len(), ecx.expr_vec(span, descriptions))
134134
})
135135
});
136-
MacItem::new(quote_item!(ecx,
136+
MacItems::new(vec![quote_item!(ecx,
137137
pub static $name: [(&'static str, &'static str), ..$count] = $expr;
138-
).unwrap())
138+
).unwrap()].into_iter())
139139
}

branches/try/src/libsyntax/ext/base.rs

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -203,25 +203,20 @@ impl MacResult for MacPat {
203203
Some(self.p)
204204
}
205205
}
206-
/// A convenience type for macros that return a single item.
207-
pub struct MacItem {
208-
i: P<ast::Item>
206+
/// A type for macros that return multiple items.
207+
pub struct MacItems {
208+
items: SmallVector<P<ast::Item>>
209209
}
210-
impl MacItem {
211-
pub fn new(i: P<ast::Item>) -> Box<MacResult+'static> {
212-
box MacItem { i: i } as Box<MacResult+'static>
210+
211+
impl MacItems {
212+
pub fn new<I: Iterator<P<ast::Item>>>(mut it: I) -> Box<MacResult+'static> {
213+
box MacItems { items: it.collect() } as Box<MacResult+'static>
213214
}
214215
}
215-
impl MacResult for MacItem {
216-
fn make_items(self: Box<MacItem>) -> Option<SmallVector<P<ast::Item>>> {
217-
Some(SmallVector::one(self.i))
218-
}
219-
fn make_stmt(self: Box<MacItem>) -> Option<P<ast::Stmt>> {
220-
Some(P(codemap::respan(
221-
self.i.span,
222-
ast::StmtDecl(
223-
P(codemap::respan(self.i.span, ast::DeclItem(self.i))),
224-
ast::DUMMY_NODE_ID))))
216+
217+
impl MacResult for MacItems {
218+
fn make_items(self: Box<MacItems>) -> Option<SmallVector<P<ast::Item>>> {
219+
Some(self.items)
225220
}
226221
}
227222

branches/try/src/libsyntax/fold.rs

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -657,26 +657,16 @@ pub fn noop_fold_fn_decl<T: Folder>(decl: P<FnDecl>, fld: &mut T) -> P<FnDecl> {
657657
})
658658
}
659659

660-
pub fn noop_fold_ty_param_bound<T>(tpb: TyParamBound, fld: &mut T)
661-
-> TyParamBound
662-
where T: Folder {
660+
pub fn noop_fold_ty_param_bound<T: Folder>(tpb: TyParamBound, fld: &mut T)
661+
-> TyParamBound {
663662
match tpb {
664663
TraitTyParamBound(ty) => TraitTyParamBound(fld.fold_trait_ref(ty)),
665664
RegionTyParamBound(lifetime) => RegionTyParamBound(fld.fold_lifetime(lifetime)),
666-
UnboxedFnTyParamBound(bound) => {
667-
match *bound {
668-
UnboxedFnBound {
669-
ref path,
670-
ref decl,
671-
ref_id
672-
} => {
673-
UnboxedFnTyParamBound(P(UnboxedFnBound {
674-
path: fld.fold_path(path.clone()),
675-
decl: fld.fold_fn_decl(decl.clone()),
676-
ref_id: fld.new_id(ref_id),
677-
}))
678-
}
679-
}
665+
UnboxedFnTyParamBound(UnboxedFnTy {decl, kind}) => {
666+
UnboxedFnTyParamBound(UnboxedFnTy {
667+
decl: fld.fold_fn_decl(decl),
668+
kind: kind,
669+
})
680670
}
681671
}
682672
}

branches/try/src/libsyntax/parse/parser.rs

Lines changed: 49 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ use ast::{TyTypeof, TyInfer, TypeMethod};
5555
use ast::{TyNil, TyParam, TyParamBound, TyParen, TyPath, TyPtr, TyQPath};
5656
use ast::{TyRptr, TyTup, TyU32, TyUnboxedFn, TyUniq, TyVec, UnUniq};
5757
use ast::{TypeImplItem, TypeTraitItem, Typedef, UnboxedClosureKind};
58-
use ast::{UnboxedFnBound, UnboxedFnTy, UnboxedFnTyParamBound};
59-
use ast::{UnnamedField, UnsafeBlock};
58+
use ast::{UnboxedFnTy, UnboxedFnTyParamBound, UnnamedField, UnsafeBlock};
6059
use ast::{UnsafeFn, ViewItem, ViewItem_, ViewItemExternCrate, ViewItemUse};
6160
use ast::{ViewPath, ViewPathGlob, ViewPathList, ViewPathSimple};
6261
use ast::{Visibility, WhereClause, WherePredicate};
@@ -3667,6 +3666,39 @@ impl<'a> Parser<'a> {
36673666
})
36683667
}
36693668

3669+
fn parse_unboxed_function_type(&mut self) -> UnboxedFnTy {
3670+
let (optional_unboxed_closure_kind, inputs) =
3671+
if self.eat(&token::OROR) {
3672+
(None, Vec::new())
3673+
} else {
3674+
self.expect_or();
3675+
3676+
let optional_unboxed_closure_kind =
3677+
self.parse_optional_unboxed_closure_kind();
3678+
3679+
let inputs = self.parse_seq_to_before_or(&token::COMMA,
3680+
|p| {
3681+
p.parse_arg_general(false)
3682+
});
3683+
self.expect_or();
3684+
(optional_unboxed_closure_kind, inputs)
3685+
};
3686+
3687+
let (return_style, output) = self.parse_ret_ty();
3688+
UnboxedFnTy {
3689+
decl: P(FnDecl {
3690+
inputs: inputs,
3691+
output: output,
3692+
cf: return_style,
3693+
variadic: false,
3694+
}),
3695+
kind: match optional_unboxed_closure_kind {
3696+
Some(kind) => kind,
3697+
None => FnMutUnboxedClosureKind,
3698+
},
3699+
}
3700+
}
3701+
36703702
// Parses a sequence of bounds if a `:` is found,
36713703
// otherwise returns empty list.
36723704
fn parse_colon_then_ty_param_bounds(&mut self)
@@ -3698,31 +3730,13 @@ impl<'a> Parser<'a> {
36983730
self.bump();
36993731
}
37003732
token::MOD_SEP | token::IDENT(..) => {
3701-
let path =
3702-
self.parse_path(LifetimeAndTypesWithoutColons).path;
3703-
if self.token == token::LPAREN {
3704-
self.bump();
3705-
let inputs = self.parse_seq_to_end(
3706-
&token::RPAREN,
3707-
seq_sep_trailing_allowed(token::COMMA),
3708-
|p| p.parse_arg_general(false));
3709-
let (return_style, output) = self.parse_ret_ty();
3710-
result.push(UnboxedFnTyParamBound(P(UnboxedFnBound {
3711-
path: path,
3712-
decl: P(FnDecl {
3713-
inputs: inputs,
3714-
output: output,
3715-
cf: return_style,
3716-
variadic: false,
3717-
}),
3718-
ref_id: ast::DUMMY_NODE_ID,
3719-
})));
3720-
} else {
3721-
result.push(TraitTyParamBound(ast::TraitRef {
3722-
path: path,
3723-
ref_id: ast::DUMMY_NODE_ID,
3724-
}))
3725-
}
3733+
let tref = self.parse_trait_ref();
3734+
result.push(TraitTyParamBound(tref));
3735+
}
3736+
token::BINOP(token::OR) | token::OROR => {
3737+
let unboxed_function_type =
3738+
self.parse_unboxed_function_type();
3739+
result.push(UnboxedFnTyParamBound(unboxed_function_type));
37263740
}
37273741
_ => break,
37283742
}
@@ -4409,6 +4423,14 @@ impl<'a> Parser<'a> {
44094423
Some(attrs))
44104424
}
44114425

4426+
/// Parse a::B<String,int>
4427+
fn parse_trait_ref(&mut self) -> TraitRef {
4428+
ast::TraitRef {
4429+
path: self.parse_path(LifetimeAndTypesWithoutColons).path,
4430+
ref_id: ast::DUMMY_NODE_ID,
4431+
}
4432+
}
4433+
44124434
/// Parse struct Foo { ... }
44134435
fn parse_item_struct(&mut self, is_virtual: bool) -> ItemInfo {
44144436
let class_name = self.parse_ident();

0 commit comments

Comments
 (0)