1
Fork 0

Reject integer suffix when tuple indexing

This commit is contained in:
Esteban Küber 2019-03-25 16:11:21 -07:00
parent 4c27fb19ba
commit 91b7423760
3 changed files with 69 additions and 43 deletions

View file

@ -3199,11 +3199,20 @@ impl<'a> Parser<'a> {
token::Ident(..) => {
e = self.parse_dot_suffix(e, lo)?;
}
token::Literal(token::Integer(name), _) => {
token::Literal(token::Integer(name), suffix) => {
let span = self.span;
self.bump();
let field = ExprKind::Field(e, Ident::new(name, span));
e = self.mk_expr(lo.to(span), field, ThinVec::new());
if let Some(suffix) = suffix {
let mut err = self.diagnostic().struct_span_err(
span,
"tuple index with a suffix is invalid",
);
err.span_label(span, format!("invalid suffix `{}`", suffix));
err.emit();
}
}
token::Literal(token::Float(n), _suf) => {
self.bump();

View file

@ -0,0 +1,9 @@
struct X(i32,i32,i32);
fn main() {
let a = X(1, 2, 3);
let b = a.1suffix;
//~^ ERROR tuple index with a suffix is invalid
println!("{}", b);
}

View file

@ -0,0 +1,8 @@
error: tuple index with a suffix is invalid
--> $DIR/issue-59418.rs:5:15
|
LL | let b = a.1suffix;
| ^^^^^^^ invalid suffix `suffix`
error: aborting due to previous error