Suggest [tail @ ..] on [..tail] and [...tail] where tail is unresolved#120597
Suggest [tail @ ..] on [..tail] and [...tail] where tail is unresolved#120597bors merged 1 commit intorust-lang:masterfrom
[tail @ ..] on [..tail] and [...tail] where tail is unresolved#120597Conversation
| // where the user might have meant `[first, rest @ ..]`. | ||
| let (span, snippet) = match side { | ||
| Side::Start => (segment.ident.span.between(range.span), " @ ".into()), | ||
| Side::End => (range.span.to(segment.ident.span), format!("{} @ ..", segment.ident)), |
There was a problem hiding this comment.
I briefly experimented with a multipart suggestion here but I didn't like how it got rendered:
LL - [head, ..tail] => {}
LL + [head, tail @ ..] => {}
There was a problem hiding this comment.
And thus I reverted to a single-piece suggestion:
LL | [head, tail @ ..] => {}
| ~~~~~~~~~
There was a problem hiding this comment.
However, I can use a multipart suggestion if you'd like me to, of course.
There was a problem hiding this comment.
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.
4bdc63e to
285d8c2
Compare
| 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 | ||
| = help: use an inclusive range pattern, like N..=M |
There was a problem hiding this comment.
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.
| | | ||
| = 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 |
|
@bors r+ rollup |
…in-pat, r=estebank Suggest `[tail @ ..]` on `[..tail]` and `[...tail]` where `tail` is unresolved Fixes rust-lang#120591. ~~Will conflict with rust-lang#120570~~ (rebased). r? estebank or compiler
…in-pat, r=estebank Suggest `[tail @ ..]` on `[..tail]` and `[...tail]` where `tail` is unresolved Fixes rust-lang#120591. ~~Will conflict with rust-lang#120570~~ (rebased). r? estebank or compiler
…iaskrgr Rollup of 9 pull requests Successful merges: - rust-lang#120302 (various const interning cleanups) - rust-lang#120520 (Some cleanups around diagnostic levels.) - rust-lang#120521 (Make `NonZero` constructors generic.) - rust-lang#120527 (Switch OwnedStore handle count to AtomicU32) - rust-lang#120564 (coverage: Split out counter increment sites from BCB node/edge counters) - rust-lang#120575 (Simplify codegen diagnostic handling) - rust-lang#120597 (Suggest `[tail @ ..]` on `[..tail]` and `[...tail]` where `tail` is unresolved) - rust-lang#120609 (hir: Stop keeping prefixes for most of `use` list stems) - rust-lang#120633 (pattern_analysis: gather up place-relevant info) r? `@ghost` `@rustbot` modify labels: rollup
…iaskrgr Rollup of 12 pull requests Successful merges: - rust-lang#120520 (Some cleanups around diagnostic levels.) - rust-lang#120575 (Simplify codegen diagnostic handling) - rust-lang#120597 (Suggest `[tail @ ..]` on `[..tail]` and `[...tail]` where `tail` is unresolved) - rust-lang#120602 (rustc_monomorphize: fix outdated comment in partition) - rust-lang#120609 (hir: Stop keeping prefixes for most of `use` list stems) - rust-lang#120631 (Emit a diagnostic for invalid target options) - rust-lang#120632 (For E0223, suggest associated functions that are similar to the path) - rust-lang#120670 (cleanup effect var handling) - rust-lang#120673 (rustc_metadata: fix typo) - rust-lang#120683 (miri: fix ICE with symbolic alignment check on extern static) - rust-lang#120690 (Remove b-naber from the compiler review rotation) - rust-lang#120713 (Make async closures test use async bound modifier) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#120597 - fmease:sugg-on-js-style-spread-op-in-pat, r=estebank Suggest `[tail @ ..]` on `[..tail]` and `[...tail]` where `tail` is unresolved Fixes rust-lang#120591. ~~Will conflict with rust-lang#120570~~ (rebased). r? estebank or compiler
Fixes #120591.
Will conflict with #120570(rebased).r? estebank or compiler