Skip to content

Commit b674872

Browse files
committed
---
yaml --- r: 44876 b: refs/heads/master c: 10faa52 h: refs/heads/master v: v3
1 parent 7ea2113 commit b674872

File tree

7 files changed

+45
-16
lines changed

7 files changed

+45
-16
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: b662d3c922f1922da55d324aa65dfe268c2bb971
2+
refs/heads/master: 10faa521aef3721effc2ac9c2df0ceca4d825f98
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: a6d9689399d091c3265f00434a69c551a61c28dc
55
refs/heads/try: ef355f6332f83371e4acf04fc4eb940ab41d78d3

trunk/CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ You're not off the hook even if you just stick to documentation; code examples i
1111
Pull requests will be treated as "review requests",
1212
and we will give feedback we expect to see corrected on [style](https://github.com/mozilla/rust/wiki/Note-style-guide) and substance before pulling.
1313
Changes contributed via pull request should focus on a single issue at a time, like any other.
14-
We will not look accept pull-requests that try to "sneak" unrelated changes in.
14+
We will not accept pull-requests that try to "sneak" unrelated changes in.
1515

1616
Normally, all pull requests must include regression tests (see [Note-testsuite](https://github.com/mozilla/rust/wiki/Note-testsuite)) that test your change.
1717
Occasionally, a change will be very difficult to test for.

trunk/doc/rust.md

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -908,6 +908,11 @@ function defined above on `[1, 2]` will instantiate type parameter `T`
908908
with `int`, and require the closure parameter to have type
909909
`fn(int)`.
910910

911+
The type parameters can also be explicitly supplied in a trailing
912+
[path](#paths) component after the function name. This might be necessary
913+
if there is not sufficient context to determine the type parameters. For
914+
example, `sys::size_of::<u32>() == 4`.
915+
911916
Since a parameter type is opaque to the generic function, the set of
912917
operations that can be performed on it is limited. Values of parameter
913918
type can always be moved, but they can only be copied when the
@@ -1085,6 +1090,15 @@ let p = Point(10, 11);
10851090
let px: int = match p { Point(x, _) => x };
10861091
~~~~
10871092

1093+
A _unit-like struct_ is a structure without any fields, defined by leaving off the fields list entirely.
1094+
Such types will have a single value, just like the [unit value `()`](#unit-and-boolean-literals) of the unit type.
1095+
For example:
1096+
1097+
~~~~
1098+
struct Cookie;
1099+
let c = [Cookie, Cookie, Cookie, Cookie];
1100+
~~~~
1101+
10881102
### Enumerations
10891103

10901104
An _enumeration_ is a simultaneous definition of a nominal [enumerated type](#enumerated-types) as well as a set of *constructors*,
@@ -1590,7 +1604,8 @@ struct_expr : expr_path '{' ident ':' expr
15901604
[ ',' ident ':' expr ] *
15911605
[ ".." expr ] '}' |
15921606
expr_path '(' expr
1593-
[ ',' expr ] * ')'
1607+
[ ',' expr ] * ')' |
1608+
expr_path
15941609
~~~~~~~~
15951610

15961611
There are several forms of structure expressions.
@@ -1600,23 +1615,28 @@ providing the field values of a new instance of the structure.
16001615
A field name can be any identifier, and is separated from its value expression by a colon.
16011616
To indicate that a field is mutable, the `mut` keyword is written before its name.
16021617

1603-
A _tuple structure expression_ constists of the [path](#paths) of a [structure item](#structures),
1618+
A _tuple structure expression_ consists of the [path](#paths) of a [structure item](#structures),
16041619
followed by a parenthesized list of one or more comma-separated expressions
16051620
(in other words, the path of a structured item followed by a tuple expression).
16061621
The structure item must be a tuple structure item.
16071622

1623+
A _unit-like structure expression_ consists only of the [path](#paths) of a [structure item](#structures).
1624+
16081625
The following are examples of structure expressions:
16091626

16101627
~~~~
16111628
# struct Point { x: float, y: float }
16121629
# struct TuplePoint(float, float);
16131630
# mod game { pub struct User { name: &str, age: uint, score: uint } }
1631+
# struct Cookie; fn some_fn<T>(t: T) {}
16141632
Point {x: 10f, y: 20f};
16151633
TuplePoint(10f, 20f);
16161634
let u = game::User {name: "Joe", age: 35u, score: 100_000};
1635+
some_fn::<Cookie>(Cookie);
16171636
~~~~
16181637

16191638
A structure expression forms a new value of the named structure type.
1639+
Note that for a given *unit-like* structure type, this will always be the same value.
16201640

16211641
A structure expression can terminate with the syntax `..` followed by an expression to denote a functional update.
16221642
The expression following `..` (the base) must be of the same structure type as the new structure type being formed.
@@ -2040,12 +2060,14 @@ an optional reference slot to serve as the function's output, bound to the
20402060
`lval` on the right hand side of the call. If the function eventually returns,
20412061
then the expression completes.
20422062

2043-
An example of a call expression:
2063+
Some examples of call expressions:
20442064

20452065
~~~~
20462066
# fn add(x: int, y: int) -> int { 0 }
2067+
# use core::from_str::FromStr::from_str;
20472068
20482069
let x: int = add(1, 2);
2070+
let pi = from_str::<f32>("3.14");
20492071
~~~~
20502072

20512073
### Lambda expressions
@@ -2643,7 +2665,10 @@ the resulting `struct` value will always be laid out in memory in the order spec
26432665
The fields of a `struct` may be qualified by [visibility modifiers](#visibility-modifiers),
26442666
to restrict access to implementation-private data in a structure.
26452667

2646-
A `tuple struct` type is just like a structure type, except that the fields are anonymous.
2668+
A _tuple struct_ type is just like a structure type, except that the fields are anonymous.
2669+
2670+
A _unit-like struct_ type is like a structure type, except that it has no fields.
2671+
The one value constructed by the associated [structure expression](#structure-expression) is the only value that inhabits such a type.
26472672

26482673
### Enumerated types
26492674

trunk/src/librustc/middle/kind.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ pub fn check_expr(e: @expr, cx: Context, v: visit::vt<Context>) {
234234
"explicit copy requires a copyable argument");
235235
}
236236
expr_repeat(element, count_expr, _) => {
237-
let count = ty::eval_repeat_count(cx.tcx, count_expr);
237+
let count = ty::eval_repeat_count(cx.tcx, count_expr, e.span);
238238
if count > 1 {
239239
let element_ty = ty::expr_ty(cx.tcx, element);
240240
check_copy(cx, element_ty, element.span,

trunk/src/librustc/middle/trans/tvec.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,8 @@ pub fn write_content(bcx: block,
410410
return expr::trans_into(bcx, element, Ignore);
411411
}
412412
SaveIn(lldest) => {
413-
let count = ty::eval_repeat_count(bcx.tcx(), count_expr);
413+
let count = ty::eval_repeat_count(bcx.tcx(), count_expr,
414+
count_expr.span);
414415
if count == 0 {
415416
return bcx;
416417
}
@@ -475,7 +476,7 @@ pub fn elements_required(bcx: block, content_expr: @ast::expr) -> uint {
475476
},
476477
ast::expr_vec(es, _) => es.len(),
477478
ast::expr_repeat(_, count_expr, _) => {
478-
ty::eval_repeat_count(bcx.tcx(), count_expr)
479+
ty::eval_repeat_count(bcx.tcx(), count_expr, content_expr.span)
479480
}
480481
_ => bcx.tcx().sess.span_bug(content_expr.span,
481482
~"Unexpected evec content")

trunk/src/librustc/middle/ty.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4247,32 +4247,35 @@ pub fn normalize_ty(cx: ctxt, t: t) -> t {
42474247
}
42484248
42494249
// Returns the repeat count for a repeating vector expression.
4250-
pub fn eval_repeat_count(tcx: ctxt, count_expr: @ast::expr) -> uint {
4250+
pub fn eval_repeat_count(tcx: ctxt,
4251+
count_expr: @ast::expr,
4252+
span: span)
4253+
-> uint {
42514254
match const_eval::eval_const_expr_partial(tcx, count_expr) {
42524255
Ok(ref const_val) => match *const_val {
42534256
const_eval::const_int(count) => return count as uint,
42544257
const_eval::const_uint(count) => return count as uint,
42554258
const_eval::const_float(count) => {
4256-
tcx.sess.span_err(count_expr.span,
4259+
tcx.sess.span_err(span,
42574260
~"expected signed or unsigned integer for \
42584261
repeat count but found float");
42594262
return count as uint;
42604263
}
42614264
const_eval::const_str(_) => {
4262-
tcx.sess.span_err(count_expr.span,
4265+
tcx.sess.span_err(span,
42634266
~"expected signed or unsigned integer for \
42644267
repeat count but found string");
42654268
return 0;
42664269
}
42674270
const_eval::const_bool(_) => {
4268-
tcx.sess.span_err(count_expr.span,
4271+
tcx.sess.span_err(span,
42694272
~"expected signed or unsigned integer for \
42704273
repeat count but found boolean");
42714274
return 0;
42724275
}
42734276
},
42744277
Err(*) => {
4275-
tcx.sess.span_err(count_expr.span,
4278+
tcx.sess.span_err(span,
42764279
~"expected constant integer for repeat count \
42774280
but found variable");
42784281
return 0;

trunk/src/librustc/middle/typeck/check/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2147,7 +2147,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
21472147
ty::mk_evec(tcx, ty::mt {ty: t, mutbl: mutability}, tt)
21482148
}
21492149
ast::expr_repeat(element, count_expr, mutbl) => {
2150-
let count = ty::eval_repeat_count(tcx, count_expr);
2150+
let count = ty::eval_repeat_count(tcx, count_expr, expr.span);
21512151
fcx.write_ty(count_expr.id, ty::mk_uint(tcx));
21522152
let tt = ast_expr_vstore_to_vstore(fcx, ev, count, vst);
21532153
let t: ty::t = fcx.infcx().next_ty_var();
@@ -2474,7 +2474,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
24742474
fcx.write_ty(id, typ);
24752475
}
24762476
ast::expr_repeat(element, count_expr, mutbl) => {
2477-
let count = ty::eval_repeat_count(tcx, count_expr);
2477+
let count = ty::eval_repeat_count(tcx, count_expr, expr.span);
24782478
fcx.write_ty(count_expr.id, ty::mk_uint(tcx));
24792479
let t: ty::t = fcx.infcx().next_ty_var();
24802480
bot |= check_expr_has_type(fcx, element, t);

0 commit comments

Comments
 (0)