-
Notifications
You must be signed in to change notification settings - Fork 13k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Suggest [tail @ ..]
on [..tail]
and [...tail]
where tail
is unresolved
#120597
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,23 @@ | ||
fn main() { | ||
match &[1, 2, 3][..] { | ||
[1, rest..] => println!("{rest:?}"), | ||
[1, rest..] => println!("{rest}"), | ||
//~^ ERROR cannot find value `rest` in this scope | ||
//~| ERROR cannot find value `rest` in this scope | ||
//~| ERROR `X..` patterns in slices are experimental | ||
_ => {} | ||
} | ||
match &[4, 5, 6][..] { | ||
[] => {} | ||
[_, ..tail] => println!("{tail}"), | ||
//~^ ERROR cannot find value `tail` in this scope | ||
//~| ERROR cannot find value `tail` in this scope | ||
//~| ERROR exclusive range pattern syntax is experimental | ||
} | ||
match &[7, 8, 9][..] { | ||
[] => {} | ||
[_, ...tail] => println!("{tail}"), | ||
//~^ ERROR cannot find value `tail` in this scope | ||
//~| ERROR cannot find value `tail` in this scope | ||
//~| ERROR range-to patterns with `...` are not allowed | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,82 @@ | ||
error: range-to patterns with `...` are not allowed | ||
--> $DIR/range-pattern-meant-to-be-slice-rest-pattern.rs:18:13 | ||
| | ||
LL | [_, ...tail] => println!("{tail}"), | ||
| ^^^ help: use `..=` instead | ||
|
||
error[E0425]: cannot find value `rest` in this scope | ||
--> $DIR/range-pattern-meant-to-be-slice-rest-pattern.rs:3:13 | ||
| | ||
LL | [1, rest..] => println!("{rest:?}"), | ||
LL | [1, rest..] => println!("{rest}"), | ||
| ^^^^ not found in this scope | ||
| | ||
help: if you meant to collect the rest of the slice in `rest`, use the at operator | ||
| | ||
LL | [1, rest @ ..] => println!("{rest:?}"), | ||
LL | [1, rest @ ..] => println!("{rest}"), | ||
| + | ||
|
||
error[E0425]: cannot find value `rest` in this scope | ||
--> $DIR/range-pattern-meant-to-be-slice-rest-pattern.rs:3:35 | ||
| | ||
LL | [1, rest..] => println!("{rest:?}"), | ||
LL | [1, rest..] => println!("{rest}"), | ||
| ^^^^ not found in this scope | ||
|
||
error[E0425]: cannot find value `tail` in this scope | ||
--> $DIR/range-pattern-meant-to-be-slice-rest-pattern.rs:11:15 | ||
| | ||
LL | [_, ..tail] => println!("{tail}"), | ||
| ^^^^ not found in this scope | ||
| | ||
help: if you meant to collect the rest of the slice in `tail`, use the at operator | ||
| | ||
LL | [_, tail @ ..] => println!("{tail}"), | ||
| ~~~~~~~~~ | ||
|
||
error[E0425]: cannot find value `tail` in this scope | ||
--> $DIR/range-pattern-meant-to-be-slice-rest-pattern.rs:11:35 | ||
| | ||
LL | [_, ..tail] => println!("{tail}"), | ||
| ^^^^ not found in this scope | ||
|
||
error[E0425]: cannot find value `tail` in this scope | ||
--> $DIR/range-pattern-meant-to-be-slice-rest-pattern.rs:18:16 | ||
| | ||
LL | [_, ...tail] => println!("{tail}"), | ||
| ^^^^ not found in this scope | ||
| | ||
help: if you meant to collect the rest of the slice in `tail`, use the at operator | ||
| | ||
LL | [_, tail @ ..] => println!("{tail}"), | ||
| ~~~~~~~~~ | ||
|
||
error[E0425]: cannot find value `tail` in this scope | ||
--> $DIR/range-pattern-meant-to-be-slice-rest-pattern.rs:18:36 | ||
| | ||
LL | [_, ...tail] => println!("{tail}"), | ||
| ^^^^ not found in this scope | ||
|
||
error[E0658]: `X..` patterns in slices are experimental | ||
--> $DIR/range-pattern-meant-to-be-slice-rest-pattern.rs:3:13 | ||
| | ||
LL | [1, rest..] => println!("{rest:?}"), | ||
LL | [1, rest..] => println!("{rest}"), | ||
| ^^^^^^ | ||
| | ||
= note: see issue #67264 <https://github.com/rust-lang/rust/issues/67264> for more information | ||
= help: add `#![feature(half_open_range_patterns_in_slices)]` to the crate attributes to enable | ||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date | ||
|
||
error: aborting due to 3 previous errors | ||
error[E0658]: exclusive range pattern syntax is experimental | ||
--> $DIR/range-pattern-meant-to-be-slice-rest-pattern.rs:11:13 | ||
| | ||
LL | [_, ..tail] => println!("{tail}"), | ||
| ^^^^^^ | ||
| | ||
= note: see issue #37854 <https://github.com/rust-lang/rust/issues/37854> for more information | ||
= help: add `#![feature(exclusive_range_pattern)]` to the crate attributes to enable | ||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hadn't seen this! Nice! |
||
= help: use an inclusive range pattern, like N..=M | ||
Comment on lines
+68
to
+77
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd like it if we could bubble information about having given a suggestion so that we don't provide less useful messages, but whatever, it's not the end of the world and it could be that someone is trying to use this nightly feature. |
||
|
||
error: aborting due to 9 previous errors | ||
|
||
Some errors have detailed explanations: E0425, E0658. | ||
For more information about an error, try `rustc --explain E0425`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I briefly experimented with a multipart suggestion here but I didn't like how it got rendered:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And thus I reverted to a single-piece suggestion:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
However, I can use a multipart suggestion if you'd like me to, of course.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I personally prefer the diff output, because it has less opportunity for confusion and behaves better in the face of longer pieces of code (think complex nested patterns, in this case it will always be an ident so it's fine), but don't care either way, as long as the users get the information.