Skip to content

Commit e028222

Browse files
committed
---
yaml --- r: 152758 b: refs/heads/try2 c: 654d644 h: refs/heads/master v: v3
1 parent de532eb commit e028222

28 files changed

+139
-110
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: d6c1b85246f99b5485f3671bfca2a4657e0c37fd
8+
refs/heads/try2: 654d6444feafaa7bae17057d8b98823c7556ea14
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/doc/rust.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3004,7 +3004,7 @@ ten_times(|j| println!("hello, {}", j));
30043004
### While loops
30053005

30063006
~~~~ {.ebnf .gram}
3007-
while_expr : "while" expr '{' block '}' ;
3007+
while_expr : "while" no_struct_literal_expr '{' block '}' ;
30083008
~~~~
30093009

30103010
A `while` loop begins by evaluating the boolean loop conditional expression.
@@ -3071,7 +3071,7 @@ A `continue` expression is only permitted in the body of a loop.
30713071
### For expressions
30723072

30733073
~~~~ {.ebnf .gram}
3074-
for_expr : "for" pat "in" expr '{' block '}' ;
3074+
for_expr : "for" pat "in" no_struct_literal_expr '{' block '}' ;
30753075
~~~~
30763076

30773077
A `for` expression is a syntactic construct for looping over elements
@@ -3105,7 +3105,7 @@ for i in range(0u, 256) {
31053105
### If expressions
31063106

31073107
~~~~ {.ebnf .gram}
3108-
if_expr : "if" expr '{' block '}'
3108+
if_expr : "if" no_struct_literal_expr '{' block '}'
31093109
else_tail ? ;
31103110
31113111
else_tail : "else" [ if_expr
@@ -3126,7 +3126,7 @@ then any `else` block is executed.
31263126
### Match expressions
31273127

31283128
~~~~ {.ebnf .gram}
3129-
match_expr : "match" expr '{' match_arm * '}' ;
3129+
match_expr : "match" no_struct_literal_expr '{' match_arm * '}' ;
31303130
31313131
match_arm : attribute * match_pat "=>" [ expr "," | '{' block '}' ] ;
31323132

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

Lines changed: 2 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3894,31 +3894,8 @@ impl<'a> Resolver<'a> {
38943894
self.resolve_error(trait_reference.path.span, msg.as_slice());
38953895
}
38963896
Some(def) => {
3897-
match def {
3898-
(DefTrait(_), _) => {
3899-
debug!("(resolving trait) found trait def: {:?}", def);
3900-
self.record_def(trait_reference.ref_id, def);
3901-
}
3902-
(def, _) => {
3903-
self.resolve_error(trait_reference.path.span,
3904-
format!("`{}` is not a trait",
3905-
self.path_idents_to_str(
3906-
&trait_reference.path)));
3907-
3908-
// If it's a typedef, give a note
3909-
match def {
3910-
DefTy(_) => {
3911-
self.session.span_note(
3912-
trait_reference.path.span,
3913-
format!("`type` aliases cannot \
3914-
be used for traits")
3915-
.as_slice());
3916-
}
3917-
_ => {}
3918-
}
3919-
}
3920-
}
3921-
3897+
debug!("(resolving trait) found trait def: {:?}", def);
3898+
self.record_def(trait_reference.ref_id, def);
39223899
}
39233900
}
39243901
}
@@ -4044,9 +4021,6 @@ impl<'a> Resolver<'a> {
40444021

40454022
this.with_current_self_type(self_type, |this| {
40464023
for method in methods.iter() {
4047-
// If this is a trait impl, ensure the method exists in trait
4048-
this.check_trait_method(&**method);
4049-
40504024
// We also need a new scope for the method-specific type parameters.
40514025
this.resolve_method(MethodRibKind(id, Provided(method.id)),
40524026
&**method);
@@ -4056,21 +4030,6 @@ impl<'a> Resolver<'a> {
40564030
});
40574031
}
40584032

4059-
fn check_trait_method(&self, method: &Method) {
4060-
// If there is a TraitRef in scope for an impl, then the method must be in the trait.
4061-
for &(did, ref trait_ref) in self.current_trait_ref.iter() {
4062-
let method_name = method.ident.name;
4063-
4064-
if self.method_map.borrow().find(&(method_name, did)).is_none() {
4065-
let path_str = self.path_idents_to_str(&trait_ref.path);
4066-
self.resolve_error(method.span,
4067-
format!("method `{}` is not a member of trait `{}`",
4068-
token::get_name(method_name),
4069-
path_str).as_slice());
4070-
}
4071-
}
4072-
}
4073-
40744033
fn resolve_module(&mut self, module: &Mod, _span: Span,
40754034
_name: Ident, id: NodeId) {
40764035
// Write the implementations in scope into the module metadata.

branches/try2/src/librustc/middle/typeck/check/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -784,8 +784,7 @@ fn check_impl_methods_against_trait(ccx: &CrateCtxt,
784784
&impl_trait_ref.substs);
785785
}
786786
None => {
787-
// This is span_bug as it should have already been caught in resolve.
788-
tcx.sess.span_bug(
787+
tcx.sess.span_err(
789788
impl_method.span,
790789
format!(
791790
"method `{}` is not a member of trait `{}`",

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

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ pub enum restriction {
8888
RESTRICT_STMT_EXPR,
8989
RESTRICT_NO_BAR_OP,
9090
RESTRICT_NO_BAR_OR_DOUBLEBAR_OP,
91+
RESTRICT_NO_STRUCT_LITERAL,
9192
}
9293

9394
type ItemInfo = (Ident, Item_, Option<Vec<Attribute> >);
@@ -2024,8 +2025,9 @@ impl<'a> Parser<'a> {
20242025

20252026
return self.mk_mac_expr(lo, hi, MacInvocTT(pth, tts, EMPTY_CTXT));
20262027
} else if self.token == token::LBRACE {
2027-
// This might be a struct literal.
2028-
if self.looking_at_struct_literal() {
2028+
// This is a struct literal, unless we're prohibited from
2029+
// parsing struct literals here.
2030+
if self.restriction != RESTRICT_NO_STRUCT_LITERAL {
20292031
// It's a struct literal.
20302032
self.bump();
20312033
let mut fields = Vec::new();
@@ -2042,6 +2044,14 @@ impl<'a> Parser<'a> {
20422044
&[token::COMMA], &[token::RBRACE]);
20432045
}
20442046

2047+
if fields.len() == 0 && base.is_none() {
2048+
let last_span = self.last_span;
2049+
self.span_err(last_span,
2050+
"structure literal must either have at \
2051+
least one field or use functional \
2052+
structure update syntax");
2053+
}
2054+
20452055
hi = self.span.hi;
20462056
self.expect(&token::RBRACE);
20472057
ex = ExprStruct(pth, fields, base);
@@ -2548,7 +2558,7 @@ impl<'a> Parser<'a> {
25482558
// parse an 'if' expression ('if' token already eaten)
25492559
pub fn parse_if_expr(&mut self) -> Gc<Expr> {
25502560
let lo = self.last_span.lo;
2551-
let cond = self.parse_expr();
2561+
let cond = self.parse_expr_res(RESTRICT_NO_STRUCT_LITERAL);
25522562
let thn = self.parse_block();
25532563
let mut els: Option<Gc<Expr>> = None;
25542564
let mut hi = thn.span.hi;
@@ -2633,7 +2643,7 @@ impl<'a> Parser<'a> {
26332643
let lo = self.last_span.lo;
26342644
let pat = self.parse_pat();
26352645
self.expect_keyword(keywords::In);
2636-
let expr = self.parse_expr();
2646+
let expr = self.parse_expr_res(RESTRICT_NO_STRUCT_LITERAL);
26372647
let loop_block = self.parse_block();
26382648
let hi = self.span.hi;
26392649

@@ -2642,7 +2652,7 @@ impl<'a> Parser<'a> {
26422652

26432653
pub fn parse_while_expr(&mut self) -> Gc<Expr> {
26442654
let lo = self.last_span.lo;
2645-
let cond = self.parse_expr();
2655+
let cond = self.parse_expr_res(RESTRICT_NO_STRUCT_LITERAL);
26462656
let body = self.parse_block();
26472657
let hi = body.span.hi;
26482658
return self.mk_expr(lo, hi, ExprWhile(cond, body));
@@ -2655,17 +2665,9 @@ impl<'a> Parser<'a> {
26552665
self.mk_expr(lo, hi, ExprLoop(body, opt_ident))
26562666
}
26572667

2658-
// For distinguishing between struct literals and blocks
2659-
fn looking_at_struct_literal(&mut self) -> bool {
2660-
self.token == token::LBRACE &&
2661-
((self.look_ahead(1, |t| token::is_plain_ident(t)) &&
2662-
self.look_ahead(2, |t| *t == token::COLON))
2663-
|| self.look_ahead(1, |t| *t == token::DOTDOT))
2664-
}
2665-
26662668
fn parse_match_expr(&mut self) -> Gc<Expr> {
26672669
let lo = self.last_span.lo;
2668-
let discriminant = self.parse_expr();
2670+
let discriminant = self.parse_expr_res(RESTRICT_NO_STRUCT_LITERAL);
26692671
self.commit_expr_expecting(discriminant, token::LBRACE);
26702672
let mut arms: Vec<Arm> = Vec::new();
26712673
while self.token != token::RBRACE {

branches/try2/src/test/compile-fail/bind-struct-early-modifiers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
fn main() {
1212
struct Foo { x: int }
13-
match Foo { x: 10 } {
13+
match (Foo { x: 10 }) {
1414
Foo { ref x: ref x } => {}, //~ ERROR unexpected `:`
1515
_ => {}
1616
}

branches/try2/src/test/compile-fail/borrowck-match-binding-is-assignment.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub fn main() {
3131
}
3232
}
3333

34-
match S { bar: 1 } {
34+
match (S { bar: 1 }) {
3535
S { bar: x } => {
3636
x += 1; //~ ERROR re-assignment of immutable variable `x`
3737
}

branches/try2/src/test/compile-fail/borrowck-move-error-with-note.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl Drop for S {
3434
}
3535

3636
fn move_in_match() {
37-
match S {f: "foo".to_string(), g: "bar".to_string()} {
37+
match (S {f: "foo".to_string(), g: "bar".to_string()}) {
3838
S { //~ ERROR cannot move out of type `S`, which defines the `Drop` trait
3939
f: _s, //~ NOTE attempting to move value to here
4040
g: _t //~ NOTE and here

branches/try2/src/test/compile-fail/borrowck-move-out-of-struct-with-dtor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ impl Drop for S {
1414
}
1515

1616
fn move_in_match() {
17-
match S {f:"foo".to_string()} {
17+
match (S {f:"foo".to_string()}) {
1818
S {f:_s} => {}
1919
//~^ ERROR cannot move out of type `S`, which defines the `Drop` trait
2020
}

branches/try2/src/test/compile-fail/issue-3907.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -11,14 +11,13 @@
1111
// aux-build:issue_3907.rs
1212
extern crate issue_3907;
1313

14-
type Foo = issue_3907::Foo;
14+
type Foo = issue_3907::Foo; //~ ERROR: reference to trait
1515

1616
struct S {
1717
name: int
1818
}
1919

2020
impl Foo for S { //~ ERROR: `Foo` is not a trait
21-
//~^ NOTE: `type` aliases cannot be used for traits
2221
fn bar() { }
2322
}
2423

branches/try2/src/test/compile-fail/issue-3973.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,26 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// ignore-test
12+
13+
use std::io;
14+
1115
struct Point {
1216
x: f64,
1317
y: f64,
1418
}
1519

16-
trait NewTrait {
17-
fn a(&self) -> String;
18-
}
19-
20-
impl NewTrait for Point {
20+
impl ToStr for Point { //~ ERROR implements a method not defined in the trait
2121
fn new(x: f64, y: f64) -> Point {
22-
//~^ ERROR method `new` is not a member of trait `NewTrait`
2322
Point { x: x, y: y }
2423
}
2524

26-
fn a(&self) -> String {
25+
fn to_str(&self) -> String {
2726
format!("({}, {})", self.x, self.y)
2827
}
2928
}
3029

3130
fn main() {
3231
let p = Point::new(0.0, 0.0);
33-
//~^ ERROR unresolved name `Point::new`
34-
//~^^ ERROR failed to resolve. Use of undeclared module `Point`
35-
println!("{}", p.a());
32+
println!("{}", p.to_str());
3633
}

branches/try2/src/test/compile-fail/issue-5035.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
// except according to those terms.
1010

1111
trait I {}
12-
type K = I;
12+
type K = I; //~ ERROR: reference to trait
1313
impl K for int {} //~ ERROR: `K` is not a trait
14-
//~^ NOTE: `type` aliases cannot be used for traits
1514
fn main() {}

branches/try2/src/test/compile-fail/match-struct.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ struct S { a: int }
1313
enum E { C(int) }
1414

1515
fn main() {
16-
match S { a: 1 } {
16+
match (S { a: 1 }) {
1717
C(_) => (), //~ ERROR mismatched types: expected `S` but found `E`
1818
_ => ()
1919
}

branches/try2/src/test/compile-fail/non-exhaustive-pattern-witness.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ enum Color {
2222
}
2323

2424
fn struct_with_a_nested_enum_and_vector() {
25-
match Foo { first: true, second: None } {
25+
match (Foo { first: true, second: None }) {
2626
//~^ ERROR non-exhaustive patterns: `Foo{first: false, second: Some([_, _, _, _])}` not covered
2727
Foo { first: true, second: None } => (),
2828
Foo { first: true, second: Some(_) } => (),
@@ -71,4 +71,4 @@ fn main() {
7171
struct_with_a_nested_enum_and_vector();
7272
enum_with_multiple_missing_variants();
7373
enum_struct_variant();
74-
}
74+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
struct Foo {
12+
x: int,
13+
}
14+
15+
impl Foo {
16+
fn hi(&self) -> bool {
17+
true
18+
}
19+
}
20+
21+
fn main() {
22+
for x in Foo {
23+
x: 3 //~ ERROR expected one of `;`, `}`
24+
}.hi() {
25+
println!("yo");
26+
}
27+
}
28+

branches/try2/src/test/compile-fail/issue-5035-2.rs renamed to branches/try2/src/test/compile-fail/struct-literal-in-if.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -8,7 +8,21 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
trait I {}
12-
type K = I; //~ ERROR: reference to trait
11+
struct Foo {
12+
x: int,
13+
}
14+
15+
impl Foo {
16+
fn hi(&self) -> bool {
17+
true
18+
}
19+
}
20+
21+
fn main() {
22+
if Foo {
23+
x: 3 //~ ERROR expected one of `;`, `}`
24+
}.hi() {
25+
println!("yo");
26+
}
27+
}
1328

14-
fn main() {}

0 commit comments

Comments
 (0)