]> git.lizzy.rs Git - rust.git/commitdiff
syntax: Relax path grammar
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>
Sat, 29 Jul 2017 01:47:12 +0000 (04:47 +0300)
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>
Thu, 10 Aug 2017 23:06:27 +0000 (02:06 +0300)
src/libsyntax/parse/parser.rs
src/test/compile-fail/issue-32995.rs
src/test/compile-fail/issue-36116.rs
src/test/compile-fail/unboxed-closure-sugar-used-on-struct-3.rs [new file with mode: 0644]
src/test/parse-fail/type-parameters-in-field-exprs.rs
src/test/parse-fail/unboxed-closure-sugar-used-on-struct-3.rs [deleted file]

index 7bf4c6799b3cb208119bbaccb6535c643788b051..9e36adf3d35963effcf01bc83b041fe7b0411645 100644 (file)
@@ -84,7 +84,7 @@ pub enum PathStyle {
     Expr,
     /// In other contexts, notably in types, no ambiguity exists and paths can be written
     /// without the disambiguator, e.g. `x<y>` - unambiguously a path.
-    /// Paths with disambiguators are rejected for now, but may be allowed in the future.
+    /// Paths with disambiguators are still accepted, `x::<Y>` - unambiguously a path too.
     Type,
     /// A path with generic arguments disallowed, e.g. `foo::bar::Baz`, used in imports,
     /// visibilities or attributes.
@@ -1835,18 +1835,7 @@ fn parse_path_segment(&mut self, style: PathStyle) -> PResult<'a, PathSegment> {
                                       && self.look_ahead(1, |t| is_args_start(t)) {
             // Generic arguments are found - `<`, `(`, `::<` or `::(`.
             let lo = self.span;
-            if self.eat(&token::ModSep) {
-                // These errors are not strictly necessary and may be removed in the future.
-                if style == PathStyle::Type {
-                    let mut err = self.diagnostic().struct_span_err(self.prev_span,
-                        "unnecessary path disambiguator");
-                    err.span_label(self.prev_span, "try removing `::`");
-                    err.emit();
-                } else if self.token == token::OpenDelim(token::Paren) {
-                    self.diagnostic().span_err(self.prev_span,
-                        "`::` is not supported before parenthesized generic arguments")
-                }
-            }
+            self.eat(&token::ModSep);
 
             let parameters = if self.eat_lt() {
                 // `<'a, T, A = U>`
index 4b7f82943bac107fc1d4f9db620661de1422b984..ffbd0c0c22a7c07d2b7513e12a7fdcb18444222a 100644 (file)
@@ -19,15 +19,11 @@ fn main() {
     //~^ ERROR parenthesized parameters may only be used with a trait
     //~| WARN previously accepted
 
-    macro_rules! pathexpr {
-        ($p:path) => { $p }
-    }
-
-    let p = pathexpr!(::std::str()::from_utf8)(b"foo").unwrap();
+    let p = ::std::str::()::from_utf8(b"foo").unwrap();
     //~^ ERROR parenthesized parameters may only be used with a trait
     //~| WARN previously accepted
 
-    let p = pathexpr!(::std::str::from_utf8())(b"foo").unwrap();
+    let p = ::std::str::from_utf8::()(b"foo").unwrap();
     //~^ ERROR parenthesized parameters may only be used with a trait
     //~| WARN previously accepted
 
index 737955b2ff351a0580326424318a2d758ca5189c..18a6e430b84ded2c8b237f352d72cb88c988c28b 100644 (file)
@@ -8,16 +8,19 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+// Unnecessary path disambiguator is ok
+
+#![feature(rustc_attrs)]
+#![allow(unused)]
+
 struct Foo<T> {
     _a: T,
 }
 
-fn main() {
+fn f() {
     let f = Some(Foo { _a: 42 }).map(|a| a as Foo::<i32>);
-    //~^ ERROR unnecessary path disambiguator
-    //~| NOTE try removing `::`
-
     let g: Foo::<i32> = Foo { _a: 42 };
-    //~^ ERROR unnecessary path disambiguator
-    //~| NOTE try removing `::`
 }
+
+#[rustc_error]
+fn main() {} //~ ERROR compilation successful
diff --git a/src/test/compile-fail/unboxed-closure-sugar-used-on-struct-3.rs b/src/test/compile-fail/unboxed-closure-sugar-used-on-struct-3.rs
new file mode 100644 (file)
index 0000000..42fffe5
--- /dev/null
@@ -0,0 +1,28 @@
+// 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.
+
+// Test that parentheses form parses in expression paths.
+
+struct Bar<A,R> {
+    f: A, r: R
+}
+
+impl<A,B> Bar<A,B> {
+    fn new() -> Bar<A,B> { panic!() }
+}
+
+fn bar() {
+    let b = Bar::<isize, usize>::new(); // OK
+
+    let b = Bar::(isize, usize)::new(); // OK too (for the parser)
+    //~^ ERROR parenthesized parameters may only be used with a trait
+}
+
+fn main() {}
index 95c307c5670990ae72a21635cbd848cd1e77692f..cb018ff1bfa398f5272ca7e87c34add1747157a7 100644 (file)
@@ -24,4 +24,6 @@ fn main() {
     //~^ ERROR field expressions may not have generic arguments
     f.x::<>;
     //~^ ERROR field expressions may not have generic arguments
+    f.x::();
+    //~^ ERROR field expressions may not have generic arguments
 }
diff --git a/src/test/parse-fail/unboxed-closure-sugar-used-on-struct-3.rs b/src/test/parse-fail/unboxed-closure-sugar-used-on-struct-3.rs
deleted file mode 100644 (file)
index 548a507..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-// 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.
-
-// compile-flags: -Z parse-only
-
-// Test that parentheses form doesn't work in expression paths.
-
-struct Bar<A,R> {
-    f: A, r: R
-}
-
-impl<A,B> Bar<A,B> {
-    fn new() -> Bar<A,B> { panic!() }
-}
-
-fn bar() {
-    let b = Box::Bar::<isize,usize>::new(); // OK
-
-    let b = Box::Bar::()::new();
-    //~^ ERROR `::` is not supported before parenthesized generic arguments
-}
-
-fn main() { }