Skip to content

Commit ad11e84

Browse files
committed
---
yaml --- r: 152927 b: refs/heads/try2 c: b47f222 h: refs/heads/master i: 152925: f35ff87 152923: c891852 152919: 35e00bf 152911: a31d11b 152895: 38db87d v: v3
1 parent 7d749a7 commit ad11e84

31 files changed

+519
-198
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: a208842b9d2e62ffeaa8d6b7e02ce523efae033c
8+
refs/heads/try2: b47f2226a25654c5b781d27a91f2fa5274b3a347
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/doc/guide-macros.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,7 @@ macro_rules! biased_match_rec (
355355
_ => { $err }
356356
}
357357
);
358+
// Produce the requested values
358359
( binds $( $bind_res:ident ),* ) => ( ($( $bind_res ),*) )
359360
)
360361
@@ -364,7 +365,7 @@ macro_rules! biased_match (
364365
( $( ($e:expr) ~ ($p:pat) else $err:stmt ; )*
365366
binds $bind_res:ident
366367
) => (
367-
let ( $( $bind_res ),* ) = biased_match_rec!(
368+
let $bind_res = biased_match_rec!(
368369
$( ($e) ~ ($p) else $err ; )*
369370
binds $bind_res
370371
);

branches/try2/src/doc/guide.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,3 +411,64 @@ rest of your Rust career.
411411

412412
Next, we'll learn more about Rust itself, by starting to write a more complicated
413413
program. We hope you want to do more with Rust than just print "Hello, world!"
414+
415+
## If
416+
417+
## Functions
418+
419+
return
420+
421+
comments
422+
423+
## Testing
424+
425+
attributes
426+
427+
stability markers
428+
429+
## Crates and Modules
430+
431+
visibility
432+
433+
## Compound Data Types
434+
435+
Tuples
436+
437+
Structs
438+
439+
Enums
440+
441+
## Match
442+
443+
## Looping
444+
445+
for
446+
447+
while
448+
449+
loop
450+
451+
break/continue
452+
453+
iterators
454+
455+
## Lambdas
456+
457+
## Generics
458+
459+
## Traits
460+
461+
## Operators and built-in Traits
462+
463+
## Ownership and Lifetimes
464+
465+
Move vs. Copy
466+
467+
Allocation
468+
469+
## Tasks
470+
471+
## Macros
472+
473+
## Unsafe
474+

branches/try2/src/doc/tutorial.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -493,11 +493,12 @@ by an *action* (expression). Each case is separated by commas. It is
493493
often convenient to use a block expression for each case, in which case
494494
the commas are optional as shown below. Literals are valid patterns and
495495
match only their own value. A single arm may match multiple different
496-
patterns by combining them with the pipe operator (`|`), so long as every
497-
pattern binds the same set of variables. Ranges of numeric literal
498-
patterns can be expressed with two dots, as in `M..N`. The underscore
499-
(`_`) is a wildcard pattern that matches any single value. (`..`) is a
500-
different wildcard that can match one or more fields in an `enum` variant.
496+
patterns by combining them with the pipe operator (`|`), so long as
497+
every pattern binds the same set of variables (see "destructuring"
498+
below). Ranges of numeric literal patterns can be expressed with two
499+
dots, as in `M..N`. The underscore (`_`) is a wildcard pattern that
500+
matches any single value. (`..`) is a different wildcard that can match
501+
one or more fields in an `enum` variant.
501502

502503
~~~
503504
# let my_number = 1;

branches/try2/src/librustc/lint/builtin.rs

Lines changed: 51 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -975,14 +975,52 @@ declare_lint!(UNNECESSARY_PARENS, Warn,
975975
pub struct UnnecessaryParens;
976976

977977
impl UnnecessaryParens {
978-
fn check_unnecessary_parens_core(&self, cx: &Context, value: &ast::Expr, msg: &str) {
978+
fn check_unnecessary_parens_core(&self, cx: &Context, value: &ast::Expr, msg: &str,
979+
struct_lit_needs_parens: bool) {
979980
match value.node {
980-
ast::ExprParen(_) => {
981-
cx.span_lint(UNNECESSARY_PARENS, value.span,
982-
format!("unnecessary parentheses around {}", msg).as_slice())
981+
ast::ExprParen(ref inner) => {
982+
let necessary = struct_lit_needs_parens && contains_exterior_struct_lit(&**inner);
983+
if !necessary {
984+
cx.span_lint(UNNECESSARY_PARENS, value.span,
985+
format!("unnecessary parentheses around {}",
986+
msg).as_slice())
987+
}
983988
}
984989
_ => {}
985990
}
991+
992+
/// Expressions that syntatically contain an "exterior" struct
993+
/// literal i.e. not surrounded by any parens or other
994+
/// delimiters, e.g. `X { y: 1 }`, `X { y: 1 }.method()`, `foo
995+
/// == X { y: 1 }` and `X { y: 1 } == foo` all do, but `(X {
996+
/// y: 1 }) == foo` does not.
997+
fn contains_exterior_struct_lit(value: &ast::Expr) -> bool {
998+
match value.node {
999+
ast::ExprStruct(..) => true,
1000+
1001+
ast::ExprAssign(ref lhs, ref rhs) |
1002+
ast::ExprAssignOp(_, ref lhs, ref rhs) |
1003+
ast::ExprBinary(_, ref lhs, ref rhs) => {
1004+
// X { y: 1 } + X { y: 2 }
1005+
contains_exterior_struct_lit(&**lhs) ||
1006+
contains_exterior_struct_lit(&**rhs)
1007+
}
1008+
ast::ExprUnary(_, ref x) |
1009+
ast::ExprCast(ref x, _) |
1010+
ast::ExprField(ref x, _, _) |
1011+
ast::ExprIndex(ref x, _) => {
1012+
// &X { y: 1 }, X { y: 1 }.y
1013+
contains_exterior_struct_lit(&**x)
1014+
}
1015+
1016+
ast::ExprMethodCall(_, _, ref exprs) => {
1017+
// X { y: 1 }.bar(...)
1018+
contains_exterior_struct_lit(&**exprs.get(0))
1019+
}
1020+
1021+
_ => false
1022+
}
1023+
}
9861024
}
9871025
}
9881026

@@ -992,16 +1030,16 @@ impl LintPass for UnnecessaryParens {
9921030
}
9931031

9941032
fn check_expr(&mut self, cx: &Context, e: &ast::Expr) {
995-
let (value, msg) = match e.node {
996-
ast::ExprIf(cond, _, _) => (cond, "`if` condition"),
997-
ast::ExprWhile(cond, _) => (cond, "`while` condition"),
998-
ast::ExprMatch(head, _) => (head, "`match` head expression"),
999-
ast::ExprRet(Some(value)) => (value, "`return` value"),
1000-
ast::ExprAssign(_, value) => (value, "assigned value"),
1001-
ast::ExprAssignOp(_, _, value) => (value, "assigned value"),
1033+
let (value, msg, struct_lit_needs_parens) = match e.node {
1034+
ast::ExprIf(cond, _, _) => (cond, "`if` condition", true),
1035+
ast::ExprWhile(cond, _) => (cond, "`while` condition", true),
1036+
ast::ExprMatch(head, _) => (head, "`match` head expression", true),
1037+
ast::ExprRet(Some(value)) => (value, "`return` value", false),
1038+
ast::ExprAssign(_, value) => (value, "assigned value", false),
1039+
ast::ExprAssignOp(_, _, value) => (value, "assigned value", false),
10021040
_ => return
10031041
};
1004-
self.check_unnecessary_parens_core(cx, &*value, msg);
1042+
self.check_unnecessary_parens_core(cx, &*value, msg, struct_lit_needs_parens);
10051043
}
10061044

10071045
fn check_stmt(&mut self, cx: &Context, s: &ast::Stmt) {
@@ -1015,7 +1053,7 @@ impl LintPass for UnnecessaryParens {
10151053
},
10161054
_ => return
10171055
};
1018-
self.check_unnecessary_parens_core(cx, &*value, msg);
1056+
self.check_unnecessary_parens_core(cx, &*value, msg, false);
10191057
}
10201058
}
10211059

branches/try2/src/librustc/middle/trans/expr.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,15 +277,19 @@ fn apply_adjustments<'a>(bcx: &'a Block<'a>,
277277
auto_ref(bcx, datum, expr)
278278
}
279279

280-
fn auto_borrow_obj<'a>(bcx: &'a Block<'a>,
280+
fn auto_borrow_obj<'a>(mut bcx: &'a Block<'a>,
281281
expr: &ast::Expr,
282282
source_datum: Datum<Expr>)
283283
-> DatumBlock<'a, Expr> {
284284
let tcx = bcx.tcx();
285285
let target_obj_ty = expr_ty_adjusted(bcx, expr);
286286
debug!("auto_borrow_obj(target={})", target_obj_ty.repr(tcx));
287287

288-
let mut datum = source_datum.to_expr_datum();
288+
// Arrange cleanup, if not already done. This is needed in
289+
// case we are auto-borrowing a Box<Trait> to &Trait
290+
let datum = unpack_datum!(
291+
bcx, source_datum.to_lvalue_datum(bcx, "autoborrowobj", expr.id));
292+
let mut datum = datum.to_expr_datum();
289293
datum.ty = target_obj_ty;
290294
DatumBlock::new(bcx, datum)
291295
}

branches/try2/src/libsyntax/ast.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,7 @@ pub enum Decl_ {
401401
DeclItem(Gc<Item>),
402402
}
403403

404+
/// represents one arm of a 'match'
404405
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
405406
pub struct Arm {
406407
pub attrs: Vec<Attribute>,

0 commit comments

Comments
 (0)