diff options
| author | Zack M. Davis <code@zackmdavis.net> | 2017-12-16 00:58:19 -0800 |
|---|---|---|
| committer | Zack M. Davis <code@zackmdavis.net> | 2017-12-16 00:58:19 -0800 |
| commit | d40197c47196d4abb8ecb897a64ac11026d95623 (patch) | |
| tree | 8eea369af36d487dd74a557c7ec410771f025769 /src | |
| parent | b3392f8ae4074de4de15befee871ad8b1523a2ed (diff) | |
| download | rust-d40197c47196d4abb8ecb897a64ac11026d95623.tar.gz rust-d40197c47196d4abb8ecb897a64ac11026d95623.zip | |
in which `..` is suggested for erroneous `...` in struct field patterns
Resolves #46718.
Diffstat (limited to 'src')
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 14 | ||||
| -rw-r--r-- | src/test/ui/did_you_mean/issue-46718-struct-pattern-dotdotdot.rs | 27 | ||||
| -rw-r--r-- | src/test/ui/did_you_mean/issue-46718-struct-pattern-dotdotdot.stderr | 8 |
3 files changed, 48 insertions, 1 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index ec77d85f030..2158c4a4fe4 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -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(); diff --git a/src/test/ui/did_you_mean/issue-46718-struct-pattern-dotdotdot.rs b/src/test/ui/did_you_mean/issue-46718-struct-pattern-dotdotdot.rs new file mode 100644 index 00000000000..0d3ac8740e2 --- /dev/null +++ b/src/test/ui/did_you_mean/issue-46718-struct-pattern-dotdotdot.rs @@ -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() {} diff --git a/src/test/ui/did_you_mean/issue-46718-struct-pattern-dotdotdot.stderr b/src/test/ui/did_you_mean/issue-46718-struct-pattern-dotdotdot.stderr new file mode 100644 index 00000000000..69a76b923b8 --- /dev/null +++ b/src/test/ui/did_you_mean/issue-46718-struct-pattern-dotdotdot.stderr @@ -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 + |
