Skip to content

Commit 7d21f21

Browse files
committed
syntax: Relax path grammar
1 parent 13d94d5 commit 7d21f21

File tree

5 files changed

+20
-32
lines changed

5 files changed

+20
-32
lines changed

src/libsyntax/parse/parser.rs

+2-13
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ pub enum PathStyle {
8484
Expr,
8585
/// In other contexts, notably in types, no ambiguity exists and paths can be written
8686
/// without the disambiguator, e.g. `x<y>` - unambiguously a path.
87-
/// Paths with disambiguators are rejected for now, but may be allowed in the future.
87+
/// Paths with disambiguators are still accepted, `x::<Y>` - unambiguously a path too.
8888
Type,
8989
/// A path with generic arguments disallowed, e.g. `foo::bar::Baz`, used in imports,
9090
/// visibilities or attributes.
@@ -1835,18 +1835,7 @@ impl<'a> Parser<'a> {
18351835
&& self.look_ahead(1, |t| is_args_start(t)) {
18361836
// Generic arguments are found - `<`, `(`, `::<` or `::(`.
18371837
let lo = self.span;
1838-
if self.eat(&token::ModSep) {
1839-
// These errors are not strictly necessary and may be removed in the future.
1840-
if style == PathStyle::Type {
1841-
let mut err = self.diagnostic().struct_span_err(self.prev_span,
1842-
"unnecessary path disambiguator");
1843-
err.span_label(self.prev_span, "try removing `::`");
1844-
err.emit();
1845-
} else if self.token == token::OpenDelim(token::Paren) {
1846-
self.diagnostic().span_err(self.prev_span,
1847-
"`::` is not supported before parenthesized generic arguments")
1848-
}
1849-
}
1838+
self.eat(&token::ModSep);
18501839

18511840
let parameters = if self.eat_lt() {
18521841
// `<'a, T, A = U>`

src/test/compile-fail/issue-32995.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,11 @@ fn main() {
1919
//~^ ERROR parenthesized parameters may only be used with a trait
2020
//~| WARN previously accepted
2121

22-
macro_rules! pathexpr {
23-
($p:path) => { $p }
24-
}
25-
26-
let p = pathexpr!(::std::str()::from_utf8)(b"foo").unwrap();
22+
let p = ::std::str::()::from_utf8(b"foo").unwrap();
2723
//~^ ERROR parenthesized parameters may only be used with a trait
2824
//~| WARN previously accepted
2925

30-
let p = pathexpr!(::std::str::from_utf8())(b"foo").unwrap();
26+
let p = ::std::str::from_utf8::()(b"foo").unwrap();
3127
//~^ ERROR parenthesized parameters may only be used with a trait
3228
//~| WARN previously accepted
3329

src/test/compile-fail/issue-36116.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,19 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// Unnecessary path disambiguator is ok
12+
13+
#![feature(rustc_attrs)]
14+
#![allow(unused)]
15+
1116
struct Foo<T> {
1217
_a: T,
1318
}
1419

15-
fn main() {
20+
fn f() {
1621
let f = Some(Foo { _a: 42 }).map(|a| a as Foo::<i32>);
17-
//~^ ERROR unnecessary path disambiguator
18-
//~| NOTE try removing `::`
19-
2022
let g: Foo::<i32> = Foo { _a: 42 };
21-
//~^ ERROR unnecessary path disambiguator
22-
//~| NOTE try removing `::`
2323
}
24+
25+
#[rustc_error]
26+
fn main() {} //~ ERROR compilation successful

src/test/parse-fail/unboxed-closure-sugar-used-on-struct-3.rs renamed to src/test/compile-fail/unboxed-closure-sugar-used-on-struct-3.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// compile-flags: -Z parse-only
12-
13-
// Test that parentheses form doesn't work in expression paths.
11+
// Test that parentheses form parses in expression paths.
1412

1513
struct Bar<A,R> {
1614
f: A, r: R
@@ -21,10 +19,10 @@ impl<A,B> Bar<A,B> {
2119
}
2220

2321
fn bar() {
24-
let b = Box::Bar::<isize,usize>::new(); // OK
22+
let b = Bar::<isize, usize>::new(); // OK
2523

26-
let b = Box::Bar::()::new();
27-
//~^ ERROR `::` is not supported before parenthesized generic arguments
24+
let b = Bar::(isize, usize)::new(); // OK too (for the parser)
25+
//~^ ERROR parenthesized parameters may only be used with a trait
2826
}
2927

30-
fn main() { }
28+
fn main() {}

src/test/parse-fail/type-parameters-in-field-exprs.rs

+2
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,6 @@ fn main() {
2424
//~^ ERROR field expressions may not have generic arguments
2525
f.x::<>;
2626
//~^ ERROR field expressions may not have generic arguments
27+
f.x::();
28+
//~^ ERROR field expressions may not have generic arguments
2729
}

0 commit comments

Comments
 (0)