about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPatrick Walton <pcwalton@mimiga.net>2014-11-11 10:45:59 -0800
committerPatrick Walton <pcwalton@mimiga.net>2014-11-11 10:45:59 -0800
commite6e58e43f8f9507474fdf35544b6b0c0fc6cef39 (patch)
treea00320aad3332c0dd6d60f8ab46f4458f6696665
parent5d29209bda553e4d23a8b499d2ceb8db5c4f8be5 (diff)
downloadrust-e6e58e43f8f9507474fdf35544b6b0c0fc6cef39.tar.gz
rust-e6e58e43f8f9507474fdf35544b6b0c0fc6cef39.zip
libsyntax: Forbid type parameters in field expressions.
This breaks code like:

    struct Foo {
        x: int,
    }

    let f: Foo = ...;
    ... f.x::<int> ...

Change this code to not contain an unused type parameter. For example:

    struct Foo {
        x: int,
    }

    let f: Foo = ...;
    ... f.x ...

Closes #18680.

[breaking-change]
-rw-r--r--src/libsyntax/parse/parser.rs9
-rw-r--r--src/test/compile-fail/type-parameters-in-field-exprs.rs24
2 files changed, 32 insertions, 1 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index 6873c015fd5..90ada8a687c 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -2415,9 +2415,16 @@ impl<'a> Parser<'a> {
                             e = self.mk_expr(lo, hi, nd);
                         }
                         _ => {
+                            if !tys.is_empty() {
+                                let last_span = self.last_span;
+                                self.span_err(last_span,
+                                              "field expressions may not \
+                                               have type parameters");
+                            }
+
                             let id = spanned(dot, hi, i);
                             let field = self.mk_field(e, id, tys);
-                            e = self.mk_expr(lo, hi, field)
+                            e = self.mk_expr(lo, hi, field);
                         }
                     }
                   }
diff --git a/src/test/compile-fail/type-parameters-in-field-exprs.rs b/src/test/compile-fail/type-parameters-in-field-exprs.rs
new file mode 100644
index 00000000000..023f7d1c29f
--- /dev/null
+++ b/src/test/compile-fail/type-parameters-in-field-exprs.rs
@@ -0,0 +1,24 @@
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+struct Foo {
+    x: int,
+    y: int,
+}
+
+fn main() {
+    let f = Foo {
+        x: 1,
+        y: 2,
+    };
+    f.x::<int>;
+    //~^ ERROR field expressions may not have type parameters
+}
+