Skip to content

Commit e6e58e4

Browse files
committed
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]
1 parent 5d29209 commit e6e58e4

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

src/libsyntax/parse/parser.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -2415,9 +2415,16 @@ impl<'a> Parser<'a> {
24152415
e = self.mk_expr(lo, hi, nd);
24162416
}
24172417
_ => {
2418+
if !tys.is_empty() {
2419+
let last_span = self.last_span;
2420+
self.span_err(last_span,
2421+
"field expressions may not \
2422+
have type parameters");
2423+
}
2424+
24182425
let id = spanned(dot, hi, i);
24192426
let field = self.mk_field(e, id, tys);
2420-
e = self.mk_expr(lo, hi, field)
2427+
e = self.mk_expr(lo, hi, field);
24212428
}
24222429
}
24232430
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2014 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+
y: int,
14+
}
15+
16+
fn main() {
17+
let f = Foo {
18+
x: 1,
19+
y: 2,
20+
};
21+
f.x::<int>;
22+
//~^ ERROR field expressions may not have type parameters
23+
}
24+

0 commit comments

Comments
 (0)