in which `..` is suggested for erroneous `...` in struct field patterns
Resolves #46718.
This commit is contained in:
parent
b3392f8ae4
commit
d40197c471
|
@ -1212,6 +1212,9 @@ impl<'a> Parser<'a> {
|
|||
pub fn span_err(&self, sp: Span, m: &str) {
|
||||
self.sess.span_diagnostic.span_err(sp, m)
|
||||
}
|
||||
pub fn struct_span_err(&self, sp: Span, m: &str) -> DiagnosticBuilder<'a> {
|
||||
self.sess.span_diagnostic.struct_span_err(sp, m)
|
||||
}
|
||||
pub fn span_err_help(&self, sp: Span, m: &str, h: &str) {
|
||||
let mut err = self.sess.span_diagnostic.mut_span_err(sp, m);
|
||||
err.help(h);
|
||||
|
@ -3445,7 +3448,16 @@ impl<'a> Parser<'a> {
|
|||
let lo = self.span;
|
||||
let hi;
|
||||
|
||||
if self.check(&token::DotDot) {
|
||||
if self.check(&token::DotDot) || self.token == token::DotDotDot {
|
||||
if self.token == token::DotDotDot { // Issue #46718
|
||||
let mut err = self.struct_span_err(self.span,
|
||||
"expected field pattern, found `...`");
|
||||
err.span_suggestion(self.span,
|
||||
"to omit remaining fields, use one fewer `.`",
|
||||
"..".to_owned());
|
||||
err.emit();
|
||||
}
|
||||
|
||||
self.bump();
|
||||
if self.token != token::CloseDelim(token::Brace) {
|
||||
let token_str = self.this_token_to_string();
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
// Copyright 2017 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.
|
||||
|
||||
#![allow(unused)]
|
||||
|
||||
struct PersonalityInventory {
|
||||
expressivity: f32,
|
||||
instrumentality: f32
|
||||
}
|
||||
|
||||
impl PersonalityInventory {
|
||||
fn expressivity(&self) -> f32 {
|
||||
match *self {
|
||||
PersonalityInventory { expressivity: exp, ... } => exp
|
||||
//~^ ERROR expected field pattern, found `...`
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
|
@ -0,0 +1,8 @@
|
|||
error: expected field pattern, found `...`
|
||||
--> $DIR/issue-46718-struct-pattern-dotdotdot.rs:21:55
|
||||
|
|
||||
21 | PersonalityInventory { expressivity: exp, ... } => exp
|
||||
| ^^^ help: to omit remaining fields, use one fewer `.`: `..`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
Loading…
Reference in New Issue