Skip to content

Commit f7cc6dc

Browse files
committedOct 28, 2016
Fix bad error message with ::< in types
1 parent 46d39f3 commit f7cc6dc

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed
 

‎src/libsyntax/parse/parser.rs

+11
Original file line numberDiff line numberDiff line change
@@ -1757,6 +1757,17 @@ impl<'a> Parser<'a> {
17571757
// First, parse an identifier.
17581758
let identifier = self.parse_path_segment_ident()?;
17591759

1760+
if self.check(&token::ModSep) && self.look_ahead(1, |t| *t == token::Lt) {
1761+
self.bump();
1762+
let prev_span = self.prev_span;
1763+
1764+
let mut err = self.diagnostic().struct_span_err(prev_span,
1765+
"unexpected token: `::`");
1766+
err.help(
1767+
"use `<...>` instead of `::<...>` if you meant to specify type arguments");
1768+
err.emit();
1769+
}
1770+
17601771
// Parse types, optionally.
17611772
let parameters = if self.eat_lt() {
17621773
let (lifetimes, types, bindings) = self.parse_generic_values_after_lt()?;

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

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2016 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<T> {
12+
_a: T,
13+
}
14+
15+
fn main() {
16+
let f = Some(Foo { _a: 42 }).map(|a| a as Foo::<i32>);
17+
//~^ ERROR unexpected token: `::`
18+
//~| HELP use `<...>` instead of `::<...>` if you meant to specify type arguments
19+
20+
let g: Foo::<i32> = Foo { _a: 42 };
21+
//~^ ERROR unexpected token: `::`
22+
//~| HELP use `<...>` instead of `::<...>` if you meant to specify type arguments
23+
}

0 commit comments

Comments
 (0)
Please sign in to comment.